LLLR parsing

Boštjan Slivnik · 2013

The idea of an LLLR parsing is presented. An LLLR(k) parser can be constructed for any LR(k) grammar but it produces the left parse of the input string in linear time (in respect to the length of the derivation) without backtracking. If used as a basis for a syntax-directed translation, it triggers semantic actions using the top-down strategy just like the canonical LL(k) parser. Hence, from a compiler writer's point of view, it acts as an LL(k) parser. The backbone of the LLLR(k) parser is the LL(k) parser which triggers the embedded left LR(k) parser whenever an LL(k) conflict appears during parsing. Once the embedded LR(k) parser resolves the conflict, it passes the control back to the backbone LL(k) parser together with the left parse of the part of the input string scanned by the embedded LR parser, and LL parsing continues. Hence, LLLR parsing is similar to LL(*) parsing except (a) it uses LR(k) parsers instead of finite automata to resolve the LL(k) conflicts and (b) that it does not need to use backtracking. An LLLR(k) parser is the most appropriate for grammars where the LL(k) conflicting nonterminals appear relatively close to the leaves of the derivation trees.

Read the paper · More papers on PaperTik