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 = |
#method numeric = theValue save:Real64Convertor. |
||
} |
} |
||
Line 1,078: | Line 1,074: | ||
] |
] |
||
#method append |
#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: |
theParser evaluate:aChar. |
||
] |
] |
||
Line 1,113: | Line 1,111: | ||
#method evaluate : aChar |
#method evaluate : aChar |
||
[ |
[ |
||
#if ( |
#if (40 == aChar)? |
||
[ |
[ |
||
theToken := SubExpression. |
theToken := SubExpression. |
||
Line 1,146: | Line 1,144: | ||
#role Operator |
#role Operator |
||
{ |
{ |
||
#method evaluate |
#method evaluate : aChar |
||
[ |
[ |
||
#if Control if:( |
#if Control if:(48 < aChar) if:(58 > aChar) |
||
[ |
[ |
||
theToken := (Token += aChar). |
theToken := (Token += aChar). |
||
Line 1,156: | Line 1,154: | ||
#shift. |
#shift. |
||
] |
] |
||
| if:( |
| if:(40 == aChar) |
||
[ |
[ |
||
theToken := SubExpression. |
theToken := SubExpression. |
||
Line 1,169: | Line 1,167: | ||
#method numeric = theTopNode numeric. |
#method numeric = theTopNode numeric. |
||
#method evaluate |
#method evaluate : aChar |
||
[ |
[ |
||
#if Control if:( |
#if Control if:(48 < aChar) if:(58 > aChar) |
||
[ |
[ |
||
theToken += aChar. |
theToken += aChar. |
||
] |
] |
||
| if:( |
| if:(42 == aChar) // * |
||
[ |
[ |
||
theTopNode := theTopNode + ProductNode. |
theTopNode := theTopNode + ProductNode. |
||
Line 1,181: | Line 1,179: | ||
#shift Operator. |
#shift Operator. |
||
] |
] |
||
| if:( |
| if:(47 == aChar) // / |
||
[ |
[ |
||
theTopNode := theTopNode + FractionNode. |
theTopNode := theTopNode + FractionNode. |
||
Line 1,187: | Line 1,185: | ||
#shift Operator. |
#shift Operator. |
||
] |
] |
||
| if:( |
| if:(43 == aChar) // + |
||
[ |
[ |
||
theTopNode := theTopNode + SummaryNode. |
theTopNode := theTopNode + SummaryNode. |
||
Line 1,193: | Line 1,191: | ||
#shift Operator. |
#shift Operator. |
||
] |
] |
||
| if:( |
| if:(45 == aChar) // - |
||
[ |
[ |
||
theTopNode := theTopNode + DifferenceNode. |
theTopNode := theTopNode + DifferenceNode. |
||
Line 1,199: | Line 1,197: | ||
#shift Operator. |
#shift Operator. |
||
] |
] |
||
| if:( |
| if:(40 == aChar) |
||
[ |
[ |
||
theToken := SubExpression. |
theToken := SubExpression. |