Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ucsd!ucsdhub!hp-sdd!hplabs!hpda!hpcuhb!hpcllla!hpclisp!hpclscu!shankar From: shankar@hpclscu.HP.COM (Shankar Unni) Newsgroups: comp.lang.c++ Subject: Re: C++ considered disenchanting Message-ID: <1000004@hpclscu.HP.COM> Date: 21 Oct 88 23:13:28 GMT References: <441@grand.UUCP> Organization: HP NSG/ISD California Language Lab Lines: 21 an LALR(1) grammar. As a resut, in order to correctly parse it, one needs a look-ahead lexical analyzer (with infinite lookahead), and a recursive descent parser, guided by some good heuristics. You don't necessarily need an infinite-lookahead lexical analyzer or heuristics or anything, if you can do one thing in the lexer: recognize typedef names IMMEDIATELY, and use a different token for typedef names. Right away, you have a grammar which can easily be made LALR(1). The trick is to do the typedef recognition. This needs some smarts in the parser. A YACC grammar for C can, for instance, store the names of identifiers in typedef declarations in some scoped table (naturally, it also has to do some scope manipulation..), and the lexer can look up an identifier in this table. The scoping is necessary because typedef names can be overriden by variable declarations inside nested blocks, and the parser must understand this. And this is not necessarily complex or slow. It can be done quite efficiently if a certain amount of care goes into the design. -- Shankar ("do you want fast or correct :-)")