3   CHOICE_AMBIGUITY_CHECK = 2;
 
   4   OTHER_AMBIGUITY_CHECK = 1;
 
   7   DEBUG_LOOKAHEAD = false;
 
   8   DEBUG_TOKEN_MANAGER = false;
 
   9   OPTIMIZE_TOKEN_MANAGER = false;
 
  10   ERROR_REPORTING = true;
 
  11   JAVA_UNICODE_ESCAPE = false;
 
  12   UNICODE_INPUT = false;
 
  14   USER_TOKEN_MANAGER = false;
 
  15   USER_CHAR_STREAM = false;
 
  17   BUILD_TOKEN_MANAGER = true;
 
  19   FORCE_LA_CHECK = false;
 
  22 PARSER_BEGIN(PHPParser)
 
  25 import org.eclipse.core.resources.IFile;
 
  26 import org.eclipse.core.resources.IMarker;
 
  27 import org.eclipse.core.runtime.CoreException;
 
  28 import org.eclipse.ui.texteditor.MarkerUtilities;
 
  29 import org.eclipse.jface.preference.IPreferenceStore;
 
  31 import java.util.Hashtable;
 
  32 import java.util.Enumeration;
 
  33 import java.util.ArrayList;
 
  34 import java.io.StringReader;
 
  36 import java.text.MessageFormat;
 
  38 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
 
  39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
  40 import net.sourceforge.phpdt.internal.compiler.ast.*;
 
  41 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
 
  42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
 
  46  * This php parser is inspired by the Java 1.2 grammar example
 
  47  * given with JavaCC. You can get JavaCC at http://www.webgain.com
 
  48  * You can test the parser with the PHPParserTestCase2.java
 
  49  * @author Matthieu Casanova
 
  51 public final class PHPParser extends PHPParserSuperclass {
 
  53   /** The file that is parsed. */
 
  54   private static IFile fileToParse;
 
  56   /** The current segment. */
 
  57   private static OutlineableWithChildren currentSegment;
 
  59   private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
 
  60   private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
 
  61   static PHPOutlineInfo outlineInfo;
 
  63   public static MethodDeclaration currentFunction;
 
  64   private static boolean assigning;
 
  66   /** The error level of the current ParseException. */
 
  67   private static int errorLevel = ERROR;
 
  68   /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
 
  69   private static String errorMessage;
 
  71   private static int errorStart = -1;
 
  72   private static int errorEnd = -1;
 
  73   private static PHPDocument phpDocument;
 
  75    * The point where html starts.
 
  76    * It will be used by the token manager to create HTMLCode objects
 
  78   public static int htmlStart;
 
  81   private final static int AstStackIncrement = 100;
 
  82   /** The stack of node. */
 
  83   private static AstNode[] nodes;
 
  84   /** The cursor in expression stack. */
 
  85   private static int nodePtr;
 
  87   public final void setFileToParse(final IFile fileToParse) {
 
  88     this.fileToParse = fileToParse;
 
  94   public PHPParser(final IFile fileToParse) {
 
  95     this(new StringReader(""));
 
  96     this.fileToParse = fileToParse;
 
 100    * Reinitialize the parser.
 
 102   private static final void init() {
 
 103     nodes = new AstNode[AstStackIncrement];
 
 109    * Add an php node on the stack.
 
 110    * @param node the node that will be added to the stack
 
 112   private static final void pushOnAstNodes(AstNode node) {
 
 114       nodes[++nodePtr] = node;
 
 115     } catch (IndexOutOfBoundsException e) {
 
 116       int oldStackLength = nodes.length;
 
 117       AstNode[] oldStack = nodes;
 
 118       nodes = new AstNode[oldStackLength + AstStackIncrement];
 
 119       System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
 
 120       nodePtr = oldStackLength;
 
 121       nodes[nodePtr] = node;
 
 125   public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
 
 126     PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
 
 127     final StringReader stream = new StringReader(strEval);
 
 128     if (jj_input_stream == null) {
 
 129       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 131     ReInit(new StringReader(strEval));
 
 136   public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
 
 138       final Reader stream = new FileReader(fileName);
 
 139       if (jj_input_stream == null) {
 
 140         jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 145     } catch (FileNotFoundException e) {
 
 146       e.printStackTrace();  //To change body of catch statement use Options | File Templates.
 
 150   public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
 
 151     final StringReader stream = new StringReader(strEval);
 
 152     if (jj_input_stream == null) {
 
 153       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 160   public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
 
 161     currentSegment = new PHPDocument(parent);
 
 162     outlineInfo = new PHPOutlineInfo(parent);
 
 163     final StringReader stream = new StringReader(s);
 
 164     if (jj_input_stream == null) {
 
 165       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 171       //PHPeclipsePlugin.log(1,phpDocument.toString());
 
 172     } catch (ParseException e) {
 
 173       processParseException(e);
 
 179    * This method will process the parse exception.
 
 180    * If the error message is null, the parse exception wasn't catched and a trace is written in the log
 
 181    * @param e the ParseException
 
 183   private static void processParseException(final ParseException e) {
 
 184     if (errorMessage == null) {
 
 185       PHPeclipsePlugin.log(e);
 
 186       errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
 
 187       errorStart = jj_input_stream.getPosition();
 
 188       errorEnd   = errorStart + 1;
 
 195    * Create marker for the parse error
 
 196    * @param e the ParseException
 
 198   private static void setMarker(final ParseException e) {
 
 200       if (errorStart == -1) {
 
 201         setMarker(fileToParse,
 
 203                   jj_input_stream.tokenBegin,
 
 204                   jj_input_stream.tokenBegin + e.currentToken.image.length(),
 
 206                   "Line " + e.currentToken.beginLine);
 
 208         setMarker(fileToParse,
 
 213                   "Line " + e.currentToken.beginLine);
 
 217     } catch (CoreException e2) {
 
 218       PHPeclipsePlugin.log(e2);
 
 223    * Create markers according to the external parser output
 
 225   private static void createMarkers(final String output, final IFile file) throws CoreException {
 
 226     // delete all markers
 
 227     file.deleteMarkers(IMarker.PROBLEM, false, 0);
 
 232     while ((brIndx = output.indexOf("<br />", indx)) != -1) {
 
 233       // newer php error output (tested with 4.2.3)
 
 234       scanLine(output, file, indx, brIndx);
 
 239       while ((brIndx = output.indexOf("<br>", indx)) != -1) {
 
 240         // older php error output (tested with 4.2.3)
 
 241         scanLine(output, file, indx, brIndx);
 
 247   private static void scanLine(final String output,
 
 250                                final int brIndx) throws CoreException {
 
 252     StringBuffer lineNumberBuffer = new StringBuffer(10);
 
 254     current = output.substring(indx, brIndx);
 
 256     if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
 
 257       int onLine = current.indexOf("on line <b>");
 
 259         lineNumberBuffer.delete(0, lineNumberBuffer.length());
 
 260         for (int i = onLine; i < current.length(); i++) {
 
 261           ch = current.charAt(i);
 
 262           if ('0' <= ch && '9' >= ch) {
 
 263             lineNumberBuffer.append(ch);
 
 267         int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
 
 269         Hashtable attributes = new Hashtable();
 
 271         current = current.replaceAll("\n", "");
 
 272         current = current.replaceAll("<b>", "");
 
 273         current = current.replaceAll("</b>", "");
 
 274         MarkerUtilities.setMessage(attributes, current);
 
 276         if (current.indexOf(PARSE_ERROR_STRING) != -1)
 
 277           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
 
 278         else if (current.indexOf(PARSE_WARNING_STRING) != -1)
 
 279           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
 
 281           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
 
 282         MarkerUtilities.setLineNumber(attributes, lineNumber);
 
 283         MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
 
 288   public final void parse(final String s) throws CoreException {
 
 289     final StringReader stream = new StringReader(s);
 
 290     if (jj_input_stream == null) {
 
 291       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 297     } catch (ParseException e) {
 
 298       processParseException(e);
 
 303    * Call the php parse command ( php -l -f <filename> )
 
 304    * and create markers according to the external parser output
 
 306   public static void phpExternalParse(final IFile file) {
 
 307     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
 
 308     final String filename = file.getLocation().toString();
 
 310     final String[] arguments = { filename };
 
 311     final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
 
 312     final String command = form.format(arguments);
 
 314     final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
 
 317       // parse the buffer to find the errors and warnings
 
 318       createMarkers(parserResult, file);
 
 319     } catch (CoreException e) {
 
 320       PHPeclipsePlugin.log(e);
 
 325    * Put a new html block in the stack.
 
 327   public static final void createNewHTMLCode() {
 
 328     final int currentPosition = SimpleCharStream.getPosition();
 
 329     if (currentPosition == htmlStart) {
 
 332     final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition).toCharArray();
 
 333     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
 
 336   private static final void parse() throws ParseException {
 
 341 PARSER_END(PHPParser)
 
 345   <PHPSTARTSHORT : "<?">    {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 346 | <PHPSTARTLONG  : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 347 | <PHPECHOSTART  : "<?=">   {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 352   <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
 
 355 /* Skip any character if we are not in php mode */
 
 373 <PHPPARSING> SPECIAL_TOKEN :
 
 375   "//" : IN_SINGLE_LINE_COMMENT
 
 377   "#"  : IN_SINGLE_LINE_COMMENT
 
 379   <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
 
 381   "/*" : IN_MULTI_LINE_COMMENT
 
 384 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
 
 386   <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
 
 389 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
 
 391   <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
 
 397   <FORMAL_COMMENT: "*/" > : PHPPARSING
 
 400 <IN_MULTI_LINE_COMMENT>
 
 403   <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
 
 406 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
 
 416 | <FUNCTION : "function">
 
 419 | <ELSEIF   : "elseif">
 
 426 /* LANGUAGE CONSTRUCT */
 
 431 | <INCLUDE            : "include">
 
 432 | <REQUIRE            : "require">
 
 433 | <INCLUDE_ONCE       : "include_once">
 
 434 | <REQUIRE_ONCE       : "require_once">
 
 435 | <GLOBAL             : "global">
 
 436 | <STATIC             : "static">
 
 437 | <CLASSACCESS        : "->">
 
 438 | <STATICCLASSACCESS  : "::">
 
 439 | <ARRAYASSIGN        : "=>">
 
 442 /* RESERVED WORDS AND LITERALS */
 
 448 | <CONTINUE : "continue">
 
 449 | <_DEFAULT : "default">
 
 451 | <EXTENDS  : "extends">
 
 456 | <RETURN   : "return">
 
 458 | <SWITCH   : "switch">
 
 463 | <ENDWHILE : "endwhile">
 
 464 | <ENDSWITCH: "endswitch">
 
 466 | <ENDFOR   : "endfor">
 
 467 | <FOREACH  : "foreach">
 
 475 | <OBJECT  : "object">
 
 477 | <BOOLEAN : "boolean">
 
 479 | <DOUBLE  : "double">
 
 482 | <INTEGER : "integer">
 
 512 | <RSIGNEDSHIFT       : ">>">
 
 513 | <RUNSIGNEDSHIFT     : ">>>">
 
 522         <DECIMAL_LITERAL> (["l","L"])?
 
 523       | <HEX_LITERAL> (["l","L"])?
 
 524       | <OCTAL_LITERAL> (["l","L"])?
 
 527   < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
 
 529   < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
 
 531   < #OCTAL_LITERAL: "0" (["0"-"7"])* >
 
 533   < FLOATING_POINT_LITERAL:
 
 534         (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
 
 535       | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
 
 536       | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
 
 537       | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
 
 540   < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 
 542   < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
 
 576   < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
 
 579       ["a"-"z"] | ["A"-"Z"]
 
 587     "_" | ["\u007f"-"\u00ff"]
 
 612 | <EQUAL_EQUAL        : "==">
 
 617 | <BANGDOUBLEEQUAL    : "!==">
 
 618 | <TRIPLEEQUAL        : "===">
 
 625 | <PLUSASSIGN         : "+=">
 
 626 | <MINUSASSIGN        : "-=">
 
 627 | <STARASSIGN         : "*=">
 
 628 | <SLASHASSIGN        : "/=">
 
 634 | <TILDEEQUAL         : "~=">
 
 635 | <LSHIFTASSIGN       : "<<=">
 
 636 | <RSIGNEDSHIFTASSIGN : ">>=">
 
 641   < DOLLAR_ID: <DOLLAR> <IDENTIFIER>  >
 
 649   {PHPParser.createNewHTMLCode();}
 
 658   } catch (TokenMgrError e) {
 
 659     PHPeclipsePlugin.log(e);
 
 660     errorStart   = SimpleCharStream.getPosition();
 
 661     errorEnd     = errorStart + 1;
 
 662     errorMessage = e.getMessage();
 
 664     throw generateParseException();
 
 669  * A php block is a <?= expression [;]?>
 
 670  * or <?php somephpcode ?>
 
 671  * or <? somephpcode ?>
 
 675   final int start = jj_input_stream.getPosition();
 
 683       setMarker(fileToParse,
 
 684                 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
 
 686                 jj_input_stream.getPosition(),
 
 688                 "Line " + token.beginLine);
 
 689     } catch (CoreException e) {
 
 690       PHPeclipsePlugin.log(e);
 
 696   } catch (ParseException e) {
 
 697     errorMessage = "'?>' expected";
 
 699     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
 700     errorEnd   = jj_input_stream.getPosition() + 1;
 
 705 PHPEchoBlock phpEchoBlock() :
 
 707   final Expression expr;
 
 708   final int pos = SimpleCharStream.getPosition();
 
 709   PHPEchoBlock echoBlock;
 
 712   <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
 
 714   echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
 
 715   pushOnAstNodes(echoBlock);
 
 725 ClassDeclaration ClassDeclaration() :
 
 727   final ClassDeclaration classDeclaration;
 
 728   final Token className;
 
 729   Token superclassName = null;
 
 735     {pos = jj_input_stream.getPosition();}
 
 736     className = <IDENTIFIER>
 
 737   } catch (ParseException e) {
 
 738     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
 
 740     errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
 741     errorEnd     = jj_input_stream.getPosition() + 1;
 
 747       superclassName = <IDENTIFIER>
 
 748     } catch (ParseException e) {
 
 749       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
 
 751       errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
 752       errorEnd   = jj_input_stream.getPosition() + 1;
 
 757     if (superclassName == null) {
 
 758       classDeclaration = new ClassDeclaration(currentSegment,
 
 759                                               className.image.toCharArray(),
 
 760                                               superclassName.image.toCharArray(),
 
 764       classDeclaration = new ClassDeclaration(currentSegment,
 
 765                                               className.image.toCharArray(),
 
 769       currentSegment.add(classDeclaration);
 
 770       currentSegment = classDeclaration;
 
 772   ClassBody(classDeclaration)
 
 773   {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
 
 774    classDeclaration.sourceEnd = SimpleCharStream.getPosition();
 
 775    pushOnAstNodes(classDeclaration);
 
 776    return classDeclaration;}
 
 779 void ClassBody(ClassDeclaration classDeclaration) :
 
 784   } catch (ParseException e) {
 
 785     errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
 
 787     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
 788     errorEnd   = jj_input_stream.getPosition() + 1;
 
 791   ( ClassBodyDeclaration(classDeclaration) )*
 
 794   } catch (ParseException e) {
 
 795     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
 
 797     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
 798     errorEnd   = jj_input_stream.getPosition() + 1;
 
 804  * A class can contain only methods and fields.
 
 806 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
 
 808   MethodDeclaration method;
 
 809   FieldDeclaration field;
 
 812   method = MethodDeclaration() {classDeclaration.addMethod(method);}
 
 813 | field = FieldDeclaration()   {classDeclaration.addVariable(field);}
 
 817  * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
 
 819 FieldDeclaration FieldDeclaration() :
 
 821   VariableDeclaration variableDeclaration;
 
 824   <VAR> variableDeclaration = VariableDeclarator()
 
 826     outlineInfo.addVariable(new String(variableDeclaration.name));
 
 827     if (currentSegment != null) {
 
 828       currentSegment.add(variableDeclaration);
 
 832       variableDeclaration = VariableDeclarator()
 
 834       if (currentSegment != null) {
 
 835         currentSegment.add(variableDeclaration);
 
 841   } catch (ParseException e) {
 
 842     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
 
 844     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
 845     errorEnd   = jj_input_stream.getPosition() + 1;
 
 850 VariableDeclaration VariableDeclarator() :
 
 852   final String varName, varValue;
 
 853   Expression initializer = null;
 
 854   final int pos = jj_input_stream.getPosition();
 
 857   varName = VariableDeclaratorId()
 
 861       initializer = VariableInitializer()
 
 862     } catch (ParseException e) {
 
 863       errorMessage = "Literal expression expected in variable initializer";
 
 865       errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
 866       errorEnd   = jj_input_stream.getPosition() + 1;
 
 870   {return new VariableDeclaration(currentSegment,
 
 871                                   varName.toCharArray(),
 
 878  * @return the variable name (with suffix)
 
 880 String VariableDeclaratorId() :
 
 883   Expression expression;
 
 884   final StringBuffer buff = new StringBuffer();
 
 885   final int pos = SimpleCharStream.getPosition();
 
 886   ConstantIdentifier ex;
 
 890     expr = Variable()   {buff.append(expr);}
 
 892       {ex = new ConstantIdentifier(expr.toCharArray(),
 
 894                                    SimpleCharStream.getPosition());}
 
 895       expression = VariableSuffix(ex)
 
 896       {buff.append(expression.toStringExpression());}
 
 898     {return buff.toString();}
 
 899   } catch (ParseException e) {
 
 900     errorMessage = "'$' expected for variable identifier";
 
 902     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
 903     errorEnd   = jj_input_stream.getPosition() + 1;
 
 910   final StringBuffer buff;
 
 911   Expression expression = null;
 
 916   token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
 
 918     if (expression == null && !assigning) {
 
 919       return token.image.substring(1);
 
 921     buff = new StringBuffer(token.image);
 
 923     buff.append(expression.toStringExpression());
 
 925     return buff.toString();
 
 928   <DOLLAR> expr = VariableName()
 
 932 String VariableName():
 
 934   final StringBuffer buff;
 
 936   Expression expression = null;
 
 940   <LBRACE> expression = Expression() <RBRACE>
 
 941   {buff = new StringBuffer('{');
 
 942    buff.append(expression.toStringExpression());
 
 944    return buff.toString();}
 
 946   token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
 
 948     if (expression == null) {
 
 951     buff = new StringBuffer(token.image);
 
 953     buff.append(expression.toStringExpression());
 
 955     return buff.toString();
 
 958   <DOLLAR> expr = VariableName()
 
 960     buff = new StringBuffer('$');
 
 962     return buff.toString();
 
 965   token = <DOLLAR_ID> {return token.image;}
 
 968 Expression VariableInitializer() :
 
 970   final Expression expr;
 
 972   final int pos = SimpleCharStream.getPosition();
 
 978   <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
 
 979   {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
 
 981                                                         SimpleCharStream.getPosition()),
 
 985   <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
 
 986   {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
 
 988                                                         SimpleCharStream.getPosition()),
 
 992   expr = ArrayDeclarator()
 
 996   {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
 
 999 ArrayVariableDeclaration ArrayVariable() :
 
1002 Expression expr2 = null;
 
1005   expr = Expression() [<ARRAYASSIGN> expr2 = Expression()]
 
1006   {return new ArrayVariableDeclaration(expr,expr2);}
 
1009 ArrayVariableDeclaration[] ArrayInitializer() :
 
1011   ArrayVariableDeclaration expr;
 
1012   final ArrayList list = new ArrayList();
 
1015   <LPAREN> [ expr = ArrayVariable()
 
1017             ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
 
1021            [<COMMA> {list.add(null);}]
 
1023   {return (ArrayVariableDeclaration[]) list.toArray();}
 
1027  * A Method Declaration.
 
1028  * <b>function</b> MetodDeclarator() Block()
 
1030 MethodDeclaration MethodDeclaration() :
 
1032   final MethodDeclaration functionDeclaration;
 
1033   Token functionToken;
 
1037   functionToken = <FUNCTION>
 
1039     functionDeclaration = MethodDeclarator()
 
1040     {outlineInfo.addVariable(new String(functionDeclaration.name));}
 
1041   } catch (ParseException e) {
 
1042     if (errorMessage != null) {
 
1045     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
 
1047     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1048     errorEnd   = jj_input_stream.getPosition() + 1;
 
1052     if (currentSegment != null) {
 
1053       currentSegment.add(functionDeclaration);
 
1054       currentSegment = functionDeclaration;
 
1056     currentFunction = functionDeclaration;
 
1060     functionDeclaration.statements = block.statements;
 
1061     currentFunction = null;
 
1062     if (currentSegment != null) {
 
1063       currentSegment = (OutlineableWithChildren) currentSegment.getParent();
 
1065     return functionDeclaration;
 
1070  * A MethodDeclarator.
 
1071  * [&] IDENTIFIER(parameters ...).
 
1072  * @return a function description for the outline
 
1074 MethodDeclaration MethodDeclarator() :
 
1076   final Token identifier;
 
1077   Token reference = null;
 
1078   final Hashtable formalParameters;
 
1079   final int pos = SimpleCharStream.getPosition();
 
1082   [ reference = <BIT_AND> ]
 
1083   identifier = <IDENTIFIER>
 
1084   formalParameters = FormalParameters()
 
1085   {return new MethodDeclaration(currentSegment,
 
1086                                  identifier.image.toCharArray(),
 
1090                                  SimpleCharStream.getPosition());}
 
1094  * FormalParameters follows method identifier.
 
1095  * (FormalParameter())
 
1097 Hashtable FormalParameters() :
 
1100   final StringBuffer buff = new StringBuffer("(");
 
1101   VariableDeclaration var;
 
1102   final Hashtable parameters = new Hashtable();
 
1107   } catch (ParseException e) {
 
1108     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
 
1110     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1111     errorEnd   = jj_input_stream.getPosition() + 1;
 
1114             [ var = FormalParameter()
 
1115               {parameters.put(new String(var.name),var);}
 
1117                 <COMMA> var = FormalParameter()
 
1118                 {parameters.put(new String(var.name),var);}
 
1123   } catch (ParseException e) {
 
1124     errorMessage = "')' expected";
 
1126     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1127     errorEnd   = jj_input_stream.getPosition() + 1;
 
1130  {return parameters;}
 
1134  * A formal parameter.
 
1135  * $varname[=value] (,$varname[=value])
 
1137 VariableDeclaration FormalParameter() :
 
1139   final VariableDeclaration variableDeclaration;
 
1143   [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
 
1145     if (token != null) {
 
1146       variableDeclaration.setReference(true);
 
1148     return variableDeclaration;}
 
1151 ConstantIdentifier Type() :
 
1154   <STRING>             {pos = SimpleCharStream.getPosition();
 
1155                         return new ConstantIdentifier(Types.STRING,
 
1157 | <BOOL>               {pos = SimpleCharStream.getPosition();
 
1158                         return new ConstantIdentifier(Types.BOOL,
 
1160 | <BOOLEAN>            {pos = SimpleCharStream.getPosition();
 
1161                         return new ConstantIdentifier(Types.BOOLEAN,
 
1163 | <REAL>               {pos = SimpleCharStream.getPosition();
 
1164                         return new ConstantIdentifier(Types.REAL,
 
1166 | <DOUBLE>             {pos = SimpleCharStream.getPosition();
 
1167                         return new ConstantIdentifier(Types.DOUBLE,
 
1169 | <FLOAT>              {pos = SimpleCharStream.getPosition();
 
1170                         return new ConstantIdentifier(Types.FLOAT,
 
1172 | <INT>                {pos = SimpleCharStream.getPosition();
 
1173                         return new ConstantIdentifier(Types.INT,
 
1175 | <INTEGER>            {pos = SimpleCharStream.getPosition();
 
1176                         return new ConstantIdentifier(Types.INTEGER,
 
1178 | <OBJECT>             {pos = SimpleCharStream.getPosition();
 
1179                         return new ConstantIdentifier(Types.OBJECT,
 
1183 Expression Expression() :
 
1185   final Expression expr;
 
1188   expr = PrintExpression()       {return expr;}
 
1189 | expr = ListExpression()        {return expr;}
 
1190 | LOOKAHEAD(varAssignation())
 
1191   expr = varAssignation()        {return expr;}
 
1192 | expr = ConditionalExpression() {return expr;}
 
1196  * A Variable assignation.
 
1197  * varName (an assign operator) any expression
 
1199 VarAssignation varAssignation() :
 
1202   final Expression expression;
 
1203   final int assignOperator;
 
1204   final int pos = SimpleCharStream.getPosition();
 
1207   varName = VariableDeclaratorId()
 
1208   assignOperator = AssignmentOperator()
 
1210       expression = Expression()
 
1211     } catch (ParseException e) {
 
1212       if (errorMessage != null) {
 
1215       errorMessage = "expression expected";
 
1217       errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1218       errorEnd   = jj_input_stream.getPosition() + 1;
 
1221     {return new VarAssignation(varName.toCharArray(),
 
1225                                SimpleCharStream.getPosition());}
 
1228 int AssignmentOperator() :
 
1231   <ASSIGN>             {return VarAssignation.EQUAL;}
 
1232 | <STARASSIGN>         {return VarAssignation.STAR_EQUAL;}
 
1233 | <SLASHASSIGN>        {return VarAssignation.SLASH_EQUAL;}
 
1234 | <REMASSIGN>          {return VarAssignation.REM_EQUAL;}
 
1235 | <PLUSASSIGN>         {return VarAssignation.PLUS_EQUAL;}
 
1236 | <MINUSASSIGN>        {return VarAssignation.MINUS_EQUAL;}
 
1237 | <LSHIFTASSIGN>       {return VarAssignation.LSHIFT_EQUAL;}
 
1238 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
 
1239 | <ANDASSIGN>          {return VarAssignation.AND_EQUAL;}
 
1240 | <XORASSIGN>          {return VarAssignation.XOR_EQUAL;}
 
1241 | <ORASSIGN>           {return VarAssignation.OR_EQUAL;}
 
1242 | <DOTASSIGN>          {return VarAssignation.DOT_EQUAL;}
 
1243 | <TILDEEQUAL>         {return VarAssignation.TILDE_EQUAL;}
 
1246 Expression ConditionalExpression() :
 
1248   final Expression expr;
 
1249   Expression expr2 = null;
 
1250   Expression expr3 = null;
 
1253   expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
 
1255   if (expr3 == null) {
 
1258   return new ConditionalExpression(expr,expr2,expr3);
 
1262 Expression ConditionalOrExpression() :
 
1264   Expression expr,expr2;
 
1268   expr = ConditionalAndExpression()
 
1271         <OR_OR> {operator = OperatorIds.OR_OR;}
 
1272       | <_ORL>  {operator = OperatorIds.ORL;}
 
1273     ) expr2 = ConditionalAndExpression()
 
1275       expr = new BinaryExpression(expr,expr2,operator);
 
1281 Expression ConditionalAndExpression() :
 
1283   Expression expr,expr2;
 
1287   expr = ConcatExpression()
 
1289   (  <AND_AND> {operator = OperatorIds.AND_AND;}
 
1290    | <_ANDL>   {operator = OperatorIds.ANDL;})
 
1291    expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
 
1296 Expression ConcatExpression() :
 
1298   Expression expr,expr2;
 
1301   expr = InclusiveOrExpression()
 
1303     <DOT> expr2 = InclusiveOrExpression()
 
1304     {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
 
1309 Expression InclusiveOrExpression() :
 
1311   Expression expr,expr2;
 
1314   expr = ExclusiveOrExpression()
 
1315   (<BIT_OR> expr2 = ExclusiveOrExpression()
 
1316    {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
 
1321 Expression ExclusiveOrExpression() :
 
1323   Expression expr,expr2;
 
1326   expr = AndExpression()
 
1328     <XOR> expr2 = AndExpression()
 
1329     {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
 
1334 Expression AndExpression() :
 
1336   Expression expr,expr2;
 
1339   expr = EqualityExpression()
 
1341     <BIT_AND> expr2 = EqualityExpression()
 
1342     {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
 
1347 Expression EqualityExpression() :
 
1349   Expression expr,expr2;
 
1353   expr = RelationalExpression()
 
1355   (   <EQUAL_EQUAL>      {operator = OperatorIds.EQUAL_EQUAL;}
 
1356     | <DIF>              {operator = OperatorIds.DIF;}
 
1357     | <NOT_EQUAL>        {operator = OperatorIds.DIF;}
 
1358     | <BANGDOUBLEEQUAL>  {operator = OperatorIds.BANG_EQUAL_EQUAL;}
 
1359     | <TRIPLEEQUAL>      {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
 
1362     expr2 = RelationalExpression()
 
1363   } catch (ParseException e) {
 
1364     if (errorMessage != null) {
 
1367     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
1369     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1370     errorEnd   = jj_input_stream.getPosition() + 1;
 
1374     expr = new BinaryExpression(expr,expr2,operator);
 
1380 Expression RelationalExpression() :
 
1382   Expression expr,expr2;
 
1386   expr = ShiftExpression()
 
1388   ( <LT> {operator = OperatorIds.LESS;}
 
1389   | <GT> {operator = OperatorIds.GREATER;}
 
1390   | <LE> {operator = OperatorIds.LESS_EQUAL;}
 
1391   | <GE> {operator = OperatorIds.GREATER_EQUAL;})
 
1392    expr2 = ShiftExpression()
 
1393   {expr = new BinaryExpression(expr,expr2,operator);}
 
1398 Expression ShiftExpression() :
 
1400   Expression expr,expr2;
 
1404   expr = AdditiveExpression()
 
1406   ( <LSHIFT>         {operator = OperatorIds.LEFT_SHIFT;}
 
1407   | <RSIGNEDSHIFT>   {operator = OperatorIds.RIGHT_SHIFT;}
 
1408   | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
 
1409   expr2 = AdditiveExpression()
 
1410   {expr = new BinaryExpression(expr,expr2,operator);}
 
1415 Expression AdditiveExpression() :
 
1417   Expression expr,expr2;
 
1421   expr = MultiplicativeExpression()
 
1423    ( <PLUS>  {operator = OperatorIds.PLUS;}
 
1424    | <MINUS> {operator = OperatorIds.MINUS;} )
 
1425    expr2 = MultiplicativeExpression()
 
1426   {expr = new BinaryExpression(expr,expr2,operator);}
 
1431 Expression MultiplicativeExpression() :
 
1433   Expression expr,expr2;
 
1438     expr = UnaryExpression()
 
1439   } catch (ParseException e) {
 
1440     if (errorMessage != null) {
 
1443     errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
 
1445     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1446     errorEnd   = jj_input_stream.getPosition() + 1;
 
1450    (  <STAR>      {operator = OperatorIds.MULTIPLY;}
 
1451     | <SLASH>     {operator = OperatorIds.DIVIDE;}
 
1452     | <REMAINDER> {operator = OperatorIds.REMAINDER;})
 
1453     expr2 = UnaryExpression()
 
1454     {expr = new BinaryExpression(expr,expr2,operator);}
 
1460  * An unary expression starting with @, & or nothing
 
1462 Expression UnaryExpression() :
 
1465   final int pos = SimpleCharStream.getPosition();
 
1468   <BIT_AND> expr = UnaryExpressionNoPrefix()
 
1469   {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
 
1471   expr = AtUnaryExpression()
 
1475 Expression AtUnaryExpression() :
 
1478   final int pos = SimpleCharStream.getPosition();
 
1482   expr = AtUnaryExpression()
 
1483   {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
 
1485   expr = UnaryExpressionNoPrefix()
 
1490 Expression UnaryExpressionNoPrefix() :
 
1494   final int pos = SimpleCharStream.getPosition();
 
1497   (  <PLUS>  {operator = OperatorIds.PLUS;}
 
1498    | <MINUS> {operator = OperatorIds.MINUS;})
 
1499    expr = UnaryExpression()
 
1500   {return new PrefixedUnaryExpression(expr,operator,pos);}
 
1502   expr = PreIncDecExpression()
 
1505   expr = UnaryExpressionNotPlusMinus()
 
1510 Expression PreIncDecExpression() :
 
1512 final Expression expr;
 
1514   final int pos = SimpleCharStream.getPosition();
 
1517   (  <INCR> {operator = OperatorIds.PLUS_PLUS;}
 
1518    | <DECR> {operator = OperatorIds.MINUS_MINUS;})
 
1519    expr = PrimaryExpression()
 
1520   {return new PrefixedUnaryExpression(expr,operator,pos);}
 
1523 Expression UnaryExpressionNotPlusMinus() :
 
1526   final int pos = SimpleCharStream.getPosition();
 
1529   <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
 
1530 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
 
1531   expr = CastExpression()         {return expr;}
 
1532 | expr = PostfixExpression()      {return expr;}
 
1533 | expr = Literal()                {return expr;}
 
1534 | <LPAREN> expr = Expression()
 
1537   } catch (ParseException e) {
 
1538     errorMessage = "')' expected";
 
1540     errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1541     errorEnd     = jj_input_stream.getPosition() + 1;
 
1547 CastExpression CastExpression() :
 
1549 final ConstantIdentifier type;
 
1550 final Expression expr;
 
1551 final int pos = SimpleCharStream.getPosition();
 
1556   | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
 
1557   <RPAREN> expr = UnaryExpression()
 
1558   {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
 
1561 Expression PostfixExpression() :
 
1565   final int pos = SimpleCharStream.getPosition();
 
1568   expr = PrimaryExpression()
 
1569   [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
 
1570   | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
 
1572     if (operator == -1) {
 
1575     return new PostfixedUnaryExpression(expr,operator,pos);
 
1579 Expression PrimaryExpression() :
 
1581   final Token identifier;
 
1583   final StringBuffer buff = new StringBuffer();
 
1584   final int pos = SimpleCharStream.getPosition();
 
1588   identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
 
1589   {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
 
1591                                                  SimpleCharStream.getPosition()),
 
1593                           ClassAccess.STATIC);}
 
1594   (expr = PrimarySuffix(expr))*
 
1597   expr = PrimaryPrefix()
 
1598   (expr = PrimarySuffix(expr))*
 
1601   expr = ArrayDeclarator()
 
1605 ArrayInitializer ArrayDeclarator() :
 
1607   final ArrayVariableDeclaration[] vars;
 
1608   final int pos = SimpleCharStream.getPosition();
 
1611   <ARRAY> vars = ArrayInitializer()
 
1612   {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
 
1615 Expression PrimaryPrefix() :
 
1617   final Expression expr;
 
1620   final int pos = SimpleCharStream.getPosition();
 
1623   token = <IDENTIFIER>           {return new ConstantIdentifier(token.image.toCharArray(),
 
1625                                                                 SimpleCharStream.getPosition());}
 
1626 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
 
1629 | var = VariableDeclaratorId()  {return new ConstantIdentifier(var.toCharArray(),
 
1631                                                                SimpleCharStream.getPosition());}
 
1634 PrefixedUnaryExpression classInstantiation() :
 
1637   final StringBuffer buff;
 
1638   final int pos = SimpleCharStream.getPosition();
 
1641   <NEW> expr = ClassIdentifier()
 
1643     {buff = new StringBuffer(expr.toStringExpression());}
 
1644     expr = PrimaryExpression()
 
1645     {buff.append(expr.toStringExpression());
 
1646     expr = new ConstantIdentifier(buff.toString().toCharArray(),
 
1648                                   SimpleCharStream.getPosition());}
 
1650   {return new PrefixedUnaryExpression(expr,
 
1655 ConstantIdentifier ClassIdentifier():
 
1659   final int pos = SimpleCharStream.getPosition();
 
1662   token = <IDENTIFIER>          {return new ConstantIdentifier(token.image.toCharArray(),
 
1664                                                                SimpleCharStream.getPosition());}
 
1665 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
 
1667                                                                SimpleCharStream.getPosition());}
 
1670 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
 
1672   final AbstractSuffixExpression expr;
 
1675   expr = Arguments(prefix)      {return expr;}
 
1676 | expr = VariableSuffix(prefix) {return expr;}
 
1679 AbstractSuffixExpression VariableSuffix(Expression prefix) :
 
1682   final int pos = SimpleCharStream.getPosition();
 
1683   Expression expression = null;
 
1688     expr = VariableName()
 
1689   } catch (ParseException e) {
 
1690     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
 
1692     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1693     errorEnd   = jj_input_stream.getPosition() + 1;
 
1696   {return new ClassAccess(prefix,
 
1697                           new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
 
1698                           ClassAccess.NORMAL);}
 
1700   <LBRACKET> [ expression = Expression() | expression = Type() ]  //Not good
 
1703   } catch (ParseException e) {
 
1704     errorMessage = "']' expected";
 
1706     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1707     errorEnd   = jj_input_stream.getPosition() + 1;
 
1710   {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
 
1719   token = <INTEGER_LITERAL>        {pos = SimpleCharStream.getPosition();
 
1720                                     return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
 
1721 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
 
1722                                     return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
 
1723 | token = <STRING_LITERAL>         {pos = SimpleCharStream.getPosition();
 
1724                                     return new StringLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
 
1725 | <TRUE>                           {pos = SimpleCharStream.getPosition();
 
1726                                     return new TrueLiteral(pos-4,pos);}
 
1727 | <FALSE>                          {pos = SimpleCharStream.getPosition();
 
1728                                     return new FalseLiteral(pos-4,pos);}
 
1729 | <NULL>                           {pos = SimpleCharStream.getPosition();
 
1730                                     return new NullLiteral(pos-4,pos);}
 
1733 FunctionCall Arguments(Expression func) :
 
1735 ArgumentDeclaration[] args = null;
 
1738   <LPAREN> [ args = ArgumentList() ]
 
1741   } catch (ParseException e) {
 
1742     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
 
1744     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1745     errorEnd   = jj_input_stream.getPosition() + 1;
 
1748   {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
 
1751 ArgumentDeclaration[] ArgumentList() :
 
1754 final ArrayList list = new ArrayList();
 
1763       } catch (ParseException e) {
 
1764         errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
 
1766         errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1767         errorEnd     = jj_input_stream.getPosition() + 1;
 
1771    {return (ArgumentDeclaration[]) list.toArray();}
 
1775  * A Statement without break.
 
1777 Statement StatementNoBreak() :
 
1779   final Statement statement;
 
1784   statement = Expression()
 
1787   } catch (ParseException e) {
 
1788     if (e.currentToken.next.kind != 4) {
 
1789       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1791       errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1792       errorEnd   = jj_input_stream.getPosition() + 1;
 
1798   statement = LabeledStatement() {return statement;}
 
1799 | statement = Block()            {return statement;}
 
1800 | statement = EmptyStatement()   {return statement;}
 
1801 | statement = StatementExpression()
 
1804   } catch (ParseException e) {
 
1805     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1807     errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1808     errorEnd     = jj_input_stream.getPosition() + 1;
 
1812 | statement = SwitchStatement()         {return statement;}
 
1813 | statement = IfStatement()             {return statement;}
 
1814 | statement = WhileStatement()          {return statement;}
 
1815 | statement = DoStatement()             {return statement;}
 
1816 | statement = ForStatement()            {return statement;}
 
1817 | statement = ForeachStatement()        {return statement;}
 
1818 | statement = ContinueStatement()       {return statement;}
 
1819 | statement = ReturnStatement()         {return statement;}
 
1820 | statement = EchoStatement()           {return statement;}
 
1821 | [token=<AT>] statement = IncludeStatement()
 
1822   {if (token != null) {
 
1823     ((InclusionStatement)statement).silent = true;
 
1826 | statement = StaticStatement()         {return statement;}
 
1827 | statement = GlobalStatement()         {return statement;}
 
1831  * A Normal statement.
 
1833 Statement Statement() :
 
1835   final Statement statement;
 
1838   statement = StatementNoBreak() {return statement;}
 
1839 | statement = BreakStatement()   {return statement;}
 
1843  * An html block inside a php syntax.
 
1845 HTMLBlock htmlBlock() :
 
1847   final int startIndex = nodePtr;
 
1848   AstNode[] blockNodes;
 
1852   <PHPEND> (phpEchoBlock())*
 
1854     (<PHPSTARTLONG> | <PHPSTARTSHORT>)
 
1855   } catch (ParseException e) {
 
1856     errorMessage = "End of file unexpected, '<?php' expected";
 
1858     errorStart   = jj_input_stream.getPosition();
 
1859     errorEnd     = jj_input_stream.getPosition();
 
1863   nbNodes = nodePtr-startIndex;
 
1864   blockNodes = new AstNode[nbNodes];
 
1865   System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
 
1866   return new HTMLBlock(nodes);}
 
1870  * An include statement. It's "include" an expression;
 
1872 InclusionStatement IncludeStatement() :
 
1874   final Expression expr;
 
1877   final int pos = jj_input_stream.getPosition();
 
1878   final InclusionStatement inclusionStatement;
 
1881       (  <REQUIRE>      {keyword = InclusionStatement.REQUIRE;}
 
1882        | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
 
1883        | <INCLUDE>      {keyword = InclusionStatement.INCLUDE;}
 
1884        | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
 
1887   } catch (ParseException e) {
 
1888     if (errorMessage != null) {
 
1891     errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
 
1893     errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1894     errorEnd     = jj_input_stream.getPosition() + 1;
 
1897   {inclusionStatement = new InclusionStatement(currentSegment,
 
1901    currentSegment.add(inclusionStatement);
 
1905   } catch (ParseException e) {
 
1906     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1908     errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1909     errorEnd     = jj_input_stream.getPosition() + 1;
 
1912   {return inclusionStatement;}
 
1915 PrintExpression PrintExpression() :
 
1917   final Expression expr;
 
1918   final int pos = SimpleCharStream.getPosition();
 
1921   <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
 
1924 ListExpression ListExpression() :
 
1927   Expression expression = null;
 
1928   ArrayList list = new ArrayList();
 
1929   final int pos = SimpleCharStream.getPosition();
 
1935   } catch (ParseException e) {
 
1936     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
 
1938     errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1939     errorEnd     = jj_input_stream.getPosition() + 1;
 
1943     expr = VariableDeclaratorId()
 
1946   {if (expr == null) list.add(null);}
 
1950     } catch (ParseException e) {
 
1951       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
 
1953       errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1954       errorEnd     = jj_input_stream.getPosition() + 1;
 
1957     expr = VariableDeclaratorId()
 
1962   } catch (ParseException e) {
 
1963     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
 
1965     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1966     errorEnd   = jj_input_stream.getPosition() + 1;
 
1969   [ <ASSIGN> expression = Expression()
 
1970     {return new ListExpression((String[]) list.toArray(),expression,pos,SimpleCharStream.getPosition());}]
 
1971   {return new ListExpression((String[]) list.toArray(),null,pos,SimpleCharStream.getPosition());}
 
1975  * An echo statement.
 
1976  * echo anyexpression (, otherexpression)*
 
1978 EchoStatement EchoStatement() :
 
1980   final ArrayList expressions = new ArrayList();
 
1982   final int pos = SimpleCharStream.getPosition();
 
1985   <ECHO> expr = Expression()
 
1986   {expressions.add(expr);}
 
1988     <COMMA> expr = Expression()
 
1989     {expressions.add(expr);}
 
1993     {return new EchoStatement((Expression[]) expressions.toArray(),pos);}
 
1994   } catch (ParseException e) {
 
1995     if (e.currentToken.next.kind != 4) {
 
1996       errorMessage = "';' expected after 'echo' statement";
 
1998       errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
1999       errorEnd     = jj_input_stream.getPosition() + 1;
 
2005 GlobalStatement GlobalStatement() :
 
2007    final int pos = jj_input_stream.getPosition();
 
2009    ArrayList vars = new ArrayList();
 
2010    GlobalStatement global;
 
2014     expr = VariableDeclaratorId()
 
2017     expr = VariableDeclaratorId()
 
2022     {global = new GlobalStatement(currentSegment,
 
2023                                   (String[]) vars.toArray(),
 
2025                                   SimpleCharStream.getPosition());
 
2026     currentSegment.add(global);
 
2028   } catch (ParseException e) {
 
2029     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
 
2031     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2032     errorEnd   = jj_input_stream.getPosition() + 1;
 
2037 StaticStatement StaticStatement() :
 
2039   final int pos = SimpleCharStream.getPosition();
 
2040   final ArrayList vars = new ArrayList();
 
2041   VariableDeclaration expr;
 
2044   <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
 
2045   (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
 
2048     {return new StaticStatement((String[])vars.toArray(),
 
2050                                 SimpleCharStream.getPosition());}
 
2051   } catch (ParseException e) {
 
2052     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
 
2054     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2055     errorEnd   = jj_input_stream.getPosition() + 1;
 
2060 LabeledStatement LabeledStatement() :
 
2062   final int pos = SimpleCharStream.getPosition();
 
2064   final Statement statement;
 
2067   label = <IDENTIFIER> <COLON> statement = Statement()
 
2068   {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
 
2080   final int pos = SimpleCharStream.getPosition();
 
2085   } catch (ParseException e) {
 
2086     errorMessage = "'{' expected";
 
2088     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2089     errorEnd   = jj_input_stream.getPosition() + 1;
 
2092   ( BlockStatement() | htmlBlock())*
 
2095   } catch (ParseException e) {
 
2096     errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
 
2098     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2099     errorEnd   = jj_input_stream.getPosition() + 1;
 
2104 Statement BlockStatement() :
 
2106   final Statement statement;
 
2109   statement = Statement()         {return statement;}
 
2110 | statement = ClassDeclaration()  {return statement;}
 
2111 | statement = MethodDeclaration() {return statement;}
 
2115  * A Block statement that will not contain any 'break'
 
2117 Statement BlockStatementNoBreak() :
 
2119   final Statement statement;
 
2122   statement = StatementNoBreak()  {return statement;}
 
2123 | statement = ClassDeclaration()  {return statement;}
 
2124 | statement = MethodDeclaration() {return statement;}
 
2127 VariableDeclaration[] LocalVariableDeclaration() :
 
2129   final ArrayList list = new ArrayList();
 
2130   VariableDeclaration var;
 
2133   var = LocalVariableDeclarator()
 
2135   ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
 
2136   {return (VariableDeclaration[]) list.toArray();}
 
2139 VariableDeclaration LocalVariableDeclarator() :
 
2141   final String varName;
 
2142   Expression init = null;
 
2143   final int pos = SimpleCharStream.getPosition();
 
2146   varName = VariableDeclaratorId() [ <ASSIGN> init = Expression() ]
 
2147   {return new VariableDeclaration(varName.toCharArray(),init,pos);}
 
2150 EmptyStatement EmptyStatement() :
 
2156   {pos = SimpleCharStream.getPosition();
 
2157    return new EmptyStatement(pos-1,pos);}
 
2160 Statement StatementExpression() :
 
2165   expr = PreIncDecExpression() {return expr;}
 
2167   expr = PrimaryExpression()
 
2168   [ <INCR> {expr = new PostfixedUnaryExpression(expr,
 
2169                                                 OperatorIds.PLUS_PLUS,
 
2170                                                 SimpleCharStream.getPosition());}
 
2171   | <DECR> {expr = new PostfixedUnaryExpression(expr,
 
2172                                                 OperatorIds.MINUS_MINUS,
 
2173                                                 SimpleCharStream.getPosition());}
 
2174   | AssignmentOperator() Expression() ]
 
2177 SwitchStatement SwitchStatement() :
 
2179   final Expression variable;
 
2180   final AbstractCase[] cases;
 
2181   final int pos = SimpleCharStream.getPosition();
 
2187   } catch (ParseException e) {
 
2188     errorMessage = "'(' expected after 'switch'";
 
2190     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2191     errorEnd   = jj_input_stream.getPosition() + 1;
 
2195     variable = Expression()
 
2196   } catch (ParseException e) {
 
2197     if (errorMessage != null) {
 
2200     errorMessage = "expression expected";
 
2202     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2203     errorEnd   = jj_input_stream.getPosition() + 1;
 
2208   } catch (ParseException e) {
 
2209     errorMessage = "')' expected";
 
2211     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2212     errorEnd   = jj_input_stream.getPosition() + 1;
 
2215   (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
 
2216   {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
 
2219 AbstractCase[] switchStatementBrace() :
 
2222   final ArrayList cases = new ArrayList();
 
2226  ( cas = switchLabel0() {cases.add(cas);})*
 
2229     {return (AbstractCase[]) cases.toArray();}
 
2230   } catch (ParseException e) {
 
2231     errorMessage = "'}' expected";
 
2233     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2234     errorEnd   = jj_input_stream.getPosition() + 1;
 
2239  * A Switch statement with : ... endswitch;
 
2240  * @param start the begin offset of the switch
 
2241  * @param end the end offset of the switch
 
2243 AbstractCase[] switchStatementColon(final int start, final int end) :
 
2246   final ArrayList cases = new ArrayList();
 
2251   setMarker(fileToParse,
 
2252             "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
 
2256             "Line " + token.beginLine);
 
2257   } catch (CoreException e) {
 
2258     PHPeclipsePlugin.log(e);
 
2260   ( cas = switchLabel0() {cases.add(cas);})*
 
2263   } catch (ParseException e) {
 
2264     errorMessage = "'endswitch' expected";
 
2266     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2267     errorEnd   = jj_input_stream.getPosition() + 1;
 
2272     {return (AbstractCase[]) cases.toArray();}
 
2273   } catch (ParseException e) {
 
2274     errorMessage = "';' expected after 'endswitch' keyword";
 
2276     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2277     errorEnd   = jj_input_stream.getPosition() + 1;
 
2282 AbstractCase switchLabel0() :
 
2284   final Expression expr;
 
2285   Statement statement;
 
2286   final ArrayList stmts = new ArrayList();
 
2287   final int pos = SimpleCharStream.getPosition();
 
2290   expr = SwitchLabel()
 
2291   ( statement = BlockStatementNoBreak() {stmts.add(statement);}
 
2292   | statement = htmlBlock()             {stmts.add(statement);})*
 
2293   [ statement = BreakStatement()        {stmts.add(statement);}]
 
2294   {if (expr == null) {//it's a default
 
2295     return new DefaultCase((Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition());
 
2297   return new Case(expr,(Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition());}
 
2302  * case Expression() :
 
2304  * @return the if it was a case and null if not
 
2306 Expression SwitchLabel() :
 
2309   final Expression expr;
 
2315   } catch (ParseException e) {
 
2316     if (errorMessage != null) throw e;
 
2317     errorMessage = "expression expected after 'case' keyword";
 
2319     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2320     errorEnd   = jj_input_stream.getPosition() + 1;
 
2326   } catch (ParseException e) {
 
2327     errorMessage = "':' expected after case expression";
 
2329     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2330     errorEnd   = jj_input_stream.getPosition() + 1;
 
2338   } catch (ParseException e) {
 
2339     errorMessage = "':' expected after 'default' keyword";
 
2341     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2342     errorEnd   = jj_input_stream.getPosition() + 1;
 
2347 Break BreakStatement() :
 
2349   Expression expression = null;
 
2350   final int start = SimpleCharStream.getPosition();
 
2353   <BREAK> [ expression = Expression() ]
 
2356   } catch (ParseException e) {
 
2357     errorMessage = "';' expected after 'break' keyword";
 
2359     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2360     errorEnd   = jj_input_stream.getPosition() + 1;
 
2363   {return new Break(expression, start, SimpleCharStream.getPosition());}
 
2366 IfStatement IfStatement() :
 
2368   final int pos = jj_input_stream.getPosition();
 
2369   Expression condition;
 
2370   IfStatement ifStatement;
 
2373   <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
 
2374   {return ifStatement;}
 
2378 Expression Condition(final String keyword) :
 
2380   final Expression condition;
 
2385   } catch (ParseException e) {
 
2386     errorMessage = "'(' expected after " + keyword + " keyword";
 
2388     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
 
2389     errorEnd   = errorStart +1;
 
2390     processParseException(e);
 
2392   condition = Expression()
 
2396   } catch (ParseException e) {
 
2397     errorMessage = "')' expected after " + keyword + " keyword";
 
2399     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2400     errorEnd   = jj_input_stream.getPosition() + 1;
 
2405 IfStatement IfStatement0(Expression condition, final int start,final int end) :
 
2407   Statement statement;
 
2408   ElseIf elseifStatement;
 
2409   Else elseStatement = null;
 
2410   ArrayList stmts = new ArrayList();
 
2411   ArrayList elseifs = new ArrayList();
 
2412   int pos = SimpleCharStream.getPosition();
 
2416   (  statement = Statement() {stmts.add(statement);}
 
2417    | statement = htmlBlock() {stmts.add(statement);})*
 
2418    (elseifStatement = ElseIfStatementColon() {elseifs.add(elseifStatement);})*
 
2419    [elseStatement = ElseStatementColon()]
 
2422   setMarker(fileToParse,
 
2423             "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
 
2427             "Line " + token.beginLine);
 
2428   } catch (CoreException e) {
 
2429     PHPeclipsePlugin.log(e);
 
2433   } catch (ParseException e) {
 
2434     errorMessage = "'endif' expected";
 
2436     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2437     errorEnd   = jj_input_stream.getPosition() + 1;
 
2442     {return new IfStatement(condition,
 
2443                             (ElseIf[]) elseifs.toArray(),
 
2446                             SimpleCharStream.getPosition());}
 
2447   } catch (ParseException e) {
 
2448     errorMessage = "';' expected after 'endif' keyword";
 
2450     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2451     errorEnd   = jj_input_stream.getPosition() + 1;
 
2455   (statement = Statement() | statement = htmlBlock())
 
2456   {stmts.add(statement);}
 
2457   ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseifs.add(elseifStatement);})*
 
2461       {pos = SimpleCharStream.getPosition();}
 
2462       statement = Statement()
 
2463       {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
 
2464     } catch (ParseException e) {
 
2465       if (errorMessage != null) {
 
2468       errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
 
2470       errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2471       errorEnd   = jj_input_stream.getPosition() + 1;
 
2475   {return new IfStatement(condition,
 
2476                           (ElseIf[]) elseifs.toArray(),
 
2479                           SimpleCharStream.getPosition());}
 
2482 ElseIf ElseIfStatementColon() :
 
2484   Expression condition;
 
2485   Statement statement;
 
2486   final ArrayList list = new ArrayList();
 
2487   final int pos = SimpleCharStream.getPosition();
 
2490   <ELSEIF> condition = Condition("elseif")
 
2491   <COLON> (  statement = Statement() {list.add(statement);}
 
2492            | statement = htmlBlock() {list.add(statement);})*
 
2493   {return new ElseIf(condition,(Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());}
 
2496 Else ElseStatementColon() :
 
2498   Statement statement;
 
2499   final ArrayList list = new ArrayList();
 
2500   final int pos = SimpleCharStream.getPosition();
 
2503   <ELSE> <COLON> (  statement = Statement() {list.add(statement);}
 
2504                   | statement = htmlBlock() {list.add(statement);})*
 
2505   {return new Else((Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());}
 
2508 ElseIf ElseIfStatement() :
 
2510   Expression condition;
 
2511   Statement statement;
 
2512   final ArrayList list = new ArrayList();
 
2513   final int pos = SimpleCharStream.getPosition();
 
2516   <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
 
2517   {return new ElseIf(condition,(Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());}
 
2520 WhileStatement WhileStatement() :
 
2522   final Expression condition;
 
2523   final Statement action;
 
2524   final int pos = SimpleCharStream.getPosition();
 
2528     condition = Condition("while")
 
2529     action    = WhileStatement0(pos,pos + 5)
 
2530     {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
 
2533 Statement WhileStatement0(final int start, final int end) :
 
2535   Statement statement;
 
2536   final ArrayList stmts = new ArrayList();
 
2537   final int pos = SimpleCharStream.getPosition();
 
2540   <COLON> (statement = Statement() {stmts.add(statement);})*
 
2542   setMarker(fileToParse,
 
2543             "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
 
2547             "Line " + token.beginLine);
 
2548   } catch (CoreException e) {
 
2549     PHPeclipsePlugin.log(e);
 
2553   } catch (ParseException e) {
 
2554     errorMessage = "'endwhile' expected";
 
2556     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2557     errorEnd   = jj_input_stream.getPosition() + 1;
 
2562     {return new Block((Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition());}
 
2563   } catch (ParseException e) {
 
2564     errorMessage = "';' expected after 'endwhile' keyword";
 
2566     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2567     errorEnd   = jj_input_stream.getPosition() + 1;
 
2571   statement = Statement()
 
2575 DoStatement DoStatement() :
 
2577   final Statement action;
 
2578   final Expression condition;
 
2579   final int pos = SimpleCharStream.getPosition();
 
2582   <DO> action = Statement() <WHILE> condition = Condition("while")
 
2585     {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
 
2586   } catch (ParseException e) {
 
2587     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
2589     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2590     errorEnd   = jj_input_stream.getPosition() + 1;
 
2595 ForeachStatement ForeachStatement() :
 
2597   Statement statement;
 
2598   Expression expression;
 
2599   final StringBuffer buff = new StringBuffer();
 
2600   final int pos = SimpleCharStream.getPosition();
 
2601   ArrayVariableDeclaration variable;
 
2607   } catch (ParseException e) {
 
2608     errorMessage = "'(' expected after 'foreach' keyword";
 
2610     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2611     errorEnd   = jj_input_stream.getPosition() + 1;
 
2615     expression = Expression()
 
2616   } catch (ParseException e) {
 
2617     errorMessage = "variable expected";
 
2619     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2620     errorEnd   = jj_input_stream.getPosition() + 1;
 
2625   } catch (ParseException e) {
 
2626     errorMessage = "'as' expected";
 
2628     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2629     errorEnd   = jj_input_stream.getPosition() + 1;
 
2633     variable = ArrayVariable()
 
2634   } catch (ParseException e) {
 
2635     errorMessage = "variable expected";
 
2637     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2638     errorEnd   = jj_input_stream.getPosition() + 1;
 
2643   } catch (ParseException e) {
 
2644     errorMessage = "')' expected after 'foreach' keyword";
 
2646     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2647     errorEnd   = jj_input_stream.getPosition() + 1;
 
2651     statement = Statement()
 
2652   } catch (ParseException e) {
 
2653     if (errorMessage != null) throw e;
 
2654     errorMessage = "statement expected";
 
2656     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2657     errorEnd   = jj_input_stream.getPosition() + 1;
 
2660   {return new ForeachStatement(expression,
 
2664                                SimpleCharStream.getPosition());}
 
2668 ForStatement ForStatement() :
 
2671 final int pos = SimpleCharStream.getPosition();
 
2672 Statement[] initializations = null;
 
2673 Expression condition = null;
 
2674 Statement[] increments = null;
 
2676 final ArrayList list = new ArrayList();
 
2677 final int startBlock, endBlock;
 
2683   } catch (ParseException e) {
 
2684     errorMessage = "'(' expected after 'for' keyword";
 
2686     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2687     errorEnd   = jj_input_stream.getPosition() + 1;
 
2690      [ initializations = ForInit() ] <SEMICOLON>
 
2691      [ condition = Expression() ] <SEMICOLON>
 
2692      [ increments = StatementExpressionList() ] <RPAREN>
 
2694       action = Statement()
 
2695       {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
 
2698       {startBlock = SimpleCharStream.getPosition();}
 
2699       (action = Statement() {list.add(action);})*
 
2702         setMarker(fileToParse,
 
2703                   "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
 
2705                   pos+token.image.length(),
 
2707                   "Line " + token.beginLine);
 
2708         } catch (CoreException e) {
 
2709           PHPeclipsePlugin.log(e);
 
2712       {endBlock = SimpleCharStream.getPosition();}
 
2715       } catch (ParseException e) {
 
2716         errorMessage = "'endfor' expected";
 
2718         errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2719         errorEnd   = jj_input_stream.getPosition() + 1;
 
2724         {return new ForStatement(initializations,condition,increments,new Block((Statement[])list.toArray(),startBlock,endBlock),pos,SimpleCharStream.getPosition());}
 
2725       } catch (ParseException e) {
 
2726         errorMessage = "';' expected after 'endfor' keyword";
 
2728         errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2729         errorEnd   = jj_input_stream.getPosition() + 1;
 
2735 Statement[] ForInit() :
 
2737   Statement[] statements;
 
2740   LOOKAHEAD(LocalVariableDeclaration())
 
2741   statements = LocalVariableDeclaration()
 
2742   {return statements;}
 
2744   statements = StatementExpressionList()
 
2745   {return statements;}
 
2748 Statement[] StatementExpressionList() :
 
2750   final ArrayList list = new ArrayList();
 
2754   expr = StatementExpression()   {list.add(expr);}
 
2755   (<COMMA> StatementExpression() {list.add(expr);})*
 
2756   {return (Statement[]) list.toArray();}
 
2759 Continue ContinueStatement() :
 
2761   Expression expr = null;
 
2762   final int pos = SimpleCharStream.getPosition();
 
2765   <CONTINUE> [ expr = Expression() ]
 
2768     {return new Continue(expr,pos,SimpleCharStream.getPosition());}
 
2769   } catch (ParseException e) {
 
2770     errorMessage = "';' expected after 'continue' statement";
 
2772     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2773     errorEnd   = jj_input_stream.getPosition() + 1;
 
2778 ReturnStatement ReturnStatement() :
 
2780   Expression expr = null;
 
2781   final int pos = SimpleCharStream.getPosition();
 
2784   <RETURN> [ expr = Expression() ]
 
2787     {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
 
2788   } catch (ParseException e) {
 
2789     errorMessage = "';' expected after 'return' statement";
 
2791     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
 
2792     errorEnd   = jj_input_stream.getPosition() + 1;