Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 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)
|
||||
}
|
||||
8
Task/Arithmetic-evaluation/E/arithmetic-evaluation-2.e
Normal file
8
Task/Arithmetic-evaluation/E/arithmetic-evaluation-2.e
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
? arithEvaluate("1 + 2")
|
||||
# value: 3
|
||||
|
||||
? arithEvaluate("(1 + 2) * 10 / 100")
|
||||
# value: 0.3
|
||||
|
||||
? arithEvaluate("(1 + 2 / 2) * (5 + 5)")
|
||||
# value: 20.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue