0

I'm learning about parsing/lexing in a course about Computer Science. For that we are using ANTLR.

I'm modifying an XML-language, so it's no longer ambigious, but when I make the changes to the grammer, ANTLR complains.

I know this specific question has been asked before, but it didn't really help!

ANTLR: rule Tokens has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2

I have taken a snapshot of the error when I'm running ANTLR from the commando-prompt. Snapshot of the error

Here is the XML-grammar:

grammar XML;

options {
language = Java;
}
@lexer::members {
boolean inTag = true;
}
xml_file returns [TaggedElement value]
: tagged_element EOF
;

tagged_element
: start_tag element_body end_tag 
;

element_body
: element
| element element_body
;

element
: data_element
| tagged_element
;

data_element
: PCDATA
;

start_tag
: OPEN_START_TAG NAME CLOSE_TAG
;

end_tag
: OPEN_END_TAG NAME CLOSE_TAG
;

OPEN_START_TAG : '<'  { inTag = true; };
OPEN_END_TAG   : '</' { inTag = true; };
CLOSE_TAG      : '>'  { inTag = false; };

NAME   : {inTag}?=> ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')* ;
WS     : {inTag}?=> (' '|'\t'|'\r'|'\n')+ { $channel = HIDDEN; } ; 
PCDATA : {!inTag}?=> (~'<')+ { setText($text.trim()); if ($text.length() == 0) $channel = HIDDEN; } ;

The problem occurs in

element_body

which is where i "fixed" the grammer. So my question is -> Whats wring with this grammar, and how can I make it work? Any help is greatly appreciated!

Community
  • 1
  • 1
Andersnk
  • 857
  • 11
  • 25

1 Answers1

2

Try factoring the rule like this:

element_body
    : element element_body?
;
nvlass
  • 665
  • 1
  • 6
  • 15