On 09/15/2009 04:41 AM, Kevin Twidle wrote:
> I have been using my PonderTalk (Smalltalk like) language for a while
> now and I have just noticed that leaving a block empty causes a parser
> error. This is with ANTLRWorks 1.2.3. I have refined the grammar to
> show the point. The problem line is ^(statements). With that taken out
> the parsing works.
>
> grammar Trial;
>
> options {
> output = AST;
> k = 2;
> }
>
> start : sentences EOF
> ;
> sentences
> : sentence? (DOT sentences)?
> -> sentence? sentences?
> ;
> sentence: WORD | block;
> block : '[' sentences ']'
> -> ^(sentences)
> ;
>
You probably want to use an imaginary token as the root node of your
block. ->^(BLOCK sentences?). Sentences acan be empty and you cannot
rewrite it as the root node. Also, you probably want tokens for SENTENCE
and perahps SENTENCES. If BLOCK is empty then deal with it specially in
the tree grammar:
block : ^(BLOCK sentences)
| BLOCK // Empty block
;
Jim
--~--~---------~--~----~------------~-------~--~----~
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