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   private static boolean assigning;
 
  65   /** The error level of the current ParseException. */
 
  66   private static int errorLevel = ERROR;
 
  67   /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
 
  68   private static String errorMessage;
 
  70   private static int errorStart = -1;
 
  71   private static int errorEnd = -1;
 
  72   private static PHPDocument phpDocument;
 
  74   private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
 
  76    * The point where html starts.
 
  77    * It will be used by the token manager to create HTMLCode objects
 
  79   public static int htmlStart;
 
  82   private final static int AstStackIncrement = 100;
 
  83   /** The stack of node. */
 
  84   private static AstNode[] nodes;
 
  85   /** The cursor in expression stack. */
 
  86   private static int nodePtr;
 
  88   public final void setFileToParse(final IFile fileToParse) {
 
  89     this.fileToParse = fileToParse;
 
  95   public PHPParser(final IFile fileToParse) {
 
  96     this(new StringReader(""));
 
  97     this.fileToParse = fileToParse;
 
 101    * Reinitialize the parser.
 
 103   private static final void init() {
 
 104     nodes = new AstNode[AstStackIncrement];
 
 110    * Add an php node on the stack.
 
 111    * @param node the node that will be added to the stack
 
 113   private static final void pushOnAstNodes(AstNode node) {
 
 115       nodes[++nodePtr] = node;
 
 116     } catch (IndexOutOfBoundsException e) {
 
 117       int oldStackLength = nodes.length;
 
 118       AstNode[] oldStack = nodes;
 
 119       nodes = new AstNode[oldStackLength + AstStackIncrement];
 
 120       System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
 
 121       nodePtr = oldStackLength;
 
 122       nodes[nodePtr] = node;
 
 126   public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
 
 127     phpDocument = new PHPDocument(parent,"_root".toCharArray());
 
 128     currentSegment = phpDocument;
 
 129     outlineInfo = new PHPOutlineInfo(parent, currentSegment);
 
 130     final StringReader stream = new StringReader(s);
 
 131     if (jj_input_stream == null) {
 
 132       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 138       phpDocument.nodes = new AstNode[nodes.length];
 
 139       System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
 
 140       if (PHPeclipsePlugin.DEBUG) {
 
 141         PHPeclipsePlugin.log(1,phpDocument.toString());
 
 143     } catch (ParseException e) {
 
 144       processParseException(e);
 
 150    * This method will process the parse exception.
 
 151    * If the error message is null, the parse exception wasn't catched and a trace is written in the log
 
 152    * @param e the ParseException
 
 154   private static void processParseException(final ParseException e) {
 
 155     if (errorMessage == null) {
 
 156       PHPeclipsePlugin.log(e);
 
 157       errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
 
 158       errorStart = SimpleCharStream.getPosition();
 
 159       errorEnd   = errorStart + 1;
 
 166    * Create marker for the parse error
 
 167    * @param e the ParseException
 
 169   private static void setMarker(final ParseException e) {
 
 171       if (errorStart == -1) {
 
 172         setMarker(fileToParse,
 
 174                   SimpleCharStream.tokenBegin,
 
 175                   SimpleCharStream.tokenBegin + e.currentToken.image.length(),
 
 177                   "Line " + e.currentToken.beginLine);
 
 179         setMarker(fileToParse,
 
 184                   "Line " + e.currentToken.beginLine);
 
 188     } catch (CoreException e2) {
 
 189       PHPeclipsePlugin.log(e2);
 
 194    * Create markers according to the external parser output
 
 196   private static void createMarkers(final String output, final IFile file) throws CoreException {
 
 197     // delete all markers
 
 198     file.deleteMarkers(IMarker.PROBLEM, false, 0);
 
 203     while ((brIndx = output.indexOf("<br />", indx)) != -1) {
 
 204       // newer php error output (tested with 4.2.3)
 
 205       scanLine(output, file, indx, brIndx);
 
 210       while ((brIndx = output.indexOf("<br>", indx)) != -1) {
 
 211         // older php error output (tested with 4.2.3)
 
 212         scanLine(output, file, indx, brIndx);
 
 218   private static void scanLine(final String output,
 
 221                                final int brIndx) throws CoreException {
 
 223     StringBuffer lineNumberBuffer = new StringBuffer(10);
 
 225     current = output.substring(indx, brIndx);
 
 227     if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
 
 228       int onLine = current.indexOf("on line <b>");
 
 230         lineNumberBuffer.delete(0, lineNumberBuffer.length());
 
 231         for (int i = onLine; i < current.length(); i++) {
 
 232           ch = current.charAt(i);
 
 233           if ('0' <= ch && '9' >= ch) {
 
 234             lineNumberBuffer.append(ch);
 
 238         int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
 
 240         Hashtable attributes = new Hashtable();
 
 242         current = current.replaceAll("\n", "");
 
 243         current = current.replaceAll("<b>", "");
 
 244         current = current.replaceAll("</b>", "");
 
 245         MarkerUtilities.setMessage(attributes, current);
 
 247         if (current.indexOf(PARSE_ERROR_STRING) != -1)
 
 248           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
 
 249         else if (current.indexOf(PARSE_WARNING_STRING) != -1)
 
 250           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
 
 252           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
 
 253         MarkerUtilities.setLineNumber(attributes, lineNumber);
 
 254         MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
 
 259   public final void parse(final String s) throws CoreException {
 
 260     final StringReader stream = new StringReader(s);
 
 261     if (jj_input_stream == null) {
 
 262       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 268     } catch (ParseException e) {
 
 269       processParseException(e);
 
 274    * Call the php parse command ( php -l -f <filename> )
 
 275    * and create markers according to the external parser output
 
 277   public static void phpExternalParse(final IFile file) {
 
 278     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
 
 279     final String filename = file.getLocation().toString();
 
 281     final String[] arguments = { filename };
 
 282     final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
 
 283     final String command = form.format(arguments);
 
 285     final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
 
 288       // parse the buffer to find the errors and warnings
 
 289       createMarkers(parserResult, file);
 
 290     } catch (CoreException e) {
 
 291       PHPeclipsePlugin.log(e);
 
 296    * Put a new html block in the stack.
 
 298   public static final void createNewHTMLCode() {
 
 299     final int currentPosition = SimpleCharStream.getPosition();
 
 300     if (currentPosition == htmlStart) {
 
 303     final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
 
 304     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
 
 307   private static final void parse() throws ParseException {
 
 312 PARSER_END(PHPParser)
 
 316   <PHPSTARTSHORT : "<?">    {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 317 | <PHPSTARTLONG  : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 318 | <PHPECHOSTART  : "<?=">   {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 323   <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
 
 326 /* Skip any character if we are not in php mode */
 
 344 <PHPPARSING> SPECIAL_TOKEN :
 
 346   "//" : IN_SINGLE_LINE_COMMENT
 
 348   "#"  : IN_SINGLE_LINE_COMMENT
 
 350   <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
 
 352   "/*" : IN_MULTI_LINE_COMMENT
 
 355 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
 
 357   <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
 
 360 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
 
 362   <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
 
 368   <FORMAL_COMMENT: "*/" > : PHPPARSING
 
 371 <IN_MULTI_LINE_COMMENT>
 
 374   <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
 
 377 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
 
 387 | <FUNCTION : "function">
 
 390 | <ELSEIF   : "elseif">
 
 397 /* LANGUAGE CONSTRUCT */
 
 402 | <INCLUDE            : "include">
 
 403 | <REQUIRE            : "require">
 
 404 | <INCLUDE_ONCE       : "include_once">
 
 405 | <REQUIRE_ONCE       : "require_once">
 
 406 | <GLOBAL             : "global">
 
 407 | <STATIC             : "static">
 
 408 | <CLASSACCESS        : "->">
 
 409 | <STATICCLASSACCESS  : "::">
 
 410 | <ARRAYASSIGN        : "=>">
 
 413 /* RESERVED WORDS AND LITERALS */
 
 419 | <CONTINUE : "continue">
 
 420 | <_DEFAULT : "default">
 
 422 | <EXTENDS  : "extends">
 
 427 | <RETURN   : "return">
 
 429 | <SWITCH   : "switch">
 
 434 | <ENDWHILE : "endwhile">
 
 435 | <ENDSWITCH: "endswitch">
 
 437 | <ENDFOR   : "endfor">
 
 438 | <FOREACH  : "foreach">
 
 446 | <OBJECT  : "object">
 
 448 | <BOOLEAN : "boolean">
 
 450 | <DOUBLE  : "double">
 
 453 | <INTEGER : "integer">
 
 483 | <RSIGNEDSHIFT       : ">>">
 
 484 | <RUNSIGNEDSHIFT     : ">>>">
 
 493         <DECIMAL_LITERAL> (["l","L"])?
 
 494       | <HEX_LITERAL> (["l","L"])?
 
 495       | <OCTAL_LITERAL> (["l","L"])?
 
 498   <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
 
 500   <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
 
 502   <#OCTAL_LITERAL: "0" (["0"-"7"])* >
 
 504   <FLOATING_POINT_LITERAL:
 
 505         (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
 
 506       | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
 
 507       | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
 
 508       | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
 
 511   <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 
 513   <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
 
 546   < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
 
 549       ["a"-"z"] | ["A"-"Z"]
 
 557     "_" | ["\u007f"-"\u00ff"]
 
 582 | <EQUAL_EQUAL        : "==">
 
 587 | <BANGDOUBLEEQUAL    : "!==">
 
 588 | <TRIPLEEQUAL        : "===">
 
 595 | <PLUSASSIGN         : "+=">
 
 596 | <MINUSASSIGN        : "-=">
 
 597 | <STARASSIGN         : "*=">
 
 598 | <SLASHASSIGN        : "/=">
 
 604 | <TILDEEQUAL         : "~=">
 
 605 | <LSHIFTASSIGN       : "<<=">
 
 606 | <RSIGNEDSHIFTASSIGN : ">>=">
 
 611   < DOLLAR_ID: <DOLLAR> <IDENTIFIER>  >
 
 620   } catch (TokenMgrError e) {
 
 621     PHPeclipsePlugin.log(e);
 
 622     errorStart   = SimpleCharStream.getPosition();
 
 623     errorEnd     = errorStart + 1;
 
 624     errorMessage = e.getMessage();
 
 626     throw generateParseException();
 
 631  * A php block is a <?= expression [;]?>
 
 632  * or <?php somephpcode ?>
 
 633  * or <? somephpcode ?>
 
 637   final int start = SimpleCharStream.getPosition();
 
 645       setMarker(fileToParse,
 
 646                 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
 
 648                 SimpleCharStream.getPosition(),
 
 650                 "Line " + token.beginLine);
 
 651     } catch (CoreException e) {
 
 652       PHPeclipsePlugin.log(e);
 
 658   } catch (ParseException e) {
 
 659     errorMessage = "'?>' expected";
 
 661     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 662     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 663     processParseException(e);
 
 667 PHPEchoBlock phpEchoBlock() :
 
 669   final Expression expr;
 
 670   final int pos = SimpleCharStream.getPosition();
 
 671   PHPEchoBlock echoBlock;
 
 674   <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
 
 676   echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
 
 677   pushOnAstNodes(echoBlock);
 
 687 ClassDeclaration ClassDeclaration() :
 
 689   final ClassDeclaration classDeclaration;
 
 690   final Token className;
 
 691   Token superclassName = null;
 
 693   char[] classNameImage = SYNTAX_ERROR_CHAR;
 
 694   char[] superclassNameImage = null;
 
 698   {pos = SimpleCharStream.getPosition();}
 
 700     className = <IDENTIFIER>
 
 701     {classNameImage = className.image.toCharArray();}
 
 702   } catch (ParseException e) {
 
 703     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
 
 705     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 706     errorEnd     = SimpleCharStream.getPosition() + 1;
 
 707     processParseException(e);
 
 712       superclassName = <IDENTIFIER>
 
 713       {superclassNameImage = superclassName .image.toCharArray();}
 
 714     } catch (ParseException e) {
 
 715       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
 
 717       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 718       errorEnd   = SimpleCharStream.getPosition() + 1;
 
 719       processParseException(e);
 
 720       superclassNameImage = SYNTAX_ERROR_CHAR;
 
 724     if (superclassNameImage == null) {
 
 725       classDeclaration = new ClassDeclaration(currentSegment,
 
 730       classDeclaration = new ClassDeclaration(currentSegment,
 
 736       currentSegment.add(classDeclaration);
 
 737       currentSegment = classDeclaration;
 
 739   ClassBody(classDeclaration)
 
 740   {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
 
 741    classDeclaration.sourceEnd = SimpleCharStream.getPosition();
 
 742    pushOnAstNodes(classDeclaration);
 
 743    return classDeclaration;}
 
 746 void ClassBody(ClassDeclaration classDeclaration) :
 
 751   } catch (ParseException e) {
 
 752     errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
 
 754     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 755     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 758   ( ClassBodyDeclaration(classDeclaration) )*
 
 761   } catch (ParseException e) {
 
 762     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
 
 764     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 765     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 771  * A class can contain only methods and fields.
 
 773 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
 
 775   MethodDeclaration method;
 
 776   FieldDeclaration field;
 
 779   method = MethodDeclaration() {method.setParent(classDeclaration);}
 
 780 | field = FieldDeclaration()
 
 784  * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
 
 786 FieldDeclaration FieldDeclaration() :
 
 788   VariableDeclaration variableDeclaration;
 
 789   VariableDeclaration[] list;
 
 790   final ArrayList arrayList = new ArrayList();
 
 791   final int pos = SimpleCharStream.getPosition();
 
 794   <VAR> variableDeclaration = VariableDeclarator()
 
 795   {arrayList.add(variableDeclaration);
 
 796    outlineInfo.addVariable(new String(variableDeclaration.name));
 
 797    currentSegment.add(variableDeclaration);}
 
 798   ( <COMMA> variableDeclaration = VariableDeclarator()
 
 799       {arrayList.add(variableDeclaration);
 
 800        outlineInfo.addVariable(new String(variableDeclaration.name));
 
 801        currentSegment.add(variableDeclaration);}
 
 805   } catch (ParseException e) {
 
 806     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
 
 808     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 809     errorEnd     = SimpleCharStream.getPosition() + 1;
 
 810     processParseException(e);
 
 813   {list = new VariableDeclaration[arrayList.size()];
 
 814    arrayList.toArray(list);
 
 815    return new FieldDeclaration(list,
 
 817                                SimpleCharStream.getPosition(),
 
 821 VariableDeclaration VariableDeclarator() :
 
 823   final String varName;
 
 824   Expression initializer = null;
 
 825   final int pos = SimpleCharStream.getPosition();
 
 828   varName = VariableDeclaratorId()
 
 832       initializer = VariableInitializer()
 
 833     } catch (ParseException e) {
 
 834       errorMessage = "Literal expression expected in variable initializer";
 
 836       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 837       errorEnd   = SimpleCharStream.getPosition() + 1;
 
 842   if (initializer == null) {
 
 843     return new VariableDeclaration(currentSegment,
 
 844                                   varName.toCharArray(),
 
 846                                   SimpleCharStream.getPosition());
 
 848     return new VariableDeclaration(currentSegment,
 
 849                                     varName.toCharArray(),
 
 857  * @return the variable name (with suffix)
 
 859 String VariableDeclaratorId() :
 
 862   Expression expression;
 
 863   final StringBuffer buff = new StringBuffer();
 
 864   final int pos = SimpleCharStream.getPosition();
 
 865   ConstantIdentifier ex;
 
 869     expr = Variable()   {buff.append(expr);}
 
 871       {ex = new ConstantIdentifier(expr.toCharArray(),
 
 873                                    SimpleCharStream.getPosition());}
 
 874       expression = VariableSuffix(ex)
 
 875       {buff.append(expression.toStringExpression());}
 
 877     {return buff.toString();}
 
 878   } catch (ParseException e) {
 
 879     errorMessage = "'$' expected for variable identifier";
 
 881     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 882     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 889   final StringBuffer buff;
 
 890   Expression expression = null;
 
 895   token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
 
 897     if (expression == null && !assigning) {
 
 898       return token.image.substring(1);
 
 900     buff = new StringBuffer(token.image);
 
 902     buff.append(expression.toStringExpression());
 
 904     return buff.toString();
 
 907   <DOLLAR> expr = VariableName()
 
 911 String VariableName():
 
 913   final StringBuffer buff;
 
 915   Expression expression = null;
 
 919   <LBRACE> expression = Expression() <RBRACE>
 
 920   {buff = new StringBuffer("{");
 
 921    buff.append(expression.toStringExpression());
 
 923    return buff.toString();}
 
 925   token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
 
 927     if (expression == null) {
 
 930     buff = new StringBuffer(token.image);
 
 932     buff.append(expression.toStringExpression());
 
 934     return buff.toString();
 
 937   <DOLLAR> expr = VariableName()
 
 939     buff = new StringBuffer("$");
 
 941     return buff.toString();
 
 944   token = <DOLLAR_ID> {return token.image;}
 
 947 Expression VariableInitializer() :
 
 949   final Expression expr;
 
 951   final int pos = SimpleCharStream.getPosition();
 
 957   <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
 
 958   {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
 
 960                                                         SimpleCharStream.getPosition()),
 
 964   <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
 
 965   {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
 
 967                                                         SimpleCharStream.getPosition()),
 
 971   expr = ArrayDeclarator()
 
 975   {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
 
 978 ArrayVariableDeclaration ArrayVariable() :
 
 980 Expression expr,expr2;
 
 984   [<ARRAYASSIGN> expr2 = Expression()
 
 985   {return new ArrayVariableDeclaration(expr,expr2);}
 
 987   {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
 
 990 ArrayVariableDeclaration[] ArrayInitializer() :
 
 992   ArrayVariableDeclaration expr;
 
 993   final ArrayList list = new ArrayList();
 
 996   <LPAREN> [ expr = ArrayVariable()
 
 998             ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
 
1002            [<COMMA> {list.add(null);}]
 
1005   ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
 
1011  * A Method Declaration.
 
1012  * <b>function</b> MetodDeclarator() Block()
 
1014 MethodDeclaration MethodDeclaration() :
 
1016   final MethodDeclaration functionDeclaration;
 
1022     functionDeclaration = MethodDeclarator()
 
1023     {outlineInfo.addVariable(new String(functionDeclaration.name));}
 
1024   } catch (ParseException e) {
 
1025     if (errorMessage != null)  throw e;
 
1026     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
 
1028     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1029     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1033     if (currentSegment != null) {
 
1034       currentSegment.add(functionDeclaration);
 
1035       currentSegment = functionDeclaration;
 
1040     functionDeclaration.statements = block.statements;
 
1041     if (currentSegment != null) {
 
1042       currentSegment = (OutlineableWithChildren) currentSegment.getParent();
 
1044     return functionDeclaration;
 
1049  * A MethodDeclarator.
 
1050  * [&] IDENTIFIER(parameters ...).
 
1051  * @return a function description for the outline
 
1053 MethodDeclaration MethodDeclarator() :
 
1055   final Token identifier;
 
1056   Token reference = null;
 
1057   final Hashtable formalParameters;
 
1058   final int pos = SimpleCharStream.getPosition();
 
1059   char[] identifierChar = SYNTAX_ERROR_CHAR;
 
1062   [reference = <BIT_AND>]
 
1064     identifier = <IDENTIFIER>
 
1065     {identifierChar = identifier.image.toCharArray();}
 
1066   } catch (ParseException e) {
 
1067     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
 
1069     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1070     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1071     processParseException(e);
 
1073   formalParameters = FormalParameters()
 
1074   {return new MethodDeclaration(currentSegment,
 
1079                                  SimpleCharStream.getPosition());}
 
1083  * FormalParameters follows method identifier.
 
1084  * (FormalParameter())
 
1086 Hashtable FormalParameters() :
 
1088   VariableDeclaration var;
 
1089   final Hashtable parameters = new Hashtable();
 
1094   } catch (ParseException e) {
 
1095     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
 
1097     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1098     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1101             [ var = FormalParameter()
 
1102               {parameters.put(new String(var.name),var);}
 
1104                 <COMMA> var = FormalParameter()
 
1105                 {parameters.put(new String(var.name),var);}
 
1110   } catch (ParseException e) {
 
1111     errorMessage = "')' expected";
 
1113     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1114     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1117  {return parameters;}
 
1121  * A formal parameter.
 
1122  * $varname[=value] (,$varname[=value])
 
1124 VariableDeclaration FormalParameter() :
 
1126   final VariableDeclaration variableDeclaration;
 
1130   [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
 
1132     if (token != null) {
 
1133       variableDeclaration.setReference(true);
 
1135     return variableDeclaration;}
 
1138 ConstantIdentifier Type() :
 
1141   <STRING>             {pos = SimpleCharStream.getPosition();
 
1142                         return new ConstantIdentifier(Types.STRING,pos,pos-6);}
 
1143 | <BOOL>               {pos = SimpleCharStream.getPosition();
 
1144                         return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
 
1145 | <BOOLEAN>            {pos = SimpleCharStream.getPosition();
 
1146                         return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
 
1147 | <REAL>               {pos = SimpleCharStream.getPosition();
 
1148                         return new ConstantIdentifier(Types.REAL,pos,pos-4);}
 
1149 | <DOUBLE>             {pos = SimpleCharStream.getPosition();
 
1150                         return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
 
1151 | <FLOAT>              {pos = SimpleCharStream.getPosition();
 
1152                         return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
 
1153 | <INT>                {pos = SimpleCharStream.getPosition();
 
1154                         return new ConstantIdentifier(Types.INT,pos,pos-3);}
 
1155 | <INTEGER>            {pos = SimpleCharStream.getPosition();
 
1156                         return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
 
1157 | <OBJECT>             {pos = SimpleCharStream.getPosition();
 
1158                         return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
 
1161 Expression Expression() :
 
1163   final Expression expr;
 
1166   expr = PrintExpression()       {return expr;}
 
1167 | expr = ListExpression()        {return expr;}
 
1168 | LOOKAHEAD(varAssignation())
 
1169   expr = varAssignation()        {return expr;}
 
1170 | expr = ConditionalExpression() {return expr;}
 
1174  * A Variable assignation.
 
1175  * varName (an assign operator) any expression
 
1177 VarAssignation varAssignation() :
 
1180   final Expression expression;
 
1181   final int assignOperator;
 
1182   final int pos = SimpleCharStream.getPosition();
 
1185   varName = VariableDeclaratorId()
 
1186   assignOperator = AssignmentOperator()
 
1188       expression = Expression()
 
1189     } catch (ParseException e) {
 
1190       if (errorMessage != null) {
 
1193       errorMessage = "expression expected";
 
1195       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1196       errorEnd   = SimpleCharStream.getPosition() + 1;
 
1199     {return new VarAssignation(varName.toCharArray(),
 
1203                                SimpleCharStream.getPosition());}
 
1206 int AssignmentOperator() :
 
1209   <ASSIGN>             {return VarAssignation.EQUAL;}
 
1210 | <STARASSIGN>         {return VarAssignation.STAR_EQUAL;}
 
1211 | <SLASHASSIGN>        {return VarAssignation.SLASH_EQUAL;}
 
1212 | <REMASSIGN>          {return VarAssignation.REM_EQUAL;}
 
1213 | <PLUSASSIGN>         {return VarAssignation.PLUS_EQUAL;}
 
1214 | <MINUSASSIGN>        {return VarAssignation.MINUS_EQUAL;}
 
1215 | <LSHIFTASSIGN>       {return VarAssignation.LSHIFT_EQUAL;}
 
1216 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
 
1217 | <ANDASSIGN>          {return VarAssignation.AND_EQUAL;}
 
1218 | <XORASSIGN>          {return VarAssignation.XOR_EQUAL;}
 
1219 | <ORASSIGN>           {return VarAssignation.OR_EQUAL;}
 
1220 | <DOTASSIGN>          {return VarAssignation.DOT_EQUAL;}
 
1221 | <TILDEEQUAL>         {return VarAssignation.TILDE_EQUAL;}
 
1224 Expression ConditionalExpression() :
 
1226   final Expression expr;
 
1227   Expression expr2 = null;
 
1228   Expression expr3 = null;
 
1231   expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
 
1233   if (expr3 == null) {
 
1236   return new ConditionalExpression(expr,expr2,expr3);
 
1240 Expression ConditionalOrExpression() :
 
1242   Expression expr,expr2;
 
1246   expr = ConditionalAndExpression()
 
1249         <OR_OR> {operator = OperatorIds.OR_OR;}
 
1250       | <_ORL>  {operator = OperatorIds.ORL;}
 
1251     ) expr2 = ConditionalAndExpression()
 
1253       expr = new BinaryExpression(expr,expr2,operator);
 
1259 Expression ConditionalAndExpression() :
 
1261   Expression expr,expr2;
 
1265   expr = ConcatExpression()
 
1267   (  <AND_AND> {operator = OperatorIds.AND_AND;}
 
1268    | <_ANDL>   {operator = OperatorIds.ANDL;})
 
1269    expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
 
1274 Expression ConcatExpression() :
 
1276   Expression expr,expr2;
 
1279   expr = InclusiveOrExpression()
 
1281     <DOT> expr2 = InclusiveOrExpression()
 
1282     {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
 
1287 Expression InclusiveOrExpression() :
 
1289   Expression expr,expr2;
 
1292   expr = ExclusiveOrExpression()
 
1293   (<BIT_OR> expr2 = ExclusiveOrExpression()
 
1294    {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
 
1299 Expression ExclusiveOrExpression() :
 
1301   Expression expr,expr2;
 
1304   expr = AndExpression()
 
1306     <XOR> expr2 = AndExpression()
 
1307     {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
 
1312 Expression AndExpression() :
 
1314   Expression expr,expr2;
 
1317   expr = EqualityExpression()
 
1319     <BIT_AND> expr2 = EqualityExpression()
 
1320     {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
 
1325 Expression EqualityExpression() :
 
1327   Expression expr,expr2;
 
1331   expr = RelationalExpression()
 
1333   (   <EQUAL_EQUAL>      {operator = OperatorIds.EQUAL_EQUAL;}
 
1334     | <DIF>              {operator = OperatorIds.DIF;}
 
1335     | <NOT_EQUAL>        {operator = OperatorIds.DIF;}
 
1336     | <BANGDOUBLEEQUAL>  {operator = OperatorIds.BANG_EQUAL_EQUAL;}
 
1337     | <TRIPLEEQUAL>      {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
 
1340     expr2 = RelationalExpression()
 
1341   } catch (ParseException e) {
 
1342     if (errorMessage != null) {
 
1345     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
1347     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1348     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1352     expr = new BinaryExpression(expr,expr2,operator);
 
1358 Expression RelationalExpression() :
 
1360   Expression expr,expr2;
 
1364   expr = ShiftExpression()
 
1366   ( <LT> {operator = OperatorIds.LESS;}
 
1367   | <GT> {operator = OperatorIds.GREATER;}
 
1368   | <LE> {operator = OperatorIds.LESS_EQUAL;}
 
1369   | <GE> {operator = OperatorIds.GREATER_EQUAL;})
 
1370    expr2 = ShiftExpression()
 
1371   {expr = new BinaryExpression(expr,expr2,operator);}
 
1376 Expression ShiftExpression() :
 
1378   Expression expr,expr2;
 
1382   expr = AdditiveExpression()
 
1384   ( <LSHIFT>         {operator = OperatorIds.LEFT_SHIFT;}
 
1385   | <RSIGNEDSHIFT>   {operator = OperatorIds.RIGHT_SHIFT;}
 
1386   | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
 
1387   expr2 = AdditiveExpression()
 
1388   {expr = new BinaryExpression(expr,expr2,operator);}
 
1393 Expression AdditiveExpression() :
 
1395   Expression expr,expr2;
 
1399   expr = MultiplicativeExpression()
 
1401    ( <PLUS>  {operator = OperatorIds.PLUS;}
 
1402    | <MINUS> {operator = OperatorIds.MINUS;} )
 
1403    expr2 = MultiplicativeExpression()
 
1404   {expr = new BinaryExpression(expr,expr2,operator);}
 
1409 Expression MultiplicativeExpression() :
 
1411   Expression expr,expr2;
 
1416     expr = UnaryExpression()
 
1417   } catch (ParseException e) {
 
1418     if (errorMessage != null) throw e;
 
1419     errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
 
1421     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1422     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1426    (  <STAR>      {operator = OperatorIds.MULTIPLY;}
 
1427     | <SLASH>     {operator = OperatorIds.DIVIDE;}
 
1428     | <REMAINDER> {operator = OperatorIds.REMAINDER;})
 
1429     expr2 = UnaryExpression()
 
1430     {expr = new BinaryExpression(expr,expr2,operator);}
 
1436  * An unary expression starting with @, & or nothing
 
1438 Expression UnaryExpression() :
 
1441   final int pos = SimpleCharStream.getPosition();
 
1444   <BIT_AND> expr = UnaryExpressionNoPrefix()
 
1445   {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
 
1447   expr = AtUnaryExpression() {return expr;}
 
1450 Expression AtUnaryExpression() :
 
1453   final int pos = SimpleCharStream.getPosition();
 
1457   expr = AtUnaryExpression()
 
1458   {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
 
1460   expr = UnaryExpressionNoPrefix()
 
1465 Expression UnaryExpressionNoPrefix() :
 
1469   final int pos = SimpleCharStream.getPosition();
 
1472   (  <PLUS>  {operator = OperatorIds.PLUS;}
 
1473    | <MINUS> {operator = OperatorIds.MINUS;})
 
1474    expr = UnaryExpression()
 
1475   {return new PrefixedUnaryExpression(expr,operator,pos);}
 
1477   expr = PreIncDecExpression()
 
1480   expr = UnaryExpressionNotPlusMinus()
 
1485 Expression PreIncDecExpression() :
 
1487 final Expression expr;
 
1489   final int pos = SimpleCharStream.getPosition();
 
1492   (  <INCR> {operator = OperatorIds.PLUS_PLUS;}
 
1493    | <DECR> {operator = OperatorIds.MINUS_MINUS;})
 
1494    expr = PrimaryExpression()
 
1495   {return new PrefixedUnaryExpression(expr,operator,pos);}
 
1498 Expression UnaryExpressionNotPlusMinus() :
 
1501   final int pos = SimpleCharStream.getPosition();
 
1504   <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
 
1505 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
 
1506   expr = CastExpression()         {return expr;}
 
1507 | expr = PostfixExpression()      {return expr;}
 
1508 | expr = Literal()                {return expr;}
 
1509 | <LPAREN> expr = Expression()
 
1512   } catch (ParseException e) {
 
1513     errorMessage = "')' expected";
 
1515     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1516     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1522 CastExpression CastExpression() :
 
1524 final ConstantIdentifier type;
 
1525 final Expression expr;
 
1526 final int pos = SimpleCharStream.getPosition();
 
1531   | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
 
1532   <RPAREN> expr = UnaryExpression()
 
1533   {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
 
1536 Expression PostfixExpression() :
 
1540   final int pos = SimpleCharStream.getPosition();
 
1543   expr = PrimaryExpression()
 
1544   [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
 
1545   | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
 
1547     if (operator == -1) {
 
1550     return new PostfixedUnaryExpression(expr,operator,pos);
 
1554 Expression PrimaryExpression() :
 
1556   final Token identifier;
 
1558   final int pos = SimpleCharStream.getPosition();
 
1562   identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
 
1563   {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
 
1565                                                  SimpleCharStream.getPosition()),
 
1567                           ClassAccess.STATIC);}
 
1568   (expr = PrimarySuffix(expr))*
 
1571   expr = PrimaryPrefix()
 
1572   (expr = PrimarySuffix(expr))*
 
1575   expr = ArrayDeclarator()
 
1579 ArrayInitializer ArrayDeclarator() :
 
1581   final ArrayVariableDeclaration[] vars;
 
1582   final int pos = SimpleCharStream.getPosition();
 
1585   <ARRAY> vars = ArrayInitializer()
 
1586   {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
 
1589 Expression PrimaryPrefix() :
 
1591   final Expression expr;
 
1594   final int pos = SimpleCharStream.getPosition();
 
1597   token = <IDENTIFIER>           {return new ConstantIdentifier(token.image.toCharArray(),
 
1599                                                                 SimpleCharStream.getPosition());}
 
1600 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
 
1603 | var = VariableDeclaratorId()  {return new ConstantIdentifier(var.toCharArray(),
 
1605                                                                SimpleCharStream.getPosition());}
 
1608 PrefixedUnaryExpression classInstantiation() :
 
1611   final StringBuffer buff;
 
1612   final int pos = SimpleCharStream.getPosition();
 
1615   <NEW> expr = ClassIdentifier()
 
1617     {buff = new StringBuffer(expr.toStringExpression());}
 
1618     expr = PrimaryExpression()
 
1619     {buff.append(expr.toStringExpression());
 
1620     expr = new ConstantIdentifier(buff.toString().toCharArray(),
 
1622                                   SimpleCharStream.getPosition());}
 
1624   {return new PrefixedUnaryExpression(expr,
 
1629 ConstantIdentifier ClassIdentifier():
 
1633   final int pos = SimpleCharStream.getPosition();
 
1636   token = <IDENTIFIER>          {return new ConstantIdentifier(token.image.toCharArray(),
 
1638                                                                SimpleCharStream.getPosition());}
 
1639 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
 
1641                                                                SimpleCharStream.getPosition());}
 
1644 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
 
1646   final AbstractSuffixExpression expr;
 
1649   expr = Arguments(prefix)      {return expr;}
 
1650 | expr = VariableSuffix(prefix) {return expr;}
 
1653 AbstractSuffixExpression VariableSuffix(Expression prefix) :
 
1656   final int pos = SimpleCharStream.getPosition();
 
1657   Expression expression = null;
 
1662     expr = VariableName()
 
1663   } catch (ParseException e) {
 
1664     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
 
1666     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1667     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1670   {return new ClassAccess(prefix,
 
1671                           new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
 
1672                           ClassAccess.NORMAL);}
 
1674   <LBRACKET> [ expression = Expression() | expression = Type() ]  //Not good
 
1677   } catch (ParseException e) {
 
1678     errorMessage = "']' expected";
 
1680     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1681     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1684   {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
 
1693   token = <INTEGER_LITERAL>        {pos = SimpleCharStream.getPosition();
 
1694                                     return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
 
1695 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
 
1696                                     return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
 
1697 | token = <STRING_LITERAL>         {pos = SimpleCharStream.getPosition();
 
1698                                     return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
 
1699 | <TRUE>                           {pos = SimpleCharStream.getPosition();
 
1700                                     return new TrueLiteral(pos-4,pos);}
 
1701 | <FALSE>                          {pos = SimpleCharStream.getPosition();
 
1702                                     return new FalseLiteral(pos-4,pos);}
 
1703 | <NULL>                           {pos = SimpleCharStream.getPosition();
 
1704                                     return new NullLiteral(pos-4,pos);}
 
1707 FunctionCall Arguments(Expression func) :
 
1709 Expression[] args = null;
 
1712   <LPAREN> [ args = ArgumentList() ]
 
1715   } catch (ParseException e) {
 
1716     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
 
1718     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1719     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1722   {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
 
1726  * An argument list is a list of arguments separated by comma :
 
1727  * argumentDeclaration() (, argumentDeclaration)*
 
1728  * @return an array of arguments
 
1730 Expression[] ArgumentList() :
 
1733 final ArrayList list = new ArrayList();
 
1742       } catch (ParseException e) {
 
1743         errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
 
1745         errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1746         errorEnd     = SimpleCharStream.getPosition() + 1;
 
1751    Expression[] arguments = new Expression[list.size()];
 
1752    list.toArray(arguments);
 
1757  * A Statement without break.
 
1759 Statement StatementNoBreak() :
 
1761   final Statement statement;
 
1766   statement = Expression()
 
1769   } catch (ParseException e) {
 
1770     if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
 
1771       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1773       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1774       errorEnd   = SimpleCharStream.getPosition() + 1;
 
1780   statement = LabeledStatement() {return statement;}
 
1781 | statement = Block()            {return statement;}
 
1782 | statement = EmptyStatement()   {return statement;}
 
1783 | statement = StatementExpression()
 
1786   } catch (ParseException e) {
 
1787     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1789     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1790     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1794 | statement = SwitchStatement()         {return statement;}
 
1795 | statement = IfStatement()             {return statement;}
 
1796 | statement = WhileStatement()          {return statement;}
 
1797 | statement = DoStatement()             {return statement;}
 
1798 | statement = ForStatement()            {return statement;}
 
1799 | statement = ForeachStatement()        {return statement;}
 
1800 | statement = ContinueStatement()       {return statement;}
 
1801 | statement = ReturnStatement()         {return statement;}
 
1802 | statement = EchoStatement()           {return statement;}
 
1803 | [token=<AT>] statement = IncludeStatement()
 
1804   {if (token != null) {
 
1805     ((InclusionStatement)statement).silent = true;
 
1808 | statement = StaticStatement()         {return statement;}
 
1809 | statement = GlobalStatement()         {return statement;}
 
1813  * A Normal statement.
 
1815 Statement Statement() :
 
1817   final Statement statement;
 
1820   statement = StatementNoBreak() {return statement;}
 
1821 | statement = BreakStatement()   {return statement;}
 
1825  * An html block inside a php syntax.
 
1827 HTMLBlock htmlBlock() :
 
1829   final int startIndex = nodePtr;
 
1830   AstNode[] blockNodes;
 
1834   <PHPEND> (phpEchoBlock())*
 
1836     (<PHPSTARTLONG> | <PHPSTARTSHORT>)
 
1837   } catch (ParseException e) {
 
1838     errorMessage = "End of file unexpected, '<?php' expected";
 
1840     errorStart   = SimpleCharStream.getPosition();
 
1841     errorEnd     = SimpleCharStream.getPosition();
 
1845   nbNodes    = nodePtr - startIndex;
 
1846   blockNodes = new AstNode[nbNodes];
 
1847   System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
 
1848   nodePtr = startIndex;
 
1849   return new HTMLBlock(blockNodes);}
 
1853  * An include statement. It's "include" an expression;
 
1855 InclusionStatement IncludeStatement() :
 
1857   final Expression expr;
 
1859   final int pos = SimpleCharStream.getPosition();
 
1860   final InclusionStatement inclusionStatement;
 
1863       (  <REQUIRE>      {keyword = InclusionStatement.REQUIRE;}
 
1864        | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
 
1865        | <INCLUDE>      {keyword = InclusionStatement.INCLUDE;}
 
1866        | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
 
1869   } catch (ParseException e) {
 
1870     if (errorMessage != null) {
 
1873     errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
 
1875     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1876     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1879   {inclusionStatement = new InclusionStatement(currentSegment,
 
1883    currentSegment.add(inclusionStatement);
 
1887   } catch (ParseException e) {
 
1888     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1890     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1891     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1894   {return inclusionStatement;}
 
1897 PrintExpression PrintExpression() :
 
1899   final Expression expr;
 
1900   final int pos = SimpleCharStream.getPosition();
 
1903   <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
 
1906 ListExpression ListExpression() :
 
1909   Expression expression = null;
 
1910   ArrayList list = new ArrayList();
 
1911   final int pos = SimpleCharStream.getPosition();
 
1917   } catch (ParseException e) {
 
1918     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
 
1920     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1921     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1925     expr = VariableDeclaratorId()
 
1928   {if (expr == null) list.add(null);}
 
1932     } catch (ParseException e) {
 
1933       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
 
1935       errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1936       errorEnd     = SimpleCharStream.getPosition() + 1;
 
1939     expr = VariableDeclaratorId()
 
1944   } catch (ParseException e) {
 
1945     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
 
1947     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1948     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1951   [ <ASSIGN> expression = Expression()
 
1953     String[] strings = new String[list.size()];
 
1954     list.toArray(strings);
 
1955     return new ListExpression(strings,
 
1958                               SimpleCharStream.getPosition());}
 
1961     String[] strings = new String[list.size()];
 
1962     list.toArray(strings);
 
1963     return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
 
1967  * An echo statement.
 
1968  * echo anyexpression (, otherexpression)*
 
1970 EchoStatement EchoStatement() :
 
1972   final ArrayList expressions = new ArrayList();
 
1974   final int pos = SimpleCharStream.getPosition();
 
1977   <ECHO> expr = Expression()
 
1978   {expressions.add(expr);}
 
1980     <COMMA> expr = Expression()
 
1981     {expressions.add(expr);}
 
1985   } catch (ParseException e) {
 
1986     if (e.currentToken.next.kind != 4) {
 
1987       errorMessage = "';' expected after 'echo' statement";
 
1989       errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1990       errorEnd     = SimpleCharStream.getPosition() + 1;
 
1994   {Expression[] exprs = new Expression[expressions.size()];
 
1995    expressions.toArray(exprs);
 
1996    return new EchoStatement(exprs,pos);}
 
1999 GlobalStatement GlobalStatement() :
 
2001    final int pos = SimpleCharStream.getPosition();
 
2003    ArrayList vars = new ArrayList();
 
2004    GlobalStatement global;
 
2008     expr = VariableDeclaratorId()
 
2011     expr = VariableDeclaratorId()
 
2017     String[] strings = new String[vars.size()];
 
2018     vars.toArray(strings);
 
2019     global = new GlobalStatement(currentSegment,
 
2022                                  SimpleCharStream.getPosition());
 
2023     currentSegment.add(global);
 
2025   } catch (ParseException e) {
 
2026     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
 
2028     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2029     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2034 StaticStatement StaticStatement() :
 
2036   final int pos = SimpleCharStream.getPosition();
 
2037   final ArrayList vars = new ArrayList();
 
2038   VariableDeclaration expr;
 
2041   <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
 
2042   (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
 
2046     String[] strings = new String[vars.size()];
 
2047     vars.toArray(strings);
 
2048     return new StaticStatement(strings,
 
2050                                 SimpleCharStream.getPosition());}
 
2051   } catch (ParseException e) {
 
2052     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
 
2054     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2055     errorEnd   = SimpleCharStream.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();
 
2081   final ArrayList list = new ArrayList();
 
2082   Statement statement;
 
2087   } catch (ParseException e) {
 
2088     errorMessage = "'{' expected";
 
2090     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2091     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2094   ( statement = BlockStatement() {list.add(statement);}
 
2095   | statement = htmlBlock()      {list.add(statement);})*
 
2098   } catch (ParseException e) {
 
2099     errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
 
2101     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2102     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2106   Statement[] statements = new Statement[list.size()];
 
2107   list.toArray(statements);
 
2108   return new Block(statements,pos,SimpleCharStream.getPosition());}
 
2111 Statement BlockStatement() :
 
2113   final Statement statement;
 
2117   statement = Statement()         {if (phpDocument == currentSegment) pushOnAstNodes(statement);
 
2119   } catch (ParseException e) {
 
2120     errorMessage = "statement expected";
 
2122     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2123     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2126 | statement = ClassDeclaration()  {return statement;}
 
2127 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
 
2132  * A Block statement that will not contain any 'break'
 
2134 Statement BlockStatementNoBreak() :
 
2136   final Statement statement;
 
2139   statement = StatementNoBreak()  {return statement;}
 
2140 | statement = ClassDeclaration()  {return statement;}
 
2141 | statement = MethodDeclaration() {return statement;}
 
2144 VariableDeclaration[] LocalVariableDeclaration() :
 
2146   final ArrayList list = new ArrayList();
 
2147   VariableDeclaration var;
 
2150   var = LocalVariableDeclarator()
 
2152   ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
 
2154     VariableDeclaration[] vars = new VariableDeclaration[list.size()];
 
2159 VariableDeclaration LocalVariableDeclarator() :
 
2161   final String varName;
 
2162   Expression initializer = null;
 
2163   final int pos = SimpleCharStream.getPosition();
 
2166   varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
 
2168    if (initializer == null) {
 
2169     return new VariableDeclaration(currentSegment,
 
2170                                   varName.toCharArray(),
 
2172                                   SimpleCharStream.getPosition());
 
2174     return new VariableDeclaration(currentSegment,
 
2175                                     varName.toCharArray(),
 
2181 EmptyStatement EmptyStatement() :
 
2187   {pos = SimpleCharStream.getPosition();
 
2188    return new EmptyStatement(pos-1,pos);}
 
2191 Statement StatementExpression() :
 
2193   Expression expr,expr2;
 
2197   expr = PreIncDecExpression() {return expr;}
 
2199   expr = PrimaryExpression()
 
2200   [ <INCR> {return new PostfixedUnaryExpression(expr,
 
2201                                                 OperatorIds.PLUS_PLUS,
 
2202                                                 SimpleCharStream.getPosition());}
 
2203   | <DECR> {return new PostfixedUnaryExpression(expr,
 
2204                                                 OperatorIds.MINUS_MINUS,
 
2205                                                 SimpleCharStream.getPosition());}
 
2206   | operator = AssignmentOperator() expr2 = Expression()
 
2207     {return new BinaryExpression(expr,expr2,operator);}
 
2212 SwitchStatement SwitchStatement() :
 
2214   final Expression variable;
 
2215   final AbstractCase[] cases;
 
2216   final int pos = SimpleCharStream.getPosition();
 
2222   } catch (ParseException e) {
 
2223     errorMessage = "'(' expected after 'switch'";
 
2225     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2226     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2230     variable = Expression()
 
2231   } catch (ParseException e) {
 
2232     if (errorMessage != null) {
 
2235     errorMessage = "expression expected";
 
2237     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2238     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2243   } catch (ParseException e) {
 
2244     errorMessage = "')' expected";
 
2246     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2247     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2250   (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
 
2251   {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
 
2254 AbstractCase[] switchStatementBrace() :
 
2257   final ArrayList cases = new ArrayList();
 
2261  ( cas = switchLabel0() {cases.add(cas);})*
 
2265     AbstractCase[] abcase = new AbstractCase[cases.size()];
 
2266     cases.toArray(abcase);
 
2268   } catch (ParseException e) {
 
2269     errorMessage = "'}' expected";
 
2271     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2272     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2277  * A Switch statement with : ... endswitch;
 
2278  * @param start the begin offset of the switch
 
2279  * @param end the end offset of the switch
 
2281 AbstractCase[] switchStatementColon(final int start, final int end) :
 
2284   final ArrayList cases = new ArrayList();
 
2289   setMarker(fileToParse,
 
2290             "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
 
2294             "Line " + token.beginLine);
 
2295   } catch (CoreException e) {
 
2296     PHPeclipsePlugin.log(e);
 
2298   ( cas = switchLabel0() {cases.add(cas);})*
 
2301   } catch (ParseException e) {
 
2302     errorMessage = "'endswitch' expected";
 
2304     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2305     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2311     AbstractCase[] abcase = new AbstractCase[cases.size()];
 
2312     cases.toArray(abcase);
 
2314   } catch (ParseException e) {
 
2315     errorMessage = "';' expected after 'endswitch' keyword";
 
2317     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2318     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2323 AbstractCase switchLabel0() :
 
2325   final Expression expr;
 
2326   Statement statement;
 
2327   final ArrayList stmts = new ArrayList();
 
2328   final int pos = SimpleCharStream.getPosition();
 
2331   expr = SwitchLabel()
 
2332   ( statement = BlockStatementNoBreak() {stmts.add(statement);}
 
2333   | statement = htmlBlock()             {stmts.add(statement);})*
 
2334   [ statement = BreakStatement()        {stmts.add(statement);}]
 
2336   Statement[] stmtsArray = new Statement[stmts.size()];
 
2337   stmts.toArray(stmtsArray);
 
2338   if (expr == null) {//it's a default
 
2339     return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
 
2341   return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
 
2346  * case Expression() :
 
2348  * @return the if it was a case and null if not
 
2350 Expression SwitchLabel() :
 
2352   final Expression expr;
 
2358   } catch (ParseException e) {
 
2359     if (errorMessage != null) throw e;
 
2360     errorMessage = "expression expected after 'case' keyword";
 
2362     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2363     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2369   } catch (ParseException e) {
 
2370     errorMessage = "':' expected after case expression";
 
2372     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2373     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2381   } catch (ParseException e) {
 
2382     errorMessage = "':' expected after 'default' keyword";
 
2384     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2385     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2390 Break BreakStatement() :
 
2392   Expression expression = null;
 
2393   final int start = SimpleCharStream.getPosition();
 
2396   <BREAK> [ expression = Expression() ]
 
2399   } catch (ParseException e) {
 
2400     errorMessage = "';' expected after 'break' keyword";
 
2402     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2403     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2406   {return new Break(expression, start, SimpleCharStream.getPosition());}
 
2409 IfStatement IfStatement() :
 
2411   final int pos = SimpleCharStream.getPosition();
 
2412   Expression condition;
 
2413   IfStatement ifStatement;
 
2416   <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
 
2417   {return ifStatement;}
 
2421 Expression Condition(final String keyword) :
 
2423   final Expression condition;
 
2428   } catch (ParseException e) {
 
2429     errorMessage = "'(' expected after " + keyword + " keyword";
 
2431     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
 
2432     errorEnd   = errorStart +1;
 
2433     processParseException(e);
 
2435   condition = Expression()
 
2438   } catch (ParseException e) {
 
2439     errorMessage = "')' expected after " + keyword + " keyword";
 
2441     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2442     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2443     processParseException(e);
 
2448 IfStatement IfStatement0(Expression condition, final int start,final int end) :
 
2450   Statement statement;
 
2452   final Statement[] statementsArray;
 
2453   ElseIf elseifStatement;
 
2454   Else elseStatement = null;
 
2456   final ArrayList elseIfList = new ArrayList();
 
2458   int pos = SimpleCharStream.getPosition();
 
2463   {stmts = new ArrayList();}
 
2464   (  statement = Statement() {stmts.add(statement);}
 
2465    | statement = htmlBlock() {stmts.add(statement);})*
 
2466    {endStatements = SimpleCharStream.getPosition();}
 
2467    (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
 
2468    [elseStatement = ElseStatementColon()]
 
2471   setMarker(fileToParse,
 
2472             "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
 
2476             "Line " + token.beginLine);
 
2477   } catch (CoreException e) {
 
2478     PHPeclipsePlugin.log(e);
 
2482   } catch (ParseException e) {
 
2483     errorMessage = "'endif' expected";
 
2485     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2486     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2491   } catch (ParseException e) {
 
2492     errorMessage = "';' expected after 'endif' keyword";
 
2494     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2495     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2499     elseIfs = new ElseIf[elseIfList.size()];
 
2500     elseIfList.toArray(elseIfs);
 
2501     if (stmts.size() == 1) {
 
2502       return new IfStatement(condition,
 
2503                              (Statement) stmts.get(0),
 
2507                               SimpleCharStream.getPosition());
 
2509       statementsArray = new Statement[stmts.size()];
 
2510       stmts.toArray(statementsArray);
 
2511       return new IfStatement(condition,
 
2512                              new Block(statementsArray,pos,endStatements),
 
2516                              SimpleCharStream.getPosition());
 
2521   (stmt = Statement() | stmt = htmlBlock())
 
2522   ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
 
2526       {pos = SimpleCharStream.getPosition();}
 
2527       statement = Statement()
 
2528       {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
 
2529     } catch (ParseException e) {
 
2530       if (errorMessage != null) {
 
2533       errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
 
2535       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2536       errorEnd   = SimpleCharStream.getPosition() + 1;
 
2541     elseIfs = new ElseIf[elseIfList.size()];
 
2542     elseIfList.toArray(elseIfs);
 
2543     return new IfStatement(condition,
 
2548                            SimpleCharStream.getPosition());}
 
2551 ElseIf ElseIfStatementColon() :
 
2553   Expression condition;
 
2554   Statement statement;
 
2555   final ArrayList list = new ArrayList();
 
2556   final int pos = SimpleCharStream.getPosition();
 
2559   <ELSEIF> condition = Condition("elseif")
 
2560   <COLON> (  statement = Statement() {list.add(statement);}
 
2561            | statement = htmlBlock() {list.add(statement);})*
 
2563   Statement[] stmtsArray = new Statement[list.size()];
 
2564   list.toArray(stmtsArray);
 
2565   return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
 
2568 Else ElseStatementColon() :
 
2570   Statement statement;
 
2571   final ArrayList list = new ArrayList();
 
2572   final int pos = SimpleCharStream.getPosition();
 
2575   <ELSE> <COLON> (  statement = Statement() {list.add(statement);}
 
2576                   | statement = htmlBlock() {list.add(statement);})*
 
2578   Statement[] stmtsArray = new Statement[list.size()];
 
2579   list.toArray(stmtsArray);
 
2580   return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
 
2583 ElseIf ElseIfStatement() :
 
2585   Expression condition;
 
2586   Statement statement;
 
2587   final ArrayList list = new ArrayList();
 
2588   final int pos = SimpleCharStream.getPosition();
 
2591   <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
 
2593   Statement[] stmtsArray = new Statement[list.size()];
 
2594   list.toArray(stmtsArray);
 
2595   return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
 
2598 WhileStatement WhileStatement() :
 
2600   final Expression condition;
 
2601   final Statement action;
 
2602   final int pos = SimpleCharStream.getPosition();
 
2606     condition = Condition("while")
 
2607     action    = WhileStatement0(pos,pos + 5)
 
2608     {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
 
2611 Statement WhileStatement0(final int start, final int end) :
 
2613   Statement statement;
 
2614   final ArrayList stmts = new ArrayList();
 
2615   final int pos = SimpleCharStream.getPosition();
 
2618   <COLON> (statement = Statement() {stmts.add(statement);})*
 
2620   setMarker(fileToParse,
 
2621             "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
 
2625             "Line " + token.beginLine);
 
2626   } catch (CoreException e) {
 
2627     PHPeclipsePlugin.log(e);
 
2631   } catch (ParseException e) {
 
2632     errorMessage = "'endwhile' expected";
 
2634     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2635     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2641     Statement[] stmtsArray = new Statement[stmts.size()];
 
2642     stmts.toArray(stmtsArray);
 
2643     return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
 
2644   } catch (ParseException e) {
 
2645     errorMessage = "';' expected after 'endwhile' keyword";
 
2647     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2648     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2652   statement = Statement()
 
2656 DoStatement DoStatement() :
 
2658   final Statement action;
 
2659   final Expression condition;
 
2660   final int pos = SimpleCharStream.getPosition();
 
2663   <DO> action = Statement() <WHILE> condition = Condition("while")
 
2666     {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
 
2667   } catch (ParseException e) {
 
2668     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
2670     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2671     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2676 ForeachStatement ForeachStatement() :
 
2678   Statement statement;
 
2679   Expression expression;
 
2680   final int pos = SimpleCharStream.getPosition();
 
2681   ArrayVariableDeclaration variable;
 
2687   } catch (ParseException e) {
 
2688     errorMessage = "'(' expected after 'foreach' keyword";
 
2690     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2691     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2695     expression = Expression()
 
2696   } catch (ParseException e) {
 
2697     errorMessage = "variable expected";
 
2699     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2700     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2705   } catch (ParseException e) {
 
2706     errorMessage = "'as' expected";
 
2708     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2709     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2713     variable = ArrayVariable()
 
2714   } catch (ParseException e) {
 
2715     errorMessage = "variable expected";
 
2717     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2718     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2723   } catch (ParseException e) {
 
2724     errorMessage = "')' expected after 'foreach' keyword";
 
2726     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2727     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2731     statement = Statement()
 
2732   } catch (ParseException e) {
 
2733     if (errorMessage != null) throw e;
 
2734     errorMessage = "statement expected";
 
2736     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2737     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2740   {return new ForeachStatement(expression,
 
2744                                SimpleCharStream.getPosition());}
 
2748 ForStatement ForStatement() :
 
2751 final int pos = SimpleCharStream.getPosition();
 
2752 Statement[] initializations = null;
 
2753 Expression condition = null;
 
2754 Statement[] increments = null;
 
2756 final ArrayList list = new ArrayList();
 
2757 final int startBlock, endBlock;
 
2763   } catch (ParseException e) {
 
2764     errorMessage = "'(' expected after 'for' keyword";
 
2766     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2767     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2770      [ initializations = ForInit() ] <SEMICOLON>
 
2771      [ condition = Expression() ] <SEMICOLON>
 
2772      [ increments = StatementExpressionList() ] <RPAREN>
 
2774       action = Statement()
 
2775       {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
 
2778       {startBlock = SimpleCharStream.getPosition();}
 
2779       (action = Statement() {list.add(action);})*
 
2782         setMarker(fileToParse,
 
2783                   "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
 
2785                   pos+token.image.length(),
 
2787                   "Line " + token.beginLine);
 
2788         } catch (CoreException e) {
 
2789           PHPeclipsePlugin.log(e);
 
2792       {endBlock = SimpleCharStream.getPosition();}
 
2795       } catch (ParseException e) {
 
2796         errorMessage = "'endfor' expected";
 
2798         errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2799         errorEnd   = SimpleCharStream.getPosition() + 1;
 
2805         Statement[] stmtsArray = new Statement[list.size()];
 
2806         list.toArray(stmtsArray);
 
2807         return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
 
2808       } catch (ParseException e) {
 
2809         errorMessage = "';' expected after 'endfor' keyword";
 
2811         errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2812         errorEnd   = SimpleCharStream.getPosition() + 1;
 
2818 Statement[] ForInit() :
 
2820   Statement[] statements;
 
2823   LOOKAHEAD(LocalVariableDeclaration())
 
2824   statements = LocalVariableDeclaration()
 
2825   {return statements;}
 
2827   statements = StatementExpressionList()
 
2828   {return statements;}
 
2831 Statement[] StatementExpressionList() :
 
2833   final ArrayList list = new ArrayList();
 
2837   expr = StatementExpression()   {list.add(expr);}
 
2838   (<COMMA> StatementExpression() {list.add(expr);})*
 
2840   Statement[] stmtsArray = new Statement[list.size()];
 
2841   list.toArray(stmtsArray);
 
2845 Continue ContinueStatement() :
 
2847   Expression expr = null;
 
2848   final int pos = SimpleCharStream.getPosition();
 
2851   <CONTINUE> [ expr = Expression() ]
 
2854     {return new Continue(expr,pos,SimpleCharStream.getPosition());}
 
2855   } catch (ParseException e) {
 
2856     errorMessage = "';' expected after 'continue' statement";
 
2858     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2859     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2864 ReturnStatement ReturnStatement() :
 
2866   Expression expr = null;
 
2867   final int pos = SimpleCharStream.getPosition();
 
2870   <RETURN> [ expr = Expression() ]
 
2873     {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
 
2874   } catch (ParseException e) {
 
2875     errorMessage = "';' expected after 'return' statement";
 
2877     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2878     errorEnd   = SimpleCharStream.getPosition() + 1;