https://github.com/flosch/blogmath
A simple sample compiler
https://github.com/flosch/blogmath
Last synced: over 1 year ago
JSON representation
A simple sample compiler
- Host: GitHub
- URL: https://github.com/flosch/blogmath
- Owner: flosch
- Created: 2013-02-24T23:38:23.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-09-14T23:21:13.000Z (almost 13 years ago)
- Last Synced: 2025-01-23T14:16:03.970Z (over 1 year ago)
- Language: Python
- Homepage: http://www.florian-schlachter.de/?tag=compiler
- Size: 129 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Blogmath
========
A simple sample compiler/interpreter - see my compiler course at http://www.florian-schlachter.de/post/compilerbau-1/
Usage
=====
$ cat test1.bm
var c = 2; // Exponent
var s = 0.5;
// Funktion zur Potenzierung
lambda pow(a) = a^c;
// Funktion zum Wurzelziehen
lambda sqrt(a) = a^s;
// Ergebnis berechnen von 5^2
var result = pow(5);
// Ergebnis berechnen von 25^0.5
var result2 = sqrt(result);
// Ergebnis ausgeben
print(result); // Gibt 25 aus
print(result2); // Gibt 5 aus
$ python blogmath.py test1.bm
Blogmath-Interpreter
Executing test1.bm...
25.0
5.0
$ python blogmath.py
Blogmath-Interpreter
('quit' or CTRL-C to terminate)
> lambda pow(x, y) = x^y;
> lambda sqrt(x) = x^0.5;
> var hundert = pow(10, 2);
> print(hundert);
100.0
> print(sqrt(hundert));
10.0
> lambda pow10(x) = pow(x, 10);
> pow10(2);
1024.0
> print(2+12/2);
8.0
> print(5+4/3); // ohne Klammerung
6.33333333333
> print((5+4)/3); // mit Klammerung
3.0
> quit