1 /***********************************************************************************************************************************
 
   2  * Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de All rights reserved. This program and the accompanying material are
 
   3  * made available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
 
   4  * http://www.eclipse.org/legal/cpl-v10.html
 
   6  * Contributors: Klaus Hartlage - www.eclipseproject.de
 
   7  **********************************************************************************************************************************/
 
   8 package net.sourceforge.phpdt.internal.compiler.parser;
 
  10 import java.util.ArrayList;
 
  12 import net.sourceforge.phpdt.core.compiler.CharOperation;
 
  13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 
  14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
 
  15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
 
  16 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
 
  17 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
 
  18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
 
  19 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
 
  20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
 
  21 import net.sourceforge.phpdt.internal.compiler.util.Util;
 
  22 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
 
  23 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
 
  24 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
 
  25 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
 
  26 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
 
  27 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
 
  28 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
 
  29 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
 
  30 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
 
  31 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
 
  32 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
 
  33 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
 
  35 import org.eclipse.core.resources.IFile;
 
  37 public class Parser //extends PHPParserSuperclass
 
  38     implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
 
  39   //internal data for the automat
 
  40   protected final static int StackIncrement = 255;
 
  42   protected int stateStackTop;
 
  44   protected int[] stack = new int[StackIncrement];
 
  46   public int firstToken; // handle for multiple parsing goals
 
  48   public int lastAct; //handle for multiple parsing goals
 
  50   protected RecoveredElement currentElement;
 
  52   public static boolean VERBOSE_RECOVERY = false;
 
  54   protected boolean diet = false; //tells the scanner to jump over some
 
  56   // parts of the code/expressions like
 
  59   public Scanner scanner;
 
  61   private ArrayList phpList;
 
  63   private int currentPHPString;
 
  65   private boolean phpEnd;
 
  67   // private static HashMap keywordMap = null;
 
  75   // row counter for syntax errors:
 
  77   // column counter for syntax errors:
 
  81   //    // current identifier
 
  87   private String stringValue;
 
  89   /** Contains the current expression. */
 
  90   // private StringBuffer expression;
 
  91   //private boolean phpMode;
 
  92   protected int modifiers;
 
  94   protected int modifiersSourceStart;
 
  96   //  protected IdentifierIndexManager indexManager;
 
  98   protected Parser(ProblemReporter problemReporter) {
 
  99     this.problemReporter = problemReporter;
 
 100     this.options = problemReporter.options;
 
 101     this.currentPHPString = 0;
 
 102     //          PHPParserSuperclass.fileToParse = fileToParse;
 
 104     //    this.indexManager = null;
 
 106     this.token = TokenNameEOF;
 
 108     //    this.rowCount = 1;
 
 109     //    this.columnCount = 0;
 
 112     this.initializeScanner();
 
 115   public void setFileToParse(IFile fileToParse) {
 
 116     this.currentPHPString = 0;
 
 117     //    PHPParserSuperclass.fileToParse = fileToParse;
 
 119     //    this.indexManager = null;
 
 121     this.token = TokenNameEOF;
 
 123     this.initializeScanner();
 
 127    * ClassDeclaration Constructor.
 
 131    *          Description of Parameter
 
 134   public Parser(IFile fileToParse) {
 
 135     //    if (keywordMap == null) {
 
 136     //      keywordMap = new HashMap();
 
 137     //      for (int i = 0; i < PHP_KEYWORS.length; i++) {
 
 138     //        keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
 
 141     this.currentPHPString = 0;
 
 142     //    PHPParserSuperclass.fileToParse = fileToParse;
 
 144     this.includesList = null;
 
 146     this.token = TokenNameEOF;
 
 148     //    this.rowCount = 1;
 
 149     //    this.columnCount = 0;
 
 152     this.initializeScanner();
 
 155   public void initializeScanner() {
 
 156     this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
 
 157         .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
 
 158         this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */);
 
 162    * Create marker for the parse error
 
 164   //  private void setMarker(String message, int charStart, int charEnd, int
 
 166   //    setMarker(fileToParse, message, charStart, charEnd, errorLevel);
 
 169    * This method will throw the SyntaxError. It will add the good lines and columns to the Error
 
 173    * @throws SyntaxError
 
 176   private void throwSyntaxError(String error) {
 
 177     int problemStartPosition = scanner.getCurrentTokenStartPosition();
 
 178     int problemEndPosition = scanner.getCurrentTokenEndPosition();
 
 179     throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
 
 183    * This method will throw the SyntaxError. It will add the good lines and columns to the Error
 
 187    * @throws SyntaxError
 
 190   //  private void throwSyntaxError(String error, int startRow) {
 
 191   //    throw new SyntaxError(startRow, 0, " ", error);
 
 193   private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
 
 194     problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
 
 195         compilationUnit.compilationResult);
 
 196     throw new SyntaxError(1, 0, " ", error);
 
 199   private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
 
 200     problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
 
 201         compilationUnit.compilationResult);
 
 204   private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
 
 205     problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
 
 206         compilationUnit.compilationResult);
 
 210    * Method Declaration.
 
 214   //  private void getChar() {
 
 215   //    if (str.length() > chIndx) {
 
 216   //      ch = str.charAt(chIndx++);
 
 221   //    chIndx = str.length() + 1;
 
 223   //    // token = TokenNameEOF;
 
 227    * gets the next token from input
 
 229   private void getNextToken() {
 
 231       token = scanner.getNextToken();
 
 233         int currentEndPosition = scanner.getCurrentTokenEndPosition();
 
 234         int currentStartPosition = scanner.getCurrentTokenStartPosition();
 
 235         System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
 
 236         System.out.println(scanner.toStringAction(token));
 
 238     } catch (InvalidInputException e) {
 
 239       token = TokenNameERROR;
 
 240       String detailedMessage = e.getMessage();
 
 242       if (detailedMessage == Scanner.UNTERMINATED_STRING) {
 
 243         throwSyntaxError("Unterminated string.");
 
 244       } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
 
 245         throwSyntaxError("Unterminated commment.");
 
 251   public void init(String s) {
 
 253     this.token = TokenNameEOF;
 
 255     //    this.rowCount = 1;
 
 256     //    this.columnCount = 0;
 
 258     //    this.phpMode = false;
 
 259     /* scanner initialization */
 
 260     scanner.setSource(s.toCharArray());
 
 261     scanner.setPHPMode(false);
 
 264   protected void initialize(boolean phpMode) {
 
 265     initialize(phpMode, null);
 
 268   protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
 
 269     compilationUnit = null;
 
 270     referenceContext = null;
 
 271     includesList = new ArrayList();
 
 272     //    this.indexManager = indexManager;
 
 274     this.token = TokenNameEOF;
 
 276     //    this.rowCount = 1;
 
 277     //    this.columnCount = 0;
 
 279     //    this.phpMode = phpMode;
 
 280     scanner.setPHPMode(phpMode);
 
 284    * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
 
 286   public void parse(String s) {
 
 292    * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
 
 294   protected void parse() {
 
 298         if (token != TokenNameEOF && token != TokenNameERROR) {
 
 301         if (token != TokenNameEOF) {
 
 302           if (token == TokenNameERROR) {
 
 303             throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
 
 305           if (token == TokenNameRPAREN) {
 
 306             throwSyntaxError("Too many closing ')'; end-of-file not reached.");
 
 308           if (token == TokenNameRBRACE) {
 
 309             throwSyntaxError("Too many closing '}'; end-of-file not reached.");
 
 311           if (token == TokenNameRBRACKET) {
 
 312             throwSyntaxError("Too many closing ']'; end-of-file not reached.");
 
 314           if (token == TokenNameLPAREN) {
 
 315             throwSyntaxError("Read character '('; end-of-file not reached.");
 
 317           if (token == TokenNameLBRACE) {
 
 318             throwSyntaxError("Read character '{';  end-of-file not reached.");
 
 320           if (token == TokenNameLBRACKET) {
 
 321             throwSyntaxError("Read character '[';  end-of-file not reached.");
 
 323           throwSyntaxError("End-of-file not reached.");
 
 326       } catch (SyntaxError sytaxErr1) {
 
 327         // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
 
 329         //        setMarker(sytaxErr1.getMessage(),
 
 330         // scanner.getCurrentTokenStartPosition(),
 
 331         // scanner.getCurrentTokenEndPosition(), ERROR);
 
 333           // if an error occured,
 
 334           // try to find keywords 'class' or 'function'
 
 335           // to parse the rest of the string
 
 336           while (token != TokenNameEOF && token != TokenNameERROR) {
 
 337             if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
 
 342           if (token == TokenNameEOF || token == TokenNameERROR) {
 
 345         } catch (SyntaxError sytaxErr2) {
 
 346           //    setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
 
 348           //          setMarker(sytaxErr2.getMessage(),
 
 349           // scanner.getCurrentTokenStartPosition(),
 
 350           // scanner.getCurrentTokenEndPosition(), ERROR);
 
 359   protected CompilationUnitDeclaration endParse(int act) {
 
 363     if (currentElement != null) {
 
 364       currentElement.topElement().updateParseTree();
 
 365       if (VERBOSE_RECOVERY) {
 
 366         System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
 
 367         System.out.println("--------------------------"); //$NON-NLS-1$
 
 368         System.out.println(compilationUnit);
 
 369         System.out.println("----------------------------------"); //$NON-NLS-1$
 
 372       if (diet & VERBOSE_RECOVERY) {
 
 373         System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
 
 374         System.out.println("--------------------------"); //$NON-NLS-1$
 
 375         System.out.println(compilationUnit);
 
 376         System.out.println("----------------------------------"); //$NON-NLS-1$
 
 379     if (scanner.recordLineSeparator) {
 
 380       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
 
 382     if (scanner.taskTags != null) {
 
 383       for (int i = 0; i < scanner.foundTaskCount; i++) {
 
 384         problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
 
 385             scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
 
 386             scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
 
 389     compilationUnit.imports = new ImportReference[includesList.size()];
 
 390     for (int i = 0; i < includesList.size(); i++) {
 
 391       compilationUnit.imports[i] = (ImportReference) includesList.get(i);
 
 393     return compilationUnit;
 
 396   //  public PHPOutlineInfo parseInfo(Object parent, String s) {
 
 397   //    PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
 
 398   //    // Stack stack = new Stack();
 
 399   //    // stack.push(outlineInfo.getDeclarations());
 
 401   //    this.token = TokenNameEOF;
 
 402   //    // this.chIndx = 0;
 
 403   //    // this.rowCount = 1;
 
 404   //    // this.columnCount = 0;
 
 405   //    this.phpEnd = false;
 
 406   //    this.phpMode = false;
 
 407   //    scanner.setSource(s.toCharArray());
 
 408   //    scanner.setPHPMode(false);
 
 411   //    parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
 
 413   //    return outlineInfo;
 
 415   private boolean isVariable() {
 
 416     return token == TokenNameVariable; //  || token == TokenNamethis;
 
 419   //  private void parseDeclarations(PHPOutlineInfo outlineInfo,
 
 420   //      OutlineableWithChildren current, boolean goBack) {
 
 422   //    // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
 
 423   //    PHPSegmentWithChildren temp;
 
 425   //    IPreferenceStore store =
 
 426   // PHPeclipsePlugin.getDefault().getPreferenceStore();
 
 428   //      while (token != TokenNameEOF && token != TokenNameERROR) {
 
 429   //        if (token == TokenNameVariable) {
 
 430   //          ident = scanner.getCurrentIdentifierSource();
 
 431   //          outlineInfo.addVariable(new String(ident));
 
 433   //        } else if (token == TokenNamevar) {
 
 435   //          if (token == TokenNameVariable
 
 436   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
 
 437   //            ident = scanner.getCurrentIdentifierSource();
 
 438   //            //substring(1) added because PHPVarDeclaration doesn't
 
 439   //            // need the $ anymore
 
 440   //            String variableName = new String(ident).substring(1);
 
 441   //            outlineInfo.addVariable(variableName);
 
 443   //            if (token != TokenNameSEMICOLON) {
 
 445   //              ident = scanner.getCurrentTokenSource();
 
 446   //              if (token > TokenNameKEYWORD) {
 
 447   //                current.add(new PHPVarDeclaration(current, variableName,
 
 448   //                // chIndx - ident.length,
 
 449   //                    scanner.getCurrentTokenStartPosition(), new String(ident)));
 
 452   //                  case TokenNameVariable :
 
 453   //                  case TokenNamethis :
 
 454   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 457   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 460   //                  case TokenNameIdentifier :
 
 461   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 464   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 467   //                  case TokenNameDoubleLiteral :
 
 468   //                    current.add(new PHPVarDeclaration(current, variableName
 
 472   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 475   //                  case TokenNameIntegerLiteral :
 
 476   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 479   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 482   //                  case TokenNameStringInterpolated :
 
 483   //                  case TokenNameStringLiteral :
 
 484   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 487   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 490   //                  case TokenNameStringConstant :
 
 491   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 494   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 498   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 501   //                        scanner.getCurrentTokenStartPosition()));
 
 506   //              ident = scanner.getCurrentIdentifierSource();
 
 507   //              current.add(new PHPVarDeclaration(current, variableName,
 
 508   //              // chIndx - ident.length
 
 509   //                  scanner.getCurrentTokenStartPosition()));
 
 512   //        } else if (token == TokenNamefunction) {
 
 514   //          if (token == TokenNameAND) {
 
 517   //          if (token == TokenNameIdentifier
 
 518   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
 
 519   //            ident = scanner.getCurrentIdentifierSource();
 
 520   //            outlineInfo.addVariable(new String(ident));
 
 521   //            temp = new PHPFunctionDeclaration(current, new String(ident),
 
 522   //            // chIndx - ident.length
 
 523   //                scanner.getCurrentTokenStartPosition());
 
 524   //            current.add(temp);
 
 526   //            parseDeclarations(outlineInfo, temp, true);
 
 528   //        } else if (token == TokenNameclass) {
 
 530   //          if (token == TokenNameIdentifier
 
 531   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
 
 532   //            ident = scanner.getCurrentIdentifierSource();
 
 533   //            outlineInfo.addVariable(new String(ident));
 
 534   //            temp = new PHPClassDeclaration(current, new String(ident),
 
 535   //            // chIndx - ident.len
 
 536   //                scanner.getCurrentTokenStartPosition());
 
 537   //            current.add(temp);
 
 538   //            // stack.push(temp);
 
 540   //            //skip tokens for classname, extends and others until
 
 541   //            // we have the opening '{'
 
 542   //            while (token != TokenNameLBRACE && token != TokenNameEOF
 
 543   //                && token != TokenNameERROR) {
 
 546   //            parseDeclarations(outlineInfo, temp, true);
 
 549   //        } else if ((token == TokenNameLBRACE)
 
 550   //            || (token == TokenNameDOLLAR_LBRACE)) {
 
 553   //        } else if (token == TokenNameRBRACE) {
 
 556   //          if (counter == 0 && goBack) {
 
 559   //        } else if (token == TokenNamerequire || token == TokenNamerequire_once
 
 560   //            || token == TokenNameinclude || token == TokenNameinclude_once) {
 
 561   //          ident = scanner.getCurrentTokenSource();
 
 563   //          int startPosition = scanner.getCurrentTokenStartPosition();
 
 565   //          char[] expr = scanner.getCurrentTokenSource(startPosition);
 
 566   //          outlineInfo.addVariable(new String(ident));
 
 567   //          current.add(new PHPReqIncDeclaration(current, new String(ident),
 
 568   //          // chIndx - ident.length,
 
 569   //              startPosition, new String(expr)));
 
 575   //    } catch (SyntaxError sytaxErr) {
 
 577   //      // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
 
 578   //      // setMarker(sytaxErr.getMessage(),
 
 579   //      // scanner.getCurrentTokenStartPosition(),
 
 580   //      // scanner.getCurrentTokenEndPosition(), ERROR);
 
 581   //      // } catch (CoreException e) {
 
 585   private void statementList() {
 
 587       statement(TokenNameEOF);
 
 588       if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
 
 589           || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
 
 590           || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch) || (token == TokenNameenddeclare)
 
 591           || (token == TokenNameEOF) || (token == TokenNameERROR)) {
 
 597   private void functionBody(MethodDeclaration methodDecl) {
 
 598     // '{' [statement-list] '}'
 
 599     if (token == TokenNameLBRACE) {
 
 602       throwSyntaxError("'{' expected in compound-statement.");
 
 604     if (token != TokenNameRBRACE) {
 
 607     if (token == TokenNameRBRACE) {
 
 608       methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
 611       throwSyntaxError("'}' expected in compound-statement.");
 
 615   private Statement statement(int previousToken) {
 
 616     Statement statement = null;
 
 617     Expression expression;
 
 618     int sourceStart = scanner.getCurrentTokenStartPosition();
 
 619     if (token == TokenNameif) {
 
 621       if (token == TokenNameLPAREN) {
 
 624         throwSyntaxError("'(' expected after 'if' keyword.");
 
 627       if (token == TokenNameRPAREN) {
 
 630         throwSyntaxError("')' expected after 'if' condition.");
 
 633       return new IfStatement(expression, statement, sourceStart, scanner.getCurrentTokenEndPosition());
 
 634     } else if (token == TokenNameswitch) {
 
 636       if (token == TokenNameLPAREN) {
 
 639         throwSyntaxError("'(' expected after 'switch' keyword.");
 
 642       if (token == TokenNameRPAREN) {
 
 645         throwSyntaxError("')' expected after 'switch' condition.");
 
 649     } else if (token == TokenNamefor) {
 
 651       if (token == TokenNameLPAREN) {
 
 654         throwSyntaxError("'(' expected after 'for' keyword.");
 
 656       if (token == TokenNameSEMICOLON) {
 
 660         if (token == TokenNameSEMICOLON) {
 
 663           throwSyntaxError("';' expected after 'for'.");
 
 666       if (token == TokenNameSEMICOLON) {
 
 670         if (token == TokenNameSEMICOLON) {
 
 673           throwSyntaxError("';' expected after 'for'.");
 
 676       if (token == TokenNameRPAREN) {
 
 680         if (token == TokenNameRPAREN) {
 
 683           throwSyntaxError("')' expected after 'for'.");
 
 688     } else if (token == TokenNamewhile) {
 
 690       if (token == TokenNameLPAREN) {
 
 693         throwSyntaxError("'(' expected after 'while' keyword.");
 
 696       if (token == TokenNameRPAREN) {
 
 699         throwSyntaxError("')' expected after 'while' condition.");
 
 703     } else if (token == TokenNamedo) {
 
 705       if (token == TokenNameLBRACE) {
 
 707         if (token != TokenNameRBRACE) {
 
 710         if (token == TokenNameRBRACE) {
 
 713           throwSyntaxError("'}' expected after 'do' keyword.");
 
 716         statement(TokenNameEOF);
 
 718       if (token == TokenNamewhile) {
 
 720         if (token == TokenNameLPAREN) {
 
 723           throwSyntaxError("'(' expected after 'while' keyword.");
 
 726         if (token == TokenNameRPAREN) {
 
 729           throwSyntaxError("')' expected after 'while' condition.");
 
 732         throwSyntaxError("'while' expected after 'do' keyword.");
 
 734       if (token == TokenNameSEMICOLON) {
 
 737         if (token != TokenNameINLINE_HTML) {
 
 738           throwSyntaxError("';' expected after do-while statement.");
 
 743     } else if (token == TokenNameforeach) {
 
 745       if (token == TokenNameLPAREN) {
 
 748         throwSyntaxError("'(' expected after 'foreach' keyword.");
 
 751       if (token == TokenNameas) {
 
 754         throwSyntaxError("'as' expected after 'foreach' exxpression.");
 
 758       foreach_optional_arg();
 
 759       if (token == TokenNameEQUAL_GREATER) {
 
 763       if (token == TokenNameRPAREN) {
 
 766         throwSyntaxError("')' expected after 'foreach' expression.");
 
 770     } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
 
 772       if (token != TokenNameSEMICOLON) {
 
 775       if (token == TokenNameSEMICOLON) {
 
 778         if (token != TokenNameINLINE_HTML) {
 
 779           throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
 
 784     } else if (token == TokenNameecho) {
 
 787       if (token == TokenNameSEMICOLON) {
 
 790         if (token != TokenNameINLINE_HTML) {
 
 791           throwSyntaxError("';' expected after 'echo' statement.");
 
 796     } else if (token == TokenNameINLINE_HTML) {
 
 799       //    } else if (token == TokenNameprint) {
 
 802       //      if (token == TokenNameSEMICOLON) {
 
 805       //        if (token != TokenNameStopPHP) {
 
 806       //          throwSyntaxError("';' expected after 'print' statement.");
 
 811     } else if (token == TokenNameglobal) {
 
 814       if (token == TokenNameSEMICOLON) {
 
 817         if (token != TokenNameINLINE_HTML) {
 
 818           throwSyntaxError("';' expected after 'global' statement.");
 
 823     } else if (token == TokenNamestatic) {
 
 826       if (token == TokenNameSEMICOLON) {
 
 829         if (token != TokenNameINLINE_HTML) {
 
 830           throwSyntaxError("';' expected after 'static' statement.");
 
 835     } else if (token == TokenNameunset) {
 
 837       if (token == TokenNameLPAREN) {
 
 840         throwSyntaxError("'(' expected after 'unset' statement.");
 
 843       if (token == TokenNameRPAREN) {
 
 846         throwSyntaxError("')' expected after 'unset' statement.");
 
 848       if (token == TokenNameSEMICOLON) {
 
 851         if (token != TokenNameINLINE_HTML) {
 
 852           throwSyntaxError("';' expected after 'unset' statement.");
 
 857     } else if (token == TokenNamefunction) {
 
 858       MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
 
 859       methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
 860       methodDecl.modifiers = AccDefault;
 
 862       functionDefinition(methodDecl);
 
 864     } else if (token == TokenNamedeclare) {
 
 865       //T_DECLARE '(' declare_list ')' declare_statement
 
 867       if (token != TokenNameLPAREN) {
 
 868         throwSyntaxError("'(' expected in 'declare' statement.");
 
 872       if (token != TokenNameRPAREN) {
 
 873         throwSyntaxError("')' expected in 'declare' statement.");
 
 878     } else if (token == TokenNametry) {
 
 880       if (token != TokenNameLBRACE) {
 
 881         throwSyntaxError("'{' expected in 'try' statement.");
 
 885       if (token != TokenNameRBRACE) {
 
 886         throwSyntaxError("'}' expected in 'try' statement.");
 
 890     } else if (token == TokenNamecatch) {
 
 892       if (token != TokenNameLPAREN) {
 
 893         throwSyntaxError("'(' expected in 'catch' statement.");
 
 896       fully_qualified_class_name();
 
 897       if (token != TokenNameVariable) {
 
 898         throwSyntaxError("Variable expected in 'catch' statement.");
 
 901       if (token != TokenNameRPAREN) {
 
 902         throwSyntaxError("')' expected in 'catch' statement.");
 
 905       if (token != TokenNameLBRACE) {
 
 906         throwSyntaxError("'{' expected in 'catch' statement.");
 
 909       if (token != TokenNameRBRACE) {
 
 911         if (token != TokenNameRBRACE) {
 
 912           throwSyntaxError("'}' expected in 'catch' statement.");
 
 916       additional_catches();
 
 918     } else if (token == TokenNamethrow) {
 
 921       if (token == TokenNameSEMICOLON) {
 
 924         throwSyntaxError("';' expected after 'throw' exxpression.");
 
 927     } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
 
 928       TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
 
 929       typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
 930       typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
 931       typeDecl.name = new char[] { ' ' };
 
 932       // default super class
 
 933       typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
 
 934       compilationUnit.types.add(typeDecl);
 
 936         pushOnAstStack(typeDecl);
 
 937         unticked_class_declaration_statement(typeDecl);
 
 938         //        classBody(typeDecl);
 
 945       //        throwSyntaxError("Unexpected keyword '" + keyword + "'");
 
 946     } else if (token == TokenNameLBRACE) {
 
 948       if (token != TokenNameRBRACE) {
 
 951       if (token == TokenNameRBRACE) {
 
 955         throwSyntaxError("'}' expected.");
 
 958       if (token != TokenNameSEMICOLON) {
 
 961       if (token == TokenNameSEMICOLON) {
 
 965         if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
 
 966           throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
 
 975   private void declare_statement() {
 
 977     //| ':' inner_statement_list T_ENDDECLARE ';'
 
 979     if (token == TokenNameCOLON) {
 
 981       // TODO: implement inner_statement_list();
 
 983       if (token != TokenNameenddeclare) {
 
 984         throwSyntaxError("'enddeclare' expected in 'declare' statement.");
 
 987       if (token != TokenNameSEMICOLON) {
 
 988         throwSyntaxError("';' expected after 'enddeclare' keyword.");
 
 992       statement(TokenNameRPAREN);
 
 996   private void declare_list() {
 
 997     //  T_STRING '=' static_scalar
 
 998     //| declare_list ',' T_STRING '=' static_scalar
 
1000       if (token != TokenNameIdentifier) {
 
1001         throwSyntaxError("Identifier expected in 'declare' list.");
 
1004       if (token != TokenNameEQUAL) {
 
1005         throwSyntaxError("'=' expected in 'declare' list.");
 
1009       if (token != TokenNameCOMMA) {
 
1016   private void additional_catches() {
 
1017     while (token == TokenNamecatch) {
 
1019       if (token != TokenNameLPAREN) {
 
1020         throwSyntaxError("'(' expected in 'catch' statement.");
 
1023       fully_qualified_class_name();
 
1024       if (token != TokenNameVariable) {
 
1025         throwSyntaxError("Variable expected in 'catch' statement.");
 
1028       if (token != TokenNameRPAREN) {
 
1029         throwSyntaxError("')' expected in 'catch' statement.");
 
1032       if (token != TokenNameLBRACE) {
 
1033         throwSyntaxError("'{' expected in 'catch' statement.");
 
1036       if (token != TokenNameRBRACE) {
 
1039       if (token != TokenNameRBRACE) {
 
1040         throwSyntaxError("'}' expected in 'catch' statement.");
 
1046   private void foreach_variable() {
 
1049     if (token == TokenNameAND) {
 
1055   private void foreach_optional_arg() {
 
1057     //| T_DOUBLE_ARROW foreach_variable
 
1058     if (token == TokenNameEQUAL_GREATER) {
 
1064   private void global_var_list() {
 
1066     //  global_var_list ',' global_var
 
1070       if (token != TokenNameCOMMA) {
 
1077   private void global_var() {
 
1081     //| '$' '{' expr '}'
 
1082     if (token == TokenNameVariable) {
 
1084     } else if (token == TokenNameDOLLAR) {
 
1086       if (token == TokenNameLPAREN) {
 
1089         if (token != TokenNameLPAREN) {
 
1090           throwSyntaxError("')' expected in global variable.");
 
1099   private void static_var_list() {
 
1101     //  static_var_list ',' T_VARIABLE
 
1102     //| static_var_list ',' T_VARIABLE '=' static_scalar
 
1104     //| T_VARIABLE '=' static_scalar
 
1106       if (token == TokenNameVariable) {
 
1108         if (token == TokenNameEQUAL) {
 
1112         if (token != TokenNameCOMMA) {
 
1122   private void unset_variables() {
 
1125     //          | unset_variables ',' unset_variable
 
1130       if (token != TokenNameCOMMA) {
 
1137   private final void initializeModifiers() {
 
1139     this.modifiersSourceStart = -1;
 
1142   private final void checkAndSetModifiers(int flag) {
 
1143     this.modifiers |= flag;
 
1144     if (this.modifiersSourceStart < 0)
 
1145       this.modifiersSourceStart = this.scanner.startPosition;
 
1148   private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
 
1149     initializeModifiers();
 
1150     if (token == TokenNameinterface) {
 
1151       //      interface_entry T_STRING
 
1152       //                interface_extends_list
 
1153       //                '{' class_statement_list '}'
 
1154       checkAndSetModifiers(AccInterface);
 
1156       typeDecl.modifiers = this.modifiers;
 
1157       typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1158       typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1159       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
1160         typeDecl.name = scanner.getCurrentIdentifierSource();
 
1161         if (token > TokenNameKEYWORD) {
 
1162           problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
 
1163               scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
 
1164           //          throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
 
1165           //              typeDecl.sourceStart, typeDecl.sourceEnd);
 
1168         interface_extends_list();
 
1170         typeDecl.name = new char[] { ' ' };
 
1171         throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
 
1175       //      class_entry_type T_STRING extends_from
 
1177       //                '{' class_statement_list'}'
 
1179       typeDecl.modifiers = this.modifiers;
 
1180       typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1181       typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1183       //identifier 'extends' identifier
 
1184       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
1185         typeDecl.name = scanner.getCurrentIdentifierSource();
 
1186         if (token > TokenNameKEYWORD) {
 
1187           problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
 
1188               scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
 
1189           //          throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
 
1190           //              typeDecl.sourceStart, typeDecl.sourceEnd);
 
1195         //      | T_EXTENDS fully_qualified_class_name
 
1196         if (token == TokenNameextends) {
 
1197           interface_extends_list();
 
1199           //          if (token != TokenNameIdentifier) {
 
1200           //            throwSyntaxError("Class name expected after keyword
 
1202           //                scanner.getCurrentTokenStartPosition(), scanner
 
1203           //                    .getCurrentTokenEndPosition());
 
1208         typeDecl.name = new char[] { ' ' };
 
1209         throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
 
1213     //  '{' class_statement_list '}'
 
1214     if (token == TokenNameLBRACE) {
 
1216       if (token != TokenNameRBRACE) {
 
1217         ArrayList list = new ArrayList();
 
1218         class_statement_list(list);
 
1219         typeDecl.fields = new FieldDeclaration[list.size()];
 
1220         for (int i = 0; i < list.size(); i++) {
 
1221           typeDecl.fields[i] = (FieldDeclaration) list.get(i);
 
1224       if (token == TokenNameRBRACE) {
 
1225         typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1228         throwSyntaxError("'}' expected at end of class body.");
 
1231       throwSyntaxError("'{' expected at start of class body.");
 
1235   private void class_entry_type() {
 
1237     //  | T_ABSTRACT T_CLASS
 
1238     //  | T_FINAL T_CLASS
 
1239     if (token == TokenNameclass) {
 
1241     } else if (token == TokenNameabstract) {
 
1242       checkAndSetModifiers(AccAbstract);
 
1244       if (token != TokenNameclass) {
 
1245         throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
 
1248     } else if (token == TokenNamefinal) {
 
1249       checkAndSetModifiers(AccFinal);
 
1251       if (token != TokenNameclass) {
 
1252         throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
 
1256       throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
 
1260   private void interface_extends_list() {
 
1262     //  | T_EXTENDS interface_list
 
1263     if (token == TokenNameextends) {
 
1269   private void implements_list() {
 
1271     //  | T_IMPLEMENTS interface_list
 
1272     if (token == TokenNameimplements) {
 
1278   private void interface_list() {
 
1280     //  fully_qualified_class_name
 
1281     //| interface_list ',' fully_qualified_class_name
 
1283       if (token == TokenNameIdentifier) {
 
1286         throwSyntaxError("Interface name expected after keyword 'implements'.");
 
1288       if (token != TokenNameCOMMA) {
 
1295   //  private void classBody(TypeDeclaration typeDecl) {
 
1296   //    //'{' [class-element-list] '}'
 
1297   //    if (token == TokenNameLBRACE) {
 
1299   //      if (token != TokenNameRBRACE) {
 
1300   //        class_statement_list();
 
1302   //      if (token == TokenNameRBRACE) {
 
1303   //        typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1306   //        throwSyntaxError("'}' expected at end of class body.");
 
1309   //      throwSyntaxError("'{' expected at start of class body.");
 
1312   private void class_statement_list(ArrayList list) {
 
1314       class_statement(list);
 
1315     } while (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
 
1316         || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
 
1317         || token == TokenNameconst);
 
1320   private void class_statement(ArrayList list) {
 
1322     //          variable_modifiers class_variable_declaration ';'
 
1323     //  | class_constant_declaration ';'
 
1324     //  | method_modifiers T_FUNCTION is_reference T_STRING
 
1325     //    '(' parameter_list ')' method_body
 
1326     initializeModifiers();
 
1327     int declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
1329     if (token == TokenNamevar) {
 
1330       checkAndSetModifiers(AccPublic);
 
1331       problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
 
1332           referenceContext, compilationUnit.compilationResult);
 
1334       class_variable_declaration(declarationSourceStart, list);
 
1335     } else if (token == TokenNameconst) {
 
1336       checkAndSetModifiers(AccFinal | AccPublic);
 
1337       class_constant_declaration(declarationSourceStart, list);
 
1338       if (token != TokenNameSEMICOLON) {
 
1339         throwSyntaxError("';' expected after class const declaration.");
 
1343       boolean hasModifiers = member_modifiers();
 
1344       if (token == TokenNamefunction) {
 
1345         if (!hasModifiers) {
 
1346           checkAndSetModifiers(AccPublic);
 
1348         MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
 
1349         methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
1350         methodDecl.modifiers = this.modifiers;
 
1352         functionDefinition(methodDecl);
 
1354         if (!hasModifiers) {
 
1355           throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
 
1357         class_variable_declaration(declarationSourceStart, list);
 
1362   private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
 
1363     //  class_constant_declaration ',' T_STRING '=' static_scalar
 
1364     //  | T_CONST T_STRING '=' static_scalar
 
1365     if (token != TokenNameconst) {
 
1366       throwSyntaxError("'const' keyword expected in class declaration.");
 
1371       if (token != TokenNameIdentifier) {
 
1372         throwSyntaxError("Identifier expected in class const declaration.");
 
1374       FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
 
1375           .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
 
1376       fieldDeclaration.modifiers = this.modifiers;
 
1377       fieldDeclaration.declarationSourceStart = declarationSourceStart;
 
1378       fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1379       fieldDeclaration.modifiersSourceStart = declarationSourceStart;
 
1380       //        fieldDeclaration.type
 
1381       list.add(fieldDeclaration);
 
1383       if (token != TokenNameEQUAL) {
 
1384         throwSyntaxError("'=' expected in class const declaration.");
 
1388       if (token != TokenNameCOMMA) {
 
1389         break; // while(true)-loop
 
1395   //  private void variable_modifiers() {
 
1396   //    // variable_modifiers:
 
1397   //    // non_empty_member_modifiers
 
1399   //    initializeModifiers();
 
1400   //    if (token == TokenNamevar) {
 
1401   //      checkAndSetModifiers(AccPublic);
 
1402   //      reportSyntaxError(
 
1403   //          "Keyword 'var' is deprecated. Please use 'public' 'private' or
 
1405   // modifier for field declarations.",
 
1406   //          scanner.getCurrentTokenStartPosition(), scanner
 
1407   //              .getCurrentTokenEndPosition());
 
1410   //      if (!member_modifiers()) {
 
1411   //        throwSyntaxError("'public' 'private' or 'protected' modifier expected for
 
1412   // field declarations.");
 
1416   //  private void method_modifiers() {
 
1417   //    //method_modifiers:
 
1419   //    //| non_empty_member_modifiers
 
1420   //    initializeModifiers();
 
1421   //    if (!member_modifiers()) {
 
1422   //      checkAndSetModifiers(AccPublic);
 
1425   private boolean member_modifiers() {
 
1432     boolean foundToken = false;
 
1434       if (token == TokenNamepublic) {
 
1435         checkAndSetModifiers(AccPublic);
 
1438       } else if (token == TokenNameprotected) {
 
1439         checkAndSetModifiers(AccProtected);
 
1442       } else if (token == TokenNameprivate) {
 
1443         checkAndSetModifiers(AccPrivate);
 
1446       } else if (token == TokenNamestatic) {
 
1447         checkAndSetModifiers(AccStatic);
 
1450       } else if (token == TokenNameabstract) {
 
1451         checkAndSetModifiers(AccAbstract);
 
1454       } else if (token == TokenNamefinal) {
 
1455         checkAndSetModifiers(AccFinal);
 
1465   private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
 
1466     //    class_variable_declaration:
 
1467     //          class_variable_declaration ',' T_VARIABLE
 
1468     //  | class_variable_declaration ',' T_VARIABLE '=' static_scalar
 
1470     //  | T_VARIABLE '=' static_scalar
 
1471     char[] classVariable;
 
1473       if (token == TokenNameVariable) {
 
1474         classVariable = scanner.getCurrentIdentifierSource();
 
1475         //  indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
 
1476         FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
 
1477             .getCurrentTokenEndPosition());
 
1478         fieldDeclaration.modifiers = this.modifiers;
 
1479         fieldDeclaration.declarationSourceStart = declarationSourceStart;
 
1480         fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1481         fieldDeclaration.modifiersSourceStart = declarationSourceStart;
 
1482         //        fieldDeclaration.type
 
1483         list.add(fieldDeclaration);
 
1485         if (token == TokenNameEQUAL) {
 
1490         //        if (token == TokenNamethis) {
 
1491         //          throwSyntaxError("'$this' not allowed after keyword 'public'
 
1492         // 'protected' 'private' 'var'.");
 
1494         throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
 
1496       if (token != TokenNameCOMMA) {
 
1501     if (token != TokenNameSEMICOLON) {
 
1502       throwSyntaxError("';' expected after field declaration.");
 
1507   private void functionDefinition(MethodDeclaration methodDecl) {
 
1508     boolean isAbstract = false;
 
1510       compilationUnit.types.add(methodDecl);
 
1512       ASTNode node = astStack[astPtr];
 
1513       if (node instanceof TypeDeclaration) {
 
1514         TypeDeclaration typeDecl = ((TypeDeclaration) node);
 
1515         if (typeDecl.methods == null) {
 
1516           typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
 
1518           AbstractMethodDeclaration[] newMethods;
 
1519           System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 1,
 
1520               typeDecl.methods.length);
 
1521           newMethods[0] = methodDecl;
 
1522           typeDecl.methods = newMethods;
 
1524         if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
 
1526         } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
 
1531     functionDeclarator(methodDecl);
 
1532     if (token == TokenNameSEMICOLON) {
 
1534         throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
 
1539     functionBody(methodDecl);
 
1542   private void functionDeclarator(MethodDeclaration methodDecl) {
 
1543     //identifier '(' [parameter-list] ')'
 
1544     if (token == TokenNameAND) {
 
1547     methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1548     methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1549     if (Scanner.isIdentifierOrKeyword(token)) {
 
1550       methodDecl.selector = scanner.getCurrentIdentifierSource();
 
1551       if (token > TokenNameKEYWORD) {
 
1552         problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
 
1553             scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
 
1554         //        reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
 
1555         //          scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
 
1558       if (token == TokenNameLPAREN) {
 
1561         throwSyntaxError("'(' expected in function declaration.");
 
1563       if (token != TokenNameRPAREN) {
 
1566       if (token != TokenNameRPAREN) {
 
1567         throwSyntaxError("')' expected in function declaration.");
 
1569         methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
 
1573       methodDecl.selector = "<undefined>".toCharArray();
 
1574       throwSyntaxError("Function name expected after keyword 'function'.");
 
1579   private void parameter_list() {
 
1580     //  non_empty_parameter_list
 
1582     non_empty_parameter_list(true);
 
1585   private void non_empty_parameter_list(boolean empty_allowed) {
 
1586     //  optional_class_type T_VARIABLE
 
1587     //  | optional_class_type '&' T_VARIABLE
 
1588     //  | optional_class_type '&' T_VARIABLE '=' static_scalar
 
1589     //  | optional_class_type T_VARIABLE '=' static_scalar
 
1590     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE
 
1591     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
 
1592     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
 
1594     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
 
1596     if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
 
1598         if (token == TokenNameIdentifier) {
 
1601         if (token == TokenNameAND) {
 
1604         if (token == TokenNameVariable) {
 
1606           if (token == TokenNameEQUAL) {
 
1611           throwSyntaxError("Variable expected in parameter list.");
 
1613         if (token != TokenNameCOMMA) {
 
1620     if (!empty_allowed) {
 
1621       throwSyntaxError("Identifier expected in parameter list.");
 
1625   private void optional_class_type() {
 
1630   private void parameterDeclaration() {
 
1632     //variable-reference
 
1633     if (token == TokenNameAND) {
 
1638         throwSyntaxError("Variable expected after reference operator '&'.");
 
1641     //variable '=' constant
 
1642     if (token == TokenNameVariable) {
 
1644       if (token == TokenNameEQUAL) {
 
1650     //    if (token == TokenNamethis) {
 
1651     //      throwSyntaxError("Reserved word '$this' not allowed in parameter
 
1656   private void labeledStatementList() {
 
1657     if (token != TokenNamecase && token != TokenNamedefault) {
 
1658       throwSyntaxError("'case' or 'default' expected.");
 
1661       if (token == TokenNamecase) {
 
1663         expr(); //constant();
 
1664         if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
 
1666           if (token == TokenNamecase || token == TokenNamedefault) {
 
1667             // empty case statement ?
 
1672         //        else if (token == TokenNameSEMICOLON) {
 
1674         //            "':' expected after 'case' keyword (Found token: " +
 
1675         // scanner.toStringAction(token) + ")",
 
1676         //            scanner.getCurrentTokenStartPosition(),
 
1677         //            scanner.getCurrentTokenEndPosition(),
 
1680         //          if (token == TokenNamecase) { // empty case statement ?
 
1686           throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
 
1688       } else { // TokenNamedefault
 
1690         if (token == TokenNameCOLON) {
 
1692           if (token == TokenNameRBRACE) {
 
1693             // empty default case
 
1696           if (token != TokenNamecase) {
 
1700           throwSyntaxError("':' character expected after 'default'.");
 
1703     } while (token == TokenNamecase || token == TokenNamedefault);
 
1706   //  public void labeledStatement() {
 
1707   //    if (token == TokenNamecase) {
 
1710   //      if (token == TokenNameDDOT) {
 
1714   //        throwSyntaxError("':' character after 'case' constant expected.");
 
1717   //    } else if (token == TokenNamedefault) {
 
1719   //      if (token == TokenNameDDOT) {
 
1723   //        throwSyntaxError("':' character after 'default' expected.");
 
1728   //  public void expressionStatement() {
 
1730   //  private void inclusionStatement() {
 
1732   //  public void compoundStatement() {
 
1734   //  public void selectionStatement() {
 
1737   //  public void iterationStatement() {
 
1740   //  public void jumpStatement() {
 
1743   //  public void outputStatement() {
 
1746   //  public void scopeStatement() {
 
1749   //  public void flowStatement() {
 
1752   //  public void definitionStatement() {
 
1754   private void ifStatement() {
 
1755     // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
 
1756     if (token == TokenNameCOLON) {
 
1758       if (token != TokenNameendif) {
 
1763           if (token == TokenNameCOLON) {
 
1765             if (token != TokenNameendif) {
 
1769             if (token == TokenNameif) { //'else if'
 
1771               elseifStatementList();
 
1773               throwSyntaxError("':' expected after 'else'.");
 
1777         case TokenNameelseif:
 
1779           elseifStatementList();
 
1783       if (token != TokenNameendif) {
 
1784         throwSyntaxError("'endif' expected.");
 
1787       if (token != TokenNameSEMICOLON) {
 
1788         throwSyntaxError("';' expected after if-statement.");
 
1792       // statement [else-statement]
 
1793       statement(TokenNameEOF);
 
1794       if (token == TokenNameelseif) {
 
1796         if (token == TokenNameLPAREN) {
 
1799           throwSyntaxError("'(' expected after 'elseif' keyword.");
 
1802         if (token == TokenNameRPAREN) {
 
1805           throwSyntaxError("')' expected after 'elseif' condition.");
 
1808       } else if (token == TokenNameelse) {
 
1810         statement(TokenNameEOF);
 
1815   private void elseifStatementList() {
 
1821         if (token == TokenNameCOLON) {
 
1823           if (token != TokenNameendif) {
 
1828           if (token == TokenNameif) { //'else if'
 
1831             throwSyntaxError("':' expected after 'else'.");
 
1835       case TokenNameelseif:
 
1844   private void elseifStatement() {
 
1845     if (token == TokenNameLPAREN) {
 
1848       if (token != TokenNameRPAREN) {
 
1849         throwSyntaxError("')' expected in else-if-statement.");
 
1852       if (token != TokenNameCOLON) {
 
1853         throwSyntaxError("':' expected in else-if-statement.");
 
1856       if (token != TokenNameendif) {
 
1862   private void switchStatement() {
 
1863     if (token == TokenNameCOLON) {
 
1864       // ':' [labeled-statement-list] 'endswitch' ';'
 
1866       labeledStatementList();
 
1867       if (token != TokenNameendswitch) {
 
1868         throwSyntaxError("'endswitch' expected.");
 
1871       if (token != TokenNameSEMICOLON) {
 
1872         throwSyntaxError("';' expected after switch-statement.");
 
1876       // '{' [labeled-statement-list] '}'
 
1877       if (token != TokenNameLBRACE) {
 
1878         throwSyntaxError("'{' expected in switch statement.");
 
1881       if (token != TokenNameRBRACE) {
 
1882         labeledStatementList();
 
1884       if (token != TokenNameRBRACE) {
 
1885         throwSyntaxError("'}' expected in switch statement.");
 
1891   private void forStatement() {
 
1892     if (token == TokenNameCOLON) {
 
1895       if (token != TokenNameendfor) {
 
1896         throwSyntaxError("'endfor' expected.");
 
1899       if (token != TokenNameSEMICOLON) {
 
1900         throwSyntaxError("';' expected after for-statement.");
 
1904       statement(TokenNameEOF);
 
1908   private void whileStatement() {
 
1909     // ':' statement-list 'endwhile' ';'
 
1910     if (token == TokenNameCOLON) {
 
1913       if (token != TokenNameendwhile) {
 
1914         throwSyntaxError("'endwhile' expected.");
 
1917       if (token != TokenNameSEMICOLON) {
 
1918         throwSyntaxError("';' expected after while-statement.");
 
1922       statement(TokenNameEOF);
 
1926   private void foreachStatement() {
 
1927     if (token == TokenNameCOLON) {
 
1930       if (token != TokenNameendforeach) {
 
1931         throwSyntaxError("'endforeach' expected.");
 
1934       if (token != TokenNameSEMICOLON) {
 
1935         throwSyntaxError("';' expected after foreach-statement.");
 
1939       statement(TokenNameEOF);
 
1943   //  private void exitStatus() {
 
1944   //    if (token == TokenNameLPAREN) {
 
1947   //      throwSyntaxError("'(' expected in 'exit-status'.");
 
1949   //    if (token != TokenNameRPAREN) {
 
1952   //    if (token == TokenNameRPAREN) {
 
1955   //      throwSyntaxError("')' expected after 'exit-status'.");
 
1958   private void expressionList() {
 
1961       if (token == TokenNameCOMMA) {
 
1969   private Expression expr() {
 
1971     //  | expr_without_variable
 
1972     //    if (token!=TokenNameEOF) {
 
1973     if (Scanner.TRACE) {
 
1974       System.out.println("TRACE: expr()");
 
1976     return expr_without_variable(true);
 
1980   private Expression expr_without_variable(boolean only_variable) {
 
1981     Expression expression = new Expression();
 
1982     expression.sourceStart = scanner.getCurrentTokenStartPosition();
 
1983     // default, may be overwritten
 
1984     expression.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1985     //          internal_functions_in_yacc
 
1994     //  | T_INC rw_variable
 
1995     //  | T_DEC rw_variable
 
1996     //  | T_INT_CAST expr
 
1997     //  | T_DOUBLE_CAST expr
 
1998     //  | T_STRING_CAST expr
 
1999     //  | T_ARRAY_CAST expr
 
2000     //  | T_OBJECT_CAST expr
 
2001     //  | T_BOOL_CAST expr
 
2002     //  | T_UNSET_CAST expr
 
2003     //  | T_EXIT exit_expr
 
2005     //  | T_ARRAY '(' array_pair_list ')'
 
2006     //  | '`' encaps_list '`'
 
2007     //  | T_LIST '(' assignment_list ')' '=' expr
 
2008     //  | T_NEW class_name_reference ctor_arguments
 
2009     //  | variable '=' expr
 
2010     //  | variable '=' '&' variable
 
2011     //  | variable '=' '&' T_NEW class_name_reference ctor_arguments
 
2012     //  | variable T_PLUS_EQUAL expr
 
2013     //  | variable T_MINUS_EQUAL expr
 
2014     //  | variable T_MUL_EQUAL expr
 
2015     //  | variable T_DIV_EQUAL expr
 
2016     //  | variable T_CONCAT_EQUAL expr
 
2017     //  | variable T_MOD_EQUAL expr
 
2018     //  | variable T_AND_EQUAL expr
 
2019     //  | variable T_OR_EQUAL expr
 
2020     //  | variable T_XOR_EQUAL expr
 
2021     //  | variable T_SL_EQUAL expr
 
2022     //  | variable T_SR_EQUAL expr
 
2023     //  | rw_variable T_INC
 
2024     //  | rw_variable T_DEC
 
2025     //  | expr T_BOOLEAN_OR expr
 
2026     //  | expr T_BOOLEAN_AND expr
 
2027     //  | expr T_LOGICAL_OR expr
 
2028     //  | expr T_LOGICAL_AND expr
 
2029     //  | expr T_LOGICAL_XOR expr
 
2041     //  | expr T_IS_IDENTICAL expr
 
2042     //  | expr T_IS_NOT_IDENTICAL expr
 
2043     //  | expr T_IS_EQUAL expr
 
2044     //  | expr T_IS_NOT_EQUAL expr
 
2046     //  | expr T_IS_SMALLER_OR_EQUAL expr
 
2048     //  | expr T_IS_GREATER_OR_EQUAL expr
 
2049     //  | expr T_INSTANCEOF class_name_reference
 
2050     //  | expr '?' expr ':' expr
 
2051     if (Scanner.TRACE) {
 
2052       System.out.println("TRACE: expr_without_variable() PART 1");
 
2055     case TokenNameisset:
 
2056     case TokenNameempty:
 
2058     case TokenNameinclude:
 
2059     case TokenNameinclude_once:
 
2060     case TokenNamerequire:
 
2061     case TokenNamerequire_once:
 
2062       internal_functions_in_yacc();
 
2065     case TokenNameLPAREN:
 
2068       if (token == TokenNameRPAREN) {
 
2071         throwSyntaxError("')' expected in expression.");
 
2081     //    | T_INT_CAST expr
 
2082     //  | T_DOUBLE_CAST expr
 
2083     //  | T_STRING_CAST expr
 
2084     //  | T_ARRAY_CAST expr
 
2085     //  | T_OBJECT_CAST expr
 
2086     //  | T_BOOL_CAST expr
 
2087     //  | T_UNSET_CAST expr
 
2088     case TokenNameclone:
 
2089     case TokenNameprint:
 
2092     case TokenNameMINUS:
 
2094     case TokenNameTWIDDLE:
 
2095     case TokenNameintCAST:
 
2096     case TokenNamedoubleCAST:
 
2097     case TokenNamestringCAST:
 
2098     case TokenNamearrayCAST:
 
2099     case TokenNameobjectCAST:
 
2100     case TokenNameboolCAST:
 
2101     case TokenNameunsetCAST:
 
2111     //| T_STRING_VARNAME
 
2113     //| T_START_HEREDOC encaps_list T_END_HEREDOC
 
2114     //          | '`' encaps_list '`'
 
2116     //  | '`' encaps_list '`'
 
2117     case TokenNameEncapsedString0:
 
2118       scanner.encapsedStringStack.push(new Character('`'));
 
2121         if (token == TokenNameEncapsedString0) {
 
2124           if (token != TokenNameEncapsedString0) {
 
2125             throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2129         scanner.encapsedStringStack.pop();
 
2133     //      | '\'' encaps_list '\''
 
2134     case TokenNameEncapsedString1:
 
2135       scanner.encapsedStringStack.push(new Character('\''));
 
2138         if (token == TokenNameEncapsedString1) {
 
2141           if (token != TokenNameEncapsedString1) {
 
2142             throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2146         scanner.encapsedStringStack.pop();
 
2150     //| '"' encaps_list '"'
 
2151     case TokenNameEncapsedString2:
 
2152       scanner.encapsedStringStack.push(new Character('"'));
 
2155         if (token == TokenNameEncapsedString2) {
 
2158           if (token != TokenNameEncapsedString2) {
 
2159             throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2163         scanner.encapsedStringStack.pop();
 
2167     case TokenNameIntegerLiteral:
 
2168     case TokenNameDoubleLiteral:
 
2169     case TokenNameStringDoubleQuote:
 
2170     case TokenNameStringSingleQuote:
 
2171     case TokenNameStringInterpolated:
 
2174     case TokenNameCLASS_C:
 
2175     case TokenNameMETHOD_C:
 
2176     case TokenNameFUNC_C:
 
2179     case TokenNameHEREDOC:
 
2182     case TokenNamearray:
 
2183       //    T_ARRAY '(' array_pair_list ')'
 
2185       if (token == TokenNameLPAREN) {
 
2187         if (token == TokenNameRPAREN) {
 
2192         if (token != TokenNameRPAREN) {
 
2193           throwSyntaxError("')' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
 
2197         throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
 
2201       //    | T_LIST '(' assignment_list ')' '=' expr
 
2203       if (token == TokenNameLPAREN) {
 
2206         if (token != TokenNameRPAREN) {
 
2207           throwSyntaxError("')' expected after 'list' keyword.");
 
2210         if (token != TokenNameEQUAL) {
 
2211           throwSyntaxError("'=' expected after 'list' keyword.");
 
2216         throwSyntaxError("'(' expected after 'list' keyword.");
 
2220       //        | T_NEW class_name_reference ctor_arguments
 
2222       class_name_reference();
 
2225     //          | T_INC rw_variable
 
2226     //          | T_DEC rw_variable
 
2227     case TokenNamePLUS_PLUS:
 
2228     case TokenNameMINUS_MINUS:
 
2232     //  | variable '=' expr
 
2233     //  | variable '=' '&' variable
 
2234     //  | variable '=' '&' T_NEW class_name_reference ctor_arguments
 
2235     //  | variable T_PLUS_EQUAL expr
 
2236     //  | variable T_MINUS_EQUAL expr
 
2237     //  | variable T_MUL_EQUAL expr
 
2238     //  | variable T_DIV_EQUAL expr
 
2239     //  | variable T_CONCAT_EQUAL expr
 
2240     //  | variable T_MOD_EQUAL expr
 
2241     //  | variable T_AND_EQUAL expr
 
2242     //  | variable T_OR_EQUAL expr
 
2243     //  | variable T_XOR_EQUAL expr
 
2244     //  | variable T_SL_EQUAL expr
 
2245     //  | variable T_SR_EQUAL expr
 
2246     //  | rw_variable T_INC
 
2247     //  | rw_variable T_DEC
 
2248     case TokenNameIdentifier:
 
2249     case TokenNameVariable:
 
2250     case TokenNameDOLLAR:
 
2253       case TokenNameEQUAL:
 
2255         if (token == TokenNameAND) {
 
2257           if (token == TokenNamenew) {
 
2258             // | variable '=' '&' T_NEW class_name_reference
 
2261             class_name_reference();
 
2270       case TokenNamePLUS_EQUAL:
 
2271       case TokenNameMINUS_EQUAL:
 
2272       case TokenNameMULTIPLY_EQUAL:
 
2273       case TokenNameDIVIDE_EQUAL:
 
2274       case TokenNameDOT_EQUAL:
 
2275       case TokenNameREMAINDER_EQUAL:
 
2276       case TokenNameAND_EQUAL:
 
2277       case TokenNameOR_EQUAL:
 
2278       case TokenNameXOR_EQUAL:
 
2279       case TokenNameRIGHT_SHIFT_EQUAL:
 
2280       case TokenNameLEFT_SHIFT_EQUAL:
 
2284       case TokenNamePLUS_PLUS:
 
2285       case TokenNameMINUS_MINUS:
 
2289         if (!only_variable) {
 
2290           throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
 
2295       if (token != TokenNameINLINE_HTML) {
 
2296         if (token > TokenNameKEYWORD) {
 
2300           throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
 
2305     if (Scanner.TRACE) {
 
2306       System.out.println("TRACE: expr_without_variable() PART 2");
 
2308     //  | expr T_BOOLEAN_OR expr
 
2309     //  | expr T_BOOLEAN_AND expr
 
2310     //  | expr T_LOGICAL_OR expr
 
2311     //  | expr T_LOGICAL_AND expr
 
2312     //  | expr T_LOGICAL_XOR expr
 
2324     //  | expr T_IS_IDENTICAL expr
 
2325     //  | expr T_IS_NOT_IDENTICAL expr
 
2326     //  | expr T_IS_EQUAL expr
 
2327     //  | expr T_IS_NOT_EQUAL expr
 
2329     //  | expr T_IS_SMALLER_OR_EQUAL expr
 
2331     //  | expr T_IS_GREATER_OR_EQUAL expr
 
2334       case TokenNameOR_OR:
 
2335       case TokenNameAND_AND:
 
2344       case TokenNameMINUS:
 
2345       case TokenNameMULTIPLY:
 
2346       case TokenNameDIVIDE:
 
2347       case TokenNameREMAINDER:
 
2348       case TokenNameLEFT_SHIFT:
 
2349       case TokenNameRIGHT_SHIFT:
 
2350       case TokenNameEQUAL_EQUAL_EQUAL:
 
2351       case TokenNameNOT_EQUAL_EQUAL:
 
2352       case TokenNameEQUAL_EQUAL:
 
2353       case TokenNameNOT_EQUAL:
 
2355       case TokenNameLESS_EQUAL:
 
2356       case TokenNameGREATER:
 
2357       case TokenNameGREATER_EQUAL:
 
2361       //  | expr T_INSTANCEOF class_name_reference
 
2362       //        | expr '?' expr ':' expr
 
2363       case TokenNameinstanceof:
 
2365         class_name_reference();
 
2367       case TokenNameQUESTION:
 
2370         if (token == TokenNameCOLON) {
 
2381   private void class_name_reference() {
 
2382     //  class_name_reference:
 
2384     //| dynamic_class_name_reference
 
2385     if (Scanner.TRACE) {
 
2386       System.out.println("TRACE: class_name_reference()");
 
2388     if (token == TokenNameIdentifier) {
 
2391       dynamic_class_name_reference();
 
2395   private void dynamic_class_name_reference() {
 
2396     //dynamic_class_name_reference:
 
2397     //  base_variable T_OBJECT_OPERATOR object_property
 
2398     // dynamic_class_name_variable_properties
 
2400     if (Scanner.TRACE) {
 
2401       System.out.println("TRACE: dynamic_class_name_reference()");
 
2404     if (token == TokenNameMINUS_GREATER) {
 
2407       dynamic_class_name_variable_properties();
 
2411   private void dynamic_class_name_variable_properties() {
 
2412     //  dynamic_class_name_variable_properties:
 
2413     //                  dynamic_class_name_variable_properties
 
2414     // dynamic_class_name_variable_property
 
2416     if (Scanner.TRACE) {
 
2417       System.out.println("TRACE: dynamic_class_name_variable_properties()");
 
2419     while (token == TokenNameMINUS_GREATER) {
 
2420       dynamic_class_name_variable_property();
 
2424   private void dynamic_class_name_variable_property() {
 
2425     //  dynamic_class_name_variable_property:
 
2426     //  T_OBJECT_OPERATOR object_property
 
2427     if (Scanner.TRACE) {
 
2428       System.out.println("TRACE: dynamic_class_name_variable_property()");
 
2430     if (token == TokenNameMINUS_GREATER) {
 
2436   private void ctor_arguments() {
 
2439     //| '(' function_call_parameter_list ')'
 
2440     if (token == TokenNameLPAREN) {
 
2442       if (token == TokenNameRPAREN) {
 
2446       non_empty_function_call_parameter_list();
 
2447       if (token != TokenNameRPAREN) {
 
2448         throwSyntaxError("')' expected in ctor_arguments.");
 
2454   private void assignment_list() {
 
2456     //  assignment_list ',' assignment_list_element
 
2457     //| assignment_list_element
 
2459       assignment_list_element();
 
2460       if (token != TokenNameCOMMA) {
 
2467   private void assignment_list_element() {
 
2468     //assignment_list_element:
 
2470     //| T_LIST '(' assignment_list ')'
 
2472     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
 
2475       if (token == TokenNamelist) {
 
2477         if (token == TokenNameLPAREN) {
 
2480           if (token != TokenNameRPAREN) {
 
2481             throwSyntaxError("')' expected after 'list' keyword.");
 
2485           throwSyntaxError("'(' expected after 'list' keyword.");
 
2491   private void array_pair_list() {
 
2494     //| non_empty_array_pair_list possible_comma
 
2495     non_empty_array_pair_list();
 
2496     if (token == TokenNameCOMMA) {
 
2501   private void non_empty_array_pair_list() {
 
2502     //non_empty_array_pair_list:
 
2503     //  non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
 
2504     //| non_empty_array_pair_list ',' expr
 
2505     //| expr T_DOUBLE_ARROW expr
 
2507     //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
 
2508     //| non_empty_array_pair_list ',' '&' w_variable
 
2509     //| expr T_DOUBLE_ARROW '&' w_variable
 
2512       if (token == TokenNameAND) {
 
2517         if (token == TokenNameAND) {
 
2520         } else if (token == TokenNameEQUAL_GREATER) {
 
2522           if (token == TokenNameAND) {
 
2530       if (token != TokenNameCOMMA) {
 
2534       if (token == TokenNameRPAREN) {
 
2540   //  private void variableList() {
 
2543   //      if (token == TokenNameCOMMA) {
 
2550   private void variable_without_objects() {
 
2551     //  variable_without_objects:
 
2552     //                  reference_variable
 
2553     //          | simple_indirect_reference reference_variable
 
2554     if (Scanner.TRACE) {
 
2555       System.out.println("TRACE: variable_without_objects()");
 
2557     while (token == TokenNameDOLLAR) {
 
2560     reference_variable();
 
2563   private void function_call() {
 
2565     //  T_STRING '(' function_call_parameter_list ')'
 
2566     //| class_constant '(' function_call_parameter_list ')'
 
2567     //| static_member '(' function_call_parameter_list ')'
 
2568     //| variable_without_objects '(' function_call_parameter_list ')'
 
2569     char[] defineName = null;
 
2570     char[] ident = null;
 
2573     if (Scanner.TRACE) {
 
2574       System.out.println("TRACE: function_call()");
 
2576     if (token == TokenNameIdentifier) {
 
2577       ident = scanner.getCurrentIdentifierSource();
 
2579       startPos = scanner.getCurrentTokenStartPosition();
 
2580       endPos = scanner.getCurrentTokenEndPosition();
 
2583       case TokenNamePAAMAYIM_NEKUDOTAYIM:
 
2587         if (token == TokenNameIdentifier) {
 
2592           variable_without_objects();
 
2597       variable_without_objects();
 
2599     if (token != TokenNameLPAREN) {
 
2600       if (defineName != null) {
 
2601         // does this identifier contain only uppercase characters?
 
2602         if (defineName.length == 3) {
 
2603           if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
 
2606         } else if (defineName.length == 4) {
 
2607           if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
 
2609           } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
 
2612         } else if (defineName.length == 5) {
 
2613           if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
 
2617         if (defineName != null) {
 
2618           for (int i = 0; i < defineName.length; i++) {
 
2619             if (Character.isLowerCase(defineName[i])) {
 
2620               problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
 
2626       // TODO is this ok ?
 
2628       //      throwSyntaxError("'(' expected in function call.");
 
2631     if (token == TokenNameRPAREN) {
 
2635     non_empty_function_call_parameter_list();
 
2636     if (token != TokenNameRPAREN) {
 
2637       String functionName;
 
2638       if (ident == null) {
 
2639         functionName = new String(" ");
 
2641         functionName = new String(ident);
 
2643       throwSyntaxError("')' expected in function call (" + functionName + ").");
 
2648   //  private void function_call_parameter_list() {
 
2649   //    function_call_parameter_list:
 
2650   //            non_empty_function_call_parameter_list { $$ = $1; }
 
2653   private void non_empty_function_call_parameter_list() {
 
2654     //non_empty_function_call_parameter_list:
 
2655     //          expr_without_variable
 
2658     //  | non_empty_function_call_parameter_list ',' expr_without_variable
 
2659     //  | non_empty_function_call_parameter_list ',' variable
 
2660     //  | non_empty_function_call_parameter_list ',' '&' w_variable
 
2661     if (Scanner.TRACE) {
 
2662       System.out.println("TRACE: non_empty_function_call_parameter_list()");
 
2665       if (token == TokenNameAND) {
 
2669         //        if (token == TokenNameIdentifier || token ==
 
2670         // TokenNameVariable
 
2671         //            || token == TokenNameDOLLAR) {
 
2674         expr_without_variable(true);
 
2677       if (token != TokenNameCOMMA) {
 
2684   private void fully_qualified_class_name() {
 
2685     if (token == TokenNameIdentifier) {
 
2688       throwSyntaxError("Class name expected.");
 
2692   private void static_member() {
 
2694     //  fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
 
2695     // variable_without_objects
 
2696     if (Scanner.TRACE) {
 
2697       System.out.println("TRACE: static_member()");
 
2699     fully_qualified_class_name();
 
2700     if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
 
2701       throwSyntaxError("'::' expected after class name (static_member).");
 
2704     variable_without_objects();
 
2707   private void base_variable_with_function_calls() {
 
2708     //  base_variable_with_function_calls:
 
2711     boolean functionCall = false;
 
2712     if (Scanner.TRACE) {
 
2713       System.out.println("TRACE: base_variable_with_function_calls()");
 
2715     //    if (token == TokenNameIdentifier) {
 
2716     //      functionCall = true;
 
2717     //    } else if (token == TokenNameVariable) {
 
2718     //      int tempToken = token;
 
2719     //      int tempPosition = scanner.currentPosition;
 
2721     //      if (token == TokenNameLPAREN) {
 
2722     //        functionCall = true;
 
2724     //      token = tempToken;
 
2725     //      scanner.currentPosition = tempPosition;
 
2726     //      scanner.phpMode = true;
 
2728     //    if (functionCall) {
 
2735   private void base_variable() {
 
2737     //                  reference_variable
 
2738     //          | simple_indirect_reference reference_variable
 
2740     if (Scanner.TRACE) {
 
2741       System.out.println("TRACE: base_variable()");
 
2743     if (token == TokenNameIdentifier) {
 
2746       while (token == TokenNameDOLLAR) {
 
2749       reference_variable();
 
2753   //  private void simple_indirect_reference() {
 
2754   //    // simple_indirect_reference:
 
2756   //    //| simple_indirect_reference '$'
 
2758   private void reference_variable() {
 
2759     //  reference_variable:
 
2760     //                  reference_variable '[' dim_offset ']'
 
2761     //          | reference_variable '{' expr '}'
 
2762     //          | compound_variable
 
2763     if (Scanner.TRACE) {
 
2764       System.out.println("TRACE: reference_variable()");
 
2766     compound_variable();
 
2768       if (token == TokenNameLBRACE) {
 
2771         if (token != TokenNameRBRACE) {
 
2772           throwSyntaxError("'}' expected in reference variable.");
 
2775       } else if (token == TokenNameLBRACKET) {
 
2777         if (token != TokenNameRBRACKET) {
 
2780           if (token != TokenNameRBRACKET) {
 
2781             throwSyntaxError("']' expected in reference variable.");
 
2791   private void compound_variable() {
 
2792     //  compound_variable:
 
2794     //          | '$' '{' expr '}'
 
2795     if (Scanner.TRACE) {
 
2796       System.out.println("TRACE: compound_variable()");
 
2798     if (token == TokenNameVariable) {
 
2801       // because of simple_indirect_reference
 
2802       while (token == TokenNameDOLLAR) {
 
2805       if (token != TokenNameLBRACE) {
 
2806         throwSyntaxError("'{' expected after compound variable token '$'.");
 
2810       if (token != TokenNameRBRACE) {
 
2811         throwSyntaxError("'}' expected after compound variable token '$'.");
 
2817   //  private void dim_offset() {
 
2823   private void object_property() {
 
2826     //| variable_without_objects
 
2827     if (Scanner.TRACE) {
 
2828       System.out.println("TRACE: object_property()");
 
2830     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
 
2831       variable_without_objects();
 
2837   private void object_dim_list() {
 
2839     //  object_dim_list '[' dim_offset ']'
 
2840     //| object_dim_list '{' expr '}'
 
2842     if (Scanner.TRACE) {
 
2843       System.out.println("TRACE: object_dim_list()");
 
2847       if (token == TokenNameLBRACE) {
 
2850         if (token != TokenNameRBRACE) {
 
2851           throwSyntaxError("'}' expected in object_dim_list.");
 
2854       } else if (token == TokenNameLBRACKET) {
 
2856         if (token == TokenNameRBRACKET) {
 
2861         if (token != TokenNameRBRACKET) {
 
2862           throwSyntaxError("']' expected in object_dim_list.");
 
2871   private void variable_name() {
 
2875     if (Scanner.TRACE) {
 
2876       System.out.println("TRACE: variable_name()");
 
2878     if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
2879       if (token > TokenNameKEYWORD) {
 
2880         // TODO show a warning "Keyword used as variable" ?
 
2884       if (token != TokenNameLBRACE) {
 
2885         throwSyntaxError("'{' expected in variable name.");
 
2889       if (token != TokenNameRBRACE) {
 
2890         throwSyntaxError("'}' expected in variable name.");
 
2896   private void r_variable() {
 
2900   private void w_variable() {
 
2904   private void rw_variable() {
 
2908   private void variable() {
 
2910     //          base_variable_with_function_calls T_OBJECT_OPERATOR
 
2911     //                  object_property method_or_not variable_properties
 
2912     //  | base_variable_with_function_calls
 
2913     base_variable_with_function_calls();
 
2914     if (token == TokenNameMINUS_GREATER) {
 
2918       variable_properties();
 
2920     //    if (token == TokenNameDOLLAR_LBRACE) {
 
2924     //      if (token != TokenNameRBRACE) {
 
2925     //        throwSyntaxError("'}' expected after indirect variable token '${'.");
 
2929     //      if (token == TokenNameVariable) {
 
2931     //        if (token == TokenNameLBRACKET) {
 
2934     //          if (token != TokenNameRBRACKET) {
 
2935     //            throwSyntaxError("']' expected in variable-list.");
 
2938     //        } else if (token == TokenNameEQUAL) {
 
2943     //        throwSyntaxError("$-variable expected in variable-list.");
 
2948   private void variable_properties() {
 
2949     //  variable_properties:
 
2950     //                  variable_properties variable_property
 
2952     while (token == TokenNameMINUS_GREATER) {
 
2953       variable_property();
 
2957   private void variable_property() {
 
2958     //  variable_property:
 
2959     //                  T_OBJECT_OPERATOR object_property method_or_not
 
2960     if (Scanner.TRACE) {
 
2961       System.out.println("TRACE: variable_property()");
 
2963     if (token == TokenNameMINUS_GREATER) {
 
2968       throwSyntaxError("'->' expected in variable_property.");
 
2972   private void method_or_not() {
 
2974     //                  '(' function_call_parameter_list ')'
 
2976     if (Scanner.TRACE) {
 
2977       System.out.println("TRACE: method_or_not()");
 
2979     if (token == TokenNameLPAREN) {
 
2981       if (token == TokenNameRPAREN) {
 
2985       non_empty_function_call_parameter_list();
 
2986       if (token != TokenNameRPAREN) {
 
2987         throwSyntaxError("')' expected in method_or_not.");
 
2993   private void exit_expr() {
 
2997     if (token != TokenNameLPAREN) {
 
3001     if (token == TokenNameRPAREN) {
 
3006     if (token != TokenNameRPAREN) {
 
3007       throwSyntaxError("')' expected after keyword 'exit'");
 
3012   private void encaps_list() {
 
3013     //                  encaps_list encaps_var
 
3014     //          | encaps_list T_STRING
 
3015     //          | encaps_list T_NUM_STRING
 
3016     //          | encaps_list T_ENCAPSED_AND_WHITESPACE
 
3017     //          | encaps_list T_CHARACTER
 
3018     //          | encaps_list T_BAD_CHARACTER
 
3019     //          | encaps_list '['
 
3020     //          | encaps_list ']'
 
3021     //          | encaps_list '{'
 
3022     //          | encaps_list '}'
 
3023     //          | encaps_list T_OBJECT_OPERATOR
 
3027       case TokenNameSTRING:
 
3030       case TokenNameLBRACE:
 
3031         //          scanner.encapsedStringStack.pop();
 
3034       case TokenNameRBRACE:
 
3035         //          scanner.encapsedStringStack.pop();
 
3038       case TokenNameLBRACKET:
 
3039         //          scanner.encapsedStringStack.pop();
 
3042       case TokenNameRBRACKET:
 
3043         //          scanner.encapsedStringStack.pop();
 
3046       case TokenNameMINUS_GREATER:
 
3047         //          scanner.encapsedStringStack.pop();
 
3050       case TokenNameVariable:
 
3051       case TokenNameDOLLAR_LBRACE:
 
3052       case TokenNameLBRACE_DOLLAR:
 
3056         char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
 
3057         if (encapsedChar == '$') {
 
3058           scanner.encapsedStringStack.pop();
 
3059           encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
 
3060           switch (encapsedChar) {
 
3062             if (token == TokenNameEncapsedString0) {
 
3065             token = TokenNameSTRING;
 
3068             if (token == TokenNameEncapsedString1) {
 
3071             token = TokenNameSTRING;
 
3074             if (token == TokenNameEncapsedString2) {
 
3077             token = TokenNameSTRING;
 
3086   private void encaps_var() {
 
3088     //          | T_VARIABLE '[' encaps_var_offset ']'
 
3089     //          | T_VARIABLE T_OBJECT_OPERATOR T_STRING
 
3090     //          | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
 
3091     //          | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
 
3092     //          | T_CURLY_OPEN variable '}'
 
3094     case TokenNameVariable:
 
3096       if (token == TokenNameLBRACKET) {
 
3098         expr(); //encaps_var_offset();
 
3099         if (token != TokenNameRBRACKET) {
 
3100           throwSyntaxError("']' expected after variable.");
 
3102         //          scanner.encapsedStringStack.pop();
 
3105       } else if (token == TokenNameMINUS_GREATER) {
 
3107         if (token != TokenNameIdentifier) {
 
3108           throwSyntaxError("Identifier expected after '->'.");
 
3110         //          scanner.encapsedStringStack.pop();
 
3114       //          // scanner.encapsedStringStack.pop();
 
3115       //          int tempToken = TokenNameSTRING;
 
3116       //          if (!scanner.encapsedStringStack.isEmpty()
 
3117       //              && (token == TokenNameEncapsedString0
 
3118       //                  || token == TokenNameEncapsedString1
 
3119       //                  || token == TokenNameEncapsedString2 || token ==
 
3120       // TokenNameERROR)) {
 
3121       //            char encapsedChar = ((Character)
 
3122       // scanner.encapsedStringStack.peek())
 
3125       //              case TokenNameEncapsedString0 :
 
3126       //                if (encapsedChar == '`') {
 
3127       //                  tempToken = TokenNameEncapsedString0;
 
3130       //              case TokenNameEncapsedString1 :
 
3131       //                if (encapsedChar == '\'') {
 
3132       //                  tempToken = TokenNameEncapsedString1;
 
3135       //              case TokenNameEncapsedString2 :
 
3136       //                if (encapsedChar == '"') {
 
3137       //                  tempToken = TokenNameEncapsedString2;
 
3140       //              case TokenNameERROR :
 
3141       //                if (scanner.source[scanner.currentPosition - 1] == '\\') {
 
3142       //                  scanner.currentPosition--;
 
3148       //          token = tempToken;
 
3151     case TokenNameDOLLAR_LBRACE:
 
3153       if (token == TokenNameDOLLAR_LBRACE) {
 
3155       } else if (token == TokenNameIdentifier) {
 
3157         if (token == TokenNameLBRACKET) {
 
3159           //            if (token == TokenNameRBRACKET) {
 
3163           if (token != TokenNameRBRACKET) {
 
3164             throwSyntaxError("']' expected after '${'.");
 
3172       if (token != TokenNameRBRACE) {
 
3173         throwSyntaxError("'}' expected.");
 
3177     case TokenNameLBRACE_DOLLAR:
 
3179       if (token == TokenNameLBRACE_DOLLAR) {
 
3181       } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
3183         if (token == TokenNameLBRACKET) {
 
3185           //            if (token == TokenNameRBRACKET) {
 
3189           if (token != TokenNameRBRACKET) {
 
3190             throwSyntaxError("']' expected.");
 
3194         } else if (token == TokenNameMINUS_GREATER) {
 
3196           if (token != TokenNameIdentifier && token != TokenNameVariable) {
 
3197             throwSyntaxError("String or Variable token expected.");
 
3200           if (token == TokenNameLBRACKET) {
 
3202             //            if (token == TokenNameRBRACKET) {
 
3206             if (token != TokenNameRBRACKET) {
 
3207               throwSyntaxError("']' expected after '${'.");
 
3213         //          if (token != TokenNameRBRACE) {
 
3214         //            throwSyntaxError("'}' expected after '{$'.");
 
3216         //          // scanner.encapsedStringStack.pop();
 
3220         if (token != TokenNameRBRACE) {
 
3221           throwSyntaxError("'}' expected.");
 
3223         //          scanner.encapsedStringStack.pop();
 
3230   private void encaps_var_offset() {
 
3235     case TokenNameSTRING:
 
3238     case TokenNameIntegerLiteral:
 
3241     case TokenNameVariable:
 
3244     case TokenNameIdentifier:
 
3248       throwSyntaxError("Variable or String token expected.");
 
3253   private void internal_functions_in_yacc() {
 
3255     ImportReference impt = null;
 
3257     case TokenNameisset:
 
3258       //        T_ISSET '(' isset_variables ')'
 
3260       if (token != TokenNameLPAREN) {
 
3261         throwSyntaxError("'(' expected after keyword 'isset'");
 
3265       if (token != TokenNameRPAREN) {
 
3266         throwSyntaxError("')' expected after keyword 'isset'");
 
3270     case TokenNameempty:
 
3271       //        T_EMPTY '(' variable ')'
 
3273       if (token != TokenNameLPAREN) {
 
3274         throwSyntaxError("'(' expected after keyword 'empty'");
 
3278       if (token != TokenNameRPAREN) {
 
3279         throwSyntaxError("')' expected after keyword 'empty'");
 
3283     case TokenNameinclude:
 
3285       start = scanner.getCurrentTokenStartPosition();
 
3289       impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3290       impt.declarationSourceEnd = impt.sourceEnd;
 
3291       impt.declarationEnd = impt.declarationSourceEnd;
 
3292       //endPosition is just before the ;
 
3293       impt.declarationSourceStart = start;
 
3294       includesList.add(impt);
 
3296     case TokenNameinclude_once:
 
3297       //        T_INCLUDE_ONCE expr
 
3298       start = scanner.getCurrentTokenStartPosition();
 
3301       impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3302       impt.declarationSourceEnd = impt.sourceEnd;
 
3303       impt.declarationEnd = impt.declarationSourceEnd;
 
3304       //endPosition is just before the ;
 
3305       impt.declarationSourceStart = start;
 
3306       includesList.add(impt);
 
3309       //        T_EVAL '(' expr ')'
 
3311       if (token != TokenNameLPAREN) {
 
3312         throwSyntaxError("'(' expected after keyword 'eval'");
 
3316       if (token != TokenNameRPAREN) {
 
3317         throwSyntaxError("')' expected after keyword 'eval'");
 
3321     case TokenNamerequire:
 
3323       start = scanner.getCurrentTokenStartPosition();
 
3326       impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3327       impt.declarationSourceEnd = impt.sourceEnd;
 
3328       impt.declarationEnd = impt.declarationSourceEnd;
 
3329       //endPosition is just before the ;
 
3330       impt.declarationSourceStart = start;
 
3331       includesList.add(impt);
 
3333     case TokenNamerequire_once:
 
3334       //        T_REQUIRE_ONCE expr
 
3335       start = scanner.getCurrentTokenStartPosition();
 
3338       impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3339       impt.declarationSourceEnd = impt.sourceEnd;
 
3340       impt.declarationEnd = impt.declarationSourceEnd;
 
3341       //endPosition is just before the ;
 
3342       impt.declarationSourceStart = start;
 
3343       includesList.add(impt);
 
3348   private void isset_variables() {
 
3350     //  | isset_variables ','
 
3351     if (token == TokenNameRPAREN) {
 
3352       throwSyntaxError("Variable expected after keyword 'isset'");
 
3356       if (token == TokenNameCOMMA) {
 
3364   private boolean common_scalar() {
 
3368     //  | T_CONSTANT_ENCAPSED_STRING
 
3375     case TokenNameIntegerLiteral:
 
3378     case TokenNameDoubleLiteral:
 
3381     case TokenNameStringDoubleQuote:
 
3384     case TokenNameStringSingleQuote:
 
3387     case TokenNameStringInterpolated:
 
3396     case TokenNameCLASS_C:
 
3399     case TokenNameMETHOD_C:
 
3402     case TokenNameFUNC_C:
 
3409   private void scalar() {
 
3412     //| T_STRING_VARNAME
 
3415     //| '"' encaps_list '"'
 
3416     //| '\'' encaps_list '\''
 
3417     //| T_START_HEREDOC encaps_list T_END_HEREDOC
 
3418     throwSyntaxError("Not yet implemented (scalar).");
 
3421   private void static_scalar() {
 
3422     //    static_scalar: /* compile-time evaluated scalars */
 
3425     //  | '+' static_scalar
 
3426     //  | '-' static_scalar
 
3427     //  | T_ARRAY '(' static_array_pair_list ')'
 
3428     //  | static_class_constant
 
3429     if (common_scalar()) {
 
3433     case TokenNameIdentifier:
 
3435       //        static_class_constant:
 
3436       //                T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
 
3437       if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
 
3439         if (token == TokenNameIdentifier) {
 
3442           throwSyntaxError("Identifier expected after '::' operator.");
 
3446     case TokenNameEncapsedString0:
 
3448         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3449         while (scanner.currentCharacter != '`') {
 
3450           if (scanner.currentCharacter == '\\') {
 
3451             scanner.currentPosition++;
 
3453           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3456       } catch (IndexOutOfBoundsException e) {
 
3457         throwSyntaxError("'`' expected at end of static string.");
 
3460     case TokenNameEncapsedString1:
 
3462         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3463         while (scanner.currentCharacter != '\'') {
 
3464           if (scanner.currentCharacter == '\\') {
 
3465             scanner.currentPosition++;
 
3467           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3470       } catch (IndexOutOfBoundsException e) {
 
3471         throwSyntaxError("'\'' expected at end of static string.");
 
3474     case TokenNameEncapsedString2:
 
3476         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3477         while (scanner.currentCharacter != '"') {
 
3478           if (scanner.currentCharacter == '\\') {
 
3479             scanner.currentPosition++;
 
3481           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3484       } catch (IndexOutOfBoundsException e) {
 
3485         throwSyntaxError("'\"' expected at end of static string.");
 
3492     case TokenNameMINUS:
 
3496     case TokenNamearray:
 
3498       if (token != TokenNameLPAREN) {
 
3499         throwSyntaxError("'(' expected after keyword 'array'");
 
3502       if (token == TokenNameRPAREN) {
 
3506       non_empty_static_array_pair_list();
 
3507       if (token != TokenNameRPAREN) {
 
3508         throwSyntaxError("')' expected after keyword 'array'");
 
3512     //      case TokenNamenull :
 
3515     //      case TokenNamefalse :
 
3518     //      case TokenNametrue :
 
3522       throwSyntaxError("Static scalar/constant expected.");
 
3526   private void non_empty_static_array_pair_list() {
 
3527     //  non_empty_static_array_pair_list:
 
3528     //  non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
 
3530     //| non_empty_static_array_pair_list ',' static_scalar
 
3531     //| static_scalar T_DOUBLE_ARROW static_scalar
 
3535       if (token == TokenNameEQUAL_GREATER) {
 
3539       if (token != TokenNameCOMMA) {
 
3543       if (token == TokenNameRPAREN) {
 
3549   public void reportSyntaxError() { //int act, int currentKind, int
 
3551     /* remember current scanner position */
 
3552     int startPos = scanner.startPosition;
 
3553     int currentPos = scanner.currentPosition;
 
3554     //          String[] expectings;
 
3555     //          String tokenName = name[symbol_index[currentKind]];
 
3556     //fetch all "accurate" possible terminals that could recover the error
 
3557     //          int start, end = start = asi(stack[stateStackTop]);
 
3558     //          while (asr[end] != 0)
 
3560     //          int length = end - start;
 
3561     //          expectings = new String[length];
 
3562     //          if (length != 0) {
 
3563     //                  char[] indexes = new char[length];
 
3564     //                  System.arraycopy(asr, start, indexes, 0, length);
 
3565     //                  for (int i = 0; i < length; i++) {
 
3566     //                          expectings[i] = name[symbol_index[indexes[i]]];
 
3569     //if the pb is an EOF, try to tell the user that they are some
 
3570     //          if (tokenName.equals(UNEXPECTED_EOF)) {
 
3571     //                  if (!this.checkAndReportBracketAnomalies(problemReporter())) {
 
3572     //                          char[] tokenSource;
 
3574     //                                  tokenSource = this.scanner.getCurrentTokenSource();
 
3575     //                          } catch (Exception e) {
 
3576     //                                  tokenSource = new char[] {};
 
3578     //                          problemReporter().parseError(
 
3579     //                                  this.scanner.startPosition,
 
3580     //                                  this.scanner.currentPosition - 1,
 
3585     //          } else { //the next test is HEAVILY grammar DEPENDENT.
 
3586     //                  if ((length == 14)
 
3587     //                          && (expectings[0] == "=") //$NON-NLS-1$
 
3588     //                          && (expectings[1] == "*=") //$NON-NLS-1$
 
3589     //                          && (expressionPtr > -1)) {
 
3590     //                                  switch(currentKind) {
 
3591     //                                          case TokenNameSEMICOLON:
 
3592     //                                          case TokenNamePLUS:
 
3593     //                                          case TokenNameMINUS:
 
3594     //                                          case TokenNameDIVIDE:
 
3595     //                                          case TokenNameREMAINDER:
 
3596     //                                          case TokenNameMULTIPLY:
 
3597     //                                          case TokenNameLEFT_SHIFT:
 
3598     //                                          case TokenNameRIGHT_SHIFT:
 
3599     //// case TokenNameUNSIGNED_RIGHT_SHIFT:
 
3600     //                                          case TokenNameLESS:
 
3601     //                                          case TokenNameGREATER:
 
3602     //                                          case TokenNameLESS_EQUAL:
 
3603     //                                          case TokenNameGREATER_EQUAL:
 
3604     //                                          case TokenNameEQUAL_EQUAL:
 
3605     //                                          case TokenNameNOT_EQUAL:
 
3606     //                                          case TokenNameXOR:
 
3607     //                                          case TokenNameAND:
 
3608     //                                          case TokenNameOR:
 
3609     //                                          case TokenNameOR_OR:
 
3610     //                                          case TokenNameAND_AND:
 
3611     //                                                  // the ; is not the expected token ==> it ends a statement when an
 
3612     // expression is not ended
 
3613     //                                                  problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
 
3615     //                                          case TokenNameRBRACE :
 
3616     //                                                  problemReporter().missingSemiColon(expressionStack[expressionPtr]);
 
3619     //                                                  char[] tokenSource;
 
3621     //                                                          tokenSource = this.scanner.getCurrentTokenSource();
 
3622     //                                                  } catch (Exception e) {
 
3623     //                                                          tokenSource = new char[] {};
 
3625     //                                                  problemReporter().parseError(
 
3626     //                                                          this.scanner.startPosition,
 
3627     //                                                          this.scanner.currentPosition - 1,
 
3631     //                                                  this.checkAndReportBracketAnomalies(problemReporter());
 
3636       tokenSource = this.scanner.getCurrentTokenSource();
 
3637     } catch (Exception e) {
 
3638       tokenSource = new char[] {};
 
3640     //                          problemReporter().parseError(
 
3641     //                                  this.scanner.startPosition,
 
3642     //                                  this.scanner.currentPosition - 1,
 
3646     this.checkAndReportBracketAnomalies(problemReporter());
 
3649     /* reset scanner where it was */
 
3650     scanner.startPosition = startPos;
 
3651     scanner.currentPosition = currentPos;
 
3654   public static final int RoundBracket = 0;
 
3656   public static final int SquareBracket = 1;
 
3658   public static final int CurlyBracket = 2;
 
3660   public static final int BracketKinds = 3;
 
3662   protected int[] nestedMethod; //the ptr is nestedType
 
3664   protected int nestedType, dimensions;
 
3667   final static int AstStackIncrement = 100;
 
3669   protected int astPtr;
 
3671   protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
 
3673   protected int astLengthPtr;
 
3675   protected int[] astLengthStack;
 
3677   ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
 
3679   public CompilationUnitDeclaration compilationUnit; /*
 
3680                                                       * the result from parse()
 
3683   protected ReferenceContext referenceContext;
 
3685   protected ProblemReporter problemReporter;
 
3687   protected CompilerOptions options;
 
3689   private ArrayList includesList;
 
3691   //  protected CompilationResult compilationResult;
 
3693    * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
 
3694    * reported, so initializes the compilation result's line positions.
 
3696   public ProblemReporter problemReporter() {
 
3697     if (scanner.recordLineSeparator) {
 
3698       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
 
3700     problemReporter.referenceContext = referenceContext;
 
3701     return problemReporter;
 
3705    * Reconsider the entire source looking for inconsistencies in {} () []
 
3707   public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
 
3708     scanner.wasAcr = false;
 
3709     boolean anomaliesDetected = false;
 
3711       char[] source = scanner.source;
 
3712       int[] leftCount = { 0, 0, 0 };
 
3713       int[] rightCount = { 0, 0, 0 };
 
3714       int[] depths = { 0, 0, 0 };
 
3715       int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
 
3716       int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
 
3717       int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
 
3718       int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
 
3719       scanner.currentPosition = scanner.initialPosition; //starting
 
3721       // (first-zero-based
 
3723       while (scanner.currentPosition < scanner.eofPosition) { //loop for
 
3728           // ---------Consume white space and handles
 
3729           // startPosition---------
 
3730           boolean isWhiteSpace;
 
3732             scanner.startPosition = scanner.currentPosition;
 
3733             //                                          if (((scanner.currentCharacter =
 
3734             // source[scanner.currentPosition++]) == '\\') &&
 
3735             // (source[scanner.currentPosition] == 'u')) {
 
3736             //                                                  isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
 
3738             if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
 
3739               if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
 
3740                 // only record line positions we have not
 
3742                 scanner.pushLineSeparator();
 
3745             isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
 
3747           } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
 
3748           // -------consume token until } is found---------
 
3749           switch (scanner.currentCharacter) {
 
3751             int index = leftCount[CurlyBracket]++;
 
3752             if (index == leftPositions[CurlyBracket].length) {
 
3753               System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
 
3754               System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
 
3756             leftPositions[CurlyBracket][index] = scanner.startPosition;
 
3757             leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
 
3761             int index = rightCount[CurlyBracket]++;
 
3762             if (index == rightPositions[CurlyBracket].length) {
 
3763               System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
 
3764               System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
 
3766             rightPositions[CurlyBracket][index] = scanner.startPosition;
 
3767             rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
 
3771             int index = leftCount[RoundBracket]++;
 
3772             if (index == leftPositions[RoundBracket].length) {
 
3773               System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
 
3774               System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
 
3776             leftPositions[RoundBracket][index] = scanner.startPosition;
 
3777             leftDepths[RoundBracket][index] = depths[RoundBracket]++;
 
3781             int index = rightCount[RoundBracket]++;
 
3782             if (index == rightPositions[RoundBracket].length) {
 
3783               System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
 
3784               System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
 
3786             rightPositions[RoundBracket][index] = scanner.startPosition;
 
3787             rightDepths[RoundBracket][index] = --depths[RoundBracket];
 
3791             int index = leftCount[SquareBracket]++;
 
3792             if (index == leftPositions[SquareBracket].length) {
 
3793               System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
 
3794               System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
 
3796             leftPositions[SquareBracket][index] = scanner.startPosition;
 
3797             leftDepths[SquareBracket][index] = depths[SquareBracket]++;
 
3801             int index = rightCount[SquareBracket]++;
 
3802             if (index == rightPositions[SquareBracket].length) {
 
3803               System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
 
3804               System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
 
3806             rightPositions[SquareBracket][index] = scanner.startPosition;
 
3807             rightDepths[SquareBracket][index] = --depths[SquareBracket];
 
3811             if (scanner.getNextChar('\\')) {
 
3812               scanner.scanEscapeCharacter();
 
3813             } else { // consume next character
 
3814               scanner.unicodeAsBackSlash = false;
 
3815               //                                                                        if (((scanner.currentCharacter =
 
3816               // source[scanner.currentPosition++]) ==
 
3818               // (source[scanner.currentPosition] ==
 
3820               //                                                                                scanner.getNextUnicodeChar();
 
3822               if (scanner.withoutUnicodePtr != 0) {
 
3823                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3827             scanner.getNextChar('\'');
 
3831             // consume next character
 
3832             scanner.unicodeAsBackSlash = false;
 
3833             //                                                  if (((scanner.currentCharacter =
 
3834             // source[scanner.currentPosition++]) == '\\') &&
 
3835             // (source[scanner.currentPosition] == 'u')) {
 
3836             //                                                          scanner.getNextUnicodeChar();
 
3838             if (scanner.withoutUnicodePtr != 0) {
 
3839               scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3842             while (scanner.currentCharacter != '"') {
 
3843               if (scanner.currentCharacter == '\r') {
 
3844                 if (source[scanner.currentPosition] == '\n')
 
3845                   scanner.currentPosition++;
 
3846                 break; // the string cannot go further that
 
3849               if (scanner.currentCharacter == '\n') {
 
3850                 break; // the string cannot go further that
 
3853               if (scanner.currentCharacter == '\\') {
 
3854                 scanner.scanEscapeCharacter();
 
3856               // consume next character
 
3857               scanner.unicodeAsBackSlash = false;
 
3858               //                                                                if (((scanner.currentCharacter =
 
3859               // source[scanner.currentPosition++]) == '\\')
 
3860               // && (source[scanner.currentPosition] == 'u'))
 
3862               //                                                                        scanner.getNextUnicodeChar();
 
3864               if (scanner.withoutUnicodePtr != 0) {
 
3865                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3872             if ((test = scanner.getNextChar('/', '*')) == 0) { //line
 
3875               if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3876                   && (source[scanner.currentPosition] == 'u')) {
 
3877                 //-------------unicode traitement
 
3879                 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3880                 scanner.currentPosition++;
 
3881                 while (source[scanner.currentPosition] == 'u') {
 
3882                   scanner.currentPosition++;
 
3884                 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3885                     || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3886                     || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3887                     || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3891                   scanner.currentCharacter = 'A';
 
3892                 } //something different from \n and \r
 
3894                   scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
3897               while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
 
3899                 scanner.startPosition = scanner.currentPosition;
 
3900                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3901                     && (source[scanner.currentPosition] == 'u')) {
 
3902                   //-------------unicode traitement
 
3904                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3905                   scanner.currentPosition++;
 
3906                   while (source[scanner.currentPosition] == 'u') {
 
3907                     scanner.currentPosition++;
 
3909                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3910                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3911                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3912                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3916                     scanner.currentCharacter = 'A';
 
3917                   } //something different from \n
 
3920                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
3924               if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
 
3925                 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
 
3926                   // only record line positions we
 
3927                   // have not recorded yet
 
3928                   scanner.pushLineSeparator();
 
3929                   if (this.scanner.taskTags != null) {
 
3930                     this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
 
3931                         .getCurrentTokenEndPosition());
 
3937             if (test > 0) { //traditional and annotation
 
3939               boolean star = false;
 
3940               // consume next character
 
3941               scanner.unicodeAsBackSlash = false;
 
3942               //                                                                        if (((scanner.currentCharacter =
 
3943               // source[scanner.currentPosition++]) ==
 
3945               // (source[scanner.currentPosition] ==
 
3947               //                                                                                scanner.getNextUnicodeChar();
 
3949               if (scanner.withoutUnicodePtr != 0) {
 
3950                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3953               if (scanner.currentCharacter == '*') {
 
3957               if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3958                   && (source[scanner.currentPosition] == 'u')) {
 
3959                 //-------------unicode traitement
 
3961                 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3962                 scanner.currentPosition++;
 
3963                 while (source[scanner.currentPosition] == 'u') {
 
3964                   scanner.currentPosition++;
 
3966                 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3967                     || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3968                     || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3969                     || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3973                   scanner.currentCharacter = 'A';
 
3974                 } //something different from * and /
 
3976                   scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
3979               //loop until end of comment */
 
3980               while ((scanner.currentCharacter != '/') || (!star)) {
 
3981                 star = scanner.currentCharacter == '*';
 
3983                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3984                     && (source[scanner.currentPosition] == 'u')) {
 
3985                   //-------------unicode traitement
 
3987                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3988                   scanner.currentPosition++;
 
3989                   while (source[scanner.currentPosition] == 'u') {
 
3990                     scanner.currentPosition++;
 
3992                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3993                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3994                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3995                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3999                     scanner.currentCharacter = 'A';
 
4000                   } //something different from * and
 
4003                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
4007               if (this.scanner.taskTags != null) {
 
4008                 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
 
4015             if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
 
4016               scanner.scanIdentifierOrKeyword(false);
 
4019             if (Character.isDigit(scanner.currentCharacter)) {
 
4020               scanner.scanNumber(false);
 
4024           //-----------------end switch while
 
4025           // try--------------------
 
4026         } catch (IndexOutOfBoundsException e) {
 
4027           break; // read until EOF
 
4028         } catch (InvalidInputException e) {
 
4029           return false; // no clue
 
4032       if (scanner.recordLineSeparator) {
 
4033         //                              compilationUnit.compilationResult.lineSeparatorPositions =
 
4034         // scanner.getLineEnds();
 
4036       // check placement anomalies against other kinds of brackets
 
4037       for (int kind = 0; kind < BracketKinds; kind++) {
 
4038         for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
 
4039           int start = leftPositions[kind][leftIndex]; // deepest
 
4041           // find matching closing bracket
 
4042           int depth = leftDepths[kind][leftIndex];
 
4044           for (int i = 0; i < rightCount[kind]; i++) {
 
4045             int pos = rightPositions[kind][i];
 
4046             // want matching bracket further in source with same
 
4048             if ((pos > start) && (depth == rightDepths[kind][i])) {
 
4053           if (end < 0) { // did not find a good closing match
 
4054             problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
 
4057           // check if even number of opening/closing other brackets
 
4058           // in between this pair of brackets
 
4060           for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
 
4061             for (int i = 0; i < leftCount[otherKind]; i++) {
 
4062               int pos = leftPositions[otherKind][i];
 
4063               if ((pos > start) && (pos < end))
 
4066             for (int i = 0; i < rightCount[otherKind]; i++) {
 
4067               int pos = rightPositions[otherKind][i];
 
4068               if ((pos > start) && (pos < end))
 
4072               problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
 
4078         // too many opening brackets ?
 
4079         for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
 
4080           anomaliesDetected = true;
 
4081           problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
 
4082               compilationUnit.compilationResult);
 
4084         // too many closing brackets ?
 
4085         for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
 
4086           anomaliesDetected = true;
 
4087           problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
 
4089         if (anomaliesDetected)
 
4092       return anomaliesDetected;
 
4093     } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
 
4094       return anomaliesDetected;
 
4095     } catch (NullPointerException e) { // jdk1.2.2 jit bug
 
4096       return anomaliesDetected;
 
4100   protected void pushOnAstLengthStack(int pos) {
 
4102       astLengthStack[++astLengthPtr] = pos;
 
4103     } catch (IndexOutOfBoundsException e) {
 
4104       int oldStackLength = astLengthStack.length;
 
4105       int[] oldPos = astLengthStack;
 
4106       astLengthStack = new int[oldStackLength + StackIncrement];
 
4107       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
 
4108       astLengthStack[astLengthPtr] = pos;
 
4112   protected void pushOnAstStack(ASTNode node) {
 
4114      * add a new obj on top of the ast stack
 
4117       astStack[++astPtr] = node;
 
4118     } catch (IndexOutOfBoundsException e) {
 
4119       int oldStackLength = astStack.length;
 
4120       ASTNode[] oldStack = astStack;
 
4121       astStack = new ASTNode[oldStackLength + AstStackIncrement];
 
4122       System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
 
4123       astPtr = oldStackLength;
 
4124       astStack[astPtr] = node;
 
4127       astLengthStack[++astLengthPtr] = 1;
 
4128     } catch (IndexOutOfBoundsException e) {
 
4129       int oldStackLength = astLengthStack.length;
 
4130       int[] oldPos = astLengthStack;
 
4131       astLengthStack = new int[oldStackLength + AstStackIncrement];
 
4132       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
 
4133       astLengthStack[astLengthPtr] = 1;
 
4137   protected void resetModifiers() {
 
4138     this.modifiers = AccDefault;
 
4139     this.modifiersSourceStart = -1; // <-- see comment into
 
4140     // modifiersFlag(int)
 
4141     this.scanner.commentPtr = -1;