Arithmetic evaluation: Difference between revisions

m
J: prevent wiki from eating empties
No edit summary
m (J: prevent wiki from eating empties)
Line 1,222:
classify=: '$()*/+-'&(((>:@#@[ # 2:) #: 2 ^ i.)&;:)
rules=: <nowiki>''</nowiki>
patterns=: ,"0 assert 1
Line 1,240:
stack=: classify '$$$$'
tokens=: ]&.>i.#words
tree=: <nowiki>''</nowiki>
while.(#queue)+.6<#stack do.
rule=: rules {~ i.&1 patterns (*./"1)@:(+./"1) .(*."1)4{.stack
rule`:6<nowiki>''</nowiki>
end.
'syntax' assert 1 0 1 1 1 1 -: {:"1 stack
Line 1,287:
You can also display the syntax tree, for example:
parse '1+1'
 
=={{header|Pascal}}==
6,962

edits