0

What is the terminator in antlr4?

For r, why don't I enter "hello world;world;world" of characters, he will arrive ; it should stop matching。why not report errors。

grammar hello ;
r : 'hello' ID ';' ; // match keyword hello followed by an identifier
ID : [a-z]+ ; // match lower-case identifiers
WS : [ \t\r\n]+ -> skip; // skip spaces, tabs, newlines

1 Answers1

0

Stackoverflow contains multiple questions of that kind. You should search first before asking the same question again.

Add the EOF token to your top level rule to tell your parser the entire input must be matched correctly to be valid:

r: 'hello' ID ';' EOF;
Mike Lischke
  • 48,925
  • 16
  • 119
  • 181