comp.lang.ada
 help / color / mirror / Atom feed
From: kst@king.cts.com (Keith Thompson)
Subject: Re: Lexical Conundrum
Date: 1998/02/23
Date: 1998-02-23T00:00:00+00:00	[thread overview]
Message-ID: <888217846.855378@wagasa.cts.com> (raw)
In-Reply-To: dewar.888209206@merv


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.




  reply	other threads:[~1998-02-23  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-02-19  0:00 Lexical Conundrum Nick Roberts
     [not found] ` <EotBMK.MnK@world.std.com>
1998-02-22  0:00   ` Robert Dewar
1998-02-23  0:00     ` Keith Thompson [this message]
1998-02-23  0:00       ` Robert Dewar
     [not found]     ` <Eou91J.Es9@world.std.com>
1998-02-23  0:00       ` Robert Dewar
1998-02-26  0:00     ` Dr Steve Sangwine
1998-02-23  0:00   ` Mark A Biggar
1998-02-24  0:00     ` Mats Weber
1998-02-24  0:00       ` Robert Dewar
1998-03-05  0:00         ` Robert I. Eachus
1998-02-23  0:00 ` Jean-Pierre Rosen
1998-02-23  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1998-02-22  0:00 Nick Roberts
1998-02-22  0:00 ` Robert Dewar
1998-02-24  0:00   ` John Roberts-Jones
replies disabled

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