X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj index c348a5e..0f04260 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -38,6 +38,7 @@ import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpdt.internal.compiler.ast.*; import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; /** @@ -46,6 +47,7 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; * given with JavaCC. You can get JavaCC at http://www.webgain.com * You can test the parser with the PHPParserTestCase2.java * @author Matthieu Casanova + * @version $Reference: 1.0$ */ public final class PHPParser extends PHPParserSuperclass { @@ -107,12 +109,12 @@ public final class PHPParser extends PHPParserSuperclass { * Add an php node on the stack. * @param node the node that will be added to the stack */ - private static final void pushOnAstNodes(AstNode node) { + private static final void pushOnAstNodes(final AstNode node) { try { nodes[++nodePtr] = node; } catch (IndexOutOfBoundsException e) { - int oldStackLength = nodes.length; - AstNode[] oldStack = nodes; + final int oldStackLength = nodes.length; + final AstNode[] oldStack = nodes; nodes = new AstNode[oldStackLength + AstStackIncrement]; System.arraycopy(oldStack, 0, nodes, 0, oldStackLength); nodePtr = oldStackLength; @@ -157,6 +159,7 @@ public final class PHPParser extends PHPParserSuperclass { } setMarker(e); errorMessage = null; + if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e); } /** @@ -269,7 +272,7 @@ public final class PHPParser extends PHPParserSuperclass { */ public static final void createNewHTMLCode() { final int currentPosition = SimpleCharStream.getPosition(); - if (currentPosition == htmlStart) { + if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) { return; } final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray(); @@ -391,6 +394,7 @@ MORE : | | | +| | | "> | @@ -456,8 +460,8 @@ MORE : { | -| -| +| +| | | | @@ -498,39 +502,16 @@ MORE : <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | | | )> -| -| -| +| +| +| } /* IDENTIFIERS */ TOKEN : { - < IDENTIFIER: (|) (||)* > + |) (||)* > | < #LETTER: ["a"-"z"] | ["A"-"Z"] @@ -657,7 +638,7 @@ PHPEchoBlock phpEchoBlock() : { final Expression expr; final int pos = SimpleCharStream.getPosition(); - PHPEchoBlock echoBlock; + final PHPEchoBlock echoBlock; } { expr = Expression() [ ] @@ -676,8 +657,7 @@ void Php() : ClassDeclaration ClassDeclaration() : { final ClassDeclaration classDeclaration; - final Token className; - Token superclassName = null; + final Token className,superclassName; final int pos; char[] classNameImage = SYNTAX_ERROR_CHAR; char[] superclassNameImage = null; @@ -732,7 +712,7 @@ ClassDeclaration ClassDeclaration() : return classDeclaration;} } -void ClassBody(ClassDeclaration classDeclaration) : +void ClassBody(final ClassDeclaration classDeclaration) : {} { try { @@ -759,10 +739,10 @@ void ClassBody(ClassDeclaration classDeclaration) : /** * A class can contain only methods and fields. */ -void ClassBodyDeclaration(ClassDeclaration classDeclaration) : +void ClassBodyDeclaration(final ClassDeclaration classDeclaration) : { - MethodDeclaration method; - FieldDeclaration field; + final MethodDeclaration method; + final FieldDeclaration field; } { method = MethodDeclaration() {classDeclaration.addMethod(method);} @@ -775,7 +755,7 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) : FieldDeclaration FieldDeclaration() : { VariableDeclaration variableDeclaration; - VariableDeclaration[] list; + final VariableDeclaration[] list; final ArrayList arrayList = new ArrayList(); final int pos = SimpleCharStream.getPosition(); } @@ -845,9 +825,8 @@ VariableDeclaration VariableDeclarator() : */ String VariableDeclaratorId() : { - String expr; + final String expr; Expression expression = null; - final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); ConstantIdentifier ex; } @@ -910,7 +889,7 @@ String Variable(): String VariableName(): { final StringBuffer buff; - String expr = null; + final String expr; Expression expression = null; final Token token; } @@ -976,7 +955,7 @@ Expression VariableInitializer() : ArrayVariableDeclaration ArrayVariable() : { -Expression expr,expr2; +final Expression expr,expr2; } { expr = Expression() @@ -1001,7 +980,7 @@ ArrayVariableDeclaration[] ArrayInitializer() : [ {list.add(null);}] { - ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()]; + final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()]; list.toArray(vars); return vars;} } @@ -1152,48 +1131,61 @@ ConstantIdentifier Type() : Expression Expression() : { final Expression expr; -} -{ - expr = PrintExpression() {return expr;} -| expr = ListExpression() {return expr;} -| LOOKAHEAD(varAssignation()) - expr = varAssignation() {return expr;} -| expr = ConditionalExpression() {return expr;} -} - -/** - * A Variable assignation. - * varName (an assign operator) any expression - */ -VarAssignation varAssignation() : -{ - String varName; - final Expression initializer; - final int assignOperator; + Expression initializer = null; + int assignOperator = -1; final int pos = SimpleCharStream.getPosition(); } { - varName = VariableDeclaratorId() - assignOperator = AssignmentOperator() + LOOKAHEAD(1) + expr = ConditionalExpression() + [ assignOperator = AssignmentOperator() try { - initializer = Expression() + {final int errorStart = SimpleCharStream.getPosition();} + initializer = Expression() } catch (ParseException e) { if (errorMessage != null) { throw e; } - errorMessage = "expression expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorEnd = SimpleCharStream.getPosition(); throw e; } - {return new VarAssignation(varName.toCharArray(), + ] + { + if (assignOperator == -1) return expr; + return new VarAssignation(expr, initializer, assignOperator, pos, - SimpleCharStream.getPosition());} + SimpleCharStream.getPosition()); + return expr;} +| expr = ExpressionWBang() {return expr;} +} + +Expression ExpressionWBang() : +{ + final Expression expr; + final int pos = SimpleCharStream.getPosition(); +} +{ + expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} +| expr = ExpressionNoBang() {return expr;} +} + +Expression ExpressionNoBang() : +{ + final Expression expr; +} +{ + expr = PrintExpression() {return expr;} +| expr = ListExpression() {return expr;} } +/** + * Any assignement operator. + * @return the assignement operator id + */ int AssignmentOperator() : {} { @@ -1428,7 +1420,7 @@ Expression MultiplicativeExpression() : */ Expression UnaryExpression() : { - Expression expr; + final Expression expr; final int pos = SimpleCharStream.getPosition(); } { @@ -1440,7 +1432,7 @@ Expression UnaryExpression() : Expression AtUnaryExpression() : { - Expression expr; + final Expression expr; final int pos = SimpleCharStream.getPosition(); } { @@ -1455,8 +1447,8 @@ Expression AtUnaryExpression() : Expression UnaryExpressionNoPrefix() : { - Expression expr; - int operator; + final Expression expr; + final int operator; final int pos = SimpleCharStream.getPosition(); } { @@ -1480,21 +1472,21 @@ final int operator; final int pos = SimpleCharStream.getPosition(); } { - ( {operator = OperatorIds.PLUS_PLUS;} - | {operator = OperatorIds.MINUS_MINUS;}) + ( {operator = OperatorIds.PLUS_PLUS;} + | {operator = OperatorIds.MINUS_MINUS;}) expr = PrimaryExpression() {return new PrefixedUnaryExpression(expr,operator,pos);} } Expression UnaryExpressionNotPlusMinus() : { - Expression expr; + final Expression expr; final int pos = SimpleCharStream.getPosition(); } { - expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} -| LOOKAHEAD( (Type() | ) ) + LOOKAHEAD( (Type() | ) ) expr = CastExpression() {return expr;} +| expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} | expr = PostfixExpression() {return expr;} | expr = Literal() {return expr;} | expr = Expression() @@ -1526,14 +1518,14 @@ final int pos = SimpleCharStream.getPosition(); Expression PostfixExpression() : { - Expression expr; + final Expression expr; int operator = -1; final int pos = SimpleCharStream.getPosition(); } { expr = PrimaryExpression() - [ {operator = OperatorIds.PLUS_PLUS;} - | {operator = OperatorIds.MINUS_MINUS;}] + [ {operator = OperatorIds.PLUS_PLUS;} + | {operator = OperatorIds.MINUS_MINUS;}] { if (operator == -1) { return expr; @@ -1549,34 +1541,16 @@ Expression PrimaryExpression() : final int pos = SimpleCharStream.getPosition(); } { - LOOKAHEAD(2) - identifier = expr = ClassIdentifier() - {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(), - pos, - SimpleCharStream.getPosition()), - expr, - ClassAccess.STATIC);} - (expr = PrimarySuffix(expr))* - {return expr;} -| expr = PrimaryPrefix() - (expr = PrimarySuffix(expr))* + ( + LOOKAHEAD(PrimarySuffix()) + expr = PrimarySuffix(expr))* {return expr;} | expr = ArrayDeclarator() {return expr;} } -ArrayInitializer ArrayDeclarator() : -{ - final ArrayVariableDeclaration[] vars; - final int pos = SimpleCharStream.getPosition(); -} -{ - vars = ArrayInitializer() - {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());} -} - Expression PrimaryPrefix() : { final Expression expr; @@ -1591,9 +1565,40 @@ Expression PrimaryPrefix() : | expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr, OperatorIds.NEW, pos);} -| var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(), - pos, - SimpleCharStream.getPosition());} +| var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment, + var.toCharArray(), + pos, + SimpleCharStream.getPosition());} +} + +AbstractSuffixExpression PrimarySuffix(final Expression prefix) : +{ + final AbstractSuffixExpression suffix; + final Expression expr; +} +{ + suffix = Arguments(prefix) {return suffix;} +| suffix = VariableSuffix(prefix) {return suffix;} +| expr = ClassIdentifier() + {suffix = new ClassAccess(prefix, + expr, + ClassAccess.STATIC); + return suffix;} +} + +/** + * An array declarator. + * array(vars) + * @return an array + */ +ArrayInitializer ArrayDeclarator() : +{ + final ArrayVariableDeclaration[] vars; + final int pos = SimpleCharStream.getPosition(); +} +{ + vars = ArrayInitializer() + {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());} } PrefixedUnaryExpression classInstantiation() : @@ -1622,26 +1627,19 @@ ConstantIdentifier ClassIdentifier(): final String expr; final Token token; final int pos = SimpleCharStream.getPosition(); + final ConstantIdentifier type; } { token = {return new ConstantIdentifier(token.image.toCharArray(), pos, SimpleCharStream.getPosition());} +| type = Type() {return type;} | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(), pos, SimpleCharStream.getPosition());} } -AbstractSuffixExpression PrimarySuffix(Expression prefix) : -{ - final AbstractSuffixExpression expr; -} -{ - expr = Arguments(prefix) {return expr;} -| expr = VariableSuffix(prefix) {return expr;} -} - -AbstractSuffixExpression VariableSuffix(Expression prefix) : +AbstractSuffixExpression VariableSuffix(final Expression prefix) : { String expr = null; final int pos = SimpleCharStream.getPosition(); @@ -1695,7 +1693,7 @@ Literal Literal() : return new NullLiteral(pos-4,pos);} } -FunctionCall Arguments(Expression func) : +FunctionCall Arguments(final Expression func) : { Expression[] args = null; } @@ -1739,7 +1737,7 @@ final ArrayList list = new ArrayList(); } )* { - Expression[] arguments = new Expression[list.size()]; + final Expression[] arguments = new Expression[list.size()]; list.toArray(arguments); return arguments;} } @@ -1798,6 +1796,66 @@ Statement StatementNoBreak() : return statement;} | statement = StaticStatement() {return statement;} | statement = GlobalStatement() {return statement;} +| statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;} +} + +Define defineStatement() : +{ + final int start = SimpleCharStream.getPosition(); + Expression defineName,defineValue; +} +{ + + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); + } + try { + defineName = Expression() + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + throw e; + } + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); + } + try { + defineValue = Expression() + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + throw e; + } + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); + } + {return new Define(currentSegment, + defineName, + defineValue, + start, + SimpleCharStream.getPosition());} } /** @@ -1818,8 +1876,8 @@ Statement Statement() : HTMLBlock htmlBlock() : { final int startIndex = nodePtr; - AstNode[] blockNodes; - int nbNodes; + final AstNode[] blockNodes; + final int nbNodes; } { (phpEchoBlock())* @@ -1897,8 +1955,8 @@ PrintExpression PrintExpression() : ListExpression ListExpression() : { String expr = null; - Expression expression = null; - ArrayList list = new ArrayList(); + final Expression expression; + final ArrayList list = new ArrayList(); final int pos = SimpleCharStream.getPosition(); } { @@ -1927,8 +1985,7 @@ ListExpression ListExpression() : errorEnd = SimpleCharStream.getPosition() + 1; throw e; } - expr = VariableDeclaratorId() - {list.add(expr);} + [expr = VariableDeclaratorId() {list.add(expr);}] )* try { @@ -1941,7 +1998,7 @@ ListExpression ListExpression() : } [ expression = Expression() { - String[] strings = new String[list.size()]; + final String[] strings = new String[list.size()]; list.toArray(strings); return new ListExpression(strings, expression, @@ -1949,7 +2006,7 @@ ListExpression ListExpression() : SimpleCharStream.getPosition());} ] { - String[] strings = new String[list.size()]; + final String[] strings = new String[list.size()]; list.toArray(strings); return new ListExpression(strings,pos,SimpleCharStream.getPosition());} } @@ -1982,7 +2039,7 @@ EchoStatement EchoStatement() : throw e; } } - {Expression[] exprs = new Expression[expressions.size()]; + {final Expression[] exprs = new Expression[expressions.size()]; expressions.toArray(exprs); return new EchoStatement(exprs,pos);} } @@ -1991,8 +2048,8 @@ GlobalStatement GlobalStatement() : { final int pos = SimpleCharStream.getPosition(); String expr; - ArrayList vars = new ArrayList(); - GlobalStatement global; + final ArrayList vars = new ArrayList(); + final GlobalStatement global; } { @@ -2005,7 +2062,7 @@ GlobalStatement GlobalStatement() : try { { - String[] strings = new String[vars.size()]; + final String[] strings = new String[vars.size()]; vars.toArray(strings); global = new GlobalStatement(currentSegment, strings, @@ -2034,7 +2091,7 @@ StaticStatement StaticStatement() : try { { - String[] strings = new String[vars.size()]; + final String[] strings = new String[vars.size()]; vars.toArray(strings); return new StaticStatement(strings, pos, @@ -2094,7 +2151,7 @@ Block Block() : throw e; } { - Statement[] statements = new Statement[list.size()]; + final Statement[] statements = new Statement[list.size()]; list.toArray(statements); return new Block(statements,pos,SimpleCharStream.getPosition());} } @@ -2104,17 +2161,8 @@ Statement BlockStatement() : final Statement statement; } { - try { statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement); return statement;} - } catch (ParseException e) { - if (errorMessage != null) throw e; - errorMessage = "statement expected"; - errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; - throw e; - } | statement = ClassDeclaration() {return statement;} | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement); currentSegment.add((MethodDeclaration) statement); @@ -2145,7 +2193,7 @@ VariableDeclaration[] LocalVariableDeclaration() : {list.add(var);} ( var = LocalVariableDeclarator() {list.add(var);})* { - VariableDeclaration[] vars = new VariableDeclaration[list.size()]; + final VariableDeclaration[] vars = new VariableDeclaration[list.size()]; list.toArray(vars); return vars;} } @@ -2182,19 +2230,19 @@ EmptyStatement EmptyStatement() : return new EmptyStatement(pos-1,pos);} } -Statement StatementExpression() : +Expression StatementExpression() : { - Expression expr,expr2; - int operator; + final Expression expr,expr2; + final int operator; } { expr = PreIncDecExpression() {return expr;} | expr = PrimaryExpression() - [ {return new PostfixedUnaryExpression(expr, + [ {return new PostfixedUnaryExpression(expr, OperatorIds.PLUS_PLUS, SimpleCharStream.getPosition());} - | {return new PostfixedUnaryExpression(expr, + | {return new PostfixedUnaryExpression(expr, OperatorIds.MINUS_MINUS, SimpleCharStream.getPosition());} | operator = AssignmentOperator() expr2 = Expression() @@ -2256,7 +2304,7 @@ AbstractCase[] switchStatementBrace() : try { { - AbstractCase[] abcase = new AbstractCase[cases.size()]; + final AbstractCase[] abcase = new AbstractCase[cases.size()]; cases.toArray(abcase); return abcase;} } catch (ParseException e) { @@ -2302,7 +2350,7 @@ AbstractCase[] switchStatementColon(final int start, final int end) : try { { - AbstractCase[] abcase = new AbstractCase[cases.size()]; + final AbstractCase[] abcase = new AbstractCase[cases.size()]; cases.toArray(abcase); return abcase;} } catch (ParseException e) { @@ -2327,7 +2375,7 @@ AbstractCase switchLabel0() : | statement = htmlBlock() {stmts.add(statement);})* [ statement = BreakStatement() {stmts.add(statement);}] { - Statement[] stmtsArray = new Statement[stmts.size()]; + final Statement[] stmtsArray = new Statement[stmts.size()]; stmts.toArray(stmtsArray); if (expr == null) {//it's a default return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition()); @@ -2403,8 +2451,8 @@ Break BreakStatement() : IfStatement IfStatement() : { final int pos = SimpleCharStream.getPosition(); - Expression condition; - IfStatement ifStatement; + final Expression condition; + final IfStatement ifStatement; } { condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2) @@ -2439,18 +2487,18 @@ Expression Condition(final String keyword) : {return condition;} } -IfStatement IfStatement0(Expression condition, final int start,final int end) : +IfStatement IfStatement0(final Expression condition, final int start,final int end) : { Statement statement; - Statement stmt; + final Statement stmt; final Statement[] statementsArray; ElseIf elseifStatement; Else elseStatement = null; - ArrayList stmts; + final ArrayList stmts; final ArrayList elseIfList = new ArrayList(); - ElseIf[] elseIfs; + final ElseIf[] elseIfs; int pos = SimpleCharStream.getPosition(); - int endStatements; + final int endStatements; } { @@ -2544,7 +2592,7 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) : ElseIf ElseIfStatementColon() : { - Expression condition; + final Expression condition; Statement statement; final ArrayList list = new ArrayList(); final int pos = SimpleCharStream.getPosition(); @@ -2554,7 +2602,7 @@ ElseIf ElseIfStatementColon() : ( statement = Statement() {list.add(statement);} | statement = htmlBlock() {list.add(statement);})* { - Statement[] stmtsArray = new Statement[list.size()]; + final Statement[] stmtsArray = new Statement[list.size()]; list.toArray(stmtsArray); return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());} } @@ -2569,22 +2617,22 @@ Else ElseStatementColon() : ( statement = Statement() {list.add(statement);} | statement = htmlBlock() {list.add(statement);})* { - Statement[] stmtsArray = new Statement[list.size()]; + final Statement[] stmtsArray = new Statement[list.size()]; list.toArray(stmtsArray); return new Else(stmtsArray,pos,SimpleCharStream.getPosition());} } ElseIf ElseIfStatement() : { - Expression condition; - Statement statement; + final Expression condition; + final Statement statement; final ArrayList list = new ArrayList(); final int pos = SimpleCharStream.getPosition(); } { condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/} { - Statement[] stmtsArray = new Statement[list.size()]; + final Statement[] stmtsArray = new Statement[list.size()]; list.toArray(stmtsArray); return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());} } @@ -2632,7 +2680,7 @@ Statement WhileStatement0(final int start, final int end) : try { { - Statement[] stmtsArray = new Statement[stmts.size()]; + final Statement[] stmtsArray = new Statement[stmts.size()]; stmts.toArray(stmtsArray); return new Block(stmtsArray,pos,SimpleCharStream.getPosition());} } catch (ParseException e) { @@ -2743,9 +2791,9 @@ ForStatement ForStatement() : { final Token token; final int pos = SimpleCharStream.getPosition(); -Statement[] initializations = null; +Expression[] initializations = null; Expression condition = null; -Statement[] increments = null; +Expression[] increments = null; Statement action; final ArrayList list = new ArrayList(); final int startBlock, endBlock; @@ -2796,7 +2844,7 @@ final int startBlock, endBlock; try { { - Statement[] stmtsArray = new Statement[list.size()]; + final Statement[] stmtsArray = new Statement[list.size()]; list.toArray(stmtsArray); return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());} } catch (ParseException e) { @@ -2809,31 +2857,31 @@ final int startBlock, endBlock; ) } -Statement[] ForInit() : +Expression[] ForInit() : { - Statement[] statements; + final Expression[] exprs; } { LOOKAHEAD(LocalVariableDeclaration()) - statements = LocalVariableDeclaration() - {return statements;} + exprs = LocalVariableDeclaration() + {return exprs;} | - statements = StatementExpressionList() - {return statements;} + exprs = StatementExpressionList() + {return exprs;} } -Statement[] StatementExpressionList() : +Expression[] StatementExpressionList() : { final ArrayList list = new ArrayList(); - Statement expr; + final Expression expr; } { expr = StatementExpression() {list.add(expr);} ( StatementExpression() {list.add(expr);})* { - Statement[] stmtsArray = new Statement[list.size()]; - list.toArray(stmtsArray); - return stmtsArray;} + final Expression[] exprsArray = new Expression[list.size()]; + list.toArray(exprsArray); + return exprsArray;} } Continue ContinueStatement() :