[antlr-interest] Problemns with Predicate using last version...
Alexandre Porcelli
porcelli at uol.com.br
Thu Apr 12 12:13:37 PDT 2007
I still trying to fix it.. and I could observe that when I change the
following Lexical Rules using a simple semantic predicate, it works
(the result is OK):
LABEL_STATEMENT
: {!isLineContinuation && getCharPositionInLine() == 0}? WS? LABEL_NAME
;
LINE_NUMBER
: {!isLineContinuation && getCharPositionInLine() == 0}? WS?
LINE_NUMBER_DIGIT
{ token = Token.SKIP_TOKEN;}
;
But... I got an output messages reporting some problems with a failed
predicate:
line 8:2 rule LABEL_STATEMENT failed predicate: {!isLineContinuation
&& getCharPositionInLine() == 0}?
line 9:2 rule LABEL_STATEMENT failed predicate: {!isLineContinuation
&& getCharPositionInLine() == 0}?
line 10:2 rule LABEL_STATEMENT failed predicate:
{!isLineContinuation && getCharPositionInLine() == 0}?
line 11:2 rule LABEL_STATEMENT failed predicate:
{!isLineContinuation && getCharPositionInLine() == 0}?
line 11:12 rule LABEL_STATEMENT failed predicate:
{!isLineContinuation && getCharPositionInLine() == 0}?
line 11:18 rule LABEL_STATEMENT failed predicate:
{!isLineContinuation && getCharPositionInLine() == 0}?
line 12:6 rule LABEL_STATEMENT failed predicate:
{!isLineContinuation && getCharPositionInLine() == 0}?
Any suggestion? Any help is welcomed!
Thanks in Advance!
Alexandre Porcelli
>
> On 4/11/07, Alexandre Porcelli <porcelli at uol.com.br> wrote:
> > I started today develop a Visual Basic 6 grammar based using ANTLR v3
> > (last build).
> >
> > I started with just the lexer rules... here is my job result:
> >
> > grammar VBGrammar;
> >
> > @lexer::members
> > {
> > boolean isLineContinuation = false;
> > }
> >
> > compilationUnit
> > : statementList*
> > ;
> >
> > statementList
> > : identifier
> > | numeric
> > | label
> > ;
> >
> > identifier
> > : IDENTIFIER
> > ;
> >
> > numeric : NUMERIC
> > ;
> >
> > label : LABEL_STATEMENT
> > ;
> >
> > LABEL_STATEMENT
> > : {!isLineContinuation && getCharPositionInLine() == 0}?=> WS?
> > (LABEL_NAME|DIGIT+ { token = Token.SKIP_TOKEN;})
> > ;
> >
> > COMMENT
> > : '\'' (ANY_EXCLUDING_NL
> > {
> > if(input.LA(1) == '_' && (input.LA(2) == '\r' || input.LA(2) == '\n')){
> > input.consume();
> > input.consume();
> > if (input.LA(1) == '\n'){
> > input.consume();
> > }
> > }
> > })*
> > {token = Token.SKIP_TOKEN;}
> > ;
> >
> > IDENTIFIER
> > : (DIGIT|'_')* LETTER ('-' | LETTER|DIGIT|'_' | '$' | '#')*
> > ;
> >
> > NUMERIC
> > : DIGIT+ ('.' DIGIT+)
> > | DIGIT+
> > ;
> >
> > WS : (' ' | '\t' )+
> > { token = Token.SKIP_TOKEN;}
> > ;
> >
> > LINE_CONTINUATION
> > : '_' F_NL
> > { isLineContinuation = true; }
> > ;
> >
> > NL : ('\r' | '\n')+
> > { token = Token.SKIP_TOKEN; isLineContinuation = false;}
> > ;
> >
> > fragment
> > LABEL_NAME
> > : LETTER (LETTER | '_' | DIGIT)+ ':'
> > ;
> >
> > fragment
> > LETTER
> > : 'a'..'z' | 'A'..'Z'
> > ;
> >
> > fragment
> > DIGIT
> > : '0'..'9'
> > ;
> >
> > fragment
> > ANY_EXCLUDING_NL
> > : '\u0000'..'\t'|'\u000B'..'\f'|'\u000E'..'\uFFFE'
> > ;
> >
> > fragment
> > F_NL : ('\r' | '\n')+
> > ;
> >
> > I use to test this grammar this file:
> >
> > 'teste
> > 'dkjshfkjs ksjdhf lksjhdf lskjhf lskjdhf ldfsdf _
> > dsdfsgfhsffd _
> > asdkjhskjdhfhkj _
> > soghskjs djkfhglksj lkjshdf glkjhsdf gsfg sdfg
> >
> >
> > 20 teste _
> > 30 teste _
> > 40 sss
> > 50 asdsdfsdf dsfad fjjh
> > label: teste
> >
> > Everything seens to be fine... but I got this error when I try to test
> > this grammar:
> >
> > line 8:2 no viable alternative at character ' '
> > line 8:3 no viable alternative at character 't'
> > line 8:4 no viable alternative at character 'e'
> > line 8:5 no viable alternative at character 's'
> > line 8:6 no viable alternative at character 't'
> > line 8:7 no viable alternative at character 'e'
> > line 8:8 no viable alternative at character ' '
> > line 9:0 no viable alternative at character '3'
> > line 9:1 no viable alternative at character '0'
> > line 9:2 no viable alternative at character ' '
> > line 9:3 no viable alternative at character 't'
> > line 9:4 no viable alternative at character 'e'
> > line 9:5 no viable alternative at character 's'
> > line 9:6 no viable alternative at character 't'
> > line 9:7 no viable alternative at character 'e'
> > line 9:8 no viable alternative at character ' '
> > line 10:0 no viable alternative at character '4'
> > line 10:1 no viable alternative at character '0'
> > line 10:2 no viable alternative at character ' '
> > line 10:3 no viable alternative at character 's'
> > line 10:4 no viable alternative at character 's'
> > line 10:5 no viable alternative at character 's'
> > line 11:2 no viable alternative at character ' '
> > line 11:3 no viable alternative at character 'a'
> > line 11:4 no viable alternative at character 's'
> > line 11:5 no viable alternative at character 'd'
> > line 11:6 no viable alternative at character 's'
> > line 11:7 no viable alternative at character 'd'
> > line 11:8 no viable alternative at character 'f'
> > line 11:9 no viable alternative at character 's'
> > line 11:10 no viable alternative at character 'd'
> > line 11:11 no viable alternative at character 'f'
> > line 11:12 no viable alternative at character ' '
> > line 11:13 no viable alternative at character 'd'
> > line 11:14 no viable alternative at character 's'
> > line 11:15 no viable alternative at character 'f'
> > line 11:16 no viable alternative at character 'a'
> > line 11:17 no viable alternative at character 'd'
> > line 11:18 no viable alternative at character ' '
> > line 11:19 no viable alternative at character 'f'
> > line 11:20 no viable alternative at character 'j'
> > line 11:21 no viable alternative at character 'j'
> > line 11:22 no viable alternative at character 'h'
> > line 12:5 no viable alternative at character ':'
> > line 12:6 no viable alternative at character ' '
> > line 12:7 no viable alternative at character 't'
> > line 12:8 no viable alternative at character 'e'
> > line 12:9 no viable alternative at character 's'
> > line 12:10 no viable alternative at character 't'
> > line 12:11 no viable alternative at character 'e'
> >
> > Any suggestion?
> >
> > Best Regards,
> > Alexandre Porcelli
> >
>
More information about the antlr-interest
mailing list