Trabajo Práctico Parseo y Generación de Código

Los tests se encuentran en la carpeta "./src/test":

  • Tests TP1 en la carpeta "tests_parser_json".

  • Tests TP2 en la carpeta "tests_interpreter".

Pre-requirements

Note: If "py" not works use "python3" / "python".

Docker

  1. Go to repository root folder

  2. Build image from Dockerfile with:

    docker build -t flecha .
  3. Execute image as container with:

    docker run -it --entrypoint bash --name flecha flecha
  4. Use commands in Tests or Execute sections (you might need to replace command "py" with "python3")

Set up

From requirement.txt file

pip install -r requirements.txt

Tests

py -m pytest -v

Execute

Help command

py ./src/main.py -h

Priority

Some commands has priority. This means that a command which has more priority force to execute in that mode and output that mode until execution ends

Commands with priorities:

1- REPL (-r|--repl) 2- Tokenizer Mode (-tM|--repl) 3- Parser Mode (-p|-pM)

Note:The priority is 1 to N where less value is more priority than a greater one

Example:

  • command -r will execute as REPL.
  • command -tM will execute as 'Tokenizer Mode' and only return all program tokens as output.
  • command -pM will execute as 'Parser mode' and only return an ast program as output.
  • command -r -pM will execute as REPL.
  • command -pM -tM will execute as Tokenizer Mode.

Enable REPL

Enables Read Evaluate Print Loop. Note: disable all other flags

py ./src/main.py -r

Example with flag "-s" or "--stringProgram"

py ./src/main.py -s "def main = 12 * 234"

Example with flag "-i" or "--inputFile"

py ./src/main.py -i "./src/test/tests_interpreter/test18.input"

Note: need to be executed from root of repo

Example with flag "-o" or "--outputFile"

py ./src/main.py -i "./src/test/tests_interpreter/test18.input" -o "./out/test18.input"

Note: need to be executed from root of repo

Show tokens with flags "-t" or "--tokenize"

py ./src/main.py -t -i "./src/test/tests_interpreter/test18.input"

Only tokenize and return tokens with flags "-tM" or "--tokenizeMode"

py ./src/main.py -tM -i "./src/test/tests_interpreter/test18.input"

Show parsed AST with flags "-p" or "--parse"

py ./src/main.py -p -i "./src/test/tests_interpreter/test18.input"

Only parse and return parsed AST with flags "-pM" or "--parseMode"

py ./src/main.py -pM -i "./src/test/tests_interpreter/test18.input"

Enable debug info (such as: Program Input) with flags "-d" or "--debug"

py ./src/main.py -d -p -t -i "./src/test/tests_interpreter/test18.input"