comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <flhota@NOSPAM.ll.mit.edu>
Subject: Re: lexical ambiguity
Date: Tue, 06 Jun 2006 09:20:25 -0400
Date: 2006-06-06T09:20:25-04:00	[thread overview]
Message-ID: <kjfhg.1599$O5.783@llslave.llan.ll.mit.edu> (raw)
In-Reply-To: <G22hg.19134$1i1.7283@attbi_s72>

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.



  reply	other threads:[~2006-06-06 13:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-02 22:13 lexical ambiguity bla_bla1357
2006-06-02 22:35 ` Frank J. Lhota
2006-06-03  5:20   ` Jeffrey R. Carter
2006-06-04 17:33     ` Frank J. Lhota
2006-06-05  1:36       ` Jeffrey R. Carter
2006-06-05 18:30         ` Frank J. Lhota
2006-06-05 20:27           ` Keith Thompson
2006-06-05 22:11             ` Jeffrey R. Carter
2006-06-06 10:39               ` Georg Bauhaus
2006-06-06 11:38                 ` M E Leypold
2006-06-07  9:02                   ` Dmitry A. Kazakov
2006-06-07 13:15                   ` Georg Bauhaus
2006-06-07 14:49                   ` Robert A Duff
2006-06-07 17:18                     ` M E Leypold
2006-06-08 21:30                       ` Robert A Duff
2006-06-09  4:41                       ` Jeffrey R. Carter
2006-06-09  8:23                       ` Georg Bauhaus
2006-06-06 13:50                 ` Simon Clubley
2006-06-06 18:56                 ` Peter C. Chapin
2006-06-06 19:41                   ` Georg Bauhaus
2006-06-05 22:16           ` Jeffrey R. Carter
2006-06-06 13:20             ` Frank J. Lhota [this message]
2006-06-02 23:27 ` Keith Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox