Arithmetic evaluation: Difference between revisions

m (→‎{{header|Sidef}}: code simplifications)
Line 1,060:
=={{header|Elena}}==
<lang elena>#define system.
#define system'routines.
#define extensions.
 
Line 1,075 ⟶ 1,076:
#method level = theLevel.
#method append &char: aChar
[
theValue += aChar.
]
#method number = convertor toReal:(theValue value) toReal.
}
 
Line 1,120 ⟶ 1,121:
#method number = theLeft number - theRight number.
}
 
// --- ProductNode ---
 
#class ProductNode :: Node
Line 1,161 ⟶ 1,160:
#method number => theTop.
}
 
// --- ProductNodeStates ---
 
#symbol operatorState = (:ch)
Line 1,169 ⟶ 1,170:
]
! [
self new &token append &char:ch goto &token.
].
].
Line 1,193 ⟶ 1,194:
]
! [
self append &char:ch.
].
].
Line 1,207 ⟶ 1,208:
]
! [
self new &token append &char:ch goto &token.
].
].
Line 1,277 ⟶ 1,278:
]
#method append &char:ch
[
((ch >= 48) and:(ch < 58))
? [ theToken append &char:ch. ]
! [ #throw InvalidArgumentException new &message:"Invalid expression". ].
]
Line 1,286 ⟶ 1,287:
#method append &literal:aLiteral
[
controlaLiteral run:aLiteral &forEacheach: ch [ self append &char:ch. ].
]
Line 1,347 ⟶ 1,348:
#method append &last:aLastNode &new:aNewNode
[
($nil == aLastNode)
? [ ^ aNewNode. ].
Line 1,355 ⟶ 1,356:
#var aParent := aLastNode.
#var aCurrent := aLastNode right.
#loop ((aCurrent$nil != nilaCurrent) and:[ aNewNode level > aCurrent level ]) ?
[ aParent := aCurrent. aCurrent := aCurrent right. ].
($nil == aCurrent)
? [ aParent set &right:aNewNode. ]
! [ aNewNode set &left:aCurrent. aParent set &right:aNewNode. ].
Line 1,369 ⟶ 1,370:
#var aScope := Scope new &parser:$self.
 
controlaText run:aText &forEacheach: ch [ aScope eval:ch. ].
 
^ aScope number.
Line 1,380 ⟶ 1,381:
#var aParser := Parser new.
 
control while:[ consoleEx(aText << console readLine:aText) length > 0] &dodoWhile:
[
consoleExconsole writeLine:"=" :(aParser run:aText)
| if &Error:e [
consoleExconsole writeLine:"Invalid Expression".
].
].
Anonymous user