I'm new to ANTLR, and trying following grammar in ANTLRWorks1.4.3.
grammar TextGra;
element : starttag (element)* endtag
;
starttag: '<' TAGNAME '>';
endtag : '</' TAGNAME '>';
TAGNAME : ('a'..'z')|('A'..'Z')|('0'..'9');
WS : (' '|'\r'|'\n')+ {skip();} ;
when try to parse simple xml fragment like this
<a><b><c></c></b></a>
lost last two endtag elements,how to handle this situation? or it's the wrong way? Tag name can't be constrained under my situation Compare to others xml parse code. or can grammar use $0 to reference previous matched token?(like in regexp). Decide tagname in the endtag by the previous matched starttag in this situation. Thanks every one for the response!