[antlr-interest] newbie: lexer rules vs parser rules

Sam Barnett-Cormack sdb at geekworld.co.uk
Sat May 20 07:47:45 PDT 2006


Dieter Frej wrote:
> ok, even though I might look like a total newbie I have to ask that:
> Are there any rule of thumb on how to decide what a literal is and what
> a rule is? (respectively what goes into the parser and what into the
> lexer?)
> 
> Digits:
> Digit
> Digits Digit
> 
> Digit:
> 0
> NonZeroDigit
> 
> NonZeroDigit: one of
> 1 2 3 4 5 6 7 8 9
> 
> I would say NonZeroDigit is a literal and goes into the lexer, right?
> What about the other two? Should both go into the parser?

On further thinking, your questions seem to suggest (to me) that you
might do well to read a book/take a course on languages and grammars and
so on. You seem to be unfamiliar with a lot of the terms, or at best not
using them in the way they are normally used.

I mean no offence by this, just suggesting a profitable course of action.

Sam

> Terence Parr wrote:
> 
>>
>> On May 18, 2006, at 12:54 AM, <JConner at ssp-uk.com>
>> <JConner at ssp-uk.com> wrote:
>>
>>> Hi All,
>>>
>>> I've started to get my feet wet with ANTLR a little, and I've come
>>> across a
>>> few things that I thought would be handled by lexer rules, but seem
>>> to be
>>> handled in general by parser rules.  For example, most of the
>>> examples I've
>>> seen handle numbers (floating, exponents, sign, etc) with parser rules,
>>
>>
>> Those should be lexer rules...most places I've seen.  Remember FLOAT
>> means lexer rule :)
>>
>> Ter
>>
>>
> 



More information about the antlr-interest mailing list