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.ArrayList;
 
  33 import java.io.StringReader;
 
  35 import java.text.MessageFormat;
 
  37 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
 
  38 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
  39 import net.sourceforge.phpdt.internal.compiler.ast.*;
 
  40 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
 
  41 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
 
  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   /** The error level of the current ParseException. */
 
  64   private static int errorLevel = ERROR;
 
  65   /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
 
  66   private static String errorMessage;
 
  68   private static int errorStart = -1;
 
  69   private static int errorEnd = -1;
 
  70   private static PHPDocument phpDocument;
 
  72   private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
 
  74    * The point where html starts.
 
  75    * It will be used by the token manager to create HTMLCode objects
 
  77   public static int htmlStart;
 
  80   private final static int AstStackIncrement = 100;
 
  81   /** The stack of node. */
 
  82   private static AstNode[] nodes;
 
  83   /** The cursor in expression stack. */
 
  84   private static int nodePtr;
 
  86   public final void setFileToParse(final IFile fileToParse) {
 
  87     this.fileToParse = fileToParse;
 
  93   public PHPParser(final IFile fileToParse) {
 
  94     this(new StringReader(""));
 
  95     this.fileToParse = fileToParse;
 
  99    * Reinitialize the parser.
 
 101   private static final void init() {
 
 102     nodes = new AstNode[AstStackIncrement];
 
 108    * Add an php node on the stack.
 
 109    * @param node the node that will be added to the stack
 
 111   private static final void pushOnAstNodes(AstNode node) {
 
 113       nodes[++nodePtr] = node;
 
 114     } catch (IndexOutOfBoundsException e) {
 
 115       int oldStackLength = nodes.length;
 
 116       AstNode[] oldStack = nodes;
 
 117       nodes = new AstNode[oldStackLength + AstStackIncrement];
 
 118       System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
 
 119       nodePtr = oldStackLength;
 
 120       nodes[nodePtr] = node;
 
 124   public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
 
 125     phpDocument = new PHPDocument(parent,"_root".toCharArray());
 
 126     currentSegment = phpDocument;
 
 127     outlineInfo = new PHPOutlineInfo(parent, currentSegment);
 
 128     final StringReader stream = new StringReader(s);
 
 129     if (jj_input_stream == null) {
 
 130       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 136       phpDocument.nodes = new AstNode[nodes.length];
 
 137       System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
 
 138       if (PHPeclipsePlugin.DEBUG) {
 
 139         PHPeclipsePlugin.log(1,phpDocument.toString());
 
 141     } catch (ParseException e) {
 
 142       processParseException(e);
 
 148    * This method will process the parse exception.
 
 149    * If the error message is null, the parse exception wasn't catched and a trace is written in the log
 
 150    * @param e the ParseException
 
 152   private static void processParseException(final ParseException e) {
 
 153     if (errorMessage == null) {
 
 154       PHPeclipsePlugin.log(e);
 
 155       errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
 
 156       errorStart = SimpleCharStream.getPosition();
 
 157       errorEnd   = errorStart + 1;
 
 164    * Create marker for the parse error
 
 165    * @param e the ParseException
 
 167   private static void setMarker(final ParseException e) {
 
 169       if (errorStart == -1) {
 
 170         setMarker(fileToParse,
 
 172                   SimpleCharStream.tokenBegin,
 
 173                   SimpleCharStream.tokenBegin + e.currentToken.image.length(),
 
 175                   "Line " + e.currentToken.beginLine);
 
 177         setMarker(fileToParse,
 
 182                   "Line " + e.currentToken.beginLine);
 
 186     } catch (CoreException e2) {
 
 187       PHPeclipsePlugin.log(e2);
 
 191   private static void scanLine(final String output,
 
 194                                final int brIndx) throws CoreException {
 
 196     StringBuffer lineNumberBuffer = new StringBuffer(10);
 
 198     current = output.substring(indx, brIndx);
 
 200     if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
 
 201       int onLine = current.indexOf("on line <b>");
 
 203         lineNumberBuffer.delete(0, lineNumberBuffer.length());
 
 204         for (int i = onLine; i < current.length(); i++) {
 
 205           ch = current.charAt(i);
 
 206           if ('0' <= ch && '9' >= ch) {
 
 207             lineNumberBuffer.append(ch);
 
 211         int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
 
 213         Hashtable attributes = new Hashtable();
 
 215         current = current.replaceAll("\n", "");
 
 216         current = current.replaceAll("<b>", "");
 
 217         current = current.replaceAll("</b>", "");
 
 218         MarkerUtilities.setMessage(attributes, current);
 
 220         if (current.indexOf(PARSE_ERROR_STRING) != -1)
 
 221           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
 
 222         else if (current.indexOf(PARSE_WARNING_STRING) != -1)
 
 223           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
 
 225           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
 
 226         MarkerUtilities.setLineNumber(attributes, lineNumber);
 
 227         MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
 
 232   public final void parse(final String s) throws CoreException {
 
 233     final StringReader stream = new StringReader(s);
 
 234     if (jj_input_stream == null) {
 
 235       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 241     } catch (ParseException e) {
 
 242       processParseException(e);
 
 247    * Call the php parse command ( php -l -f <filename> )
 
 248    * and create markers according to the external parser output
 
 250   public static void phpExternalParse(final IFile file) {
 
 251     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
 
 252     final String filename = file.getLocation().toString();
 
 254     final String[] arguments = { filename };
 
 255     final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
 
 256     final String command = form.format(arguments);
 
 258     final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
 
 261       // parse the buffer to find the errors and warnings
 
 262       createMarkers(parserResult, file);
 
 263     } catch (CoreException e) {
 
 264       PHPeclipsePlugin.log(e);
 
 269    * Put a new html block in the stack.
 
 271   public static final void createNewHTMLCode() {
 
 272     final int currentPosition = SimpleCharStream.getPosition();
 
 273     if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
 
 276     final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
 
 277     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
 
 283   public static final void createNewTask() {
 
 284     final int currentPosition = SimpleCharStream.getPosition();
 
 285     final String  todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
 
 286                                                                   SimpleCharStream.currentBuffer.indexOf("\n",
 
 289       setMarker(fileToParse,
 
 291                 SimpleCharStream.getBeginLine(),
 
 293                 "Line "+SimpleCharStream.getBeginLine());
 
 294     } catch (CoreException e) {
 
 295       PHPeclipsePlugin.log(e);
 
 299   private static final void parse() throws ParseException {
 
 304 PARSER_END(PHPParser)
 
 308   <PHPSTARTSHORT : "<?">    {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 309 | <PHPSTARTLONG  : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 310 | <PHPECHOSTART  : "<?=">   {PHPParser.createNewHTMLCode();} : PHPPARSING
 
 315   <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
 
 318 /* Skip any character if we are not in php mode */
 
 336 <PHPPARSING> SPECIAL_TOKEN :
 
 338   "//" : IN_SINGLE_LINE_COMMENT
 
 339 | "#"  : IN_SINGLE_LINE_COMMENT
 
 340 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
 
 341 | "/*" : IN_MULTI_LINE_COMMENT
 
 344 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
 
 346   <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
 
 350 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
 
 352  "todo" {PHPParser.createNewTask();}
 
 355 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
 
 360 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
 
 365 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
 
 375 | <FUNCTION : "function">
 
 378 | <ELSEIF   : "elseif">
 
 385 /* LANGUAGE CONSTRUCT */
 
 390 | <INCLUDE            : "include">
 
 391 | <REQUIRE            : "require">
 
 392 | <INCLUDE_ONCE       : "include_once">
 
 393 | <REQUIRE_ONCE       : "require_once">
 
 394 | <GLOBAL             : "global">
 
 395 | <DEFINE             : "define">
 
 396 | <STATIC             : "static">
 
 397 | <CLASSACCESS        : "->">
 
 398 | <STATICCLASSACCESS  : "::">
 
 399 | <ARRAYASSIGN        : "=>">
 
 402 /* RESERVED WORDS AND LITERALS */
 
 408 | <CONTINUE : "continue">
 
 409 | <_DEFAULT : "default">
 
 411 | <EXTENDS  : "extends">
 
 416 | <RETURN   : "return">
 
 418 | <SWITCH   : "switch">
 
 423 | <ENDWHILE : "endwhile">
 
 424 | <ENDSWITCH: "endswitch">
 
 426 | <ENDFOR   : "endfor">
 
 427 | <FOREACH  : "foreach">
 
 435 | <OBJECT  : "object">
 
 437 | <BOOLEAN : "boolean">
 
 439 | <DOUBLE  : "double">
 
 442 | <INTEGER : "integer">
 
 462 | <MINUS_MINUS        : "--">
 
 472 | <RSIGNEDSHIFT       : ">>">
 
 473 | <RUNSIGNEDSHIFT     : ">>>">
 
 482         <DECIMAL_LITERAL> (["l","L"])?
 
 483       | <HEX_LITERAL> (["l","L"])?
 
 484       | <OCTAL_LITERAL> (["l","L"])?
 
 487   <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
 
 489   <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
 
 491   <#OCTAL_LITERAL: "0" (["0"-"7"])* >
 
 493   <FLOATING_POINT_LITERAL:
 
 494         (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
 
 495       | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
 
 496       | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
 
 497       | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
 
 500   <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 
 502   <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
 
 503 |   <STRING_1: "\"" ( ~["\""] | "\\\"" | "\\" )* "\"">
 
 504 |   <STRING_2: "'" ( ~["'"] | "\\'" )* "'">
 
 505 |   <STRING_3: "`" ( ~["`"] | "\\`" )* "`">
 
 512   < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
 
 515       ["a"-"z"] | ["A"-"Z"]
 
 523     "_" | ["\u007f"-"\u00ff"]
 
 548 | <EQUAL_EQUAL        : "==">
 
 553 | <BANGDOUBLEEQUAL    : "!==">
 
 554 | <TRIPLEEQUAL        : "===">
 
 561 | <PLUSASSIGN         : "+=">
 
 562 | <MINUSASSIGN        : "-=">
 
 563 | <STARASSIGN         : "*=">
 
 564 | <SLASHASSIGN        : "/=">
 
 570 | <TILDEEQUAL         : "~=">
 
 571 | <LSHIFTASSIGN       : "<<=">
 
 572 | <RSIGNEDSHIFTASSIGN : ">>=">
 
 577   <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
 
 585     {PHPParser.createNewHTMLCode();}
 
 586   } catch (TokenMgrError e) {
 
 587     PHPeclipsePlugin.log(e);
 
 588     errorStart   = SimpleCharStream.getPosition();
 
 589     errorEnd     = errorStart + 1;
 
 590     errorMessage = e.getMessage();
 
 592     throw generateParseException();
 
 597  * A php block is a <?= expression [;]?>
 
 598  * or <?php somephpcode ?>
 
 599  * or <? somephpcode ?>
 
 603   final int start = SimpleCharStream.getPosition();
 
 604   final PHPEchoBlock phpEchoBlock;
 
 607   phpEchoBlock = phpEchoBlock()
 
 608   {pushOnAstNodes(phpEchoBlock);}
 
 613       setMarker(fileToParse,
 
 614                 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
 
 616                 SimpleCharStream.getPosition(),
 
 618                 "Line " + token.beginLine);
 
 619     } catch (CoreException e) {
 
 620       PHPeclipsePlugin.log(e);
 
 626   } catch (ParseException e) {
 
 627     errorMessage = "'?>' expected";
 
 629     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 630     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 631     processParseException(e);
 
 635 PHPEchoBlock phpEchoBlock() :
 
 637   final Expression expr;
 
 638   final int pos = SimpleCharStream.getPosition();
 
 639   PHPEchoBlock echoBlock;
 
 642   <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
 
 644   echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
 
 645   pushOnAstNodes(echoBlock);
 
 655 ClassDeclaration ClassDeclaration() :
 
 657   final ClassDeclaration classDeclaration;
 
 658   final Token className;
 
 659   Token superclassName = null;
 
 661   char[] classNameImage = SYNTAX_ERROR_CHAR;
 
 662   char[] superclassNameImage = null;
 
 666   {pos = SimpleCharStream.getPosition();}
 
 668     className = <IDENTIFIER>
 
 669     {classNameImage = className.image.toCharArray();}
 
 670   } catch (ParseException e) {
 
 671     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
 
 673     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 674     errorEnd     = SimpleCharStream.getPosition() + 1;
 
 675     processParseException(e);
 
 680       superclassName = <IDENTIFIER>
 
 681       {superclassNameImage = superclassName.image.toCharArray();}
 
 682     } catch (ParseException e) {
 
 683       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
 
 685       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 686       errorEnd   = SimpleCharStream.getPosition() + 1;
 
 687       processParseException(e);
 
 688       superclassNameImage = SYNTAX_ERROR_CHAR;
 
 692     if (superclassNameImage == null) {
 
 693       classDeclaration = new ClassDeclaration(currentSegment,
 
 698       classDeclaration = new ClassDeclaration(currentSegment,
 
 704       currentSegment.add(classDeclaration);
 
 705       currentSegment = classDeclaration;
 
 707   ClassBody(classDeclaration)
 
 708   {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
 
 709    classDeclaration.sourceEnd = SimpleCharStream.getPosition();
 
 710    pushOnAstNodes(classDeclaration);
 
 711    return classDeclaration;}
 
 714 void ClassBody(ClassDeclaration classDeclaration) :
 
 719   } catch (ParseException e) {
 
 720     errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
 
 722     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 723     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 726   ( ClassBodyDeclaration(classDeclaration) )*
 
 729   } catch (ParseException e) {
 
 730     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
 
 732     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 733     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 739  * A class can contain only methods and fields.
 
 741 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
 
 743   MethodDeclaration method;
 
 744   FieldDeclaration field;
 
 747   method = MethodDeclaration() {classDeclaration.addMethod(method);}
 
 748 | field = FieldDeclaration()   {classDeclaration.addField(field);}
 
 752  * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
 
 754 FieldDeclaration FieldDeclaration() :
 
 756   VariableDeclaration variableDeclaration;
 
 757   VariableDeclaration[] list;
 
 758   final ArrayList arrayList = new ArrayList();
 
 759   final int pos = SimpleCharStream.getPosition();
 
 762   <VAR> variableDeclaration = VariableDeclarator()
 
 763   {arrayList.add(variableDeclaration);
 
 764    outlineInfo.addVariable(new String(variableDeclaration.name));}
 
 765   ( <COMMA> variableDeclaration = VariableDeclarator()
 
 766       {arrayList.add(variableDeclaration);
 
 767        outlineInfo.addVariable(new String(variableDeclaration.name));}
 
 771   } catch (ParseException e) {
 
 772     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
 
 774     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 775     errorEnd     = SimpleCharStream.getPosition() + 1;
 
 776     processParseException(e);
 
 779   {list = new VariableDeclaration[arrayList.size()];
 
 780    arrayList.toArray(list);
 
 781    return new FieldDeclaration(list,
 
 783                                SimpleCharStream.getPosition(),
 
 787 VariableDeclaration VariableDeclarator() :
 
 789   final String varName;
 
 790   Expression initializer = null;
 
 791   final int pos = SimpleCharStream.getPosition();
 
 794   varName = VariableDeclaratorId()
 
 798       initializer = VariableInitializer()
 
 799     } catch (ParseException e) {
 
 800       errorMessage = "Literal expression expected in variable initializer";
 
 802       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 803       errorEnd   = SimpleCharStream.getPosition() + 1;
 
 808   if (initializer == null) {
 
 809     return new VariableDeclaration(currentSegment,
 
 810                                   varName.toCharArray(),
 
 812                                   SimpleCharStream.getPosition());
 
 814     return new VariableDeclaration(currentSegment,
 
 815                                     varName.toCharArray(),
 
 823  * @return the variable name (with suffix)
 
 825 String VariableDeclaratorId() :
 
 828   Expression expression = null;
 
 829   final StringBuffer buff = new StringBuffer();
 
 830   final int pos = SimpleCharStream.getPosition();
 
 831   ConstantIdentifier ex;
 
 837       {ex = new ConstantIdentifier(expr.toCharArray(),
 
 839                                    SimpleCharStream.getPosition());}
 
 840       expression = VariableSuffix(ex)
 
 843      if (expression == null) {
 
 846      return expression.toStringExpression();
 
 848   } catch (ParseException e) {
 
 849     errorMessage = "'$' expected for variable identifier";
 
 851     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 852     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 858  * Return a variablename without the $.
 
 859  * @return a variable name
 
 863   final StringBuffer buff;
 
 864   Expression expression = null;
 
 869   token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
 
 871     if (expression == null) {
 
 872       return token.image.substring(1);
 
 874     buff = new StringBuffer(token.image);
 
 876     buff.append(expression.toStringExpression());
 
 878     return buff.toString();
 
 881   <DOLLAR> expr = VariableName()
 
 886  * A Variable name (without the $)
 
 887  * @return a variable name String
 
 889 String VariableName():
 
 891   final StringBuffer buff;
 
 893   Expression expression = null;
 
 897   <LBRACE> expression = Expression() <RBRACE>
 
 898   {buff = new StringBuffer("{");
 
 899    buff.append(expression.toStringExpression());
 
 901    return buff.toString();}
 
 903   token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
 
 905     if (expression == null) {
 
 908     buff = new StringBuffer(token.image);
 
 910     buff.append(expression.toStringExpression());
 
 912     return buff.toString();
 
 915   <DOLLAR> expr = VariableName()
 
 917     buff = new StringBuffer("$");
 
 919     return buff.toString();
 
 922   token = <DOLLAR_ID> {return token.image;}
 
 925 Expression VariableInitializer() :
 
 927   final Expression expr;
 
 929   final int pos = SimpleCharStream.getPosition();
 
 935   <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
 
 936   {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
 
 938                                                         SimpleCharStream.getPosition()),
 
 942   <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
 
 943   {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
 
 945                                                         SimpleCharStream.getPosition()),
 
 949   expr = ArrayDeclarator()
 
 953   {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
 
 956 ArrayVariableDeclaration ArrayVariable() :
 
 958 Expression expr,expr2;
 
 962   [<ARRAYASSIGN> expr2 = Expression()
 
 963   {return new ArrayVariableDeclaration(expr,expr2);}
 
 965   {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
 
 968 ArrayVariableDeclaration[] ArrayInitializer() :
 
 970   ArrayVariableDeclaration expr;
 
 971   final ArrayList list = new ArrayList();
 
 974   <LPAREN> [ expr = ArrayVariable()
 
 976             ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
 
 980            [<COMMA> {list.add(null);}]
 
 983   ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
 
 989  * A Method Declaration.
 
 990  * <b>function</b> MetodDeclarator() Block()
 
 992 MethodDeclaration MethodDeclaration() :
 
 994   final MethodDeclaration functionDeclaration;
 
 996   final OutlineableWithChildren seg = currentSegment;
 
1001     functionDeclaration = MethodDeclarator()
 
1002     {outlineInfo.addVariable(new String(functionDeclaration.name));}
 
1003   } catch (ParseException e) {
 
1004     if (errorMessage != null)  throw e;
 
1005     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
 
1007     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1008     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1011   {currentSegment = functionDeclaration;}
 
1013   {functionDeclaration.statements = block.statements;
 
1014    currentSegment = seg;
 
1015    return functionDeclaration;}
 
1019  * A MethodDeclarator.
 
1020  * [&] IDENTIFIER(parameters ...).
 
1021  * @return a function description for the outline
 
1023 MethodDeclaration MethodDeclarator() :
 
1025   final Token identifier;
 
1026   Token reference = null;
 
1027   final Hashtable formalParameters;
 
1028   final int pos = SimpleCharStream.getPosition();
 
1029   char[] identifierChar = SYNTAX_ERROR_CHAR;
 
1032   [reference = <BIT_AND>]
 
1034     identifier = <IDENTIFIER>
 
1035     {identifierChar = identifier.image.toCharArray();}
 
1036   } catch (ParseException e) {
 
1037     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
 
1039     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1040     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1041     processParseException(e);
 
1043   formalParameters = FormalParameters()
 
1044   {return new MethodDeclaration(currentSegment,
 
1049                                 SimpleCharStream.getPosition());}
 
1053  * FormalParameters follows method identifier.
 
1054  * (FormalParameter())
 
1056 Hashtable FormalParameters() :
 
1058   VariableDeclaration var;
 
1059   final Hashtable parameters = new Hashtable();
 
1064   } catch (ParseException e) {
 
1065     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
 
1067     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1068     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1069     processParseException(e);
 
1071             [ var = FormalParameter()
 
1072               {parameters.put(new String(var.name),var);}
 
1074                 <COMMA> var = FormalParameter()
 
1075                 {parameters.put(new String(var.name),var);}
 
1080   } catch (ParseException e) {
 
1081     errorMessage = "')' expected";
 
1083     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1084     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1085     processParseException(e);
 
1087  {return parameters;}
 
1091  * A formal parameter.
 
1092  * $varname[=value] (,$varname[=value])
 
1094 VariableDeclaration FormalParameter() :
 
1096   final VariableDeclaration variableDeclaration;
 
1100   [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
 
1102     if (token != null) {
 
1103       variableDeclaration.setReference(true);
 
1105     return variableDeclaration;}
 
1108 ConstantIdentifier Type() :
 
1111   <STRING>             {pos = SimpleCharStream.getPosition();
 
1112                         return new ConstantIdentifier(Types.STRING,pos,pos-6);}
 
1113 | <BOOL>               {pos = SimpleCharStream.getPosition();
 
1114                         return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
 
1115 | <BOOLEAN>            {pos = SimpleCharStream.getPosition();
 
1116                         return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
 
1117 | <REAL>               {pos = SimpleCharStream.getPosition();
 
1118                         return new ConstantIdentifier(Types.REAL,pos,pos-4);}
 
1119 | <DOUBLE>             {pos = SimpleCharStream.getPosition();
 
1120                         return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
 
1121 | <FLOAT>              {pos = SimpleCharStream.getPosition();
 
1122                         return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
 
1123 | <INT>                {pos = SimpleCharStream.getPosition();
 
1124                         return new ConstantIdentifier(Types.INT,pos,pos-3);}
 
1125 | <INTEGER>            {pos = SimpleCharStream.getPosition();
 
1126                         return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
 
1127 | <OBJECT>             {pos = SimpleCharStream.getPosition();
 
1128                         return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
 
1131 Expression Expression() :
 
1133   final Expression expr;
 
1134   Token bangToken = null;
 
1135   final int pos = SimpleCharStream.getPosition();
 
1138   <BANG> expr = Expression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
 
1139 | expr = ExpressionNoBang() {return expr;}
 
1142 Expression ExpressionNoBang() :
 
1144   final Expression expr;
 
1147   expr = PrintExpression()       {return expr;}
 
1148 | expr = ListExpression()        {return expr;}
 
1149 | LOOKAHEAD(varAssignation())
 
1150   expr = varAssignation()        {return expr;}
 
1151 | expr = ConditionalExpression() {return expr;}
 
1155  * A Variable assignation.
 
1156  * varName (an assign operator) any expression
 
1158 VarAssignation varAssignation() :
 
1161   final Expression initializer;
 
1162   final int assignOperator;
 
1163   final int pos = SimpleCharStream.getPosition();
 
1166   varName = VariableDeclaratorId()
 
1167   assignOperator = AssignmentOperator()
 
1169       initializer = Expression()
 
1170     } catch (ParseException e) {
 
1171       if (errorMessage != null) {
 
1174       errorMessage = "expression expected";
 
1176       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1177       errorEnd   = SimpleCharStream.getPosition() + 1;
 
1180     {return new VarAssignation(varName.toCharArray(),
 
1184                                SimpleCharStream.getPosition());}
 
1187 int AssignmentOperator() :
 
1190   <ASSIGN>             {return VarAssignation.EQUAL;}
 
1191 | <STARASSIGN>         {return VarAssignation.STAR_EQUAL;}
 
1192 | <SLASHASSIGN>        {return VarAssignation.SLASH_EQUAL;}
 
1193 | <REMASSIGN>          {return VarAssignation.REM_EQUAL;}
 
1194 | <PLUSASSIGN>         {return VarAssignation.PLUS_EQUAL;}
 
1195 | <MINUSASSIGN>        {return VarAssignation.MINUS_EQUAL;}
 
1196 | <LSHIFTASSIGN>       {return VarAssignation.LSHIFT_EQUAL;}
 
1197 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
 
1198 | <ANDASSIGN>          {return VarAssignation.AND_EQUAL;}
 
1199 | <XORASSIGN>          {return VarAssignation.XOR_EQUAL;}
 
1200 | <ORASSIGN>           {return VarAssignation.OR_EQUAL;}
 
1201 | <DOTASSIGN>          {return VarAssignation.DOT_EQUAL;}
 
1202 | <TILDEEQUAL>         {return VarAssignation.TILDE_EQUAL;}
 
1205 Expression ConditionalExpression() :
 
1207   final Expression expr;
 
1208   Expression expr2 = null;
 
1209   Expression expr3 = null;
 
1212   expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
 
1214   if (expr3 == null) {
 
1217   return new ConditionalExpression(expr,expr2,expr3);
 
1221 Expression ConditionalOrExpression() :
 
1223   Expression expr,expr2;
 
1227   expr = ConditionalAndExpression()
 
1230         <OR_OR> {operator = OperatorIds.OR_OR;}
 
1231       | <_ORL>  {operator = OperatorIds.ORL;}
 
1232     ) expr2 = ConditionalAndExpression()
 
1234       expr = new BinaryExpression(expr,expr2,operator);
 
1240 Expression ConditionalAndExpression() :
 
1242   Expression expr,expr2;
 
1246   expr = ConcatExpression()
 
1248   (  <AND_AND> {operator = OperatorIds.AND_AND;}
 
1249    | <_ANDL>   {operator = OperatorIds.ANDL;})
 
1250    expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
 
1255 Expression ConcatExpression() :
 
1257   Expression expr,expr2;
 
1260   expr = InclusiveOrExpression()
 
1262     <DOT> expr2 = InclusiveOrExpression()
 
1263     {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
 
1268 Expression InclusiveOrExpression() :
 
1270   Expression expr,expr2;
 
1273   expr = ExclusiveOrExpression()
 
1274   (<BIT_OR> expr2 = ExclusiveOrExpression()
 
1275    {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
 
1280 Expression ExclusiveOrExpression() :
 
1282   Expression expr,expr2;
 
1285   expr = AndExpression()
 
1287     <XOR> expr2 = AndExpression()
 
1288     {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
 
1293 Expression AndExpression() :
 
1295   Expression expr,expr2;
 
1298   expr = EqualityExpression()
 
1300     <BIT_AND> expr2 = EqualityExpression()
 
1301     {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
 
1306 Expression EqualityExpression() :
 
1308   Expression expr,expr2;
 
1312   expr = RelationalExpression()
 
1314   (   <EQUAL_EQUAL>      {operator = OperatorIds.EQUAL_EQUAL;}
 
1315     | <DIF>              {operator = OperatorIds.DIF;}
 
1316     | <NOT_EQUAL>        {operator = OperatorIds.DIF;}
 
1317     | <BANGDOUBLEEQUAL>  {operator = OperatorIds.BANG_EQUAL_EQUAL;}
 
1318     | <TRIPLEEQUAL>      {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
 
1321     expr2 = RelationalExpression()
 
1322   } catch (ParseException e) {
 
1323     if (errorMessage != null) {
 
1326     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
1328     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1329     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1333     expr = new BinaryExpression(expr,expr2,operator);
 
1339 Expression RelationalExpression() :
 
1341   Expression expr,expr2;
 
1345   expr = ShiftExpression()
 
1347   ( <LT> {operator = OperatorIds.LESS;}
 
1348   | <GT> {operator = OperatorIds.GREATER;}
 
1349   | <LE> {operator = OperatorIds.LESS_EQUAL;}
 
1350   | <GE> {operator = OperatorIds.GREATER_EQUAL;})
 
1351    expr2 = ShiftExpression()
 
1352   {expr = new BinaryExpression(expr,expr2,operator);}
 
1357 Expression ShiftExpression() :
 
1359   Expression expr,expr2;
 
1363   expr = AdditiveExpression()
 
1365   ( <LSHIFT>         {operator = OperatorIds.LEFT_SHIFT;}
 
1366   | <RSIGNEDSHIFT>   {operator = OperatorIds.RIGHT_SHIFT;}
 
1367   | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
 
1368   expr2 = AdditiveExpression()
 
1369   {expr = new BinaryExpression(expr,expr2,operator);}
 
1374 Expression AdditiveExpression() :
 
1376   Expression expr,expr2;
 
1380   expr = MultiplicativeExpression()
 
1382    ( <PLUS>  {operator = OperatorIds.PLUS;}
 
1383    | <MINUS> {operator = OperatorIds.MINUS;} )
 
1384    expr2 = MultiplicativeExpression()
 
1385   {expr = new BinaryExpression(expr,expr2,operator);}
 
1390 Expression MultiplicativeExpression() :
 
1392   Expression expr,expr2;
 
1397     expr = UnaryExpression()
 
1398   } catch (ParseException e) {
 
1399     if (errorMessage != null) throw e;
 
1400     errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
 
1402     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1403     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1407    (  <STAR>      {operator = OperatorIds.MULTIPLY;}
 
1408     | <SLASH>     {operator = OperatorIds.DIVIDE;}
 
1409     | <REMAINDER> {operator = OperatorIds.REMAINDER;})
 
1410     expr2 = UnaryExpression()
 
1411     {expr = new BinaryExpression(expr,expr2,operator);}
 
1417  * An unary expression starting with @, & or nothing
 
1419 Expression UnaryExpression() :
 
1422   final int pos = SimpleCharStream.getPosition();
 
1425   <BIT_AND> expr = UnaryExpressionNoPrefix()
 
1426   {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
 
1428   expr = AtUnaryExpression() {return expr;}
 
1431 Expression AtUnaryExpression() :
 
1434   final int pos = SimpleCharStream.getPosition();
 
1438   expr = AtUnaryExpression()
 
1439   {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
 
1441   expr = UnaryExpressionNoPrefix()
 
1446 Expression UnaryExpressionNoPrefix() :
 
1450   final int pos = SimpleCharStream.getPosition();
 
1453   (  <PLUS>  {operator = OperatorIds.PLUS;}
 
1454    | <MINUS> {operator = OperatorIds.MINUS;})
 
1455    expr = UnaryExpression()
 
1456   {return new PrefixedUnaryExpression(expr,operator,pos);}
 
1458   expr = PreIncDecExpression()
 
1461   expr = UnaryExpressionNotPlusMinus()
 
1466 Expression PreIncDecExpression() :
 
1468 final Expression expr;
 
1470   final int pos = SimpleCharStream.getPosition();
 
1473   (  <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
 
1474    | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
 
1475    expr = PrimaryExpression()
 
1476   {return new PrefixedUnaryExpression(expr,operator,pos);}
 
1479 Expression UnaryExpressionNotPlusMinus() :
 
1482   final int pos = SimpleCharStream.getPosition();
 
1485 //  <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
 
1486   LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
 
1487   expr = CastExpression()         {return expr;}
 
1488 | expr = PostfixExpression()      {return expr;}
 
1489 | expr = Literal()                {return expr;}
 
1490 | <LPAREN> expr = Expression()
 
1493   } catch (ParseException e) {
 
1494     errorMessage = "')' expected";
 
1496     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1497     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1503 CastExpression CastExpression() :
 
1505 final ConstantIdentifier type;
 
1506 final Expression expr;
 
1507 final int pos = SimpleCharStream.getPosition();
 
1512   | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
 
1513   <RPAREN> expr = UnaryExpression()
 
1514   {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
 
1517 Expression PostfixExpression() :
 
1521   final int pos = SimpleCharStream.getPosition();
 
1524   expr = PrimaryExpression()
 
1525   [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
 
1526   | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
 
1528     if (operator == -1) {
 
1531     return new PostfixedUnaryExpression(expr,operator,pos);
 
1535 Expression PrimaryExpression() :
 
1537   final Token identifier;
 
1539   final int pos = SimpleCharStream.getPosition();
 
1543   identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
 
1544   {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
 
1546                                                  SimpleCharStream.getPosition()),
 
1548                           ClassAccess.STATIC);}
 
1550   LOOKAHEAD(PrimarySuffix())
 
1551   expr = PrimarySuffix(expr))*
 
1554   expr = PrimaryPrefix()
 
1556   LOOKAHEAD(PrimarySuffix())
 
1557   expr = PrimarySuffix(expr))*
 
1560   expr = ArrayDeclarator()
 
1565  * An array declarator.
 
1569 ArrayInitializer ArrayDeclarator() :
 
1571   final ArrayVariableDeclaration[] vars;
 
1572   final int pos = SimpleCharStream.getPosition();
 
1575   <ARRAY> vars = ArrayInitializer()
 
1576   {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
 
1579 Expression PrimaryPrefix() :
 
1581   final Expression expr;
 
1584   final int pos = SimpleCharStream.getPosition();
 
1587   token = <IDENTIFIER>           {return new ConstantIdentifier(token.image.toCharArray(),
 
1589                                                                 SimpleCharStream.getPosition());}
 
1590 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
 
1593 | var = VariableDeclaratorId()  {return new VariableDeclaration(currentSegment,
 
1596                                                                 SimpleCharStream.getPosition());}
 
1599 PrefixedUnaryExpression classInstantiation() :
 
1602   final StringBuffer buff;
 
1603   final int pos = SimpleCharStream.getPosition();
 
1606   <NEW> expr = ClassIdentifier()
 
1608     {buff = new StringBuffer(expr.toStringExpression());}
 
1609     expr = PrimaryExpression()
 
1610     {buff.append(expr.toStringExpression());
 
1611     expr = new ConstantIdentifier(buff.toString().toCharArray(),
 
1613                                   SimpleCharStream.getPosition());}
 
1615   {return new PrefixedUnaryExpression(expr,
 
1620 ConstantIdentifier ClassIdentifier():
 
1624   final int pos = SimpleCharStream.getPosition();
 
1627   token = <IDENTIFIER>          {return new ConstantIdentifier(token.image.toCharArray(),
 
1629                                                                SimpleCharStream.getPosition());}
 
1630 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
 
1632                                                                SimpleCharStream.getPosition());}
 
1635 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
 
1637   final AbstractSuffixExpression expr;
 
1640   expr = Arguments(prefix)      {return expr;}
 
1641 | expr = VariableSuffix(prefix) {return expr;}
 
1644 AbstractSuffixExpression VariableSuffix(Expression prefix) :
 
1647   final int pos = SimpleCharStream.getPosition();
 
1648   Expression expression = null;
 
1653     expr = VariableName()
 
1654   } catch (ParseException e) {
 
1655     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
 
1657     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1658     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1661   {return new ClassAccess(prefix,
 
1662                           new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
 
1663                           ClassAccess.NORMAL);}
 
1665   <LBRACKET> [ expression = Expression() | expression = Type() ]  //Not good
 
1668   } catch (ParseException e) {
 
1669     errorMessage = "']' expected";
 
1671     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1672     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1675   {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
 
1684   token = <INTEGER_LITERAL>        {pos = SimpleCharStream.getPosition();
 
1685                                     return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
 
1686 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
 
1687                                     return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
 
1688 | token = <STRING_LITERAL>         {pos = SimpleCharStream.getPosition();
 
1689                                     return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
 
1690 | <TRUE>                           {pos = SimpleCharStream.getPosition();
 
1691                                     return new TrueLiteral(pos-4,pos);}
 
1692 | <FALSE>                          {pos = SimpleCharStream.getPosition();
 
1693                                     return new FalseLiteral(pos-4,pos);}
 
1694 | <NULL>                           {pos = SimpleCharStream.getPosition();
 
1695                                     return new NullLiteral(pos-4,pos);}
 
1698 FunctionCall Arguments(Expression func) :
 
1700 Expression[] args = null;
 
1703   <LPAREN> [ args = ArgumentList() ]
 
1706   } catch (ParseException e) {
 
1707     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
 
1709     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1710     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1713   {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
 
1717  * An argument list is a list of arguments separated by comma :
 
1718  * argumentDeclaration() (, argumentDeclaration)*
 
1719  * @return an array of arguments
 
1721 Expression[] ArgumentList() :
 
1724 final ArrayList list = new ArrayList();
 
1733       } catch (ParseException e) {
 
1734         errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
 
1736         errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1737         errorEnd     = SimpleCharStream.getPosition() + 1;
 
1742    Expression[] arguments = new Expression[list.size()];
 
1743    list.toArray(arguments);
 
1748  * A Statement without break.
 
1750 Statement StatementNoBreak() :
 
1752   final Statement statement;
 
1757   statement = Expression()
 
1760   } catch (ParseException e) {
 
1761     if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
 
1762       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1764       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1765       errorEnd   = SimpleCharStream.getPosition() + 1;
 
1771   statement = LabeledStatement() {return statement;}
 
1772 | statement = Block()            {return statement;}
 
1773 | statement = EmptyStatement()   {return statement;}
 
1774 | statement = StatementExpression()
 
1777   } catch (ParseException e) {
 
1778     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1780     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1781     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1785 | statement = SwitchStatement()         {return statement;}
 
1786 | statement = IfStatement()             {return statement;}
 
1787 | statement = WhileStatement()          {return statement;}
 
1788 | statement = DoStatement()             {return statement;}
 
1789 | statement = ForStatement()            {return statement;}
 
1790 | statement = ForeachStatement()        {return statement;}
 
1791 | statement = ContinueStatement()       {return statement;}
 
1792 | statement = ReturnStatement()         {return statement;}
 
1793 | statement = EchoStatement()           {return statement;}
 
1794 | [token=<AT>] statement = IncludeStatement()
 
1795   {if (token != null) {
 
1796     ((InclusionStatement)statement).silent = true;
 
1799 | statement = StaticStatement()         {return statement;}
 
1800 | statement = GlobalStatement()         {return statement;}
 
1801 | statement = defineStatement()         {currentSegment.add((Outlineable)statement);return statement;}
 
1804 Define defineStatement() :
 
1806   final int start = SimpleCharStream.getPosition();
 
1807   Expression defineName,defineValue;
 
1813   } catch (ParseException e) {
 
1814     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
 
1816     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1817     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1818     processParseException(e);
 
1821     defineName = Expression()
 
1822   } catch (ParseException e) {
 
1823     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
1825     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1826     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1831   } catch (ParseException e) {
 
1832     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
 
1834     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1835     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1836     processParseException(e);
 
1839     (   defineValue = PrintExpression()
 
1840       | LOOKAHEAD(varAssignation())
 
1841         defineValue = varAssignation()
 
1842       | defineValue = ConditionalExpression())
 
1843   } catch (ParseException e) {
 
1844     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
1846     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1847     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1852   } catch (ParseException e) {
 
1853     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
 
1855     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1856     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1857     processParseException(e);
 
1859   {return new Define(currentSegment,
 
1863                      SimpleCharStream.getPosition());}
 
1867  * A Normal statement.
 
1869 Statement Statement() :
 
1871   final Statement statement;
 
1874   statement = StatementNoBreak() {return statement;}
 
1875 | statement = BreakStatement()   {return statement;}
 
1879  * An html block inside a php syntax.
 
1881 HTMLBlock htmlBlock() :
 
1883   final int startIndex = nodePtr;
 
1884   AstNode[] blockNodes;
 
1888   <PHPEND> (phpEchoBlock())*
 
1890     (<PHPSTARTLONG> | <PHPSTARTSHORT>)
 
1891   } catch (ParseException e) {
 
1892     errorMessage = "unexpected end of file , '<?php' expected";
 
1894     errorStart   = SimpleCharStream.getPosition();
 
1895     errorEnd     = SimpleCharStream.getPosition();
 
1899   nbNodes    = nodePtr - startIndex;
 
1900   blockNodes = new AstNode[nbNodes];
 
1901   System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
 
1902   nodePtr = startIndex;
 
1903   return new HTMLBlock(blockNodes);}
 
1907  * An include statement. It's "include" an expression;
 
1909 InclusionStatement IncludeStatement() :
 
1911   final Expression expr;
 
1913   final int pos = SimpleCharStream.getPosition();
 
1914   final InclusionStatement inclusionStatement;
 
1917       (  <REQUIRE>      {keyword = InclusionStatement.REQUIRE;}
 
1918        | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
 
1919        | <INCLUDE>      {keyword = InclusionStatement.INCLUDE;}
 
1920        | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
 
1923   } catch (ParseException e) {
 
1924     if (errorMessage != null) {
 
1927     errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
 
1929     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1930     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1933   {inclusionStatement = new InclusionStatement(currentSegment,
 
1937    currentSegment.add(inclusionStatement);
 
1941   } catch (ParseException e) {
 
1942     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
1944     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1945     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1948   {return inclusionStatement;}
 
1951 PrintExpression PrintExpression() :
 
1953   final Expression expr;
 
1954   final int pos = SimpleCharStream.getPosition();
 
1957   <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
 
1960 ListExpression ListExpression() :
 
1963   Expression expression = null;
 
1964   ArrayList list = new ArrayList();
 
1965   final int pos = SimpleCharStream.getPosition();
 
1971   } catch (ParseException e) {
 
1972     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
 
1974     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1975     errorEnd     = SimpleCharStream.getPosition() + 1;
 
1979     expr = VariableDeclaratorId()
 
1982   {if (expr == null) list.add(null);}
 
1986     } catch (ParseException e) {
 
1987       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
 
1989       errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1990       errorEnd     = SimpleCharStream.getPosition() + 1;
 
1993     expr = VariableDeclaratorId()
 
1998   } catch (ParseException e) {
 
1999     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
 
2001     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2002     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2005   [ <ASSIGN> expression = Expression()
 
2007     String[] strings = new String[list.size()];
 
2008     list.toArray(strings);
 
2009     return new ListExpression(strings,
 
2012                               SimpleCharStream.getPosition());}
 
2015     String[] strings = new String[list.size()];
 
2016     list.toArray(strings);
 
2017     return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
 
2021  * An echo statement.
 
2022  * echo anyexpression (, otherexpression)*
 
2024 EchoStatement EchoStatement() :
 
2026   final ArrayList expressions = new ArrayList();
 
2028   final int pos = SimpleCharStream.getPosition();
 
2031   <ECHO> expr = Expression()
 
2032   {expressions.add(expr);}
 
2034     <COMMA> expr = Expression()
 
2035     {expressions.add(expr);}
 
2039   } catch (ParseException e) {
 
2040     if (e.currentToken.next.kind != 4) {
 
2041       errorMessage = "';' expected after 'echo' statement";
 
2043       errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2044       errorEnd     = SimpleCharStream.getPosition() + 1;
 
2048   {Expression[] exprs = new Expression[expressions.size()];
 
2049    expressions.toArray(exprs);
 
2050    return new EchoStatement(exprs,pos);}
 
2053 GlobalStatement GlobalStatement() :
 
2055    final int pos = SimpleCharStream.getPosition();
 
2057    ArrayList vars = new ArrayList();
 
2058    GlobalStatement global;
 
2062     expr = VariableDeclaratorId()
 
2065     expr = VariableDeclaratorId()
 
2071     String[] strings = new String[vars.size()];
 
2072     vars.toArray(strings);
 
2073     global = new GlobalStatement(currentSegment,
 
2076                                  SimpleCharStream.getPosition());
 
2077     currentSegment.add(global);
 
2079   } catch (ParseException e) {
 
2080     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
 
2082     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2083     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2088 StaticStatement StaticStatement() :
 
2090   final int pos = SimpleCharStream.getPosition();
 
2091   final ArrayList vars = new ArrayList();
 
2092   VariableDeclaration expr;
 
2095   <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
 
2096   (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
 
2100     String[] strings = new String[vars.size()];
 
2101     vars.toArray(strings);
 
2102     return new StaticStatement(strings,
 
2104                                 SimpleCharStream.getPosition());}
 
2105   } catch (ParseException e) {
 
2106     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
 
2108     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2109     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2114 LabeledStatement LabeledStatement() :
 
2116   final int pos = SimpleCharStream.getPosition();
 
2118   final Statement statement;
 
2121   label = <IDENTIFIER> <COLON> statement = Statement()
 
2122   {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
 
2134   final int pos = SimpleCharStream.getPosition();
 
2135   final ArrayList list = new ArrayList();
 
2136   Statement statement;
 
2141   } catch (ParseException e) {
 
2142     errorMessage = "'{' expected";
 
2144     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2145     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2148   ( statement = BlockStatement() {list.add(statement);}
 
2149   | statement = htmlBlock()      {list.add(statement);})*
 
2152   } catch (ParseException e) {
 
2153     errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
 
2155     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2156     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2160   Statement[] statements = new Statement[list.size()];
 
2161   list.toArray(statements);
 
2162   return new Block(statements,pos,SimpleCharStream.getPosition());}
 
2165 Statement BlockStatement() :
 
2167   final Statement statement;
 
2171   statement = Statement()         {if (phpDocument == currentSegment) pushOnAstNodes(statement);
 
2173   } catch (ParseException e) {
 
2174     if (errorMessage != null) throw e;
 
2175     errorMessage = "statement expected";
 
2177     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2178     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2181 | statement = ClassDeclaration()  {return statement;}
 
2182 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
 
2183                                    currentSegment.add((MethodDeclaration) statement);
 
2188  * A Block statement that will not contain any 'break'
 
2190 Statement BlockStatementNoBreak() :
 
2192   final Statement statement;
 
2195   statement = StatementNoBreak()  {return statement;}
 
2196 | statement = ClassDeclaration()  {return statement;}
 
2197 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
 
2201 VariableDeclaration[] LocalVariableDeclaration() :
 
2203   final ArrayList list = new ArrayList();
 
2204   VariableDeclaration var;
 
2207   var = LocalVariableDeclarator()
 
2209   ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
 
2211     VariableDeclaration[] vars = new VariableDeclaration[list.size()];
 
2216 VariableDeclaration LocalVariableDeclarator() :
 
2218   final String varName;
 
2219   Expression initializer = null;
 
2220   final int pos = SimpleCharStream.getPosition();
 
2223   varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
 
2225    if (initializer == null) {
 
2226     return new VariableDeclaration(currentSegment,
 
2227                                   varName.toCharArray(),
 
2229                                   SimpleCharStream.getPosition());
 
2231     return new VariableDeclaration(currentSegment,
 
2232                                     varName.toCharArray(),
 
2238 EmptyStatement EmptyStatement() :
 
2244   {pos = SimpleCharStream.getPosition();
 
2245    return new EmptyStatement(pos-1,pos);}
 
2248 Expression StatementExpression() :
 
2250   Expression expr,expr2;
 
2254   expr = PreIncDecExpression() {return expr;}
 
2256   expr = PrimaryExpression()
 
2257   [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
 
2258                                                 OperatorIds.PLUS_PLUS,
 
2259                                                 SimpleCharStream.getPosition());}
 
2260   | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
 
2261                                                 OperatorIds.MINUS_MINUS,
 
2262                                                 SimpleCharStream.getPosition());}
 
2263   | operator = AssignmentOperator() expr2 = Expression()
 
2264     {return new BinaryExpression(expr,expr2,operator);}
 
2269 SwitchStatement SwitchStatement() :
 
2271   final Expression variable;
 
2272   final AbstractCase[] cases;
 
2273   final int pos = SimpleCharStream.getPosition();
 
2279   } catch (ParseException e) {
 
2280     errorMessage = "'(' expected after 'switch'";
 
2282     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2283     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2287     variable = Expression()
 
2288   } catch (ParseException e) {
 
2289     if (errorMessage != null) {
 
2292     errorMessage = "expression expected";
 
2294     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2295     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2300   } catch (ParseException e) {
 
2301     errorMessage = "')' expected";
 
2303     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2304     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2307   (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
 
2308   {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
 
2311 AbstractCase[] switchStatementBrace() :
 
2314   final ArrayList cases = new ArrayList();
 
2318  ( cas = switchLabel0() {cases.add(cas);})*
 
2322     AbstractCase[] abcase = new AbstractCase[cases.size()];
 
2323     cases.toArray(abcase);
 
2325   } catch (ParseException e) {
 
2326     errorMessage = "'}' expected";
 
2328     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2329     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2334  * A Switch statement with : ... endswitch;
 
2335  * @param start the begin offset of the switch
 
2336  * @param end the end offset of the switch
 
2338 AbstractCase[] switchStatementColon(final int start, final int end) :
 
2341   final ArrayList cases = new ArrayList();
 
2346   setMarker(fileToParse,
 
2347             "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
 
2351             "Line " + token.beginLine);
 
2352   } catch (CoreException e) {
 
2353     PHPeclipsePlugin.log(e);
 
2355   ( cas = switchLabel0() {cases.add(cas);})*
 
2358   } catch (ParseException e) {
 
2359     errorMessage = "'endswitch' expected";
 
2361     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2362     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2368     AbstractCase[] abcase = new AbstractCase[cases.size()];
 
2369     cases.toArray(abcase);
 
2371   } catch (ParseException e) {
 
2372     errorMessage = "';' expected after 'endswitch' keyword";
 
2374     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2375     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2380 AbstractCase switchLabel0() :
 
2382   final Expression expr;
 
2383   Statement statement;
 
2384   final ArrayList stmts = new ArrayList();
 
2385   final int pos = SimpleCharStream.getPosition();
 
2388   expr = SwitchLabel()
 
2389   ( statement = BlockStatementNoBreak() {stmts.add(statement);}
 
2390   | statement = htmlBlock()             {stmts.add(statement);})*
 
2391   [ statement = BreakStatement()        {stmts.add(statement);}]
 
2393   Statement[] stmtsArray = new Statement[stmts.size()];
 
2394   stmts.toArray(stmtsArray);
 
2395   if (expr == null) {//it's a default
 
2396     return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
 
2398   return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
 
2403  * case Expression() :
 
2405  * @return the if it was a case and null if not
 
2407 Expression SwitchLabel() :
 
2409   final Expression expr;
 
2415   } catch (ParseException e) {
 
2416     if (errorMessage != null) throw e;
 
2417     errorMessage = "expression expected after 'case' keyword";
 
2419     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2420     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2426   } catch (ParseException e) {
 
2427     errorMessage = "':' expected after case expression";
 
2429     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2430     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2438   } catch (ParseException e) {
 
2439     errorMessage = "':' expected after 'default' keyword";
 
2441     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2442     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2447 Break BreakStatement() :
 
2449   Expression expression = null;
 
2450   final int start = SimpleCharStream.getPosition();
 
2453   <BREAK> [ expression = Expression() ]
 
2456   } catch (ParseException e) {
 
2457     errorMessage = "';' expected after 'break' keyword";
 
2459     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2460     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2463   {return new Break(expression, start, SimpleCharStream.getPosition());}
 
2466 IfStatement IfStatement() :
 
2468   final int pos = SimpleCharStream.getPosition();
 
2469   Expression condition;
 
2470   IfStatement ifStatement;
 
2473   <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
 
2474   {return ifStatement;}
 
2478 Expression Condition(final String keyword) :
 
2480   final Expression condition;
 
2485   } catch (ParseException e) {
 
2486     errorMessage = "'(' expected after " + keyword + " keyword";
 
2488     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
 
2489     errorEnd   = errorStart +1;
 
2490     processParseException(e);
 
2492   condition = Expression()
 
2495   } catch (ParseException e) {
 
2496     errorMessage = "')' expected after " + keyword + " keyword";
 
2498     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2499     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2500     processParseException(e);
 
2505 IfStatement IfStatement0(Expression condition, final int start,final int end) :
 
2507   Statement statement;
 
2509   final Statement[] statementsArray;
 
2510   ElseIf elseifStatement;
 
2511   Else elseStatement = null;
 
2513   final ArrayList elseIfList = new ArrayList();
 
2515   int pos = SimpleCharStream.getPosition();
 
2520   {stmts = new ArrayList();}
 
2521   (  statement = Statement() {stmts.add(statement);}
 
2522    | statement = htmlBlock() {stmts.add(statement);})*
 
2523    {endStatements = SimpleCharStream.getPosition();}
 
2524    (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
 
2525    [elseStatement = ElseStatementColon()]
 
2528   setMarker(fileToParse,
 
2529             "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
 
2533             "Line " + token.beginLine);
 
2534   } catch (CoreException e) {
 
2535     PHPeclipsePlugin.log(e);
 
2539   } catch (ParseException e) {
 
2540     errorMessage = "'endif' expected";
 
2542     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2543     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2548   } catch (ParseException e) {
 
2549     errorMessage = "';' expected after 'endif' keyword";
 
2551     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2552     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2556     elseIfs = new ElseIf[elseIfList.size()];
 
2557     elseIfList.toArray(elseIfs);
 
2558     if (stmts.size() == 1) {
 
2559       return new IfStatement(condition,
 
2560                              (Statement) stmts.get(0),
 
2564                               SimpleCharStream.getPosition());
 
2566       statementsArray = new Statement[stmts.size()];
 
2567       stmts.toArray(statementsArray);
 
2568       return new IfStatement(condition,
 
2569                              new Block(statementsArray,pos,endStatements),
 
2573                              SimpleCharStream.getPosition());
 
2578   (stmt = Statement() | stmt = htmlBlock())
 
2579   ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
 
2583       {pos = SimpleCharStream.getPosition();}
 
2584       statement = Statement()
 
2585       {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
 
2586     } catch (ParseException e) {
 
2587       if (errorMessage != null) {
 
2590       errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
 
2592       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2593       errorEnd   = SimpleCharStream.getPosition() + 1;
 
2598     elseIfs = new ElseIf[elseIfList.size()];
 
2599     elseIfList.toArray(elseIfs);
 
2600     return new IfStatement(condition,
 
2605                            SimpleCharStream.getPosition());}
 
2608 ElseIf ElseIfStatementColon() :
 
2610   Expression condition;
 
2611   Statement statement;
 
2612   final ArrayList list = new ArrayList();
 
2613   final int pos = SimpleCharStream.getPosition();
 
2616   <ELSEIF> condition = Condition("elseif")
 
2617   <COLON> (  statement = Statement() {list.add(statement);}
 
2618            | statement = htmlBlock() {list.add(statement);})*
 
2620   Statement[] stmtsArray = new Statement[list.size()];
 
2621   list.toArray(stmtsArray);
 
2622   return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
 
2625 Else ElseStatementColon() :
 
2627   Statement statement;
 
2628   final ArrayList list = new ArrayList();
 
2629   final int pos = SimpleCharStream.getPosition();
 
2632   <ELSE> <COLON> (  statement = Statement() {list.add(statement);}
 
2633                   | statement = htmlBlock() {list.add(statement);})*
 
2635   Statement[] stmtsArray = new Statement[list.size()];
 
2636   list.toArray(stmtsArray);
 
2637   return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
 
2640 ElseIf ElseIfStatement() :
 
2642   Expression condition;
 
2643   Statement statement;
 
2644   final ArrayList list = new ArrayList();
 
2645   final int pos = SimpleCharStream.getPosition();
 
2648   <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
 
2650   Statement[] stmtsArray = new Statement[list.size()];
 
2651   list.toArray(stmtsArray);
 
2652   return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
 
2655 WhileStatement WhileStatement() :
 
2657   final Expression condition;
 
2658   final Statement action;
 
2659   final int pos = SimpleCharStream.getPosition();
 
2663     condition = Condition("while")
 
2664     action    = WhileStatement0(pos,pos + 5)
 
2665     {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
 
2668 Statement WhileStatement0(final int start, final int end) :
 
2670   Statement statement;
 
2671   final ArrayList stmts = new ArrayList();
 
2672   final int pos = SimpleCharStream.getPosition();
 
2675   <COLON> (statement = Statement() {stmts.add(statement);})*
 
2677   setMarker(fileToParse,
 
2678             "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
 
2682             "Line " + token.beginLine);
 
2683   } catch (CoreException e) {
 
2684     PHPeclipsePlugin.log(e);
 
2688   } catch (ParseException e) {
 
2689     errorMessage = "'endwhile' expected";
 
2691     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2692     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2698     Statement[] stmtsArray = new Statement[stmts.size()];
 
2699     stmts.toArray(stmtsArray);
 
2700     return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
 
2701   } catch (ParseException e) {
 
2702     errorMessage = "';' expected after 'endwhile' keyword";
 
2704     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2705     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2709   statement = Statement()
 
2713 DoStatement DoStatement() :
 
2715   final Statement action;
 
2716   final Expression condition;
 
2717   final int pos = SimpleCharStream.getPosition();
 
2720   <DO> action = Statement() <WHILE> condition = Condition("while")
 
2723     {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
 
2724   } catch (ParseException e) {
 
2725     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
2727     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2728     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2733 ForeachStatement ForeachStatement() :
 
2735   Statement statement;
 
2736   Expression expression;
 
2737   final int pos = SimpleCharStream.getPosition();
 
2738   ArrayVariableDeclaration variable;
 
2744   } catch (ParseException e) {
 
2745     errorMessage = "'(' expected after 'foreach' keyword";
 
2747     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2748     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2752     expression = Expression()
 
2753   } catch (ParseException e) {
 
2754     errorMessage = "variable expected";
 
2756     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2757     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2762   } catch (ParseException e) {
 
2763     errorMessage = "'as' expected";
 
2765     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2766     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2770     variable = ArrayVariable()
 
2771   } catch (ParseException e) {
 
2772     errorMessage = "variable expected";
 
2774     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2775     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2780   } catch (ParseException e) {
 
2781     errorMessage = "')' expected after 'foreach' keyword";
 
2783     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2784     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2788     statement = Statement()
 
2789   } catch (ParseException e) {
 
2790     if (errorMessage != null) throw e;
 
2791     errorMessage = "statement expected";
 
2793     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2794     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2797   {return new ForeachStatement(expression,
 
2801                                SimpleCharStream.getPosition());}
 
2805 ForStatement ForStatement() :
 
2808 final int pos = SimpleCharStream.getPosition();
 
2809 Expression[] initializations = null;
 
2810 Expression condition = null;
 
2811 Expression[] increments = null;
 
2813 final ArrayList list = new ArrayList();
 
2814 final int startBlock, endBlock;
 
2820   } catch (ParseException e) {
 
2821     errorMessage = "'(' expected after 'for' keyword";
 
2823     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2824     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2827      [ initializations = ForInit() ] <SEMICOLON>
 
2828      [ condition = Expression() ] <SEMICOLON>
 
2829      [ increments = StatementExpressionList() ] <RPAREN>
 
2831       action = Statement()
 
2832       {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
 
2835       {startBlock = SimpleCharStream.getPosition();}
 
2836       (action = Statement() {list.add(action);})*
 
2839         setMarker(fileToParse,
 
2840                   "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
 
2842                   pos+token.image.length(),
 
2844                   "Line " + token.beginLine);
 
2845         } catch (CoreException e) {
 
2846           PHPeclipsePlugin.log(e);
 
2849       {endBlock = SimpleCharStream.getPosition();}
 
2852       } catch (ParseException e) {
 
2853         errorMessage = "'endfor' expected";
 
2855         errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2856         errorEnd   = SimpleCharStream.getPosition() + 1;
 
2862         Statement[] stmtsArray = new Statement[list.size()];
 
2863         list.toArray(stmtsArray);
 
2864         return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
 
2865       } catch (ParseException e) {
 
2866         errorMessage = "';' expected after 'endfor' keyword";
 
2868         errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2869         errorEnd   = SimpleCharStream.getPosition() + 1;
 
2875 Expression[] ForInit() :
 
2880   LOOKAHEAD(LocalVariableDeclaration())
 
2881   exprs = LocalVariableDeclaration()
 
2884   exprs = StatementExpressionList()
 
2888 Expression[] StatementExpressionList() :
 
2890   final ArrayList list = new ArrayList();
 
2894   expr = StatementExpression()   {list.add(expr);}
 
2895   (<COMMA> StatementExpression() {list.add(expr);})*
 
2897   Expression[] exprsArray = new Expression[list.size()];
 
2898   list.toArray(exprsArray);
 
2902 Continue ContinueStatement() :
 
2904   Expression expr = null;
 
2905   final int pos = SimpleCharStream.getPosition();
 
2908   <CONTINUE> [ expr = Expression() ]
 
2911     {return new Continue(expr,pos,SimpleCharStream.getPosition());}
 
2912   } catch (ParseException e) {
 
2913     errorMessage = "';' expected after 'continue' statement";
 
2915     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2916     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2921 ReturnStatement ReturnStatement() :
 
2923   Expression expr = null;
 
2924   final int pos = SimpleCharStream.getPosition();
 
2927   <RETURN> [ expr = Expression() ]
 
2930     {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
 
2931   } catch (ParseException e) {
 
2932     errorMessage = "';' expected after 'return' statement";
 
2934     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2935     errorEnd   = SimpleCharStream.getPosition() + 1;