Anonymous user
Arithmetic evaluation: Difference between revisions
m
→{{header|Elena}}
Alextretyak (talk | contribs) m (→{{header|11l}}) |
|||
Line 1,183:
=={{header|Elena}}==
ELENA
<lang elena>import system'routines
import extensions
import extensions'text
class Token
{
object theValue
constructor new(int
theValue :=
append
theValue
}
class Node
{
constructor new(int
}
class SummaryNode
{
constructor new(int
<= new(
}
class DifferenceNode
{
constructor new(int
<= new(
}
class ProductNode
{
constructor new(int
<= new(
}
class FractionNode
{
constructor new(int
<= new(
}
class Expression
{
constructor new(int
{
set(object node)
{
Top := node
}
}
}
Line 1,272 ⟶ 1,278:
{
eval(ch)
ch =>
$40
^
^
}
Line 1,286 ⟶ 1,292:
{
eval(ch)
ch =>
$41
^
$42
^
$43
^
$45
^
$47
^
^
}
Line 1,312 ⟶ 1,318:
{
eval(ch)
ch =>
$40
^
$45
^
^
}
class Scope
{
object theState
int theLevel
object theParser
object theToken
object theExpression
constructor new
theState := startState
theLevel := 0
theExpression := Expression
theParser :=
newToken()
theToken := theParser
newSummary()
theToken := nil
theParser
newDifference()
theToken := nil
theParser
newProduct()
theToken := nil
theParser
newFraction()
theToken := nil
theParser
newBracket()
theToken := nil
theLevel := theLevel + 10
theParser
closeBracket()
if (theLevel < 10)
theLevel := theLevel - 10
append
if
{
theToken.append:ch
[ InvalidArgumentException new:"Invalid expression"; raise ]▼
else
{
}
}
append(
gotoStarting()
theState := startState
gotoToken()
theState := tokenState
gotoOperator()
theState := operatorState
dispatch() => theState
}
class Parser
{
appendToken(object
var
^
appendSummary(object
appendDifference(object
appendProduct(object
appendFraction(object
appendSubexpression(object
append(object
if(nil ==
if (
var
var
while
if (nil ==
{
}
else
{
newNode.Left := current; parent.Right := newNode
};
^
run
var
^
}
public program()
{
var
var
try
{
catch(Exception e)
console writeLine:"Invalid Expression"▼
▲ aText clear
]</lang>▼
text.clear()
}
=={{header|Emacs Lisp}}==
|