Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Arithmetic-evaluation/E/arithmetic-evaluation-1.e
Normal file
18
Task/Arithmetic-evaluation/E/arithmetic-evaluation-1.e
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def eParser := <elang:syntax.makeEParser>
|
||||
def LiteralExpr := <elang:evm.makeLiteralExpr>.asType()
|
||||
def arithEvaluate(expr :String) {
|
||||
def ast := eParser(expr)
|
||||
|
||||
def evalAST(ast) {
|
||||
return switch (ast) {
|
||||
match e`@a + @b` { evalAST(a) + evalAST(b) }
|
||||
match e`@a - @b` { evalAST(a) - evalAST(b) }
|
||||
match e`@a * @b` { evalAST(a) * evalAST(b) }
|
||||
match e`@a / @b` { evalAST(a) / evalAST(b) }
|
||||
match e`-@a` { -(evalAST(a)) }
|
||||
match l :LiteralExpr { l.getValue() }
|
||||
}
|
||||
}
|
||||
|
||||
return evalAST(ast)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue