2023 Volume 31 Pages 421-431
Context-free grammars with lookahead (CFGLAs) are context-free grammars with positive and negative lookahead. In this paper, we develop a recognition algorithm for CFGLA by combining derivatives of context-free grammars and derivatives of regular expressions with lookahead. The original semantics of CFGLA has some problems, and the recognition algorithm does not run in polynomial time. We introduce better semantics with the least fixed point of pairs of lower and upper bounds. Under the new semantics, the recognition algorithm runs in O(n3 |G|) time and O(n2 |G|) space for an input string of the length n and a given CFGLA G.