[antlr-interest] Rules in lexer or parser + impact of "protected" keyword

Bharath S payasam79 at yahoo.com
Thu Apr 8 09:35:19 PDT 2004


Hi Ter,

Thanks for your clarification. I did it this way:

Interval: ((INT)('s'))=> Seconds...
          | ((INT)('d'))=>days..
and so on.

---------------------------------------------------
Another important question: I have all of my
production rules in my lexer and as I include more
rules, I find that I have to keep 80% of my rules as
"protected", to avoid non-determinism. For example, if
I have a "Time" rule, all of the constituting rules
(seconds, days, minutes, hours etc) are protected. I
am positive that placing rules in the parser instead
of the lexer will alleviate this situation but I'm not
sure how. Could someone please tell me the difference
of having rules in parser/lexer and more importantly,
will it eliminate my "protected" clutter?
----------------------------------------------------


--- Terence Parr <parrt at cs.usfca.edu> wrote:
> 
> On Apr 7, 2004, at 6:24 AM, Bharath S wrote:
> 
> > Hi Ter,
> >
> > I need to have a rule called time units, lets say,
> > that can be any unit (seconds or days or
> minutes..).
> > ----------------------------
> > Test: "Time:"(Secs|Days|mins|hours);
> > ----------------------------
> > is required for the same purpose. If I have "Test"
> as
> > my lexer rule, I want the user to enter any time
> unit
> > and I should be able to parse it and print out a
> > result that looks like:
> > ___________________________
> > Time: 25s
> > (or)
> > Time: 12d
> > ---------------------------
> >
> > and so on. Also each of the time units work
> perfectly
> > when I test them alone.
> 
> Ok, now I understand.  Left factor Days and Secs
> etc...  pull INT into 
> a common rule.  That is, pull INT out of Days and
> Secs and into Test; 
> should work.
> 
> Test: INT (Secs|Days) ;
> 
> protected
> Secs : 's' ;
> 
> Terence
> 
> >
> > Thanks Ter.
> >
> > --- Terence Parr <parrt at cs.usfca.edu> wrote:
> >>
> >> On Apr 6, 2004, at 2:08 PM, Bharath S wrote:
> >>> I have a rule of the form:
> >>> ----------------------------------------
> >>> Time: ('0'..'9')+
> >>>       ('d'{$setType(Days);} |
> 's'{$setType(Secs);}
> >>>       | {$setType(INT);}) ;
> >>>
> >>> and
> >>> -------------------------
> >>> protected Days: INT('d');
> >>> protected Secs: INT('s');
> >>> protected INT: ('0'..'9')+;
> >>> ---------------------------
> >>> When I try "Test: Secs|Days", I get a
> >> non-determinism
> >>> warning and it makes sense because both rules
> have
> >>> common left prefixes. However, I have no clue to
> >> how I
> >>> can fix it. If I write a separate rule to remove
> >>> common prefixes in "Secs" and "Days", it
> conflicts
> >>> with the above rule, "Time". Am I missing
> >> something
> >>> obvious?
> --
> Professor Comp. Sci., University of San Francisco
> Creator, ANTLR Parser Generator,
> http://www.antlr.org
> Cofounder, http://www.jguru.com
> Cofounder, http://www.knowspam.net enjoy email
> again!
> Cofounder, http://www.peerscope.com pure link
> sharing
> 
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
>      antlr-interest-unsubscribe at yahoogroups.com
> 
>  
> 


__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list