Related articles |
---|
The signs of literals lin@cs.monash.edu.au (Hung-Ta Lin) (1997-12-07) |
Re: The signs of literals dlmoore@ix.netcom.com (David L Moore) (1997-12-10) |
Re: The signs of literals clark@quarry.zk3.dec.com (Chris Clark USG) (1997-12-10) |
Re: The signs of literals hbaker@netcom.com (1997-12-12) |
Re: The signs of literals tim@wagner.Princeton.EDU (1997-12-12) |
Re: The signs of literals mtimmerm@microstar.no-spam.com (Matt Timmermans) (1997-12-12) |
Re: The signs of literals dlmoore@ix.netcom.com (David L Moore) (1997-12-13) |
From: | Hung-Ta Lin <lin@cs.monash.edu.au> |
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:
(+|-)?[0-9]+
?
The former disallows expressions such as + - 4; the latter requires no
space between the sign and the digit sequence.
Any comment is welcome.
Thanks,
Lin
--
Lin Hung-Ta email: lin@cs.monash.edu.au
Department of Computer Science Monash Univeristy, Clayton, Australia
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.