18 lines
622 B
Plaintext
18 lines
622 B
Plaintext
composer calculator
|
|
(<WS>?) <addition|multiplication|term> (<WS>?)
|
|
rule addition: [<addition|multiplication|term> (<WS>?) <'[+-]'> (<WS>?) <multiplication|term>] ->
|
|
\(when <?($(2) <='+'>)> do $(1) + $(3) !
|
|
otherwise $(1) - $(3) !
|
|
\)
|
|
rule multiplication: [<multiplication|term> (<WS>?) <'[*/]'> (<WS>?) <term>] ->
|
|
\(when <?($(2) <='*'>)> do $(1) * $(3) !
|
|
otherwise $(1) ~/ $(3) !
|
|
\)
|
|
rule term: <INT|parentheses>
|
|
rule parentheses: (<'\('> <WS>?) <addition|multiplication|term> (<WS>? <'\)'>)
|
|
end calculator
|
|
|
|
'(100 - 5 * (2+3*4) + 2) / 2' -> calculator -> !OUT::write
|
|
'
|
|
' -> !OUT::write
|