Simple Computation of LALR(1) Lookahead Sets (original) (raw)

Practical Arbitrary Lookahead LR Parsing

Journal of Computer and System Sciences, 1990

We present a practical technique for computing lookahead for an LR(0) parser, that progressively attempts single-symbol, multi-symbol, and arbitrary lookahead. The technique determines the amount of lookahead required, and the user is spared the task of guessing it. The class of context-free grammars defined by our technique is a subset of the LR-regular grammars; we show that unlike LR-regular, the problem of determining whether an arbitrary grammar is in the class, is decidable. When restricted to k-symbol lookahead, the technique has the power of LALR(k) parsers. It has been successfully used to resolve multi-symbol lookahead conflicts in grammars for FORTRAN, Ada, C, COBOL, and PL/I, and its performance compares favorably with that of two well-known, commercially available parser generators.