[antlr-interest] java example grammar
ronald.petty at milliman.com
ronald.petty at milliman.com
Fri Apr 23 16:44:40 PDT 2004
I was trying to use the java grammar as a bases for a VB grammar (just
seeing how to handle expression order etc). The first structure I was
trying to figure out for the for loop. In the java.g there is
statement
:
...
// For statement
| "for"
LPAREN!
forInit SEMI! // initializer
forCond SEMI! // condition test
forIter // updater
RPAREN!
statement // statement to loop
over
....
;
If I was using this as the input
for ( i = 0; .......
It would match "for" "(" then call the rule forInit.
forInit
// if it looks like a declaration, it is
: ( (declaration)=> declaration
// otherwise it could be an expression list...
| expressionList
)?
{#forInit = #(#[FOR_INIT,"FOR_INIT"],#forInit);}
;
I noticed that "i" cannot be a declaration because of the typeSpec in the
declaration rule would mean it needs to "int i" or something like that, so
I assume "i" is an expressionList (also because i had to be declared
already). So following that path lead to this
expressionList ->
expression->
assignmentExpression->
conditionalExpression->
logicalOrExpression->
logicalAndExpression->
inclusiveOrExpression->
exclusiveOrExpression->
andExpression->
equalityExpression->
relationalExpression-> (not 100% here) (nested question; ( subrule1 )* |
subrule2 if you don't match subrule1 do you have to match subrule2? I
think this does a zero match subrule1 here
shiftExpression->
additiveExpression->
multiplicativeExpression->
unaryExpression->
unaryExpressionNotPlusMinus->
postfixExpression->
primaryExpression->
identPrimary->
IDENT (Match finally)
Hopefully I was right in this, if this is true, is this because
1) "i" is not a declaration (becuase in Java it has already been
declared (and if Option Explicit is on in VB this is the same as having it
Dim i somewhere or Public i)
2) "i" is really an expression becuase it is really an LValue
which is the output of someprevious RValue? (I hope I am not slaughtering
terms here)
3) and becuase of 2) this means that an LValue is the simplest
kind of expression and that is why it is at the end of this chain (meaning
it is the highest on the precendence) (not sure about this)
I am thinking in the right way about this?
Thanks alot
Ron
**************************************************************************************
This communication is intended solely for the addressee and is
confidential. If you are not the intended recipient, any disclosure,
copying, distribution or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. Unless indicated
to the contrary: it does not constitute professional advice or
opinions upon which reliance may be made by the addressee or any
other party, and it should be considered to be a work in progress.
**************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20040423/6fee4516/attachment.html
More information about the antlr-interest
mailing list