[antlr-interest] is it a bug, or am I too stupid?
Markus Kuhla
bace.spam at gmx.net
Sat Apr 28 11:15:36 PDT 2007
Hi,
thanks for your reply! You're absolutely right concerning the newlines? I fixed it, but it still won't work. The Parser recognizes the separator **** as a bullet-hierarchie and this fails, because after **** is no text (text is required after the bullet *'s). But if the parser gets an error, why is there no backtracking? I actually told him to do this at the decision (separator | bullet-hierarchie). I cannot enable backtracking for the whole grammar, because it's really big. Please can you help me, how to enable backtrack for this decision, or what I'm doing wrong with the grammar:
grammar ambg;
ASTERISK : '*';
NEWLINE : (('\r')? '\n' | '\r');
BLANKS : (' ' | '\t')+;
ELSE : .;
page : (page_element)+;
page_element options {backtrack=true; memoize=true;}
: (separator | bullet_hierarchie);
separator : (BLANKS)? ASTERISK ASTERISK ASTERISK ASTERISK (BLANKS)? NEWLINE;
bullet_hierarchie : (bullet_item)+;
bullet_item : ASTERISK content;
content : ASTERISK content
| text;
text : ~(NEWLINE | ASTERISK)+ NEWLINE;
newline : NEWLINE | EOF;
the input is:
*1
**2
*** 3
**** 4
***** 5
******6
**7
*8
****
Thank you very much!!!!
Best, Markus
Miguel Ping schrieb:
> Hi there,
>
> From what I can see, you are requiring a newline in these 3 rules:
>
> page_element : (separator | bullet_hierarchie) newline;
> separator : (BLANKS)? ASTERISK ASTERISK ASTERISK ASTERISK (BLANKS)? NEWLINE;
> bullet_hierarchie : (bullet_item newline)+;
>
> So when bullet_hierarchie ends, you require a newline before exiting rule page_element. Try removing newline from rules separator and bullet_hierarchie, so that page_element handles newlines and the other rules handle only what matters.
>
> Btw, i take it you are using antlr v3, if so, you don't need to specify lookahead with the k=6 statement in the options
>
> Happy parsing,
>
> Miguel Ping
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070428/32eee397/attachment.html
More information about the antlr-interest
mailing list