Hi Eric,


Thank you for your answer.
As long as lexer & parser can not apparently interact, I will use some semantic 
gate predicate.

My goal was to simplify some contextual checking and avoid lexical conflicts 
with some local rules control
in various places of my grammar.


For ex, with your response, I will use sth like:

a1:   bool_var '=' init_val;

...

init_val:   nb=NUMBER;
{$nb.text == "0" || $nb.text == "1" }?
NUMBER: ('0'..'9')+

Originally, I wanted to switch a lexer mode at begin/end of init_val 
and use a specific lexer rule BOOL_VALUE to avoid lexical conflicts
with NUMBER  ('0'..'9')+ for ex
sth like
init_val:    {fullNb=false;} BOOL_NB {fullNb=true;}


BOOL_VALUE: {!fullNb}? ('0'|'1')
NUMBER: {fullNb}? ('0'..'9')+
Apparently, no way, right ?
Here, '0' or '1' is a simple test in init_val but

my grammar have some more complex init_val set for ex conflicting with NUMBER 
(more complex
than simple 0..9+ and would have been nice to have a specific lexer rule for it 
to minimize context checking ;-( 

Regards

Jerome



________________________________
De : Eric <[email protected]>
À : Rampon Jerome <[email protected]>; ANTLR interest 
<[email protected]>
Envoyé le : Mardi 18 Octobre 2011 17h04
Objet : Re: [antlr-interest] lexer mode controlled in grammar rules ?





On Tue, Oct 18, 2011 at 9:08 AM, Rampon Jerome <[email protected]> wrote:


>
>
>Hi,
>
>
>I noticed in the following link
>
>http://www.antlr.org/wiki/display/ANTLR3/1.+Lexer
>the possibility to use lexer modes (controlled in the example via the boolean 
>tagMode settings in lexer rules)
>
>Is there one way to switch the lexer mode at grammar rule level or is it only 
>possible at lexer level ?
>
 
The parser also supports gated semantic predicates.While you may find more info 
about gated semantic predicates by using http://antlr.markmail.org/ and 
searching on "gated semantic predicate", if you are serious about using ANTLR, 
I would strongly suggest you buy 
http://pragprog.com/book/tpantlr/the-definitive-antlr-reference The book has 
the most accurate info on the subject less reading the source code.
 
 
Apparently @members declarations are not shared in both lexer and parser 
>and  lexer::members, parser::members declaration are dedicated to the lexer 
>for the 1st one,
>
>and the parser for 2nd one
>
 
See: http://www.antlr.org/wiki/pages/viewpage.action?pageId=4882470
 
The lexer runs first and creates a list of tokens. Then the parser is feed the 
list of tokens created by the lexer. The parser does not communicate with the 
lexer. 
 
 

>
>One way to do it if not via @members ?
>
>Thanks
>
>Jerome
>
>List: http://www.antlr.org/mailman/listinfo/antlr-interest
>Unsubscribe: 
>http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
> 
Hope this helps, Eric

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to