Skip to content

2. rajinipp: The interpreter

Aadhithya Sankar edited this page May 17, 2022 · 4 revisions

The rajini++ code one writes is interpreted as executable python code, thanks to the rajinipp interpreter. In fact, it is the interpreter that is developed in this project. This page documents the exposed api of the interpreter.

rajinipp.runner

  • rajinipp.runner exposes the rajini++ interpreter to accessed from python scripts.

rajinipp.runner.RppRunner

  • The rajinipp.runner.RppRunner class allows access to the rajinipp interpreter
  • In fact, the rajinipp.runner.RppRunner function is used in the tests for the rajiniPP repository!
  • rajinipp.runner.RppRunner can in principle be used in any python script to execute rajini++ code.

Methods

  • rajinipp.runner.RppRunner.tokenize(code: str): tokenizes the input rajini++ code and returns the tokens.
  • rajinipp.runner.RppRunner.exec(code: str, log_level:str="ERROR:"): Executes the input rajini++ program code.
  • rajinipp.runner.RppRunner.eval(code_line: str, log_level:str="ERROR:"): evaluates the input rajini++ statement and returns the output.

Embedding rajini++ code in python scripts

Because the rajinipp interpreter is written completely in python, it is possible to run rajini++ code inside python scripts (experimental)!

Example Code:

<script src="https://gist.github.com/aadhithya/1e61d2af32fc77e24da9772a5b6022ba.js"></script>

Output:

Hello, World from python!
Hello world from rajini++!
Executing 5+5 in rajini++
5 + 5 = 10.0