John Gardener wrote:
Gerald, hi;

Thank you very much for your response;

YES, you are right, I can see that: " Your NAME rule is consuming all tokens. "

What I can not see is how to correct this properly?

Thanks again,

John

grammar Simple;  

options {
    language = Java;
}

@parser::header {
    package simple;
    import static java.lang.System.out;
}

@lexer::header{
  package simple;
  import static java.lang.System.out;
}

// PARSER

record :
  digit name EOF
  { out.println( "+record: " +  $text );  };

digit : DIGIT
  { out.println( "+digit: " +  $text );  };
 
name : (DIGIT|LETTER)
  ;

Change the name parser rule as above.

// LEXER

DIGIT : '0'..'9'
  { out.println("+DIGIT: " + $text ); } ;

LETTER : 'A'..'Z'
  { out.println("+LETTER: " + $text ); } ;


Remove the NAME lexer rule. Lexer rules must be unambiguous or be just 'fragment' rules (basically called by other lexer rules). The lexer runs all the way through the text creating tokens, and when it is entirely complete, the parser is given the token set. The parser does not drive the lexer, so the lexer cannot know whether to return you a NAME token or a LETTER token. Have a read of the getting started articles on the Wiki - most of these new user issues are covered and it will help you a lot. If you have the money, buy a copy of the book too.

Jim

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
-~----------~----~----~----~------~----~------~--~---



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

Reply via email to