Re: The signs of literals

tim@wagner.Princeton.EDU (Tim Hollebeek)
12 Dec 1997 14:51:25 -0500

          From comp.compilers

Related articles
The signs of literals (Hung-Ta Lin) (1997-12-07)
Re: The signs of literals (David L Moore) (1997-12-10)
Re: The signs of literals (Chris Clark USG) (1997-12-10)
Re: The signs of literals (1997-12-12)
Re: The signs of literals tim@wagner.Princeton.EDU (1997-12-12)
Re: The signs of literals (Matt Timmermans) (1997-12-12)
Re: The signs of literals (David L Moore) (1997-12-13)
| List of all articles for this month |

From: tim@wagner.Princeton.EDU (Tim Hollebeek)
Newsgroups: comp.compilers
Date: 12 Dec 1997 14:51:25 -0500
Organization: Chemistry Department, Princeton University
References: 97-12-053 97-12-060
Keywords: lex

Hung-Ta Lin wrote:
> >
> > Hi, I am working on a grammar that explicitly treats sign as part of a
> > integer literal:
> > The grammar is ambiguous because [minus could be part of the literal or a
> > part of a unary minus expression]:

David L Moore <> writes:
> Two quick points.

A fourth:

The canonical example of lexer ambiguity, I think, is the C construct
'i+++++j' which tokenizes as 'i++ ++ + j' (which the grammar rejects)
and not as 'i++ + ++j' which the grammar would accept. In general,
languages have arbitrary rules about tokenization, and longest match
is not uncommon. Sometimes there are really fun ones. I still
maintain a language where '])' can be the right bracket for indexing
followed by a parenthesis, or the close of a '([' construct. Figuring
out which one it is in the lexer would be a real pain, so the lexer
just returns ']' and ')' and lets the grammar figure it out. This has
the unfortunate side effect of allowing whitespace between the two.
That's what happens when you inherit a 6 year old flaw in the language
design, and have to support it.

Tim Hollebeek

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.