Re:We Need to Know LR and Recursive Descent Parsing Techniques
by ufo on Tuesday January 17, 2023 @09:17AM
(#34412596)
The price for this is that you have to refactor the grammar, replacing all uses of left recursion with right recursion (iteration).
Re:We Need to Know LR and Recursive Descent Parsing Techniques
by bear8642 on Tuesday January 17, 2023 @01:06PM
(#34416108)
Which might then change the semantics of your grammar - remember this being pointed out in 3rd year compilers course
Re:We Need to Know LR and Recursive Descent Parsing Techniques
by peterfirefly on Tuesday January 17, 2023 @01:25PM
(#34416423)
Seems like a relevant place to put a link to this paper:
David R. Hanson, "Compact Recursive-descent Parsing of Expressions", 1985
https://drhanson.s3.amazonaws.com/storage/documents/compact....
There are languages (such as ML) that allow the definition of new operators with a choice of precedence and associativity. Using a table like the one Hanson suggests and modifying it at compile-time is an obvious way to handle that feature.
Re:We Need to Know LR and Recursive Descent Parsing Techniques
by bruce343434 on Tuesday January 17, 2023 @01:39PM
(#34416691)
When you do precedence like this in recdesc, you will get functions like parse_prec_1, parse_prec_2 and so forth. If you generalize this function body, and pass along a "current precedence", then generalize the precedences for each operator into a table, you have just reinvented Pratt Parsing.
Very few binary operators should be right-associative. Basically just ?: and = .