The signs of literals

Hung-Ta Lin <>
7 Dec 1997 22:07:12 -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: Hung-Ta Lin <>
Newsgroups: comp.compilers
Date: 7 Dec 1997 22:07:12 -0500
Organization: Compilers Central
Keywords: syntax, design

Hi, I am working on a grammar that explicitly treats sign as part of a
integer literal:

exp5 ::= [+|-] exp6
exp6 ::= integer_literal | ...

integer_literal::= [+|-] digit {digit}

The grammar is ambiguous because:

FIRST([+|-] exp6) == FOLLOW([+|-] exp6) = { PlusToken, MinusToken }.

That is, given a + or -, it is not clear whether it is the beginning of a
exp5 or integer_literal.

Would it be okay to change that grammar to:

exp5 ::= [+|-] exp6
exp6 ::= integer_literal | ...

integer_literal ::= digit {digit}

or I should treat integer_literal as a lexical token:


The former disallows expressions such as + - 4; the latter requires no
space between the sign and the digit sequence.

Any comment is welcome.

Lin Hung-Ta email:
Department of Computer Science Monash Univeristy, Clayton, Australia

Post a followup to this message

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