Arithmetic evaluation: Difference between revisions

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


=={{header|Pascal}}==
=={{header|Pascal}}==