4 ms·
I've found parser expression grammars (PEG) to be a good solution to avoiding the ambiguity stated at the very beginning. This is done by making all choices (|)
by asrp 10y ago
I've found parser expression grammars (PEG) to be a good solution to avoiding the ambiguity stated at the very beginning. This is done by making all choices (|) into ordered choices.
I've recently used PEGs to write a Python parser (parsing all of Python, except for possible bugs) in ~500 lines of Python [2]. Its entirely interpreted. No parser is generated, only trees.
I'll also add that Floyd's operator precedence grammar [3] includes an algorithm which can deduce precedences from a grammar.
[1] https://en.wikipedia.org/wiki/Parsing_expression_grammar https://en.wikipedia.org/wiki/Parsing_expression_grammar
[2] https://github.com/asrp/pymetaterp https://github.com/asrp/pymetaterp
[3] https://en.wikipedia.org/wiki/Operator-precedence_grammar https://en.wikipedia.org/wiki/Operator-precedence_grammar