[antlr-interest] Disambiguate following rules
forumer at smartmobili.com
forumer at smartmobili.com
Sun Oct 28 01:26:52 PDT 2012
Hi,
I have a grammar with the following rules and that is using backtrack
option. Now when I remove backtrack
I have a problem with the var_decl rule :
Decision can match input such as "IDENTIFIER" using multiple
alternatives: 1, 2
Any idea about how to fix this ?
variable_declaration
: VAR variable_declaration_list
| empty_statement
;
variable_declaration_list
: var_decl ( ',' var_decl )*
;
var_decl
: identifier ( '=' expression )?
| expression
;
/***EXPR*************************/
expression
: assignment_expression (',' assignment_expression )*
;
argument_expression_list
: assignment_expression ( ',' assignment_expression )*
;
assignment_expression
: conditional_expression ( assignment_operator
assignment_expression )?
;
assignment_operator
: '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' |
'^=' | '|=' | '>>>='
;
constant_expression
: conditional_expression
;
conditional_expression
//: logical_or_expression ( '?' logical_or_expression ':'
logical_or_expression )?
: logical_or_expression ( '?' expression ':' expression )?
;
logical_or_expression
: logical_and_expression ('||' logical_and_expression )*
;
logical_and_expression
: inclusive_or_expression ('&&' inclusive_or_expression )*
;
inclusive_or_expression
: exclusive_or_expression ('|' exclusive_or_expression )*
;
exclusive_or_expression
: and_expression ('^' and_expression)* ;
and_expression
: equality_expression ('&' equality_expression)*
;
equality_expression
/* === and !== for javascript */
: relational_expression (('!=' | '==' | '===' | '!==' )
relational_expression)*
;
relational_expression
/* instanceof and in are for javascript */
: shift_expression ( RELATION_OPERATOR shift_expression)*
;
RELATION_OPERATOR
: '<' | '>' | '<=' | '>=' | 'in' | 'instanceof' // Don't
tokenize these!
;
shift_expression
: additive_expression (('<<' | '>>') additive_expression)*
;
additive_expression
: multiplicative_expression (('+' | '-')
multiplicative_expression)*
;
multiplicative_expression
: unary_expression ( ('*' | REGEX_OR_DIVIDE | '%') unary_expression
)* /* no cast expression for objj */
;
unary_expression
: postfix_expression
| '++' unary_expression
| '--' unary_expression
| unary_operator unary_expression /* no cast expression for objj
*/
;
unary_operator
// : '&' | '*' | '+' | '-' | '~' | '!'
: '+' | '-' | '~' | '!'
;
postfix_expression
: primary_expression
( '[' ']'
| '[' expression ']'
| '(' ')'
| '(' argument_expression_list ')'
| '.' identifier
| '++'
| '--'
)*
;
primary_expression
: TRUE | FALSE
| 'defined' '(' expression ')' /* for prepocessing */
| TYPEOF identifier /* javascript */
| TYPEOF '(' identifier ')' /* javascript */
| '[' expression? ']' /* objj array? DIES */
| '[' expression ',' expression ( ',' expression )* ']' /* objj
array? DIES */
| message_expression /* '[' receiver message_selector ']' */
| selector_expression
| protocol_expression
| encode_expression
| '{' STRING_LITERAL ':' primary_expression ( ',' STRING_LITERAL
':' primary_expression )* '}' /* js obj array? */
| '{' '}' /* js
empty obj array? */
| constant
| identifier
| VAR identifier
| '(' expression ')'
;
identifier
: a=IDENTIFIER { /*System.out.println ($a.text);*/ }
;
IDENTIFIER
: ('_'|'A'..'Z'|'a'..'z')('_'|'A'..'Z'|'a'..'z'|'0'..'9')*
;
More information about the antlr-interest
mailing list