Cynthia is a small interpreted script language for basic mathematical expressions.
Project description
Cynthia script language
Cynthia is a small interpreted script language for basic mathematical expressions written in python.
The language currently supports:
- the four fundamental operations of arithmetic (addition, subtraction, multiplication, division)
- parentheses which can modify the order of operations.
- variables and variable assignments
- a number of built-in functions
Built-in functions:
min(*args) -> number
Returns the minimum value of the arguments.
max(*args) -> number
Returns the maximum value of the arguments.
print(*args)
Prints the arguments to the standard output.
Installation
pip install cynthia-language
Usage
shell enviroment
Cynthia language can be run in a shell enviroment where each expression will be evaluated and printed out to the standard output.
$: python -m cynthia
cynthia> 3 * (5 + 2) / 4
5.25
cynthia> x = 3 * 3
cynthia> 4 * x - 5
31
executing .cynthia files
Cynthia language code can be written in .cynthia files:
# example.cynthia file
# you can write comments
a = 1
b = 2
c = a + b * 3
result = min(a, b, c)
print(result)
Which can be executed with the interpreter:
python -m cynthia example.cynthia
CFG for the syntax
program
: statement_list EOF
;
statement_list
: statement
| statement EOL statement_list
;
statement
: assignment_statement
| expr
| EMPTY
;
assignment_statement
: VARIABLE ASSIGN expr
;
expr
: term
| term PLUS expr
| term MINUS expr
:
term
: factor
| factor MUL term
| factor DIV term
;
factor
: NUMBER
| VARIABLE
| L_PAREN expr R_PAREN
| PLUS expr
| MINUS expr
| function_call
;
function_call
: ID L_PAREN args R_PAREN
;
args
: expr
| expr COMMA args
;
Use the language tools directly
Language tools can be used directly.
from cynthia.tools import Interpreter
interpreter = Interpreter()
interpreter.interpret('x=1+2')
interpreter['x']
# 3
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cynthia_language-0.1.3.tar.gz.
File metadata
- Download URL: cynthia_language-0.1.3.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a2f925ad49d9f129eaa16f61aa51dad734534d6fcaaa7c47a110582106b8bad
|
|
| MD5 |
cb24401867e0939d9b68e1494ee0aef7
|
|
| BLAKE2b-256 |
2f8b16da4c7a9c4df914325b4d207ba7a496d9bdb5ee8b7f4ac35a47c5f7a63d
|
File details
Details for the file cynthia_language-0.1.3-py3-none-any.whl.
File metadata
- Download URL: cynthia_language-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9826fbf0cc747da23ea14f01389909b06320c99078864558de893f641d2bd69
|
|
| MD5 |
5b61ceb924449a5b21dfb975adbed111
|
|
| BLAKE2b-256 |
9e1fd18a6bdea0b9a97f1bd6f4066d14d57b72e5e1e22a4c95760f57496f2c34
|