comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: lexical ambiguity
Date: Fri, 02 Jun 2006 23:27:04 GMT
Date: 2006-06-02T23:27:04+00:00	[thread overview]
Message-ID: <lnslmnrvef.fsf@nuthaus.mib.org> (raw)
In-Reply-To: 1nozvv83n7lhc.1b3qf0olmyllp$.dlg@40tude.net

bla_bla1357 <bla_bla1357MaknispaM@yahoo.com> writes:
> I'm doing a lexical analysis of Ada using Lex as part of a student project.
> The highlight is on using Lex, not on the programming language of Ada and
> I'm not farmilliar with using Ada. So what I woulkd like to find out is if
> there is any lexical ambiguity in Ada (like the ambiguity in C with the
> unary and binary plus and minus). Thanks in advance...

I suppose it depends on what you mean by "lexical ambiguity".

Strictly speaking, there are no grammatical ambiguities in either
language.  There are plenty of things that look like ambiguities, but
they're all resolved by the rules of the language.

In C, for example, this:
    x+++++y
looks like it could be parsed as
    x ++ + ++ y
which would be a legal expression, but in fact it's tokenized as
    x ++ ++ + y
which results in a syntax error.  (C's typedef names do cause some
interesting lexical problems, but that's another topic.)

Ada, like, C, has unary and binary "+" and "-" operators, but each
operator is easily identified based on the syntactic context in which
it appears.  One well-known case of a near ambiguity is:
    Character'('x')
If Ada followed C's "maximal munch" rule, this would be tokenized
as
    Character '(' x '...
leading to a syntax error; instead, it's tokenized as:
    Character ' ( 'x' )

So, there are no real ambiguities in either language, but each uses
different rules to resolve things that would otherwise have been
ambiguous.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.



      parent reply	other threads:[~2006-06-02 23:27 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
2006-06-02 23:27 ` Keith Thompson [this message]
replies disabled

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