Arithmetic evaluation: Difference between revisions
Content added Content deleted
m (whitespace/cleanup) |
m (→Icon and Unicon: header simplification) |
||
Line 951: | Line 951: | ||
Left _ -> error "Did not parse"</lang> |
Left _ -> error "Did not parse"</lang> |
||
== |
=={{header|Icon}} and {{header|Unicon}}== |
||
⚫ | |||
A compact recursive descent parser using Hanson's device. This program |
A compact recursive descent parser using Hanson's device. This program |
||
* handles left and right associativity and different precedences |
* handles left and right associativity and different precedences |
||
Line 963: | Line 964: | ||
* Notice that the code looks remarkably like a typical grammar, rather than being an opaque cryptic solution |
* Notice that the code looks remarkably like a typical grammar, rather than being an opaque cryptic solution |
||
* Does not rely on any library to silently solve 1/2 the problem; in fact, this code would probably suit being put into a library almost verbatim |
* Does not rely on any library to silently solve 1/2 the problem; in fact, this code would probably suit being put into a library almost verbatim |
||
==={{header|Icon}}=== |
|||
⚫ | |||
<lang Icon>procedure main() #: simple arithmetical parser / evaluator |
<lang Icon>procedure main() #: simple arithmetical parser / evaluator |
||
write("Usage: Input expression = Abstract Syntax Tree = Value, ^Z to end.") |
write("Usage: Input expression = Abstract Syntax Tree = Value, ^Z to end.") |