Skip to content

REPL Support - Group 5 #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

JohnnySpider
Copy link

Documentation

Group Members

  • João Pedro Daher Aranha - 190109742
  • João Ubirajara - 211055399
  • Kauan Henrique - 221017050
  • Paulo Filho - 200025937
  • Ramon Oliveira de Azevedo - 242039630

Summary

This pull request implements Read-Eval-Print Loop (REPL) and Command Line Interface (CLI) to the R-Python language.

  • The command to generate an executable for RPython is cargo run --release and the generated executable is in r-python-REPL/target/release
  • To run a r-python program via cli, the command is cargo run -- --exec path_to_r-python_file or ./r-python --exec path_to_r-python_file. The cli outputs by default the environment before and after execution, since the 'print' statement was not yet available.
  • REPL is initialized via ./r-python and expects ';' as end character to every line provided to the program. This decision was used so that REPL supports multiline statements like 'IfThenElse'.
  • cargo run -- -h or ./r-python -h shows all available options to run.
  • The REPL is integrated to type_checker via check_exp and check_stmt functions

Functions

  • main.rs function can invoke repl() or cli() depending on the arguments provided.
pub fn repl( env: Option<Environment<EnvValue>>,env_type: Option<Environment<Type>>) -> io::Result<()>
pub fn cli(file_path: &String) -> io::Result<()>

REPL functions

fn repl_parse_expression(input: &str,current_env: &Environment<EnvValue>,current_env_type: &Environment<Type>) -> Result<String, String>
fn repl_parse_statements(input: &str, mut current_env: Environment<EnvValue>, mut current_env_type: Environment<Type>) -> Result<(Environment<EnvValue>, Environment<Type>), String>

Each function takes an input string, along with two environments: one for variable names and values (Environment<EnvValue>) and one for variable types (Environment<Type>). Since only assignments modify the environment, only the second function arguments are mutable.

The repl_parse_statement returns a tuple (Environment <EnvValue>, Environment<Type>), which is verified in tests.

Features

Inline rpython via CLI

Usage: cargo run -- -c "10+10" or ./rpython -c "10+10"

Executes file and loads environment in REPL

Usage: cargo run -- --exec path_to_rpython_file -i or ./rpython --exec path_to_rpython_file -i

Supports internal commands in REPL preceded by !:

  • !exit: Terminates the REPL session.
  • !reset: Resets the execution environment.
  • !clear: Clears the screen.
  • !help: Displays available commands.

Tests

  • The functionalitites where tested through 18 tests in repl.rs, which integrates both interpreter and type checker verifications.
  • The language enforces that a variable’s type is fixed after its first assignment. For example, the statement a=10 followed by a=True will result in a type mismatch error.

Other fixes

  • Updated tests: test_propagation_parsing_statements() and check_assignment_error1() have been modified to ensure that types are handled by the type checker (inference), rather than by the parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants