4   CHOICE_AMBIGUITY_CHECK = 2;
 
   5   OTHER_AMBIGUITY_CHECK = 1;
 
   8   DEBUG_LOOKAHEAD = false;
 
   9   DEBUG_TOKEN_MANAGER = false;
 
  10   OPTIMIZE_TOKEN_MANAGER = false;
 
  11   ERROR_REPORTING = true;
 
  12   JAVA_UNICODE_ESCAPE = false;
 
  13   UNICODE_INPUT = false;
 
  15   USER_TOKEN_MANAGER = false;
 
  16   USER_CHAR_STREAM = false;
 
  18   BUILD_TOKEN_MANAGER = true;
 
  20   FORCE_LA_CHECK = false;
 
  21   COMMON_TOKEN_ACTION = true;
 
  24 PARSER_BEGIN(PHPParser)
 
  27 import org.eclipse.core.resources.IFile;
 
  28 import org.eclipse.core.resources.IMarker;
 
  29 import org.eclipse.core.runtime.CoreException;
 
  30 import org.eclipse.ui.texteditor.MarkerUtilities;
 
  31 import org.eclipse.jface.preference.IPreferenceStore;
 
  33 import java.util.Hashtable;
 
  34 import java.util.ArrayList;
 
  35 import java.io.StringReader;
 
  37 import java.text.MessageFormat;
 
  39 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
 
  40 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
  41 import net.sourceforge.phpdt.internal.compiler.ast.*;
 
  42 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
 
  43 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
 
  44 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
 
  45 import net.sourceforge.phpdt.internal.corext.Assert;
 
  49  * This php parser is inspired by the Java 1.2 grammar example
 
  50  * given with JavaCC. You can get JavaCC at http://www.webgain.com
 
  51  * You can test the parser with the PHPParserTestCase2.java
 
  52  * @author Matthieu Casanova
 
  54 public final class PHPParser extends PHPParserSuperclass {
 
  56 //todo : fix the variables names bug
 
  57 //todo : handle tilde operator
 
  60   /** The current segment. */
 
  61   private static OutlineableWithChildren currentSegment;
 
  63   private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
 
  64   private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
 
  65   static PHPOutlineInfo outlineInfo;
 
  67   /** The error level of the current ParseException. */
 
  68   private static int errorLevel = ERROR;
 
  69   /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
 
  70   private static String errorMessage;
 
  72   private static int errorStart = -1;
 
  73   private static int errorEnd = -1;
 
  74   private static PHPDocument phpDocument;
 
  76   private static final String SYNTAX_ERROR_CHAR = "syntax error";
 
  78    * The point where html starts.
 
  79    * It will be used by the token manager to create HTMLCode objects
 
  81   public static int htmlStart;
 
  84   private final static int AstStackIncrement = 100;
 
  85   /** The stack of node. */
 
  86   private static AstNode[] nodes;
 
  87   /** The cursor in expression stack. */
 
  88   private static int nodePtr;
 
  90   public static final boolean PARSER_DEBUG = false;
 
  92   public final void setFileToParse(final IFile fileToParse) {
 
  93     PHPParser.fileToParse = fileToParse;
 
  99   public PHPParser(final IFile fileToParse) {
 
 100     this(new StringReader(""));
 
 101     PHPParser.fileToParse = fileToParse;
 
 104   public static final void phpParserTester(final String strEval) throws ParseException {
 
 105     final StringReader stream = new StringReader(strEval);
 
 106     if (jj_input_stream == null) {
 
 107       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 109     ReInit(new StringReader(strEval));
 
 111     phpDocument = new PHPDocument(null,"_root".toCharArray());
 
 112     currentSegment = phpDocument;
 
 113     outlineInfo = new PHPOutlineInfo(null, currentSegment);
 
 114     PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
 
 118   public static final void htmlParserTester(final File fileName) throws FileNotFoundException, ParseException {
 
 119     final Reader stream = new FileReader(fileName);
 
 120     if (jj_input_stream == null) {
 
 121       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 125     phpDocument = new PHPDocument(null,"_root".toCharArray());
 
 126     currentSegment = phpDocument;
 
 127     outlineInfo = new PHPOutlineInfo(null, currentSegment);
 
 131   public static final void htmlParserTester(final String strEval) throws ParseException {
 
 132     final StringReader stream = new StringReader(strEval);
 
 133     if (jj_input_stream == null) {
 
 134       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 138     phpDocument = new PHPDocument(null,"_root".toCharArray());
 
 139     currentSegment = phpDocument;
 
 140     outlineInfo = new PHPOutlineInfo(null, currentSegment);
 
 145    * Reinitialize the parser.
 
 147   private static final void init() {
 
 148     nodes = new AstNode[AstStackIncrement];
 
 154    * Add an php node on the stack.
 
 155    * @param node the node that will be added to the stack
 
 157   private static final void pushOnAstNodes(final AstNode node) {
 
 159       nodes[++nodePtr] = node;
 
 160     } catch (IndexOutOfBoundsException e) {
 
 161       final int oldStackLength = nodes.length;
 
 162       final AstNode[] oldStack = nodes;
 
 163       nodes = new AstNode[oldStackLength + AstStackIncrement];
 
 164       System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
 
 165       nodePtr = oldStackLength;
 
 166       nodes[nodePtr] = node;
 
 170   public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
 
 171     phpDocument = new PHPDocument(parent,"_root".toCharArray());
 
 172     currentSegment = phpDocument;
 
 173     outlineInfo = new PHPOutlineInfo(parent, currentSegment);
 
 174     final StringReader stream = new StringReader(s);
 
 175     if (jj_input_stream == null) {
 
 176       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 182       phpDocument.nodes = new AstNode[nodes.length];
 
 183       System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
 
 184       if (PHPeclipsePlugin.DEBUG) {
 
 185         PHPeclipsePlugin.log(1,phpDocument.toString());
 
 187     } catch (ParseException e) {
 
 188       processParseException(e);
 
 194    * This function will throw the exception if we are in debug mode
 
 195    * and process it if we are in production mode.
 
 196    * this should be fast since the PARSER_DEBUG is static final so the difference will be at compile time
 
 197    * @param e the exception
 
 198    * @throws ParseException the thrown exception
 
 200   private static void processParseExceptionDebug(final ParseException e) throws ParseException {
 
 204     processParseException(e);
 
 207    * This method will process the parse exception.
 
 208    * If the error message is null, the parse exception wasn't catched and a trace is written in the log
 
 209    * @param e the ParseException
 
 211   private static void processParseException(final ParseException e) {
 
 212     if (errorMessage == null) {
 
 213       PHPeclipsePlugin.log(e);
 
 214       errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
 
 215       errorStart = e.currentToken.sourceStart;
 
 216       errorEnd   = e.currentToken.sourceEnd;
 
 220   //  if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
 
 224    * Create marker for the parse error.
 
 225    * @param e the ParseException
 
 227   private static void setMarker(final ParseException e) {
 
 229       if (errorStart == -1) {
 
 230         setMarker(fileToParse,
 
 232                   e.currentToken.sourceStart,
 
 233                   e.currentToken.sourceEnd,
 
 235                   "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+":"+e.currentToken.sourceEnd);
 
 237         setMarker(fileToParse,
 
 242                   "Line " + e.currentToken.beginLine+", "+errorStart+":"+errorEnd);
 
 246     } catch (CoreException e2) {
 
 247       PHPeclipsePlugin.log(e2);
 
 251   private static void scanLine(final String output,
 
 254                                final int brIndx) throws CoreException {
 
 256     final StringBuffer lineNumberBuffer = new StringBuffer(10);
 
 258     current = output.substring(indx, brIndx);
 
 260     if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
 
 261       final int onLine = current.indexOf("on line <b>");
 
 263         lineNumberBuffer.delete(0, lineNumberBuffer.length());
 
 264         for (int i = onLine; i < current.length(); i++) {
 
 265           ch = current.charAt(i);
 
 266           if ('0' <= ch && '9' >= ch) {
 
 267             lineNumberBuffer.append(ch);
 
 271         final int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
 
 273         final Hashtable attributes = new Hashtable();
 
 275         current = current.replaceAll("\n", "");
 
 276         current = current.replaceAll("<b>", "");
 
 277         current = current.replaceAll("</b>", "");
 
 278         MarkerUtilities.setMessage(attributes, current);
 
 280         if (current.indexOf(PARSE_ERROR_STRING) != -1)
 
 281           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
 
 282         else if (current.indexOf(PARSE_WARNING_STRING) != -1)
 
 283           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
 
 285           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
 
 286         MarkerUtilities.setLineNumber(attributes, lineNumber);
 
 287         MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
 
 292   public final void parse(final String s) {
 
 293     final StringReader stream = new StringReader(s);
 
 294     if (jj_input_stream == null) {
 
 295       jj_input_stream = new SimpleCharStream(stream, 1, 1);
 
 301     } catch (ParseException e) {
 
 302       processParseException(e);
 
 307    * Call the php parse command ( php -l -f <filename> )
 
 308    * and create markers according to the external parser output
 
 310   public static void phpExternalParse(final IFile file) {
 
 311     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
 
 312     final String filename = file.getLocation().toString();
 
 314     final String[] arguments = { filename };
 
 315     final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
 
 316     final String command = form.format(arguments);
 
 318     final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
 
 321       // parse the buffer to find the errors and warnings
 
 322       createMarkers(parserResult, file);
 
 323     } catch (CoreException e) {
 
 324       PHPeclipsePlugin.log(e);
 
 329    * Put a new html block in the stack.
 
 331   public static final void createNewHTMLCode() {
 
 332     final int currentPosition = token.sourceStart;
 
 333     if (currentPosition == htmlStart ||
 
 334           currentPosition < htmlStart ||
 
 335           currentPosition > SimpleCharStream.currentBuffer.length()) {
 
 338     final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,
 
 339                                                                   currentPosition).toCharArray();
 
 340     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
 
 343   /** Create a new task. */
 
 344   public static final void createNewTask(final int todoStart) {
 
 345     final String  todo = SimpleCharStream.currentBuffer.substring(todoStart,
 
 346                                                                   SimpleCharStream.currentBuffer.indexOf("\n",
 
 350         setMarker(fileToParse,
 
 352                   SimpleCharStream.getBeginLine(),
 
 354                   "Line "+SimpleCharStream.getBeginLine());
 
 355       } catch (CoreException e) {
 
 356         PHPeclipsePlugin.log(e);
 
 361   private static final void parse() throws ParseException {
 
 366 PARSER_END(PHPParser)
 
 370   // CommonTokenAction: use the begins/ends fields added to the Jack
 
 371   // CharStream class to set corresponding fields in each Token (which was
 
 372   // also extended with new fields). By default Jack doesn't supply absolute
 
 373   // offsets, just line/column offsets
 
 374   static void CommonTokenAction(Token t) {
 
 375     t.sourceStart = input_stream.beginOffset;
 
 376     t.sourceEnd = input_stream.endOffset;
 
 377   } // CommonTokenAction
 
 382   <PHPSTARTSHORT : "<?">    : PHPPARSING
 
 383 | <PHPSTARTLONG  : "<?php"> : PHPPARSING
 
 384 | <PHPECHOSTART  : "<?=">   : PHPPARSING
 
 387 <PHPPARSING, IN_SINGLE_LINE_COMMENT,IN_VARIABLE> TOKEN :
 
 389   <PHPEND :"?>"> : DEFAULT
 
 392 /* Skip any character if we are not in php mode */
 
 409 <IN_VARIABLE> SPECIAL_TOKEN :
 
 418 <PHPPARSING> SPECIAL_TOKEN :
 
 420   "//" : IN_SINGLE_LINE_COMMENT
 
 421 | "#"  : IN_SINGLE_LINE_COMMENT
 
 422 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
 
 423 | "/*" : IN_MULTI_LINE_COMMENT
 
 426 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
 
 428   <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
 
 432 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
 
 440   todoToken = "TODO" {createNewTask(todoToken.sourceStart);}
 
 442 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
 
 447 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
 
 452 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
 
 462 | <FUNCTION : "function">
 
 465 | <ELSEIF   : "elseif">
 
 472 /* LANGUAGE CONSTRUCT */
 
 477 | <INCLUDE            : "include">
 
 478 | <REQUIRE            : "require">
 
 479 | <INCLUDE_ONCE       : "include_once">
 
 480 | <REQUIRE_ONCE       : "require_once">
 
 481 | <GLOBAL             : "global">
 
 482 | <DEFINE             : "define">
 
 483 | <STATIC             : "static">
 
 486 <PHPPARSING,IN_VARIABLE> TOKEN :
 
 488   <CLASSACCESS        : "->"> : PHPPARSING
 
 489 | <STATICCLASSACCESS  : "::"> : PHPPARSING
 
 490 | <ARRAYASSIGN        : "=>"> : PHPPARSING
 
 493 /* RESERVED WORDS AND LITERALS */
 
 499 | <CONTINUE : "continue">
 
 500 | <_DEFAULT : "default">
 
 502 | <EXTENDS  : "extends">
 
 507 | <RETURN   : "return">
 
 509 | <SWITCH   : "switch">
 
 514 | <ENDWHILE : "endwhile">
 
 515 | <ENDSWITCH: "endswitch">
 
 517 | <ENDFOR   : "endfor">
 
 518 | <FOREACH  : "foreach">
 
 526 | <OBJECT  : "object">
 
 528 | <BOOLEAN : "boolean">
 
 530 | <DOUBLE  : "double">
 
 533 | <INTEGER : "integer">
 
 537 <PHPPARSING,IN_VARIABLE> TOKEN :
 
 539   <AT                 : "@"> : PHPPARSING
 
 540 | <BANG               : "!"> : PHPPARSING
 
 541 | <TILDE              : "~"> : PHPPARSING
 
 542 | <HOOK               : "?"> : PHPPARSING
 
 543 | <COLON              : ":"> : PHPPARSING
 
 547 <PHPPARSING,IN_VARIABLE> TOKEN :
 
 549   <OR_OR              : "||"> : PHPPARSING
 
 550 | <AND_AND            : "&&"> : PHPPARSING
 
 551 | <PLUS_PLUS          : "++"> : PHPPARSING
 
 552 | <MINUS_MINUS        : "--"> : PHPPARSING
 
 553 | <PLUS               : "+"> : PHPPARSING
 
 554 | <MINUS              : "-"> : PHPPARSING
 
 555 | <STAR               : "*"> : PHPPARSING
 
 556 | <SLASH              : "/"> : PHPPARSING
 
 557 | <BIT_AND            : "&"> : PHPPARSING
 
 558 | <BIT_OR             : "|"> : PHPPARSING
 
 559 | <XOR                : "^"> : PHPPARSING
 
 560 | <REMAINDER          : "%">  : PHPPARSING
 
 561 | <LSHIFT             : "<<"> : PHPPARSING
 
 562 | <RSIGNEDSHIFT       : ">>"> : PHPPARSING
 
 563 | <RUNSIGNEDSHIFT     : ">>>"> : PHPPARSING
 
 564 | <_ORL               : "OR"> : PHPPARSING
 
 565 | <_ANDL              : "AND"> : PHPPARSING
 
 572         <DECIMAL_LITERAL> (["l","L"])?
 
 573       | <HEX_LITERAL> (["l","L"])?
 
 574       | <OCTAL_LITERAL> (["l","L"])?
 
 577   <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
 
 579   <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
 
 581   <#OCTAL_LITERAL: "0" (["0"-"7"])* >
 
 583   <FLOATING_POINT_LITERAL:
 
 584         (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
 
 585       | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
 
 586       | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
 
 587       | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
 
 590   <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 
 592   <STRING_LITERAL: (<STRING_2> | <STRING_3>)>
 
 593 //|   <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
 
 594 |   <STRING_2: "'"  ( ~["'","\\"]  | "\\" ~[] )* "'">
 
 595 |   <STRING_3: "`"  ( ~["`","\\"]  | "\\" ~[] )* "`">
 
 598 <IN_STRING,DOLLAR_IN_STRING> SKIP :
 
 600   <ESCAPED : ("\\" ~[])> : IN_STRING
 
 605   <DOUBLEQUOTE : "\""> : IN_STRING
 
 611   <DOLLARS : "$"> : DOLLAR_IN_STRING
 
 614 <IN_STRING,DOLLAR_IN_STRING> TOKEN :
 
 616   <DOUBLEQUOTE2 : "\""> : PHPPARSING
 
 619 <DOLLAR_IN_STRING> TOKEN :
 
 621   <LBRACE1 : "{"> : DOLLAR_IN_STRING_EXPR
 
 624 <IN_STRING> SPECIAL_TOKEN :
 
 629 <SKIPSTRING> SPECIAL_TOKEN :
 
 639 <DOLLAR_IN_STRING_EXPR> TOKEN :
 
 641   <RBRACE1 : "}"> : DOLLAR_IN_STRING
 
 644 <DOLLAR_IN_STRING_EXPR> TOKEN :
 
 654 <DOLLAR_IN_STRING_EXPR,IN_STRING> SKIP :
 
 661 <PHPPARSING,IN_VARIABLE> TOKEN : {<DOLLAR : "$"> : IN_VARIABLE}
 
 664 <PHPPARSING, IN_VARIABLE, DOLLAR_IN_STRING> TOKEN :
 
 666   <IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
 
 669       ["a"-"z"] | ["A"-"Z"]
 
 677     "_" | ["\u007f"-"\u00ff"]
 
 681 <DOLLAR_IN_STRING> SPECIAL_TOKEN :
 
 687 <PHPPARSING,IN_VARIABLE> TOKEN :
 
 689   <LPAREN    : "("> : PHPPARSING
 
 690 | <RPAREN    : ")"> : PHPPARSING
 
 691 | <LBRACE    : "{"> : PHPPARSING
 
 692 | <RBRACE    : "}"> : PHPPARSING
 
 693 | <LBRACKET  : "["> : PHPPARSING
 
 694 | <RBRACKET  : "]"> : PHPPARSING
 
 695 | <SEMICOLON : ";"> : PHPPARSING
 
 696 | <COMMA     : ","> : PHPPARSING
 
 697 | <DOT       : "."> : PHPPARSING
 
 702 <PHPPARSING,IN_VARIABLE> TOKEN :
 
 704   <GT                 : ">"> : PHPPARSING
 
 705 | <LT                 : "<"> : PHPPARSING
 
 706 | <EQUAL_EQUAL        : "=="> : PHPPARSING
 
 707 | <LE                 : "<="> : PHPPARSING
 
 708 | <GE                 : ">="> : PHPPARSING
 
 709 | <NOT_EQUAL          : "!="> : PHPPARSING
 
 710 | <DIF                : "<>"> : PHPPARSING
 
 711 | <BANGDOUBLEEQUAL    : "!=="> : PHPPARSING
 
 712 | <TRIPLEEQUAL        : "==="> : PHPPARSING
 
 716 <PHPPARSING,IN_VARIABLE> TOKEN :
 
 718   <ASSIGN             : "="> : PHPPARSING
 
 719 | <PLUSASSIGN         : "+="> : PHPPARSING
 
 720 | <MINUSASSIGN        : "-="> : PHPPARSING
 
 721 | <STARASSIGN         : "*="> : PHPPARSING
 
 722 | <SLASHASSIGN        : "/="> : PHPPARSING
 
 723 | <ANDASSIGN          : "&="> : PHPPARSING
 
 724 | <ORASSIGN           : "|="> : PHPPARSING
 
 725 | <XORASSIGN          : "^="> : PHPPARSING
 
 726 | <DOTASSIGN          : ".="> : PHPPARSING
 
 727 | <REMASSIGN          : "%="> : PHPPARSING
 
 728 | <TILDEEQUAL         : "~="> : PHPPARSING
 
 729 | <LSHIFTASSIGN       : "<<="> : PHPPARSING
 
 730 | <RSIGNEDSHIFTASSIGN : ">>="> : PHPPARSING
 
 745     {PHPParser.createNewHTMLCode();}
 
 746   } catch (TokenMgrError e) {
 
 747     PHPeclipsePlugin.log(e);
 
 748     errorStart   = SimpleCharStream.beginOffset;
 
 749     errorEnd     = SimpleCharStream.endOffset;
 
 750     errorMessage = e.getMessage();
 
 752     throw generateParseException();
 
 757  * A php block is a <?= expression [;]?>
 
 758  * or <?php somephpcode ?>
 
 759  * or <? somephpcode ?>
 
 763   final PHPEchoBlock phpEchoBlock;
 
 764   final Token token,phpEnd;
 
 767   phpEchoBlock = phpEchoBlock()
 
 768   {pushOnAstNodes(phpEchoBlock);}
 
 771     | token = <PHPSTARTSHORT>
 
 773       setMarker(fileToParse,
 
 774                 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
 
 778                 "Line " + token.beginLine);
 
 779     } catch (CoreException e) {
 
 780       PHPeclipsePlugin.log(e);
 
 783   {PHPParser.createNewHTMLCode();}
 
 787    {htmlStart = phpEnd.sourceEnd;}
 
 788   } catch (ParseException e) {
 
 789     errorMessage = "'?>' expected";
 
 791     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 792     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 793     processParseExceptionDebug(e);
 
 797 PHPEchoBlock phpEchoBlock() :
 
 799   final Expression expr;
 
 800   final PHPEchoBlock echoBlock;
 
 801   final Token token, token2;
 
 804   token = <PHPECHOSTART> {PHPParser.createNewHTMLCode();}
 
 805   expr = Expression() [ <SEMICOLON> ] token2 = <PHPEND>
 
 807   htmlStart = token2.sourceEnd;
 
 809   echoBlock = new PHPEchoBlock(expr,token.sourceStart,token2.sourceEnd);
 
 810   pushOnAstNodes(echoBlock);
 
 820 ClassDeclaration ClassDeclaration() :
 
 822   final ClassDeclaration classDeclaration;
 
 823   Token className = null;
 
 824   final Token superclassName, token, extendsToken;
 
 825   String classNameImage = SYNTAX_ERROR_CHAR;
 
 826   String superclassNameImage = null;
 
 832     className = <IDENTIFIER>
 
 833     {classNameImage = className.image;}
 
 834   } catch (ParseException e) {
 
 835     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
 
 837     errorStart   = token.sourceEnd+1;
 
 838     errorEnd     = token.sourceEnd+1;
 
 839     processParseExceptionDebug(e);
 
 842     extendsToken = <EXTENDS>
 
 844       superclassName = <IDENTIFIER>
 
 845       {superclassNameImage = superclassName.image;}
 
 846     } catch (ParseException e) {
 
 847       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
 
 849       errorStart = extendsToken.sourceEnd+1;
 
 850       errorEnd   = extendsToken.sourceEnd+1;
 
 851       processParseExceptionDebug(e);
 
 852       superclassNameImage = SYNTAX_ERROR_CHAR;
 
 857     if (className == null) {
 
 858       start = token.sourceStart;
 
 859       end = token.sourceEnd;
 
 861       start = className.sourceStart;
 
 862       end = className.sourceEnd;
 
 864     if (superclassNameImage == null) {
 
 866       classDeclaration = new ClassDeclaration(currentSegment,
 
 871       classDeclaration = new ClassDeclaration(currentSegment,
 
 877       currentSegment.add(classDeclaration);
 
 878       currentSegment = classDeclaration;
 
 880   classEnd = ClassBody(classDeclaration)
 
 881   {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
 
 882    classDeclaration.sourceEnd = classEnd;
 
 883    pushOnAstNodes(classDeclaration);
 
 884    return classDeclaration;}
 
 887 int ClassBody(final ClassDeclaration classDeclaration) :
 
 894   } catch (ParseException e) {
 
 895     errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
 
 897     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 898     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 899     processParseExceptionDebug(e);
 
 901   ( ClassBodyDeclaration(classDeclaration) )*
 
 904     {return token.sourceEnd;}
 
 905   } catch (ParseException e) {
 
 906     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
 
 908     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
 909     errorEnd   = SimpleCharStream.getPosition() + 1;
 
 910     processParseExceptionDebug(e);
 
 911     return PHPParser.token.sourceEnd;
 
 916  * A class can contain only methods and fields.
 
 918 void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
 
 920   final MethodDeclaration method;
 
 921   final FieldDeclaration field;
 
 924   method = MethodDeclaration() {method.analyzeCode();
 
 925                                 classDeclaration.addMethod(method);}
 
 926 | field = FieldDeclaration()   {classDeclaration.addField(field);}
 
 930  * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
 
 931  * it is only used by ClassBodyDeclaration()
 
 933 FieldDeclaration FieldDeclaration() :
 
 935   VariableDeclaration variableDeclaration;
 
 936   final VariableDeclaration[] list;
 
 937   final ArrayList arrayList = new ArrayList();
 
 943   token = <VAR> variableDeclaration = VariableDeclaratorNoSuffix()
 
 945     arrayList.add(variableDeclaration);
 
 946     outlineInfo.addVariable(variableDeclaration.name());
 
 947     pos = variableDeclaration.sourceEnd;
 
 950     <COMMA> variableDeclaration = VariableDeclaratorNoSuffix()
 
 952         arrayList.add(variableDeclaration);
 
 953         outlineInfo.addVariable(variableDeclaration.name());
 
 954         pos = variableDeclaration.sourceEnd;
 
 959   } catch (ParseException e) {
 
 960     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
 
 964     processParseExceptionDebug(e);
 
 967   {list = new VariableDeclaration[arrayList.size()];
 
 968    arrayList.toArray(list);
 
 970    if (token2 == null) {
 
 971      end = list[list.length-1].sourceEnd;
 
 973      end = token2.sourceEnd;
 
 975    return new FieldDeclaration(list,
 
 982  * a strict variable declarator : there cannot be a suffix here.
 
 983  * It will be used by fields and formal parameters
 
 985 VariableDeclaration VariableDeclaratorNoSuffix() :
 
 987   final Token token, lbrace,rbrace;
 
 988   Expression expr, initializer = null;
 
 996      {variable = new Variable(token.image,token.sourceStart,token.sourceEnd);}
 
 998      lbrace = <LBRACE> expr = Expression() rbrace = <RBRACE>
 
 999      {variable = new Variable(expr,lbrace.sourceStart,rbrace.sourceEnd);}
 
1002     assignToken = <ASSIGN>
 
1004       initializer = VariableInitializer()
 
1005     } catch (ParseException e) {
 
1006       errorMessage = "Literal expression expected in variable initializer";
 
1008       errorStart = assignToken.sourceEnd +1;
 
1009       errorEnd   = assignToken.sourceEnd +1;
 
1010       processParseExceptionDebug(e);
 
1014   if (initializer == null) {
 
1015     return new VariableDeclaration(currentSegment,
 
1017                                    variable.sourceStart,
 
1018                                    variable.sourceEnd);
 
1020   return new VariableDeclaration(currentSegment,
 
1023                                  VariableDeclaration.EQUAL,
 
1024                                  variable.sourceStart);
 
1029  * this will be used by static statement
 
1031 VariableDeclaration VariableDeclarator() :
 
1033   final AbstractVariable variable;
 
1034   Expression initializer = null;
 
1038   variable = VariableDeclaratorId()
 
1042       initializer = VariableInitializer()
 
1043     } catch (ParseException e) {
 
1044       errorMessage = "Literal expression expected in variable initializer";
 
1046       errorStart = token.sourceEnd+1;
 
1047       errorEnd   = token.sourceEnd+1;
 
1048       processParseExceptionDebug(e);
 
1052   if (initializer == null) {
 
1053     return new VariableDeclaration(currentSegment,
 
1055                                    variable.sourceStart,
 
1056                                    variable.sourceEnd);
 
1058     return new VariableDeclaration(currentSegment,
 
1061                                    VariableDeclaration.EQUAL,
 
1062                                    variable.sourceStart);
 
1068  * @return the variable name (with suffix)
 
1070 AbstractVariable VariableDeclaratorId() :
 
1073   AbstractVariable expression = null;
 
1080       expression = VariableSuffix(var)
 
1083      if (expression == null) {
 
1088   } catch (ParseException e) {
 
1089     errorMessage = "'$' expected for variable identifier";
 
1091     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1092     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1097 Variable Variable() :
 
1099   Variable variable = null;
 
1103   token = <DOLLAR> variable = Var()
 
1111   Variable variable = null;
 
1112   final Token token,token2;
 
1113   ConstantIdentifier constant;
 
1114   Expression expression;
 
1117   token = <DOLLAR> variable = Var()
 
1118   {return new Variable(variable,variable.sourceStart,variable.sourceEnd);}
 
1120   token = <LBRACE> expression = Expression() token2 = <RBRACE>
 
1122    return new Variable(expression,
 
1127   token = <IDENTIFIER>
 
1128   {return new Variable(token.image,token.sourceStart,token.sourceEnd);}
 
1131 Expression VariableInitializer() :
 
1133   final Expression expr;
 
1134   final Token token, token2;
 
1140   token2 = <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
 
1141   {return new PrefixedUnaryExpression(new NumberLiteral(token),
 
1143                                       token2.sourceStart);}
 
1145   token2 = <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
 
1146   {return new PrefixedUnaryExpression(new NumberLiteral(token),
 
1148                                       token2.sourceStart);}
 
1150   expr = ArrayDeclarator()
 
1153   token = <IDENTIFIER>
 
1154   {return new ConstantIdentifier(token);}
 
1157 ArrayVariableDeclaration ArrayVariable() :
 
1159 final Expression expr,expr2;
 
1164     <ARRAYASSIGN> expr2 = Expression()
 
1165     {return new ArrayVariableDeclaration(expr,expr2);}
 
1167   {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
 
1170 ArrayVariableDeclaration[] ArrayInitializer() :
 
1172   ArrayVariableDeclaration expr;
 
1173   final ArrayList list = new ArrayList();
 
1178       expr = ArrayVariable()
 
1180       ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
 
1185       <COMMA> {list.add(null);}
 
1189   final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
 
1195  * A Method Declaration.
 
1196  * <b>function</b> MetodDeclarator() Block()
 
1198 MethodDeclaration MethodDeclaration() :
 
1200   final MethodDeclaration functionDeclaration;
 
1202   final OutlineableWithChildren seg = currentSegment;
 
1208     functionDeclaration = MethodDeclarator(token.sourceStart)
 
1209     {outlineInfo.addVariable(functionDeclaration.name);}
 
1210   } catch (ParseException e) {
 
1211     if (errorMessage != null)  throw e;
 
1212     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
 
1214     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
1215     errorEnd   = SimpleCharStream.getPosition() + 1;
 
1218   {currentSegment = functionDeclaration;}
 
1220   {functionDeclaration.statements = block.statements;
 
1221    currentSegment = seg;
 
1222    return functionDeclaration;}
 
1226  * A MethodDeclarator.
 
1227  * [&] IDENTIFIER(parameters ...).
 
1228  * @return a function description for the outline
 
1230 MethodDeclaration MethodDeclarator(final int start) :
 
1232   Token identifier = null;
 
1233   Token reference = null;
 
1234   final Hashtable formalParameters = new Hashtable();
 
1235   String identifierChar = SYNTAX_ERROR_CHAR;
 
1239   [reference = <BIT_AND> {end = reference.sourceEnd;}]
 
1241     identifier = <IDENTIFIER>
 
1243       identifierChar = identifier.image;
 
1244       end = identifier.sourceEnd;
 
1246   } catch (ParseException e) {
 
1247     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
 
1249     errorStart = e.currentToken.sourceEnd;
 
1250     errorEnd   = e.currentToken.next.sourceStart;
 
1251     processParseExceptionDebug(e);
 
1253   end = FormalParameters(formalParameters)
 
1255   int nameStart, nameEnd;
 
1256   if (identifier == null) {
 
1257     if (reference == null) {
 
1258       nameStart = start + 9;
 
1259       nameEnd = start + 10;
 
1261       nameStart = reference.sourceEnd + 1;
 
1262       nameEnd = reference.sourceEnd + 2;
 
1265       nameStart = identifier.sourceStart;
 
1266       nameEnd = identifier.sourceEnd;
 
1268   return new MethodDeclaration(currentSegment,
 
1280  * FormalParameters follows method identifier.
 
1281  * (FormalParameter())
 
1283 int FormalParameters(final Hashtable parameters) :
 
1285   VariableDeclaration var;
 
1287   Token tok = PHPParser.token;
 
1288   int end = tok.sourceEnd;
 
1293   {end = tok.sourceEnd;}
 
1294   } catch (ParseException e) {
 
1295     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
 
1297     errorStart = e.currentToken.next.sourceStart;
 
1298     errorEnd   = e.currentToken.next.sourceEnd;
 
1299     processParseExceptionDebug(e);
 
1302     var = FormalParameter()
 
1303     {parameters.put(var.name(),var);end = var.sourceEnd;}
 
1305       <COMMA> var = FormalParameter()
 
1306       {parameters.put(var.name(),var);end = var.sourceEnd;}
 
1311     {end = token.sourceEnd;}
 
1312   } catch (ParseException e) {
 
1313     errorMessage = "')' expected";
 
1315     errorStart = e.currentToken.next.sourceStart;
 
1316     errorEnd   = e.currentToken.next.sourceEnd;
 
1317     processParseExceptionDebug(e);
 
1323  * A formal parameter.
 
1324  * $varname[=value] (,$varname[=value])
 
1326 VariableDeclaration FormalParameter() :
 
1328   final VariableDeclaration variableDeclaration;
 
1332   [token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
 
1334     if (token != null) {
 
1335       variableDeclaration.setReference(true);
 
1337     return variableDeclaration;}
 
1340 ConstantIdentifier Type() :
 
1341 {final Token token;}
 
1343   token = <STRING>    {return new ConstantIdentifier(token);}
 
1344 | token = <BOOL>      {return new ConstantIdentifier(token);}
 
1345 | token = <BOOLEAN>   {return new ConstantIdentifier(token);}
 
1346 | token = <REAL>      {return new ConstantIdentifier(token);}
 
1347 | token = <DOUBLE>    {return new ConstantIdentifier(token);}
 
1348 | token = <FLOAT>     {return new ConstantIdentifier(token);}
 
1349 | token = <INT>       {return new ConstantIdentifier(token);}
 
1350 | token = <INTEGER>   {return new ConstantIdentifier(token);}
 
1351 | token = <OBJECT>    {return new ConstantIdentifier(token);}
 
1354 Expression Expression() :
 
1356   final Expression expr;
 
1357   Expression initializer = null;
 
1358   int assignOperator = -1;
 
1362   expr = ConditionalExpression()
 
1364     assignOperator = AssignmentOperator()
 
1366       initializer = Expression()
 
1367     } catch (ParseException e) {
 
1368       if (errorMessage != null) {
 
1371       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
1373       errorEnd   = SimpleCharStream.getPosition();
 
1378     if (assignOperator != -1) {// todo : change this, very very bad :(
 
1379         if (expr instanceof AbstractVariable) {
 
1380           return new VariableDeclaration(currentSegment,
 
1381                                          (AbstractVariable) expr,
 
1384                                          initializer.sourceEnd);
 
1386         String varName = expr.toStringExpression().substring(1);
 
1387         return new VariableDeclaration(currentSegment,
 
1388                                        new Variable(varName,
 
1392                                        initializer.sourceEnd);
 
1396 | expr = ExpressionWBang()       {return expr;}
 
1399 Expression ExpressionWBang() :
 
1401   final Expression expr;
 
1405   token = <BANG> expr = ExpressionWBang()
 
1406   {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,token.sourceStart);}
 
1407 | expr = ExpressionNoBang() {return expr;}
 
1410 Expression ExpressionNoBang() :
 
1415   expr = ListExpression()    {return expr;}
 
1417   expr = PrintExpression()   {return expr;}
 
1421  * Any assignement operator.
 
1422  * @return the assignement operator id
 
1424 int AssignmentOperator() :
 
1427   <ASSIGN>             {return VariableDeclaration.EQUAL;}
 
1428 | <STARASSIGN>         {return VariableDeclaration.STAR_EQUAL;}
 
1429 | <SLASHASSIGN>        {return VariableDeclaration.SLASH_EQUAL;}
 
1430 | <REMASSIGN>          {return VariableDeclaration.REM_EQUAL;}
 
1431 | <PLUSASSIGN>         {return VariableDeclaration.PLUS_EQUAL;}
 
1432 | <MINUSASSIGN>        {return VariableDeclaration.MINUS_EQUAL;}
 
1433 | <LSHIFTASSIGN>       {return VariableDeclaration.LSHIFT_EQUAL;}
 
1434 | <RSIGNEDSHIFTASSIGN> {return VariableDeclaration.RSIGNEDSHIFT_EQUAL;}
 
1435 | <ANDASSIGN>          {return VariableDeclaration.AND_EQUAL;}
 
1436 | <XORASSIGN>          {return VariableDeclaration.XOR_EQUAL;}
 
1437 | <ORASSIGN>           {return VariableDeclaration.OR_EQUAL;}
 
1438 | <DOTASSIGN>          {return VariableDeclaration.DOT_EQUAL;}
 
1439 | <TILDEEQUAL>         {return VariableDeclaration.TILDE_EQUAL;}
 
1442 Expression ConditionalExpression() :
 
1444   final Expression expr;
 
1445   Expression expr2 = null;
 
1446   Expression expr3 = null;
 
1449   expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
 
1451   if (expr3 == null) {
 
1454   return new ConditionalExpression(expr,expr2,expr3);
 
1458 Expression ConditionalOrExpression() :
 
1460   Expression expr,expr2;
 
1464   expr = ConditionalAndExpression()
 
1467         <OR_OR> {operator = OperatorIds.OR_OR;}
 
1468       | <_ORL>  {operator = OperatorIds.ORL;}
 
1470     expr2 = ConditionalAndExpression()
 
1472       expr = new BinaryExpression(expr,expr2,operator);
 
1478 Expression ConditionalAndExpression() :
 
1480   Expression expr,expr2;
 
1484   expr = ConcatExpression()
 
1486   (  <AND_AND> {operator = OperatorIds.AND_AND;}
 
1487    | <_ANDL>   {operator = OperatorIds.ANDL;})
 
1488    expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
 
1493 Expression ConcatExpression() :
 
1495   Expression expr,expr2;
 
1498   expr = InclusiveOrExpression()
 
1500     <DOT> expr2 = InclusiveOrExpression()
 
1501     {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
 
1506 Expression InclusiveOrExpression() :
 
1508   Expression expr,expr2;
 
1511   expr = ExclusiveOrExpression()
 
1512   (<BIT_OR> expr2 = ExclusiveOrExpression()
 
1513    {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
 
1518 Expression ExclusiveOrExpression() :
 
1520   Expression expr,expr2;
 
1523   expr = AndExpression()
 
1525     <XOR> expr2 = AndExpression()
 
1526     {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
 
1531 Expression AndExpression() :
 
1533   Expression expr,expr2;
 
1536   expr = EqualityExpression()
 
1539     <BIT_AND> expr2 = EqualityExpression()
 
1540     {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
 
1545 Expression EqualityExpression() :
 
1547   Expression expr,expr2;
 
1552   expr = RelationalExpression()
 
1554   (   token = <EQUAL_EQUAL>      {operator = OperatorIds.EQUAL_EQUAL;}
 
1555     | token = <DIF>              {operator = OperatorIds.DIF;}
 
1556     | token = <NOT_EQUAL>        {operator = OperatorIds.DIF;}
 
1557     | token = <BANGDOUBLEEQUAL>  {operator = OperatorIds.BANG_EQUAL_EQUAL;}
 
1558     | token = <TRIPLEEQUAL>      {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
 
1561     expr2 = RelationalExpression()
 
1562   } catch (ParseException e) {
 
1563     if (errorMessage != null) {
 
1566     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
1568     errorStart = token.sourceEnd +1;
 
1569     errorEnd   = token.sourceEnd +1;
 
1570     expr2 = new ConstantIdentifier(SYNTAX_ERROR_CHAR,token.sourceEnd +1,token.sourceEnd +1);
 
1571     processParseExceptionDebug(e);
 
1574     expr = new BinaryExpression(expr,expr2,operator);
 
1580 Expression RelationalExpression() :
 
1582   Expression expr,expr2;
 
1586   expr = ShiftExpression()
 
1588   ( <LT> {operator = OperatorIds.LESS;}
 
1589   | <GT> {operator = OperatorIds.GREATER;}
 
1590   | <LE> {operator = OperatorIds.LESS_EQUAL;}
 
1591   | <GE> {operator = OperatorIds.GREATER_EQUAL;})
 
1592    expr2 = ShiftExpression()
 
1593   {expr = new BinaryExpression(expr,expr2,operator);}
 
1598 Expression ShiftExpression() :
 
1600   Expression expr,expr2;
 
1604   expr = AdditiveExpression()
 
1606   ( <LSHIFT>         {operator = OperatorIds.LEFT_SHIFT;}
 
1607   | <RSIGNEDSHIFT>   {operator = OperatorIds.RIGHT_SHIFT;}
 
1608   | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
 
1609   expr2 = AdditiveExpression()
 
1610   {expr = new BinaryExpression(expr,expr2,operator);}
 
1615 Expression AdditiveExpression() :
 
1617   Expression expr,expr2;
 
1621   expr = MultiplicativeExpression()
 
1624      ( <PLUS>  {operator = OperatorIds.PLUS;}
 
1625      | <MINUS> {operator = OperatorIds.MINUS;}
 
1627    expr2 = MultiplicativeExpression()
 
1628   {expr = new BinaryExpression(expr,expr2,operator);}
 
1633 Expression MultiplicativeExpression() :
 
1635   Expression expr,expr2;
 
1640     expr = UnaryExpression()
 
1641   } catch (ParseException e) {
 
1642     if (errorMessage != null) throw e;
 
1643     errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
 
1645     errorStart = PHPParser.token.sourceStart;
 
1646     errorEnd   = PHPParser.token.sourceEnd;
 
1650    (  <STAR>      {operator = OperatorIds.MULTIPLY;}
 
1651     | <SLASH>     {operator = OperatorIds.DIVIDE;}
 
1652     | <REMAINDER> {operator = OperatorIds.REMAINDER;})
 
1653     expr2 = UnaryExpression()
 
1654     {expr = new BinaryExpression(expr,expr2,operator);}
 
1660  * An unary expression starting with @, & or nothing
 
1662 Expression UnaryExpression() :
 
1664   final Expression expr;
 
1667  /* <BIT_AND> expr = UnaryExpressionNoPrefix()             //why did I had that ?
 
1668   {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
 
1670   expr = AtNotTildeUnaryExpression() {return expr;}
 
1673 Expression AtNotTildeUnaryExpression() :
 
1675   final Expression expr;
 
1680   expr = AtNotTildeUnaryExpression()
 
1681   {return new PrefixedUnaryExpression(expr,OperatorIds.AT,token.sourceStart);}
 
1684   expr = AtNotTildeUnaryExpression()
 
1685   {return new PrefixedUnaryExpression(expr,OperatorIds.TWIDDLE,token.sourceStart);}
 
1688   expr = AtNotUnaryExpression()
 
1689   {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,token.sourceStart);}
 
1691   expr = UnaryExpressionNoPrefix()
 
1696  * An expression prefixed (or not) by one or more @ and !.
 
1697  * @return the expression
 
1699 Expression AtNotUnaryExpression() :
 
1701   final Expression expr;
 
1706   expr = AtNotUnaryExpression()
 
1707   {return new PrefixedUnaryExpression(expr,OperatorIds.AT,token.sourceStart);}
 
1710   expr = AtNotUnaryExpression()
 
1711   {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,token.sourceStart);}
 
1713   expr = UnaryExpressionNoPrefix()
 
1717 Expression UnaryExpressionNoPrefix() :
 
1719   final Expression expr;
 
1723   token = <PLUS> expr = AtNotTildeUnaryExpression()   {return new PrefixedUnaryExpression(expr,
 
1725                                                                                      token.sourceStart);}
 
1727   token = <MINUS> expr = AtNotTildeUnaryExpression()  {return new PrefixedUnaryExpression(expr,
 
1729                                                                                      token.sourceStart);}
 
1731   expr = PreIncDecExpression()
 
1734   expr = UnaryExpressionNotPlusMinus()
 
1739 Expression PreIncDecExpression() :
 
1741 final Expression expr;
 
1747       token = <PLUS_PLUS>   {operator = OperatorIds.PLUS_PLUS;}
 
1749       token = <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
 
1751   expr = PrimaryExpression()
 
1752   {return new PrefixedUnaryExpression(expr,operator,token.sourceStart);}
 
1755 Expression UnaryExpressionNotPlusMinus() :
 
1757   final Expression expr;
 
1760   LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
 
1761   expr = CastExpression()         {return expr;}
 
1762 | expr = PostfixExpression()      {return expr;}
 
1763 | expr = Literal()                {return expr;}
 
1764 | <LPAREN> expr = Expression()
 
1767   } catch (ParseException e) {
 
1768     errorMessage = "')' expected";
 
1770     errorStart   = expr.sourceEnd +1;
 
1771     errorEnd     = expr.sourceEnd +1;
 
1772     processParseExceptionDebug(e);
 
1777 CastExpression CastExpression() :
 
1779 final ConstantIdentifier type;
 
1780 final Expression expr;
 
1781 final Token token,token1;
 
1788       token = <ARRAY> {type = new ConstantIdentifier(token);}
 
1790   <RPAREN> expr = UnaryExpression()
 
1791   {return new CastExpression(type,expr,token1.sourceStart,expr.sourceEnd);}
 
1794 Expression PostfixExpression() :
 
1796   final Expression expr;
 
1801   expr = PrimaryExpression()
 
1803       token = <PLUS_PLUS>   {operator = OperatorIds.PLUS_PLUS;}
 
1805       token = <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
 
1808     if (operator == -1) {
 
1811     return new PostfixedUnaryExpression(expr,operator,token.sourceEnd);
 
1815 Expression PrimaryExpression() :
 
1821   [token = <BIT_AND>] expr = refPrimaryExpression(token)
 
1824   expr = ArrayDeclarator()
 
1828 Expression refPrimaryExpression(final Token reference) :
 
1831   Expression expr2 = null;
 
1832   final Token identifier;
 
1835   identifier = <IDENTIFIER>
 
1837     expr = new ConstantIdentifier(identifier);
 
1840     <STATICCLASSACCESS> expr2 = ClassIdentifier()
 
1841     {expr = new ClassAccess(expr,
 
1843                             ClassAccess.STATIC);}
 
1845   [ expr2 = Arguments(expr) ]
 
1847     if (expr2 == null) {
 
1848       if (reference != null) {
 
1849         ParseException e = generateParseException();
 
1850         errorMessage = "you cannot use a constant by reference";
 
1852         errorStart   = reference.sourceStart;
 
1853         errorEnd     = reference.sourceEnd;
 
1854         processParseExceptionDebug(e);
 
1861   expr = VariableDeclaratorId()  //todo use the reference parameter ...
 
1862   [ expr = Arguments(expr) ]
 
1866   expr = ClassIdentifier()
 
1869     if (reference == null) {
 
1870       start = token.sourceStart;
 
1872       start = reference.sourceStart;
 
1874     expr = new ClassInstantiation(expr,
 
1878   [ expr = Arguments(expr) ]
 
1883  * An array declarator.
 
1887 ArrayInitializer ArrayDeclarator() :
 
1889   final ArrayVariableDeclaration[] vars;
 
1893   token = <ARRAY> vars = ArrayInitializer()
 
1894   {return new ArrayInitializer(vars,
 
1896                                PHPParser.token.sourceEnd);}
 
1899 Expression ClassIdentifier():
 
1901   final Expression expr;
 
1905   token = <IDENTIFIER>          {return new ConstantIdentifier(token);}
 
1906 | expr = Type()                 {return expr;}
 
1907 | expr = VariableDeclaratorId() {return expr;}
 
1911  * Used by Variabledeclaratorid and primarysuffix
 
1913 AbstractVariable VariableSuffix(final AbstractVariable prefix) :
 
1915   Expression expression = null;
 
1916   final Token classAccessToken,lbrace,rbrace;
 
1921   classAccessToken = <CLASSACCESS>
 
1924       lbrace = <LBRACE> expression = Expression() rbrace = <RBRACE>
 
1926                  expression = new Variable(expression,
 
1931         token = <IDENTIFIER>
 
1932         {expression = new ConstantIdentifier(token.image,token.sourceStart,token.sourceEnd);}
 
1934         expression = Variable()
 
1936   } catch (ParseException e) {
 
1937     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
 
1939     errorStart = classAccessToken.sourceEnd +1;
 
1940     errorEnd   = classAccessToken.sourceEnd +1;
 
1941     processParseExceptionDebug(e);
 
1943   {return new ClassAccess(prefix,
 
1945                           ClassAccess.NORMAL);}
 
1947   token = <LBRACKET> {pos = token.sourceEnd+1;}
 
1948   [  expression = Expression() {pos = expression.sourceEnd+1;}
 
1949    | expression = Type()       {pos = expression.sourceEnd+1;}]  //Not good
 
1952     {pos = token.sourceEnd;}
 
1953   } catch (ParseException e) {
 
1954     errorMessage = "']' expected";
 
1958     processParseExceptionDebug(e);
 
1960   {return new ArrayDeclarator(prefix,expression,pos);}
 
1962   token = <LBRACE> {pos = token.sourceEnd+1;}
 
1963   [  expression = Expression() {pos = expression.sourceEnd+1;}
 
1964    | expression = Type()       {pos = expression.sourceEnd+1;}]  //Not good
 
1967     {pos = token.sourceEnd;}
 
1968   } catch (ParseException e) {
 
1969     errorMessage = "']' expected";
 
1973     processParseExceptionDebug(e);
 
1975   {return new ArrayDeclarator(prefix,expression,pos);}//todo : check braces here
 
1981   StringLiteral literal;
 
1984   token = <INTEGER_LITERAL>        {return new NumberLiteral(token);}
 
1985 | token = <FLOATING_POINT_LITERAL> {return new NumberLiteral(token);}
 
1986 | token = <STRING_LITERAL>         {return new StringLiteral(token);}
 
1987 | token = <TRUE>                   {return new TrueLiteral(token);}
 
1988 | token = <FALSE>                  {return new FalseLiteral(token);}
 
1989 | token = <NULL>                   {return new NullLiteral(token);}
 
1990 | literal = evaluableString()        {return literal;}
 
1993 StringLiteral evaluableString() :
 
1995   ArrayList list = new ArrayList();
 
1997   Token token,lbrace,rbrace;
 
1998   AbstractVariable var;
 
2002   start = <DOUBLEQUOTE>
 
2006         token = <IDENTIFIER> {list.add(new Variable(token.image,
 
2012          {list.add(new Variable(token.image,
 
2018   end = <DOUBLEQUOTE2>
 
2020   AbstractVariable[] vars = new AbstractVariable[list.size()];
 
2022   return new StringLiteral(SimpleCharStream.currentBuffer.substring(start.sourceEnd,end.sourceStart),
 
2029 FunctionCall Arguments(final Expression func) :
 
2031 Expression[] args = null;
 
2032 final Token token,lparen;
 
2035   lparen = <LPAREN> [ args = ArgumentList() ]
 
2038     {return new FunctionCall(func,args,token.sourceEnd);}
 
2039   } catch (ParseException e) {
 
2040     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
 
2043         errorStart = lparen.sourceEnd+1;
 
2044         errorEnd   = lparen.sourceEnd+2;
 
2046         errorStart = args[args.length-1].sourceEnd+1;
 
2047         errorEnd   = args[args.length-1].sourceEnd+2;
 
2049     processParseExceptionDebug(e);
 
2051   {return new FunctionCall(func,args,args[args.length-1].sourceEnd);}
 
2055  * An argument list is a list of arguments separated by comma :
 
2056  * argumentDeclaration() (, argumentDeclaration)*
 
2057  * @return an array of arguments
 
2059 Expression[] ArgumentList() :
 
2062 final ArrayList list = new ArrayList();
 
2068   {list.add(arg);pos = arg.sourceEnd;}
 
2069   ( token = <COMMA> {pos = token.sourceEnd;}
 
2073          pos = arg.sourceEnd;}
 
2074       } catch (ParseException e) {
 
2075         errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
 
2079         processParseException(e);
 
2083    final Expression[] arguments = new Expression[list.size()];
 
2084    list.toArray(arguments);
 
2089  * A Statement without break.
 
2090  * @return a statement
 
2092 Statement StatementNoBreak() :
 
2094   final Statement statement;
 
2099   statement = expressionStatement()     {return statement;}
 
2101   statement = LabeledStatement()        {return statement;}
 
2102 | statement = Block()                   {return statement;}
 
2103 | statement = EmptyStatement()          {return statement;}
 
2104 | statement = SwitchStatement()         {return statement;}
 
2105 | statement = IfStatement()             {return statement;}
 
2106 | statement = WhileStatement()          {return statement;}
 
2107 | statement = DoStatement()             {return statement;}
 
2108 | statement = ForStatement()            {return statement;}
 
2109 | statement = ForeachStatement()        {return statement;}
 
2110 | statement = ContinueStatement()       {return statement;}
 
2111 | statement = ReturnStatement()         {return statement;}
 
2112 | statement = EchoStatement()           {return statement;}
 
2113 | [token=<AT>] statement = IncludeStatement()
 
2114   {if (token != null) {
 
2115     ((InclusionStatement)statement).silent = true;
 
2116     statement.sourceStart = token.sourceStart;
 
2119 | statement = StaticStatement()         {return statement;}
 
2120 | statement = GlobalStatement()         {return statement;}
 
2121 | statement = defineStatement()         {currentSegment.add((Outlineable)statement);return statement;}
 
2125  * A statement expression.
 
2127  * @return an expression
 
2129 Statement expressionStatement() :
 
2131   final Statement statement;
 
2135   statement = Expression()
 
2138     {statement.sourceEnd = token.sourceEnd;}
 
2139   } catch (ParseException e) {
 
2140     if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
 
2141       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
2143       errorStart = statement.sourceEnd+1;
 
2144       errorEnd   = statement.sourceEnd+1;
 
2145       processParseExceptionDebug(e);
 
2151 Define defineStatement() :
 
2153   Expression defineName,defineValue;
 
2154   final Token defineToken;
 
2159   defineToken = <DEFINE> {pos = defineToken.sourceEnd+1;}
 
2162     {pos = token.sourceEnd+1;}
 
2163   } catch (ParseException e) {
 
2164     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
 
2168     processParseExceptionDebug(e);
 
2171     defineName = Expression()
 
2172     {pos = defineName.sourceEnd+1;}
 
2173   } catch (ParseException e) {
 
2174     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
2178     processParseExceptionDebug(e);
 
2179     defineName = new StringLiteral(SYNTAX_ERROR_CHAR,pos,pos);
 
2183     {pos = defineName.sourceEnd+1;}
 
2184   } catch (ParseException e) {
 
2185     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
 
2189     processParseExceptionDebug(e);
 
2192     defineValue = Expression()
 
2193     {pos = defineValue.sourceEnd+1;}
 
2194   } catch (ParseException e) {
 
2195     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
 
2199     processParseExceptionDebug(e);
 
2200     defineValue = new StringLiteral(SYNTAX_ERROR_CHAR,pos,pos);
 
2204     {pos = token.sourceEnd+1;}
 
2205   } catch (ParseException e) {
 
2206     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
 
2210     processParseExceptionDebug(e);
 
2212   {return new Define(currentSegment,
 
2215                      defineToken.sourceStart,
 
2220  * A Normal statement.
 
2222 Statement Statement() :
 
2224   final Statement statement;
 
2227   statement = StatementNoBreak() {return statement;}
 
2228 | statement = BreakStatement()   {return statement;}
 
2232  * An html block inside a php syntax.
 
2234 HTMLBlock htmlBlock() :
 
2236   final int startIndex = nodePtr;
 
2237   final AstNode[] blockNodes;
 
2243   {htmlStart = phpEnd.sourceEnd;}
 
2246     (<PHPSTARTLONG> | <PHPSTARTSHORT>)
 
2247     {PHPParser.createNewHTMLCode();}
 
2248   } catch (ParseException e) {
 
2249     errorMessage = "unexpected end of file , '<?php' expected";
 
2251     errorStart   = SimpleCharStream.getPosition();
 
2252     errorEnd     = SimpleCharStream.getPosition();
 
2256   nbNodes    = nodePtr - startIndex;
 
2260   blockNodes = new AstNode[nbNodes];
 
2261   System.arraycopy(nodes,startIndex+1,blockNodes,0,nbNodes);
 
2262   nodePtr = startIndex;
 
2263   return new HTMLBlock(blockNodes);}
 
2267  * An include statement. It's "include" an expression;
 
2269 InclusionStatement IncludeStatement() :
 
2273   final InclusionStatement inclusionStatement;
 
2274   final Token token, token2;
 
2278       (  token = <REQUIRE>      {keyword = InclusionStatement.REQUIRE;pos=token.sourceEnd;}
 
2279        | token = <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;pos=token.sourceEnd;}
 
2280        | token = <INCLUDE>      {keyword = InclusionStatement.INCLUDE;pos=token.sourceEnd;}
 
2281        | token = <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;pos=token.sourceEnd;})
 
2284     {pos = expr.sourceEnd;}
 
2285   } catch (ParseException e) {
 
2286     if (errorMessage != null) {
 
2289     errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
 
2291     errorStart   = e.currentToken.next.sourceStart;
 
2292     errorEnd     = e.currentToken.next.sourceEnd;
 
2293     expr = new ConstantIdentifier(SYNTAX_ERROR_CHAR,pos,pos);
 
2294     processParseExceptionDebug(e);
 
2297     token2 = <SEMICOLON>
 
2298     {pos=token2.sourceEnd;}
 
2299   } catch (ParseException e) {
 
2300     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
2302     errorStart   = e.currentToken.next.sourceStart;
 
2303     errorEnd     = e.currentToken.next.sourceEnd;
 
2304     processParseExceptionDebug(e);
 
2307    inclusionStatement = new InclusionStatement(currentSegment,
 
2312    currentSegment.add(inclusionStatement);
 
2313    return inclusionStatement;
 
2317 PrintExpression PrintExpression() :
 
2319   final Expression expr;
 
2320   final Token printToken;
 
2323   token = <PRINT> expr = Expression()
 
2324   {return new PrintExpression(expr,token.sourceStart,expr.sourceEnd);}
 
2327 ListExpression ListExpression() :
 
2329   Expression expr = null;
 
2330   final Expression expression;
 
2331   final ArrayList list = new ArrayList();
 
2333   final Token listToken, rParen;
 
2337   listToken = <LIST> {pos = listToken.sourceEnd;}
 
2339     token = <LPAREN> {pos = token.sourceEnd;}
 
2340   } catch (ParseException e) {
 
2341     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
 
2343     errorStart   = listToken.sourceEnd+1;
 
2344     errorEnd     = listToken.sourceEnd+1;
 
2345     processParseExceptionDebug(e);
 
2348     expr = VariableDeclaratorId()
 
2349     {list.add(expr);pos = expr.sourceEnd;}
 
2351   {if (expr == null) list.add(null);}
 
2355       {pos = token.sourceEnd;}
 
2356     } catch (ParseException e) {
 
2357       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
 
2361       processParseExceptionDebug(e);
 
2363     [expr = VariableDeclaratorId() {list.add(expr);pos = expr.sourceEnd;}]
 
2367     {pos = rParen.sourceEnd;}
 
2368   } catch (ParseException e) {
 
2369     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
 
2373       processParseExceptionDebug(e);
 
2375   [ <ASSIGN> expression = Expression()
 
2377     final AbstractVariable[] vars = new AbstractVariable[list.size()];
 
2379     return new ListExpression(vars,
 
2381                               listToken.sourceStart,
 
2382                               expression.sourceEnd);}
 
2385     final AbstractVariable[] vars = new AbstractVariable[list.size()];
 
2387     return new ListExpression(vars,listToken.sourceStart,pos);}
 
2391  * An echo statement.
 
2392  * echo anyexpression (, otherexpression)*
 
2394 EchoStatement EchoStatement() :
 
2396   final ArrayList expressions = new ArrayList();
 
2399   Token token2 = null;
 
2402   token = <ECHO> expr = Expression()
 
2403   {expressions.add(expr);}
 
2405     <COMMA> expr = Expression()
 
2406     {expressions.add(expr);}
 
2409     token2 = <SEMICOLON>
 
2410   } catch (ParseException e) {
 
2411     if (e.currentToken.next.kind != 4) {
 
2412       errorMessage = "';' expected after 'echo' statement";
 
2414       errorStart   = e.currentToken.sourceEnd;
 
2415       errorEnd     = e.currentToken.sourceEnd;
 
2416       processParseExceptionDebug(e);
 
2420    final Expression[] exprs = new Expression[expressions.size()];
 
2421    expressions.toArray(exprs);
 
2422    if (token2 == null) {
 
2423      return new EchoStatement(exprs,token.sourceStart, exprs[exprs.length-1].sourceEnd);
 
2425    return new EchoStatement(exprs,token.sourceStart, token2.sourceEnd);
 
2429 GlobalStatement GlobalStatement() :
 
2432    final ArrayList vars = new ArrayList();
 
2433    final GlobalStatement global;
 
2434    final Token token, token2;
 
2440     {vars.add(expr);pos = expr.sourceEnd+1;}
 
2443     {vars.add(expr);pos = expr.sourceEnd+1;}
 
2446     token2 = <SEMICOLON>
 
2447     {pos = token2.sourceEnd+1;}
 
2448   } catch (ParseException e) {
 
2449     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
 
2453     processParseExceptionDebug(e);
 
2456     final Variable[] variables = new Variable[vars.size()];
 
2457     vars.toArray(variables);
 
2458     global = new GlobalStatement(currentSegment,
 
2462     currentSegment.add(global);
 
2466 StaticStatement StaticStatement() :
 
2468   final ArrayList vars = new ArrayList();
 
2469   VariableDeclaration expr;
 
2470   final Token token, token2;
 
2474   token = <STATIC> expr = VariableDeclarator() {vars.add(expr);pos = expr.sourceEnd+1;}
 
2476     <COMMA> expr = VariableDeclarator() {vars.add(expr);pos = expr.sourceEnd+1;}
 
2479     token2 = <SEMICOLON>
 
2480     {pos = token2.sourceEnd+1;}
 
2481   } catch (ParseException e) {
 
2482     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
 
2486     processParseException(e);
 
2489     final VariableDeclaration[] variables = new VariableDeclaration[vars.size()];
 
2490     vars.toArray(variables);
 
2491     return new StaticStatement(variables,
 
2496 LabeledStatement LabeledStatement() :
 
2499   final Statement statement;
 
2502   label = <IDENTIFIER> <COLON> statement = Statement()
 
2503   {return new LabeledStatement(label.image,statement,label.sourceStart,statement.sourceEnd);}
 
2515   final ArrayList list = new ArrayList();
 
2516   Statement statement;
 
2517   final Token token, token2;
 
2523     {pos = token.sourceEnd+1;start=token.sourceStart;}
 
2524   } catch (ParseException e) {
 
2525     errorMessage = "'{' expected";
 
2527     pos = PHPParser.token.sourceEnd+1;
 
2531     processParseExceptionDebug(e);
 
2533   ( statement = BlockStatement() {list.add(statement);pos = statement.sourceEnd+1;}
 
2534   | statement = htmlBlock()      {if (statement != null) {
 
2535                                     list.add(statement);
 
2536                                     pos = statement.sourceEnd+1;
 
2538                                   pos = PHPParser.token.sourceEnd+1;
 
2543     {pos = token2.sourceEnd+1;}
 
2544   } catch (ParseException e) {
 
2545     errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
 
2549     processParseExceptionDebug(e);
 
2552   final Statement[] statements = new Statement[list.size()];
 
2553   list.toArray(statements);
 
2554   return new Block(statements,start,pos);}
 
2557 Statement BlockStatement() :
 
2559   final Statement statement;
 
2563     statement = Statement()         {if (phpDocument == currentSegment) pushOnAstNodes(statement);
 
2565   } catch (ParseException e) {
 
2566     errorMessage = "unexpected token : '"+ e.currentToken.image +"', a statement was expected";
 
2568     errorStart = e.currentToken.sourceStart;
 
2569     errorEnd   = e.currentToken.sourceEnd;
 
2572 | statement = ClassDeclaration()  {return statement;}
 
2573 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
 
2574                                    currentSegment.add((MethodDeclaration) statement);
 
2575                                    ((MethodDeclaration) statement).analyzeCode();
 
2580  * A Block statement that will not contain any 'break'
 
2582 Statement BlockStatementNoBreak() :
 
2584   final Statement statement;
 
2587   statement = StatementNoBreak()  {return statement;}
 
2588 | statement = ClassDeclaration()  {return statement;}
 
2589 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
 
2590                                    ((MethodDeclaration) statement).analyzeCode();
 
2595  * used only by ForInit()
 
2597 Expression[] LocalVariableDeclaration() :
 
2599   final ArrayList list = new ArrayList();
 
2605   ( <COMMA> var = Expression() {list.add(var);})*
 
2607     final Expression[] vars = new Expression[list.size()];
 
2614  * used only by LocalVariableDeclaration().
 
2616 VariableDeclaration LocalVariableDeclarator() :
 
2618   final Variable varName;
 
2619   Expression initializer = null;
 
2622   varName = Variable() [ <ASSIGN> initializer = Expression() ]
 
2624    if (initializer == null) {
 
2625     return new VariableDeclaration(currentSegment,
 
2627                                    varName.sourceStart,
 
2630     return new VariableDeclaration(currentSegment,
 
2633                                    VariableDeclaration.EQUAL,
 
2634                                    varName.sourceStart);
 
2638 EmptyStatement EmptyStatement() :
 
2644   {return new EmptyStatement(token.sourceStart,token.sourceEnd);}
 
2648  * used only by StatementExpressionList() which is used only by ForInit() and ForStatement()
 
2650 Expression StatementExpression() :
 
2652   final Expression expr;
 
2653   final Token operator;
 
2656   expr = PreIncDecExpression() {return expr;}
 
2658   expr = PrimaryExpression()
 
2659   [ operator = <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
 
2660                                                                 OperatorIds.PLUS_PLUS,
 
2661                                                                 operator.sourceEnd);}
 
2662   | operator = <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
 
2663                                                                   OperatorIds.MINUS_MINUS,
 
2664                                                                   operator.sourceEnd);}
 
2669 SwitchStatement SwitchStatement() :
 
2671   Expression variable;
 
2672   final AbstractCase[] cases;
 
2673   final Token switchToken,lparenToken,rparenToken;
 
2677   switchToken = <SWITCH> {pos = switchToken.sourceEnd+1;}
 
2679     lparenToken = <LPAREN>
 
2680     {pos = lparenToken.sourceEnd+1;}
 
2681   } catch (ParseException e) {
 
2682     errorMessage = "'(' expected after 'switch'";
 
2686     processParseExceptionDebug(e);
 
2689     variable = Expression() {pos = variable.sourceEnd+1;}
 
2690   } catch (ParseException e) {
 
2691     if (errorMessage != null) {
 
2694     errorMessage = "expression expected";
 
2698     processParseExceptionDebug(e);
 
2699     variable = new ConstantIdentifier(SYNTAX_ERROR_CHAR,pos,pos);
 
2702     rparenToken = <RPAREN> {pos = rparenToken.sourceEnd+1;}
 
2703   } catch (ParseException e) {
 
2704     errorMessage = "')' expected";
 
2708     processParseExceptionDebug(e);
 
2710   (  cases = switchStatementBrace()
 
2711    | cases = switchStatementColon(switchToken.sourceStart, switchToken.sourceEnd))
 
2712   {return new SwitchStatement(variable,
 
2714                               switchToken.sourceStart,
 
2715                               PHPParser.token.sourceEnd);}
 
2718 AbstractCase[] switchStatementBrace() :
 
2721   final ArrayList cases = new ArrayList();
 
2726   token = <LBRACE> {pos = token.sourceEnd;}
 
2727  ( cas = switchLabel0() {cases.add(cas);pos = cas.sourceEnd;})*
 
2730     {pos = token.sourceEnd;}
 
2731   } catch (ParseException e) {
 
2732     errorMessage = "'}' expected";
 
2736     processParseExceptionDebug(e);
 
2739     final AbstractCase[] abcase = new AbstractCase[cases.size()];
 
2740     cases.toArray(abcase);
 
2746  * A Switch statement with : ... endswitch;
 
2747  * @param start the begin offset of the switch
 
2748  * @param end the end offset of the switch
 
2750 AbstractCase[] switchStatementColon(final int start, final int end) :
 
2753   final ArrayList cases = new ArrayList();
 
2758   token = <COLON> {pos = token.sourceEnd;}
 
2760   setMarker(fileToParse,
 
2761             "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
 
2765             "Line " + token.beginLine);
 
2766   } catch (CoreException e) {
 
2767     PHPeclipsePlugin.log(e);
 
2769   ( cas = switchLabel0() {cases.add(cas);pos = cas.sourceEnd;})*
 
2771     token = <ENDSWITCH> {pos = token.sourceEnd;}
 
2772   } catch (ParseException e) {
 
2773     errorMessage = "'endswitch' expected";
 
2777     processParseExceptionDebug(e);
 
2780     token = <SEMICOLON> {pos = token.sourceEnd;}
 
2781   } catch (ParseException e) {
 
2782     errorMessage = "';' expected after 'endswitch' keyword";
 
2786     processParseExceptionDebug(e);
 
2789     final AbstractCase[] abcase = new AbstractCase[cases.size()];
 
2790     cases.toArray(abcase);
 
2795 AbstractCase switchLabel0() :
 
2797   final Expression expr;
 
2798   Statement statement;
 
2799   final ArrayList stmts = new ArrayList();
 
2800   final Token token = PHPParser.token;
 
2803   expr = SwitchLabel()
 
2804   ( statement = BlockStatementNoBreak() {stmts.add(statement);}
 
2805   | statement = htmlBlock()             {if (statement != null) {stmts.add(statement);}}
 
2806   | statement = BreakStatement()        {stmts.add(statement);})*
 
2807   //[ statement = BreakStatement()        {stmts.add(statement);}]
 
2809     final int listSize = stmts.size();
 
2810     final Statement[] stmtsArray = new Statement[listSize];
 
2811     stmts.toArray(stmtsArray);
 
2812     if (expr == null) {//it's a default
 
2813       return new DefaultCase(stmtsArray,token.sourceStart,stmtsArray[listSize-1].sourceEnd);
 
2815     if (listSize != 0) {
 
2816       return new Case(expr,stmtsArray,expr.sourceStart,stmtsArray[listSize-1].sourceEnd);
 
2818       return new Case(expr,stmtsArray,expr.sourceStart,expr.sourceEnd);
 
2825  * case Expression() :
 
2827  * @return the if it was a case and null if not
 
2829 Expression SwitchLabel() :
 
2831   final Expression expr;
 
2837   } catch (ParseException e) {
 
2838     if (errorMessage != null) throw e;
 
2839     errorMessage = "expression expected after 'case' keyword";
 
2841     errorStart = token.sourceEnd +1;
 
2842     errorEnd   = token.sourceEnd +1;
 
2848   } catch (ParseException e) {
 
2849     errorMessage = "':' expected after case expression";
 
2851     errorStart = expr.sourceEnd+1;
 
2852     errorEnd   = expr.sourceEnd+1;
 
2853     processParseExceptionDebug(e);
 
2859   } catch (ParseException e) {
 
2860     errorMessage = "':' expected after 'default' keyword";
 
2862     errorStart = token.sourceEnd+1;
 
2863     errorEnd   = token.sourceEnd+1;
 
2864     processParseExceptionDebug(e);
 
2869 Break BreakStatement() :
 
2871   Expression expression = null;
 
2872   final Token token, token2;
 
2876   token = <BREAK> {pos = token.sourceEnd+1;}
 
2877   [ expression = Expression() {pos = expression.sourceEnd+1;}]
 
2879     token2 = <SEMICOLON>
 
2880     {pos = token2.sourceEnd;}
 
2881   } catch (ParseException e) {
 
2882     errorMessage = "';' expected after 'break' keyword";
 
2886     processParseExceptionDebug(e);
 
2888   {return new Break(expression, token.sourceStart, pos);}
 
2891 IfStatement IfStatement() :
 
2893   final Expression condition;
 
2894   final IfStatement ifStatement;
 
2898   token = <IF> condition = Condition("if")
 
2899   ifStatement = IfStatement0(condition,token.sourceStart,token.sourceEnd)
 
2900   {return ifStatement;}
 
2904 Expression Condition(final String keyword) :
 
2906   final Expression condition;
 
2911   } catch (ParseException e) {
 
2912     errorMessage = "'(' expected after " + keyword + " keyword";
 
2914     errorStart = PHPParser.token.sourceEnd + 1;
 
2915     errorEnd   = PHPParser.token.sourceEnd + 1;
 
2916     processParseExceptionDebug(e);
 
2918   condition = Expression()
 
2921   } catch (ParseException e) {
 
2922     errorMessage = "')' expected after " + keyword + " keyword";
 
2924     errorStart = condition.sourceEnd+1;
 
2925     errorEnd   = condition.sourceEnd+1;
 
2926     processParseExceptionDebug(e);
 
2931 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
 
2933   Statement statement;
 
2934   final Statement stmt;
 
2935   final Statement[] statementsArray;
 
2936   ElseIf elseifStatement;
 
2937   Else elseStatement = null;
 
2938   final ArrayList stmts;
 
2939   final ArrayList elseIfList = new ArrayList();
 
2940   final ElseIf[] elseIfs;
 
2941   int pos = SimpleCharStream.getPosition();
 
2942   final int endStatements;
 
2946   {stmts = new ArrayList();}
 
2947   (  statement = Statement() {stmts.add(statement);}
 
2948    | statement = htmlBlock() {if (statement != null) {stmts.add(statement);}})*
 
2949    {endStatements = SimpleCharStream.getPosition();}
 
2950    (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
 
2951    [elseStatement = ElseStatementColon()]
 
2954   setMarker(fileToParse,
 
2955             "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
 
2959             "Line " + token.beginLine);
 
2960   } catch (CoreException e) {
 
2961     PHPeclipsePlugin.log(e);
 
2965   } catch (ParseException e) {
 
2966     errorMessage = "'endif' expected";
 
2968     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2969     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2974   } catch (ParseException e) {
 
2975     errorMessage = "';' expected after 'endif' keyword";
 
2977     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
2978     errorEnd   = SimpleCharStream.getPosition() + 1;
 
2982     elseIfs = new ElseIf[elseIfList.size()];
 
2983     elseIfList.toArray(elseIfs);
 
2984     if (stmts.size() == 1) {
 
2985       return new IfStatement(condition,
 
2986                              (Statement) stmts.get(0),
 
2990                               SimpleCharStream.getPosition());
 
2992       statementsArray = new Statement[stmts.size()];
 
2993       stmts.toArray(statementsArray);
 
2994       return new IfStatement(condition,
 
2995                              new Block(statementsArray,pos,endStatements),
 
2999                              SimpleCharStream.getPosition());
 
3004   (stmt = Statement() | stmt = htmlBlock())
 
3005   ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
 
3009       {pos = SimpleCharStream.getPosition();}
 
3010       statement = Statement()
 
3011       {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
 
3012     } catch (ParseException e) {
 
3013       if (errorMessage != null) {
 
3016       errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
 
3018       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
3019       errorEnd   = SimpleCharStream.getPosition() + 1;
 
3024     elseIfs = new ElseIf[elseIfList.size()];
 
3025     elseIfList.toArray(elseIfs);
 
3026     return new IfStatement(condition,
 
3031                            SimpleCharStream.getPosition());}
 
3034 ElseIf ElseIfStatementColon() :
 
3036   final Expression condition;
 
3037   Statement statement;
 
3038   final ArrayList list = new ArrayList();
 
3039   final Token elseifToken;
 
3042   elseifToken = <ELSEIF> condition = Condition("elseif")
 
3043   <COLON> (  statement = Statement() {list.add(statement);}
 
3044            | statement = htmlBlock() {if (statement != null) {list.add(statement);}})*
 
3046   final int sizeList = list.size();
 
3047   final Statement[] stmtsArray = new Statement[sizeList];
 
3048   list.toArray(stmtsArray);
 
3049   return new ElseIf(condition,stmtsArray ,
 
3050                     elseifToken.sourceStart,
 
3051                     stmtsArray[sizeList-1].sourceEnd);}
 
3054 Else ElseStatementColon() :
 
3056   Statement statement;
 
3057   final ArrayList list = new ArrayList();
 
3058   final Token elseToken;
 
3061   elseToken = <ELSE> <COLON> (  statement = Statement() {list.add(statement);}
 
3062                   | statement = htmlBlock() {if (statement != null) {list.add(statement);}})*
 
3064   final int sizeList = list.size();
 
3065   final Statement[] stmtsArray = new Statement[sizeList];
 
3066   list.toArray(stmtsArray);
 
3067   return new Else(stmtsArray,elseToken.sourceStart,stmtsArray[sizeList-1].sourceEnd);}
 
3070 ElseIf ElseIfStatement() :
 
3072   final Expression condition;
 
3073   //final Statement statement;
 
3074   final Token elseifToken;
 
3075   final Statement[] statement = new Statement[1];
 
3078   elseifToken = <ELSEIF> condition = Condition("elseif") statement[0] = Statement()
 
3080   return new ElseIf(condition,statement,elseifToken.sourceStart,statement[0].sourceEnd);}
 
3083 WhileStatement WhileStatement() :
 
3085   final Expression condition;
 
3086   final Statement action;
 
3087   final Token whileToken;
 
3090   whileToken = <WHILE>
 
3091     condition = Condition("while")
 
3092     action    = WhileStatement0(whileToken.sourceStart,whileToken.sourceEnd)
 
3093     {return new WhileStatement(condition,action,whileToken.sourceStart,action.sourceEnd);}
 
3096 Statement WhileStatement0(final int start, final int end) :
 
3098   Statement statement;
 
3099   final ArrayList stmts = new ArrayList();
 
3100   final int pos = SimpleCharStream.getPosition();
 
3103   <COLON> (statement = Statement() {stmts.add(statement);})*
 
3105   setMarker(fileToParse,
 
3106             "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
 
3110             "Line " + token.beginLine);
 
3111   } catch (CoreException e) {
 
3112     PHPeclipsePlugin.log(e);
 
3116   } catch (ParseException e) {
 
3117     errorMessage = "'endwhile' expected";
 
3119     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
3120     errorEnd   = SimpleCharStream.getPosition() + 1;
 
3126     final Statement[] stmtsArray = new Statement[stmts.size()];
 
3127     stmts.toArray(stmtsArray);
 
3128     return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
 
3129   } catch (ParseException e) {
 
3130     errorMessage = "';' expected after 'endwhile' keyword";
 
3132     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
 
3133     errorEnd   = SimpleCharStream.getPosition() + 1;
 
3137   statement = Statement()
 
3141 DoStatement DoStatement() :
 
3143   final Statement action;
 
3144   final Expression condition;
 
3146   Token token2 = null;
 
3149   token = <DO> action = Statement() <WHILE> condition = Condition("while")
 
3151     token2 = <SEMICOLON>
 
3152   } catch (ParseException e) {
 
3153     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
 
3155     errorStart = condition.sourceEnd+1;
 
3156     errorEnd   = condition.sourceEnd+1;
 
3157     processParseExceptionDebug(e);
 
3160     if (token2 == null) {
 
3161       return new DoStatement(condition,action,token.sourceStart,condition.sourceEnd);
 
3163     return new DoStatement(condition,action,token.sourceStart,token2.sourceEnd);
 
3167 ForeachStatement ForeachStatement() :
 
3169   Statement statement = null;
 
3170   Expression expression = null;
 
3171   ArrayVariableDeclaration variable = null;
 
3173   Token lparenToken = null;
 
3174   Token asToken = null;
 
3175   Token rparenToken = null;
 
3179   foreachToken = <FOREACH>
 
3181     lparenToken = <LPAREN>
 
3182     {pos = lparenToken.sourceEnd+1;}
 
3183   } catch (ParseException e) {
 
3184     errorMessage = "'(' expected after 'foreach' keyword";
 
3186     errorStart = foreachToken.sourceEnd+1;
 
3187     errorEnd   = foreachToken.sourceEnd+1;
 
3188     processParseExceptionDebug(e);
 
3189     {pos = foreachToken.sourceEnd+1;}
 
3192     expression = Expression()
 
3193     {pos = expression.sourceEnd+1;}
 
3194   } catch (ParseException e) {
 
3195     errorMessage = "variable expected";
 
3199     processParseExceptionDebug(e);
 
3203     {pos = asToken.sourceEnd+1;}
 
3204   } catch (ParseException e) {
 
3205     errorMessage = "'as' expected";
 
3209     processParseExceptionDebug(e);
 
3212     variable = ArrayVariable()
 
3213     {pos = variable.sourceEnd+1;}
 
3214   } catch (ParseException e) {
 
3215     if (errorMessage != null) throw e;
 
3216     errorMessage = "variable expected";
 
3220     processParseExceptionDebug(e);
 
3223     rparenToken = <RPAREN>
 
3224     {pos = rparenToken.sourceEnd+1;}
 
3225   } catch (ParseException e) {
 
3226     errorMessage = "')' expected after 'foreach' keyword";
 
3230     processParseExceptionDebug(e);
 
3233     statement = Statement()
 
3234     {pos = rparenToken.sourceEnd+1;}
 
3235   } catch (ParseException e) {
 
3236     if (errorMessage != null) throw e;
 
3237     errorMessage = "statement expected";
 
3241     processParseExceptionDebug(e);
 
3243   {return new ForeachStatement(expression,
 
3246                                foreachToken.sourceStart,
 
3247                                statement.sourceEnd);}
 
3252  * a for declaration.
 
3253  * @return a node representing the for statement
 
3255 ForStatement ForStatement() :
 
3257 final Token token,tokenEndFor,token2,tokenColon;
 
3259 Expression[] initializations = null;
 
3260 Expression condition = null;
 
3261 Expression[] increments = null;
 
3263 final ArrayList list = new ArrayList();
 
3269   } catch (ParseException e) {
 
3270     errorMessage = "'(' expected after 'for' keyword";
 
3272     errorStart = token.sourceEnd;
 
3273     errorEnd   = token.sourceEnd +1;
 
3274     processParseExceptionDebug(e);
 
3276      [ initializations = ForInit() ] <SEMICOLON>
 
3277      [ condition = Expression() ] <SEMICOLON>
 
3278      [ increments = StatementExpressionList() ] <RPAREN>
 
3280       action = Statement()
 
3281       {return new ForStatement(initializations,
 
3288       tokenColon = <COLON> {pos = tokenColon.sourceEnd+1;}
 
3289       (action = Statement() {list.add(action);pos = action.sourceEnd+1;})*
 
3292         setMarker(fileToParse,
 
3293                   "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
 
3297                   "Line " + token.beginLine);
 
3298         } catch (CoreException e) {
 
3299           PHPeclipsePlugin.log(e);
 
3303         tokenEndFor = <ENDFOR>
 
3304         {pos = tokenEndFor.sourceEnd+1;}
 
3305       } catch (ParseException e) {
 
3306         errorMessage = "'endfor' expected";
 
3310         processParseExceptionDebug(e);
 
3313         token2 = <SEMICOLON>
 
3314         {pos = token2.sourceEnd+1;}
 
3315       } catch (ParseException e) {
 
3316         errorMessage = "';' expected after 'endfor' keyword";
 
3320         processParseExceptionDebug(e);
 
3323       final Statement[] stmtsArray = new Statement[list.size()];
 
3324       list.toArray(stmtsArray);
 
3325       return new ForStatement(initializations,
 
3328                               new Block(stmtsArray,
 
3329                                         stmtsArray[0].sourceStart,
 
3330                                         stmtsArray[stmtsArray.length-1].sourceEnd),
 
3336 Expression[] ForInit() :
 
3338   final Expression[] exprs;
 
3341   LOOKAHEAD(LocalVariableDeclaration())
 
3342   exprs = LocalVariableDeclaration()
 
3345   exprs = StatementExpressionList()
 
3349 Expression[] StatementExpressionList() :
 
3351   final ArrayList list = new ArrayList();
 
3352   final Expression expr;
 
3355   expr = Expression()   {list.add(expr);}
 
3356   (<COMMA> Expression() {list.add(expr);})*
 
3358     final Expression[] exprsArray = new Expression[list.size()];
 
3359     list.toArray(exprsArray);
 
3364 Continue ContinueStatement() :
 
3366   Expression expr = null;
 
3368   Token token2 = null;
 
3371   token = <CONTINUE> [ expr = Expression() ]
 
3373     token2 = <SEMICOLON>
 
3374   } catch (ParseException e) {
 
3375     errorMessage = "';' expected after 'continue' statement";
 
3378       errorStart = token.sourceEnd+1;
 
3379       errorEnd   = token.sourceEnd+1;
 
3381       errorStart = expr.sourceEnd+1;
 
3382       errorEnd   = expr.sourceEnd+1;
 
3384     processParseExceptionDebug(e);
 
3387     if (token2 == null) {
 
3389         return new Continue(expr,token.sourceStart,token.sourceEnd);
 
3391       return new Continue(expr,token.sourceStart,expr.sourceEnd);
 
3393     return new Continue(expr,token.sourceStart,token2.sourceEnd);
 
3397 ReturnStatement ReturnStatement() :
 
3399   Expression expr = null;
 
3401   Token token2 = null;
 
3404   token = <RETURN> [ expr = Expression() ]
 
3406     token2 = <SEMICOLON>
 
3407   } catch (ParseException e) {
 
3408     errorMessage = "';' expected after 'return' statement";
 
3411       errorStart = token.sourceEnd+1;
 
3412       errorEnd   = token.sourceEnd+1;
 
3414       errorStart = expr.sourceEnd+1;
 
3415       errorEnd   = expr.sourceEnd+1;
 
3417     processParseExceptionDebug(e);
 
3420     if (token2 == null) {
 
3422         return new ReturnStatement(expr,token.sourceStart,token.sourceEnd);
 
3424       return new ReturnStatement(expr,token.sourceStart,expr.sourceEnd);
 
3426     return new ReturnStatement(expr,token.sourceStart,token2.sourceEnd);