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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1f96acbbf1e7e66a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bloom-beacon.mit.edu!llslave.llan.ll.mit.edu!53ab2750!not-for-mail From: "Frank J. Lhota" User-Agent: Thunderbird 1.5.0.2 (Windows/20060308) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: lexical ambiguity References: <1nozvv83n7lhc.1b3qf0olmyllp$.dlg@40tude.net> <9M_gg.1598$O5.554@llslave.llan.ll.mit.edu> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Tue, 06 Jun 2006 09:20:25 -0400 NNTP-Posting-Host: 155.34.132.115 X-Complaints-To: news@ll.mit.edu X-Trace: llslave.llan.ll.mit.edu 1149600080 155.34.132.115 (Tue, 06 Jun 2006 09:21:20 EDT) NNTP-Posting-Date: Tue, 06 Jun 2006 09:21:20 EDT Xref: g2news2.google.com comp.lang.ada:4695 Date: 2006-06-06T09:20:25-04:00 List-Id: Jeffrey R. Carter wrote: > Frank J. Lhota wrote: >> >> Well, there is a good reason to consider this worst case scenario. I >> have seen quick and dirty Ada lexers that try to determine if a single >> quote starts a character literal by looking ahead 2 character. As this >> scenario shows, this approach is not guaranteed to work. > > That's too simple minded. A character literal can't follow an > identifier, so this must be either an attribute or a qualified > expression (presuming it's not an error). Since "(" can't be an > attribute, it must be a qualified expression. I'm not sure how to parse > "...", though. That is precisely my point: the character look-ahead is too simple minded. As you and other posters have pointed out, if we simply keep track of the last token, we can use that information to determine how to handle the single quote. > You still have an evil mind, since you didn't include any spaces between > the components of the aggregate, making it even harder for humans to > parse (lack of spaces shouldn't make any difference to machine parsing). This example was to illustrate a worst case scenario for an Ada lexer. It was *not* presented as an example of recommended programming style, which it clearly is not.