Hi, i have one problems on lexer rules and i can't understand why.
As attachment there's a piece of my grammar where i got the error:
Debugging i can correctly match 'NULL', but i can't match 'DEFAULT NULL'
there something that i miss....
I think there is something wrong with lexer rule precedence, but not sure.
Any help would be really appreciated
Greetings Max
grammar test4;
options
{
language=Java;
backtrack=true;
memoize=true;
}
start:
'DEFAULT'? expr SEMICOLON
;
expr
: or_expr
;
or_expr
: and_expr ( 'OR' and_expr )*
;
and_expr
: not_expr ( 'AND' not_expr )*
;
not_expr
: 'NOT'? compare_expr
;
compare_expr
: is_null_expr ( ( EQ | NEQ | LTH | LEQ | GTH | GEQ ) is_null_expr )?
;
is_null_expr
: like_expr ( 'IS' 'NOT'? 'NULL' )?
;
like_expr
: between_expr ( 'NOT'? ('LIKE' | 'LIKEC' | 'LIKE2' | 'LIKE4' )
between_expr )?
;
between_expr
: in_expr ( 'NOT'? 'BETWEEN' in_expr 'AND' in_expr )?
;
in_expr
: add_expr ('NOT'? 'IN' LPAREN add_expr ( COMMA add_expr )* RPAREN )?
;
numeric_expression
: add_expr
;
add_expr
: mul_expr ( ( MINUS | PLUS | DOUBLEVERTBAR ) mul_expr )*
;
mul_expr
: unary_sign_expr ( ( STAR | DIVIDE | 'MOD' ) unary_sign_expr )*
;
unary_sign_expr
: ( MINUS | PLUS )? exponent_expr
;
exponent_expr
: atom ( EXPONENT atom )?
;
atom
: variable_or_function_call ( PERCENT attribute )?
| 'SQL' PERCENT attribute
| string_literal
| numeric_atom
| boolean_atom
| 'NULL'
| LPAREN expr RPAREN
;
variable_or_function_call
: call ( DOT call )* ( DOT delete_call )?
;
attribute
: 'BULK_ROWCOUNT' LPAREN expr RPAREN
| 'FOUND'
| 'ISOPEN'
|' NOTFOUND'
| 'ROWCOUNT'
;
call_args
: LPAREN ( parameter ( COMMA parameter )* )? RPAREN
;
boolean_atom
: boolean_literal
| collection_exists
| conditional_predicate
;
call
: COLON? identifier ( LPAREN ( parameter ( COMMA parameter )* )? RPAREN
)?
;
delete_call
: 'DELETE' ( LPAREN parameter? RPAREN )?
;
collection_exists
: identifier DOT 'EXISTS' LPAREN expr RPAREN
;
conditional_predicate
: 'INSERTING'
| 'UPDATING' ( LPAREN QUOTED_STRING RPAREN )?
| 'DELETING'
;
parameter
: ( identifier ARROW )? expr
;
numeric_atom
: numeric_literal
;
numeric_literal
: INT
| NUMBER
;
string_literal
: QUOTED_STRING
;
sql_expressions
: expr ( COMMA expr )*
;
boolean_literal
: 'TRUE' | 'FALSE'
;
//
=====================================================================================
// COMMON RULES
//
=====================================================================================
identifier
: IDENTIFIER
;
quoted_string
: QUOTED_STRING | QSTRING
;
//
=====================================================================================
// LEXER RULES
//
=====================================================================================
PERCENT : '%'
;
AT : '@'
;
QUOTE
: '\''
;
COLON : ':'
;
COMMA : ','
;
DOT : '.'
;
EQ : '='
;
NEQ : '!=' | '^=' | '<>'
;
GTH : '>'
;
LTH : '<'
;
GEQ : '>='
;
LEQ : '<='
;
LPAREN : '('
;
RBRACK
: ']'
;
LBRACK
: '['
;
EXPONENT
: '**'
;
DOUBLEVERTBAR
: '||'
;
ARROW
: '=>'
;
MINUS : '-'
;
PLUS : '+'
;
DIVIDE
: '/'
;
RPAREN : ')'
;
SEMICOLON
: ';'
;
STAR : '*'
;
UC : '_'
;
/*
END SIMBOLS
*/
INT : NUM
;
DATE : DIGIT DIGIT ('GEN' | 'FEB' | 'MAR' | 'APR' |'MAG' | 'GIU' | 'LUG' |
'AGO' | 'SET' | 'OTT' | 'NOV'| 'DIC') DIGIT DIGIT (DIGIT DIGIT)?
;
DQ_STRING
: DOUBLEQUOTED_STRING
;
IDENTIFIER
: 'A' .. 'Z' ( 'A' .. 'Z' | '0' .. '9' | '_' | '$' | '#' )*
| DOUBLEQUOTED_STRING
;
QUOTED_STRING
: ( 'n'|'N' )? '\'' ( '\'\'' | ~('\'') )* '\''
;
QSTRING : ('q'|'Q') ( QS_ANGLE | QS_BRACE | QS_BRACK | QS_PAREN
) ;
fragment QS_ANGLE : QUOTE '<' ( options {greedy=false;} : . )* '>' QUOTE ;
fragment QS_BRACE : QUOTE '{' ( options {greedy=false;} : . )* '}' QUOTE ;
fragment QS_BRACK : QUOTE '[' ( options {greedy=false;} : . )* ']' QUOTE ;
fragment QS_PAREN : QUOTE '(' ( options {greedy=false;} : . )* ')' QUOTE ;
fragment QS_OTHER_CH : ~('<'|'{'|'['|'('|' '|'\t'|'\n'|'\r');
fragment QS_OTHER : QUOTE delimiter=QS_OTHER_CH
( { input.LT(1) != $delimiter.text.charAt(0) || ( input.LT(1) ==
$delimiter.text.charAt(0) && input.LT(2) != '\'') }? => . )*
( { input.LT(1) == $delimiter.text.charAt(0) && input.LT(2) == '\'' }?
=> . ) QUOTE
;
fragment
DOUBLEQUOTED_STRING
: '"' ( ~('"') )* '"'
;
fragment
LETTER : ('a'..'z'|'A'..'Z')
;
fragment
DIGIT : '0'..'9'
;
WS : ( ' '
| '\t'
| '\r'
| '\n'
) {$channel=HIDDEN;}
;
NUMBER
:
( ( NUM DOT NUM ) => NUM DOT NUM
| DOT NUM
| NUM
)
( 'E' ( PLUS | MINUS )? NUM )?
;
fragment
NUM
: '0' .. '9' ( '0' .. '9' )*
;
SL_COMMENT
: '--' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
;
ML_COMMENT
: '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
;
TYPE_ATTR
: '%TYPE'
;
ROWTYPE_ATTR
: '%ROWTYPE'
;
NOTFOUND_ATTR
: '%NOTFOUND'
;
FOUND_ATTR
: '%FOUND'
;
ISOPEN_ATTR
: '%ISOPEN'
;
ROWCOUNT_ATTR
: '%ROWCOUNT'
;
BULK_ROWCOUNT_ATTR
: '%BULK_ROWCOUNT'
;
CHARSET_ATTR
: '%CHARSET'
;
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
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.