Package: ply-pybasic
# pybasicA structured BASIC interpreter written in Python.```plainusage: pybasic.py [-h] [-a] [-s AST_PATH] [program_name]Execute pybasic programs, or start an REPL session.positional arguments:program_name          The path of the source program to execute. If notspecified, an REPL session will be started.optional arguments:-h, --help            show this help message and exit-a, --ast             Execute a binary abstract syntax tree file rather thana source program. This will be ignored in REPL mode.-s AST_PATH, --save AST_PATHSave the binary abstract syntax tree of the sourceprogram to the given path. The source program will notbe executed. This will be ignored in REPL mode.```#### expressionsSupported expressions:- `<expression>`: Math expressions. Support operators: `+`, `-`, `*`,`/`, `\`(exact division), `MOD`- `<rel_expression>`: Logic expressions. Support operators: `AND`,`OR`, `NOT`, `=`(equals to), `<>`Please notice `=` in `<rel_expression>` is different from `=` in assignment statement.Literal values and function calls are also treated as `<expression>`. For example:```basic123                ' 123123.5              ' 123.5"123!"             ' "123!"{1, 2, 3}          ' [1, 2, 3]SQR(5)             ' 2.23606797749979```#### assignmentsUse `LET <id> = <expression>` or simply `<id> = <expression>`.Declarations are not required, for a variable are defined immediately before it is assigned for the first time. However, you can still use `DIM` to create an array filled with initial values. For example:```basicDIM A(5) AS INTEGERPRINT A     ' [0, 0, 0, 0, 0]```#### control structuresSupported control structures:- `WHILE <rel_expression> ... END WHILE / WEND`- `DO ... LOOP`- `DO ... LOOP WHILE / UNTIL <rel_expression>`- `FOR <id> = <expression> TO <expression> ... NEXT <id> / END FOR`Please notice that `GOTO` is not supported.#### data typesSupported data types:- `INTEGER` (mapped to Python type `int`)- `DECIMAL` (mapped to Python type `float`)- `STRING` (mapped to Python type `str`)Please notice that pybasic does not actually store data types, which means the type of variables can be modified at runtime.Use `AS` operator to do type conversions. For example:```basic2.5 AS INTEGER       ' 22.5 AS STRING        ' "2.5"```#### functionsSome inner functions are provided, like `SQR()` and etc.Single-line functions can be defined with `DEFUN`. For example:```basicDEFUN F(x) = x * xPRINT F(5)          ' 25```Multi-line functions can be defined with `SUB ... END SUB` or `FUNCTION ... END FUNCTION`.Functions can be called directly by using the function name as an order. For example:```basicDEFUN PRTYES(s) = PRINT("yes! " + s)SUB PRTYEAH(s)PRINT "yeah! " + sEND SUBPRTYES "pybasic"           ' "yes! pybasic"PRTYEAH "pybasic"          ' "yeah! pybasic"```#### I/OUnlike most BASIC dialects, pybasic provides `PRINT()` and `INPUT()` functions instead of statements. For example:```basicA = INPUT() AS INTEGER    ' input 17PRINT "My age is " + A    ' "My age is 17"```#### modulesUse ```USE``` to import a Python module or another pybasic program. Pybasic will try finding a file ended with ```.bas``` or ```.py``` following the module's name in the current working directory. If no such file is finded, an error will be raised. For example:```basic' HELLO.basFUNCTION PRTHELLO(A)PRINT "Hello, " + AEND FUNCTION``````python# MORNING.pyfrom pybasic import global_table@global_table.reflect('PRTMORN')def print_morning(a):print('Good morning, %s' % a)``````basic' MAIN.basUSE HELLOUSE MORNINGPRTHELLO "Jack" ' Hello, JackPRTMORN "Mary"  ' Good morning, Mary```Any code in the module will be executed. If the module is python-based, it will be executed at runtime; if it is pybasic-based, it will be compiled into the main program before being executed.