[antlr-interest] Grammar Problem
Henrique
hjrnunes at student.dei.uc.pt
Thu Aug 7 10:40:38 PDT 2008
Hi guys!
I'm having some trouble with my grammar for parsing CFA files... As I posted
before, I'm trying to convert their Yacc grammar to ANTLR and now I'm having
some trouble. I suspect it's the left recursions or rather the way I got
ridden of them.
The grammar is attached and can also be seen
here<http://hjrnunes.googlepages.com/antlrgrammar>
.
here's the rules I'm having trouble with:
rule : RULE USER_STRING LEFTBRACKET buncha_replacements? RIGHTBRACKET
| RULE USER_STRING USER_RATIONAL LEFTBRACKET buncha_replacements?
RIGHTBRACKET
;
buncha_replacements
: (replacement)+
;
replacement
: USER_STRING modification
| USER_STRING STAR modification USER_STRING modification
;
Here's an example of what it should parse:
rule Foo {
CIRCLE { b 1 }
CIRCLE {}
}
Now I'm getting a MismatchedTokenException: mismatched input 'CIRCLE'
expecting RIGHTBRACKET in the first alternative.
Here are the relevant original YACC rules:
rule:
RULE USER_STRING LEFTBRACKET buncha_replacements RIGHTBRACKET
|
RULE USER_STRING USER_RATIONAL LEFTBRACKET buncha_replacements
RIGHTBRACKET
;
buncha_replacements:
buncha_replacements replacement
|
;
The strange thing - at least for me is that the background rule that is
quite similar works like a charm:
background
: BACKGROUND LEFTBRACKET buncha_color_adjustments? RIGHTBRACKET
;
buncha_color_adjustments
: (color_adjustment)+
;
It should work almost similarly...
What would be the right way to convert such left recursive rules into
something appropriate for ANTLR?
I hope you guys can shed some insight on this... I'm somewhat of a newbie
concerning parsing and ANTLR.
Thanks!
Henrique Nunes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080807/f4cad9e6/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cfdg.g
Type: application/octet-stream
Size: 3277 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080807/f4cad9e6/attachment.obj
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.txt
Url: http://www.antlr.org/pipermail/antlr-interest/attachments/20080807/f4cad9e6/attachment.txt
More information about the antlr-interest
mailing list