1

First rule never works. It should handle something like 'ID1.ID2.ID3.ID4.ID5'. But other rules work as expected. What is wrong with it?

grammar testInt;

data_source:
     (ID '.' ID '.' ID ('.' ID)+)=>program_ref
    | (ID '.' ID '.' ID)=>var_ref
    | (ID '.' ID)=>program_ref
    | resource;

program_ref: ID ('.' ID)+;
var_ref:    ID '.' ID '.' ID;
resource:   ID;

ID:  (LETTER | ('_'(LETTER | DIGIT))) ('_'? (LETTER | DIGIT))*;
WSFULL:(' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;};

fragment LETTER: (('a'..'z') | ('A'..'Z'));
fragment DIGIT: '0'..'9';
Overdose
  • 1,470
  • 3
  • 16
  • 29

1 Answers1

1

It appears ANTLR first tries to match var_ref before program_ref because the latter can potentially match just 2 ID's where var_ref matches 3 and the parser matches tokens greedily.

I assume this is just a dummy (part of your) grammar: is there a real world problem you're trying to solve?

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288