[antlr-interest] Guard condition into while and if statements
Herumor
herumor at fastwebnet.it
Mon Jul 24 06:32:49 PDT 2006
Hello people,
after a week of vacation I got back to work on my project for uni.
Following some examples I created this piece of a grammar for ANTLR 3.
I dunno how to close this though when I define mulexpr and how to link
this with an identifier for example.
This piece of a grammar in fact (the 2nd) declares the precedence of
each operator compared to another but it doesn't say what comes before
the operator and what next.
Before the following piece of code I wrote this one (the 1st) on my own
which should allow us to create an expression to put into the round
brackets of a while statement or into an if one. This though didn't
consider the precedence which I considered instead in the second piece
of code.
I need to correlate the 2 things.
Thanks forward for help.
1st piece of code
*
parExpression : LRBRACK expression RRBRACK;
expression : fouropexpr;
fouropexpr : (Identifier | NumberString) ((PLUS | MINUS |MUL |DIV | MOD)
(Identifier | NumberString))* relexpr*;
relexpr : (EQUAL | NOT_EQUAL | GT | LT | GTE | LTE) fouropexpr lorexpr*;
lorexpr : landexpr ( LOR landexpr)*;
landexpr: LAND relexpr;*
/---------------------------------------------------------------------------------------------------------------
/
2nd piece of code
/
/*expression
: conditionalExpression (assignmentOperator expression)?
;
conditionalExpression : conditionalAndExpression ( LOR
conditionalAndExpression )* ;
conditionalAndExpression : bitwiseor ( LAND bitwiseor )* ;
bitwiseor : bitwisexor ( BOR bitwisexor)* ;
bitwisexor : bitwiseand (BXOR bitwiseand)* ;
bitwiseand : equalityexpr ( BAND equalityexpr )* ;
equalityexpr : relationalexpr ( (EQUAL | NOT_EQUAL) relationalexpr)* ;
relationalexpr : shiftexpr ((LTE | LT | GTE | GT) shiftexpr)* ;
shiftexpr : addexpr ((SR | BSR | SL) addexpr)* ;
addexpr: mulexpr ((PLUS | MINUS) mulexpr)* ;
mulexpr :
assignmentOperator : ASSIGN
| BAND_ASSIGN
| BOR_ASSIGN
| BXOR_ASSIGN
| SL_ASSIGN
| BSR_ASSIGN
| SR_ASSIGN
| MOD_ASSIGN
| MUL_ASSIGN
| DIV_ASSIGN
| MINUS_ASSIGN
| PLUS_ASSIGN
;*/
/*// OPERATORS
QUESTION : '?' ;
LRBRACK : '(' ;
RRBRACK : ')' ;
LSBRACK : '[' ;
RSBRACK : ']' ;
LCBRACK : '{' ;
RCBRACK : '}' ;
COLON : ':' ;
COMMA : ',' ;
DOT : '.' ;
LNOT : '!' ;
INC : '++' ;
DEC : '--' ;
MOD : '%' ;
SEMI : ';' ;
// ARITHMETIC OPERATORS
DIV : '/' ;
PLUS : '+' ;
MINUS : '-' ;
MUL : '*' ;
// LOGICAL OPERATORS
LAND : '&&' ;
LOR : '||' ;
// RELATIONAL OPERATORS
LTE : '<=' ;
LT : '<' ;
GTE : '>=' ;
GT : '>' ;
// ASSIGN OPERATORS
ASSIGN : '=' ;
BAND_ASSIGN : '&=' ;
BOR_ASSIGN : '|=' ;
BXOR_ASSIGN : '^=' ;
SL_ASSIGN : '<<=' ;
BSR_ASSIGN : '>>>=' ;
SR_ASSIGN : '>>=' ;
MOD_ASSIGN : '%=' ;
MUL_ASSIGN : '*=' ;
DIV_ASSIGN : '/=' ;
MINUS_ASSIGN : '-=' ;
PLUS_ASSIGN : '+=' ;
// BITWISE OPERATORS
BXOR : '^' ;
BOR : '|' ;
BAND : '&' ;
BNOT : '~' ;
// EQUALITY OPERATORS
EQUAL : '==' ;
NOT_EQUAL : '!=' ;
// SHIFT
SR : '>>' ;
BSR : '>>>' ;
SL : '<<' ;*/
///
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060724/a18c707d/attachment.html
More information about the antlr-interest
mailing list