Hi. I am trying to create a very simple parser but I don’t undestand why it fails. If I have the following parser:
S = E; E = 'N' | 'W' | 'S' | 'E'
Then
(parser "N")
=> [:S [:E "N"]]
but if I add a rule to expand to multiple it stops parsing:
S = E; E = 'N' | 'W' | 'S' | 'E'; E = E E;
(parser "N")
=> Parse error at line 1, column 1:
N
^
Seems odd that adding more production rules would make it parse less….am not sure, but I would try adding the second E production as an alternative to the first E production
Hm I’ll just rewrite it all I think
Another puzzle:
S = DIR+; DIR = ('N' | 'W' | 'S' | 'E')+;
This produces:
(parser2 "WWWW")
=> [:S [:DIR "W"] [:DIR "W"] [:DIR "W"] [:DIR "W"]]
I would prefers that DIR was greedy in that it would only parse as a single element if there are multiple letters in a row… how would I do that?