https://github.com/0x1000000/expressions
Abstract Syntax Tree Models for basic arithmetic expressions.
https://github.com/0x1000000/expressions
arithmetic-expressions
Last synced: about 1 year ago
JSON representation
Abstract Syntax Tree Models for basic arithmetic expressions.
- Host: GitHub
- URL: https://github.com/0x1000000/expressions
- Owner: 0x1000000
- License: mit
- Created: 2020-09-16T17:20:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-16T17:25:08.000Z (almost 6 years ago)
- Last Synced: 2023-12-18T02:29:23.956Z (over 2 years ago)
- Topics: arithmetic-expressions
- Language: C#
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Code for article "Abstract Syntax Tree TODO"
Abstract Syntax Tree Models for basic arithmetic expressions.
They allow printing, evaluation, modification:
```cs
Expr expr = Parser.Parse("1+(5-2)*2");
Console.WriteLine($"{expr.Print()} = {expr.Evaluate()}");
expr = 2*expr - 3;
Console.WriteLine($"{expr.Print()} = {expr.Evaluate()}");
var exprSimple = expr.OpenParentheses();
Console.WriteLine($"{expr.Print()} = {exprSimple.Print()} = {exprSimple.Evaluate()}");
```
Result:
```
1+(5-2)*2 = 7
2*(1+(5-2)*2)-3 = 11
2*(1+(5-2)*2)-3 = 2*1+2*5*2-2*2*2-3 = 11
```