how to fix conflicting lexer rules when importing a grammar to another one

33 views
Skip to first unread message

Alia Ibrahim

unread,
May 29, 2014, 12:04:45 PM5/29/14
to antlr-di...@googlegroups.com
Hello

if i have a grammar like IRI grammar (https://github.com/antlr/grammars-v4/blob/master/iri/IRI.g4)
where alphabet is defined as follows:

 
    alpha
     : A
     | B
     | C
     | D
     | E
     | F
     | G
     | H
     | I
     | J
     | K
     | L
     | M
     | N
     ;

and the lexer rule is

    A : [aA];
    B : [bB];
    C : [cC];
    D : [dD];
    E : [eE];
    F : [fF];
    G : [gG];
    H : [hH];
    I : [iI];
    J : [jJ];
    K : [kK];
    L : [lL];
    M : [mM];
    N : [nN];


i need to import this grammar into another grammar which has the rule

    fragment LETTER : [a-zA-Z] ;
    fragment DIGIT : [0-9] ;
    IDENT : LETTER (LETTER | DIGIT)* ;

no the alpha rule will not be met because the IDENT rule in the root grammar will override it

i know it can be solved by changing the IDENT rule to

    ident : alpha (alpha | digit);

but i dont want to do that, i want to have the IDENT as a token without going to every letter independently
any suggestions ???

Terence Parr

unread,
May 30, 2014, 8:59:51 PM5/30/14
to antlr-di...@googlegroups.com
I wouldn't recommend trying to merge those lexers as you have conflicting token definitions. If you truly need to do this, then do everything in the parser by moving IDENT into the parser as well.
Ter


--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Dictation in use. Please excuse homophones, malapropisms, and nonsense. 
Reply all
Reply to author
Forward
0 new messages