ANTL – First Steps
October 29, 2008 at 1:53 pm Leave a comment
I’ve done very good on my C# test (I scored 929 out of 1000), so I have now a MCTS 70-536 certificate.
Today I’ve started a little ANTLR tutorial. I need to get used to using ANTLR for one of my homeworks, for the compilers class. I use the following link:
http://javadude.com/articles/antlrtut/
I am still at the lexer part and I’ve encountered a problem. First, the tutorial uses ” for quotes and the ANTLR version I’m using (1.2.1) uses simple quotes. The problmes was related to the CHARLIT rule:
CHARLIT : '\''! . '\''! ;
Because I was writting a parser grammar, I couldn’t use ! to ignore simple quotes, so I constantly got the following error message:
(133): XL.g: illegal option output Consult the console for more information.
The console was empty, so no hints there… So in order to ignore simple quotes I’ve added a protected rule (for protected rules the lexer doesn’t create tokens):
protected QUOTE
: '\''
;
and I’ve added a filtering option:
options {
filter=QUOTE;
}
So now my chars literal rule looks like this:
CHARLIT
: QUOTE ~(QUOTE) QUOTE
;
Next step: string literals:)
Entry filed under: Uncategorized. Tags: .
Trackback this post | Subscribe to the comments via RSS Feed