Arithmetic evaluation: Difference between revisions
Content added Content deleted
m (→{{header|Tailspin}}: slightly more readable) |
m (→{{header|Tailspin}}: readability fix) |
||
Line 5,980: | Line 5,980: | ||
=={{header|Tailspin}}== |
=={{header|Tailspin}}== |
||
<lang tailspin> |
<lang tailspin> |
||
templates |
templates leftAssociate |
||
when <[](1)> do $(1) ! |
when <[](1)> do $(1) ! |
||
otherwise [ { left: $(1), op: $(2), right: $(3)}, $(4..last)...] -> # |
otherwise [ { left: $(1), op: $(2), right: $(3)}, $(4..last)...] -> # |
||
end leftAssociate |
|||
end variadicToBinary |
|||
composer parseArithmetic |
composer parseArithmetic |
||
(<WS>?) <addition|multiplication|term> (<WS>?) |
(<WS>?) <addition|multiplication|term> (<WS>?) |
||
rule addition: [<multiplication|term> <addedTerm>+ ] -> |
rule addition: [<multiplication|term> <addedTerm>+ ] -> leftAssociate |
||
rule addedTerm: (<WS>?) <'[+-]'> (<WS>?) <multiplication|term> |
rule addedTerm: (<WS>?) <'[+-]'> (<WS>?) <multiplication|term> |
||
rule multiplication: [<term> <multipliedTerm>+] -> |
rule multiplication: [<term> <multipliedTerm>+] -> leftAssociate |
||
rule multipliedTerm: (<WS>?) <'[*/]'> (<WS>?) <term> |
rule multipliedTerm: (<WS>?) <'[*/]'> (<WS>?) <term> |
||
rule term: <INT|parentheses> |
rule term: <INT|parentheses> |