Skip to content

Abstract Syntax Tree Models for basic arithmetic expressions.

License

Notifications You must be signed in to change notification settings

0x1000000/Expressions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code for article "Abstract Syntax Tree TODO"

Abstract Syntax Tree Models for basic arithmetic expressions.

They allow printing, evaluation, modification:

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

About

Abstract Syntax Tree Models for basic arithmetic expressions.

Topics

Resources

License

Stars

Watchers

Forks

Languages