Skip to main content

A simple calculator programme

Project description

A simple calculator

This is a simple calculator when I try to recall my compiler courses.


Use the package manager pip to install compiler-calc.

pip install compiler-calc 


from compiler_calc.simple_calc import LexAnalysis, SyntaxAnalysis

# To highlight lexcial and syntax analysis
lex_analyser = LexAnalysis()
syntax_analyser = SyntaxAnalysis()

# You can define your own helper functions
def calculate(expr, lex=lex_analyser, syn=syntax_analyser):
    expr_list = lex(expr)
    return syn(expr_list)

calculate('5+4*3^2') # 41
calculate('1/0') # ValueError


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for compiler-calc, version 0.0.1rc4
Filename, size File type Python version Upload date Hashes
Filename, size compiler-calc-0.0.1rc4.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page