ANTLR v3 catch all unknown functions
I'm wringing a parsing app for lisp like language using antlr v3 but I
need the tool to handle all the functions that it doesn't know how to
handle yet and I'm struggling on how to implement it correctly here is the
basic structure I have:
wrapPrimary
: '(' primary ')'
;
primary
: 'a'^ secondary+
| 'b'^ secondary+
| 'c'^ secondary+
| unknown
;
secondary
: '(' tertiary ')'
| final
;
tertiary
: 'd'^ secondary secondary
| 'e'^ secondary secondary
| unknown
;
unknown
: ~('a'|'b'|'c'|'d'|'e') (~('('|')')|wrapPrimary)*
;
// Basic type
final
: varible
| string
| number
;
So code would be handle something like
(blah VAR (a VAR "STRING"))
(b (blah VAR VAR) VAR)
Where var or string are correct basic types However code fails on (blah
VAR (d VAR "STRING")) Changing unknown to
unknown
: ~('a'|'b'|'c'|'d'|'e') (~('('|')')|wrapPrimary|secondary)*
;
ANTLR complaints about multiple alternatives for matching Joining primary
and tertiary together breaks the language structure i.e 'a' needs to be
followed by 'd' or 'e' Is there easy way to implement sort of catch all in
antlar?
Thank you in advance! I'm quite new to ANTLR
No comments:
Post a Comment