Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!decwrl!shelby!unix!hplabs!hp-ses!hpcuhb!hpcllla!hpclisp!hpclscu!shankar From: shankar@hpclscu.HP.COM (Shankar Unni) Newsgroups: comp.lang.c++ Subject: Re: zortech problem with lex Message-ID: <58170007@hpclscu.HP.COM> Date: 1 Mar 90 22:11:26 GMT References: <6300008@ux1.cso.uiuc.edu> Organization: Hewlett-Packard Calif. Language Lab Lines: 23 > I saw that comment about C++ not being LALR(1) in the g++ distribution, > and at the time believed it. However, my biggest thrill at OOPSLA '89 > was sitting at the same table as Bjarne Stroustrup for a few hours drinking > free beer. He said that he IS USING A LALR(1) GRAMMER for C++ 2.0. > He appeared sober & honest, therefore I assume that C++ is LALR(1), but > non-trivial. No, it becomes LALR(1) only by a trick: a feedback mechanism by which the lexer can: (a) consult a symbol table to see if an identifier is really a typedef name, and (b) an ambiguity resolver called by the parser to handle any remaining ambiguities. The whole thing is done by adding another layer between the lexer and the parser, with these smarts built in. Using the classical model of a table-driven scanner and parser, it is impossible to write a LALR(1) description for C++ (or for that matter, C). It could be LR(2), though; I can't be sure.. ---- Shankar Unni.