From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3b05f12bd7a2a871 X-Google-Attributes: gid103376,public From: kst@king.cts.com (Keith Thompson) Subject: Re: Lexical Conundrum Date: 1998/02/23 Message-ID: <888217846.855378@wagasa.cts.com>#1/1 X-Deja-AN: 327749321 References: <01bd3d80$101287c0$LocalHost@xhv46.dial.pipex.com> Cache-Post-Path: wagasa.cts.com!kst@king.cts.com Organization: CTS Network Services Newsgroups: comp.lang.ada Date: 1998-02-23T00:00:00+00:00 List-Id: The C language definition resolves this kind of thing by mandating that lexical analysis is "greedy", i.e., that the lexical analyzer always forms the longest lexical token that it can, regardless of whether it will cause problems later. This is sometimes referred to as "maximal munch". (This makes the lexer somewhat easier to write -- and, far more importantly, IMHO, makes the lexical legality rules easier to describe.) A common C puzzle is to parse the expression x+++++y. If it could be tokenized as x ++ + ++ y, it would be legal, but "the maximal munch" rule requires it to be tokenized as x ++ ++ + y, which is an error when it's processed by later compilation phases. To stray even further from relevancy, this can be a legal expression in C++ if the "++" operator is overloaded (I think). Getting back to the topic of this newsgroup, I *think* the only constructs in the Ada grammar to which this doesn't apply are Type_Name'('z') and Prefix'A'B, where A is a (hypothetical) one-letter attribute name. I suspect this is because the Ada grammar was thought out more carefully than the C grammar when the language was being designed, avoiding most such problems in the first place. In other words, although there are no actual ambiguities in the grammar of either language, Ada's grammar has fewer constructs that look like ambiguities at first glance. The if-else problem is another example of this. -- Keith Thompson (The_Other_Keith) kst@cts.com <*> ^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H San Diego, California, USA Trying to keep my daily caffeine intake between the RDA and the LD50.