Arithmetic evaluation: Difference between revisions

Content added Content deleted
Line 937: Line 937:
=={{header|Elena}}==
=={{header|Elena}}==
<lang elena>#define std'basic'*.
<lang elena>#define std'basic'*.
#define std'routines'*.
#define std'patterns'*.
#define std'patterns'*.
#define std'basic'factories'*.
#define sys'io'*.
#define sys'io'*.
#define std'dictionary'*.
#define std'dictionary'*.


#subject parse_order.
#subject parse_order.

// --- Token ---


#class Token
#class Token
Line 968: Line 964:
]
]
#method numeric = Real64Convert eval:(theValue literal).
#method numeric = theValue save:Real64Convertor.
}
}


Line 1,078: Line 1,074:
]
]
#method append &numeric:aCode
#method append : aChar
[
[
#var aCode := Int32Value::aChar.

#if control if:(aCode == 41)
#if control if:(aCode == 41)
[
[
Line 1,092: Line 1,090:
[ #shift EOF. ^ $self. ].
[ #shift EOF. ^ $self. ].
theParser evaluate:$param.
theParser evaluate:aChar.
]
]
Line 1,113: Line 1,111:
#method evaluate : aChar
#method evaluate : aChar
[
[
#if (aChar numeric == 40)?
#if (40 == aChar)?
[
[
theToken := SubExpression.
theToken := SubExpression.
Line 1,146: Line 1,144:
#role Operator
#role Operator
{
{
#method evaluate &numeric:aCode &literal:aChar
#method evaluate : aChar
[
[
#if Control if:(aCode > 48) if:(aCode < 58)
#if Control if:(48 < aChar) if:(58 > aChar)
[
[
theToken := (Token += aChar).
theToken := (Token += aChar).
Line 1,156: Line 1,154:
#shift.
#shift.
]
]
| if:(aCode == 40)
| if:(40 == aChar)
[
[
theToken := SubExpression.
theToken := SubExpression.
Line 1,169: Line 1,167:
#method numeric = theTopNode numeric.
#method numeric = theTopNode numeric.
#method evaluate &numeric:aCode &literal:aChar
#method evaluate : aChar
[
[
#if Control if:(aCode > 48) if:(aCode < 58)
#if Control if:(48 < aChar) if:(58 > aChar)
[
[
theToken += aChar.
theToken += aChar.
]
]
| if:(aCode == 42) // *
| if:(42 == aChar) // *
[
[
theTopNode := theTopNode + ProductNode.
theTopNode := theTopNode + ProductNode.
Line 1,181: Line 1,179:
#shift Operator.
#shift Operator.
]
]
| if:(aCode == 47) // /
| if:(47 == aChar) // /
[
[
theTopNode := theTopNode + FractionNode.
theTopNode := theTopNode + FractionNode.
Line 1,187: Line 1,185:
#shift Operator.
#shift Operator.
]
]
| if:(aCode == 43) // +
| if:(43 == aChar) // +
[
[
theTopNode := theTopNode + SummaryNode.
theTopNode := theTopNode + SummaryNode.
Line 1,193: Line 1,191:
#shift Operator.
#shift Operator.
]
]
| if:(aCode == 45) // -
| if:(45 == aChar) // -
[
[
theTopNode := theTopNode + DifferenceNode.
theTopNode := theTopNode + DifferenceNode.
Line 1,199: Line 1,197:
#shift Operator.
#shift Operator.
]
]
| if:(aCode == 40)
| if:(40 == aChar)
[
[
theToken := SubExpression.
theToken := SubExpression.