1 /*******************************************************************************
 
   2  * Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de All rights
 
   3  * reserved. This program and the accompanying material are made available under
 
   4  * the terms of the Common Public License v1.0 which accompanies this
 
   5  * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
 
   7  * Contributors: Klaus Hartlage - www.eclipseproject.de
 
   8  ******************************************************************************/
 
   9 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.AbstractMethodDeclaration;
 
  24 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
 
  25 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
 
  26 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
 
  27 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
 
  28 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
 
  29 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
 
  30 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
 
  32 import org.eclipse.core.resources.IFile;
 
  33 public class Parser //extends PHPParserSuperclass
 
  34     implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
 
  35   //internal data for the automat
 
  36   protected final static int StackIncrement = 255;
 
  37   protected int stateStackTop;
 
  38   protected int[] stack = new int[StackIncrement];
 
  39   public int firstToken; // handle for multiple parsing goals
 
  40   public int lastAct; //handle for multiple parsing goals
 
  41   protected RecoveredElement currentElement;
 
  42   public static boolean VERBOSE_RECOVERY = false;
 
  43   protected boolean diet = false; //tells the scanner to jump over some
 
  44   // parts of the code/expressions like
 
  47   public Scanner scanner;
 
  48   private ArrayList phpList;
 
  49   private int currentPHPString;
 
  50   private boolean phpEnd;
 
  51   // private static HashMap keywordMap = null;
 
  57   // row counter for syntax errors:
 
  59   // column counter for syntax errors:
 
  63   //    // current identifier
 
  67   private String stringValue;
 
  68   /** Contains the current expression. */
 
  69   // private StringBuffer expression;
 
  70   //private boolean phpMode;
 
  71   protected int modifiers;
 
  72   protected int modifiersSourceStart;
 
  73 //  protected IdentifierIndexManager indexManager;
 
  75   protected Parser(ProblemReporter problemReporter) {
 
  76     this.problemReporter = problemReporter;
 
  77     this.options = problemReporter.options;
 
  78     this.currentPHPString = 0;
 
  79     //          PHPParserSuperclass.fileToParse = fileToParse;
 
  81 //    this.indexManager = null;
 
  83     this.token = TokenNameEOF;
 
  86     //    this.columnCount = 0;
 
  89     this.initializeScanner();
 
  91   public void setFileToParse(IFile fileToParse) {
 
  92     this.currentPHPString = 0;
 
  93     //    PHPParserSuperclass.fileToParse = fileToParse;
 
  95 //    this.indexManager = null;
 
  97     this.token = TokenNameEOF;
 
  99     this.initializeScanner();
 
 102    * ClassDeclaration Constructor.
 
 106    *          Description of Parameter
 
 109   public Parser(IFile fileToParse) {
 
 110     //    if (keywordMap == null) {
 
 111     //      keywordMap = new HashMap();
 
 112     //      for (int i = 0; i < PHP_KEYWORS.length; i++) {
 
 113     //        keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
 
 116     this.currentPHPString = 0;
 
 117     //    PHPParserSuperclass.fileToParse = fileToParse;
 
 119     this.includesList = null;
 
 121     this.token = TokenNameEOF;
 
 123     //    this.rowCount = 1;
 
 124     //    this.columnCount = 0;
 
 127     this.initializeScanner();
 
 129   public void initializeScanner() {
 
 130     this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
 
 131         .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
 
 132         this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */);
 
 135    * Create marker for the parse error
 
 137   //  private void setMarker(String message, int charStart, int charEnd, int
 
 139   //    setMarker(fileToParse, message, charStart, charEnd, errorLevel);
 
 142    * This method will throw the SyntaxError. It will add the good lines and
 
 143    * columns to the Error
 
 147    * @throws SyntaxError
 
 150   private void throwSyntaxError(String error) {
 
 151     int problemStartPosition = scanner.getCurrentTokenStartPosition();
 
 152     int problemEndPosition = scanner.getCurrentTokenEndPosition();
 
 153     throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
 
 156    * This method will throw the SyntaxError. It will add the good lines and
 
 157    * columns to the Error
 
 161    * @throws SyntaxError
 
 164   //  private void throwSyntaxError(String error, int startRow) {
 
 165   //    throw new SyntaxError(startRow, 0, " ", error);
 
 167   private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
 
 168     problemReporter.phpParsingError(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
 
 169         compilationUnit.compilationResult);
 
 170     throw new SyntaxError(1, 0, " ", error);
 
 172   private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
 
 173     problemReporter.phpParsingError(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
 
 174         compilationUnit.compilationResult);
 
 176   private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
 
 177     problemReporter.phpParsingWarning(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
 
 178         compilationUnit.compilationResult);
 
 181    * Method Declaration.
 
 185   //  private void getChar() {
 
 186   //    if (str.length() > chIndx) {
 
 187   //      ch = str.charAt(chIndx++);
 
 192   //    chIndx = str.length() + 1;
 
 194   //    // token = TokenNameEOF;
 
 198    * gets the next token from input
 
 200   private void getNextToken() {
 
 202       token = scanner.getNextToken();
 
 204         int currentEndPosition = scanner.getCurrentTokenEndPosition();
 
 205         int currentStartPosition = scanner.getCurrentTokenStartPosition();
 
 206         System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
 
 207         System.out.println(scanner.toStringAction(token));
 
 209     } catch (InvalidInputException e) {
 
 210       token = TokenNameERROR;
 
 211       String detailedMessage = e.getMessage();
 
 213       if (detailedMessage==Scanner.UNTERMINATED_STRING) {
 
 214         throwSyntaxError("Unterminated string.");
 
 215       } else if (detailedMessage==Scanner.UNTERMINATED_COMMENT) {
 
 216         throwSyntaxError("Unterminated commment.");
 
 221   public void init(String s) {
 
 223     this.token = TokenNameEOF;
 
 225     //    this.rowCount = 1;
 
 226     //    this.columnCount = 0;
 
 228     //    this.phpMode = false;
 
 229     /* scanner initialization */
 
 230     scanner.setSource(s.toCharArray());
 
 231     scanner.setPHPMode(false);
 
 233   protected void initialize(boolean phpMode) {
 
 234     initialize(phpMode, null);
 
 236   protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
 
 237     compilationUnit = null;
 
 238     referenceContext = null;
 
 239     includesList = new ArrayList();
 
 240 //    this.indexManager = indexManager;
 
 242     this.token = TokenNameEOF;
 
 244     //    this.rowCount = 1;
 
 245     //    this.columnCount = 0;
 
 247     //    this.phpMode = phpMode;
 
 248     scanner.setPHPMode(phpMode);
 
 251    * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
 
 254   public void parse(String s) {
 
 259    * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
 
 262   protected void parse() {
 
 266         if (token != TokenNameEOF && token != TokenNameERROR) {
 
 269         if (token != TokenNameEOF) {
 
 270           if (token == TokenNameERROR) {
 
 271             throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
 
 273           if (token == TokenNameRPAREN) {
 
 274             throwSyntaxError("Too many closing ')'; end-of-file not reached.");
 
 276           if (token == TokenNameRBRACE) {
 
 277             throwSyntaxError("Too many closing '}'; end-of-file not reached.");
 
 279           if (token == TokenNameRBRACKET) {
 
 280             throwSyntaxError("Too many closing ']'; end-of-file not reached.");
 
 282           if (token == TokenNameLPAREN) {
 
 283             throwSyntaxError("Read character '('; end-of-file not reached.");
 
 285           if (token == TokenNameLBRACE) {
 
 286             throwSyntaxError("Read character '{';  end-of-file not reached.");
 
 288           if (token == TokenNameLBRACKET) {
 
 289             throwSyntaxError("Read character '[';  end-of-file not reached.");
 
 291           throwSyntaxError("End-of-file not reached.");
 
 294       } catch (SyntaxError sytaxErr1) {
 
 295         // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
 
 297         //        setMarker(sytaxErr1.getMessage(),
 
 298         // scanner.getCurrentTokenStartPosition(),
 
 299         // scanner.getCurrentTokenEndPosition(), ERROR);
 
 301           // if an error occured,
 
 302           // try to find keywords 'class' or 'function'
 
 303           // to parse the rest of the string
 
 304           while (token != TokenNameEOF && token != TokenNameERROR) {
 
 305             if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
 
 310           if (token == TokenNameEOF || token == TokenNameERROR) {
 
 313         } catch (SyntaxError sytaxErr2) {
 
 314           //    setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
 
 316           //          setMarker(sytaxErr2.getMessage(),
 
 317           // scanner.getCurrentTokenStartPosition(),
 
 318           // scanner.getCurrentTokenEndPosition(), ERROR);
 
 327   protected CompilationUnitDeclaration endParse(int act) {
 
 331     if (currentElement != null) {
 
 332       currentElement.topElement().updateParseTree();
 
 333       if (VERBOSE_RECOVERY) {
 
 334         System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
 
 335         System.out.println("--------------------------"); //$NON-NLS-1$
 
 336         System.out.println(compilationUnit);
 
 337         System.out.println("----------------------------------"); //$NON-NLS-1$
 
 340       if (diet & VERBOSE_RECOVERY) {
 
 341         System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
 
 342         System.out.println("--------------------------"); //$NON-NLS-1$
 
 343         System.out.println(compilationUnit);
 
 344         System.out.println("----------------------------------"); //$NON-NLS-1$
 
 347     if (scanner.recordLineSeparator) {
 
 348       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
 
 350     if (scanner.taskTags != null) {
 
 351       for (int i = 0; i < scanner.foundTaskCount; i++) {
 
 352         problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
 
 353             scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
 
 354             scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
 
 357     compilationUnit.imports = new ImportReference[includesList.size()];
 
 358     for (int i = 0; i < includesList.size(); i++) {
 
 359       compilationUnit.imports[i] = (ImportReference) includesList.get(i);
 
 361     return compilationUnit;
 
 363   //  public PHPOutlineInfo parseInfo(Object parent, String s) {
 
 364   //    PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
 
 365   //    // Stack stack = new Stack();
 
 366   //    // stack.push(outlineInfo.getDeclarations());
 
 368   //    this.token = TokenNameEOF;
 
 369   //    // this.chIndx = 0;
 
 370   //    // this.rowCount = 1;
 
 371   //    // this.columnCount = 0;
 
 372   //    this.phpEnd = false;
 
 373   //    this.phpMode = false;
 
 374   //    scanner.setSource(s.toCharArray());
 
 375   //    scanner.setPHPMode(false);
 
 378   //    parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
 
 380   //    return outlineInfo;
 
 382   private boolean isVariable() {
 
 383     return token == TokenNameVariable; //  || token == TokenNamethis;
 
 385   //  private void parseDeclarations(PHPOutlineInfo outlineInfo,
 
 386   //      OutlineableWithChildren current, boolean goBack) {
 
 388   //    // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
 
 389   //    PHPSegmentWithChildren temp;
 
 391   //    IPreferenceStore store =
 
 392   // PHPeclipsePlugin.getDefault().getPreferenceStore();
 
 394   //      while (token != TokenNameEOF && token != TokenNameERROR) {
 
 395   //        if (token == TokenNameVariable) {
 
 396   //          ident = scanner.getCurrentIdentifierSource();
 
 397   //          outlineInfo.addVariable(new String(ident));
 
 399   //        } else if (token == TokenNamevar) {
 
 401   //          if (token == TokenNameVariable
 
 402   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
 
 403   //            ident = scanner.getCurrentIdentifierSource();
 
 404   //            //substring(1) added because PHPVarDeclaration doesn't
 
 405   //            // need the $ anymore
 
 406   //            String variableName = new String(ident).substring(1);
 
 407   //            outlineInfo.addVariable(variableName);
 
 409   //            if (token != TokenNameSEMICOLON) {
 
 411   //              ident = scanner.getCurrentTokenSource();
 
 412   //              if (token > TokenNameKEYWORD) {
 
 413   //                current.add(new PHPVarDeclaration(current, variableName,
 
 414   //                // chIndx - ident.length,
 
 415   //                    scanner.getCurrentTokenStartPosition(), new String(ident)));
 
 418   //                  case TokenNameVariable :
 
 419   //                  case TokenNamethis :
 
 420   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 423   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 426   //                  case TokenNameIdentifier :
 
 427   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 430   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 433   //                  case TokenNameDoubleLiteral :
 
 434   //                    current.add(new PHPVarDeclaration(current, variableName
 
 438   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 441   //                  case TokenNameIntegerLiteral :
 
 442   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 445   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 448   //                  case TokenNameStringInterpolated :
 
 449   //                  case TokenNameStringLiteral :
 
 450   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 453   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 456   //                  case TokenNameStringConstant :
 
 457   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 460   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 464   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 467   //                        scanner.getCurrentTokenStartPosition()));
 
 472   //              ident = scanner.getCurrentIdentifierSource();
 
 473   //              current.add(new PHPVarDeclaration(current, variableName,
 
 474   //              // chIndx - ident.length
 
 475   //                  scanner.getCurrentTokenStartPosition()));
 
 478   //        } else if (token == TokenNamefunction) {
 
 480   //          if (token == TokenNameAND) {
 
 483   //          if (token == TokenNameIdentifier
 
 484   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
 
 485   //            ident = scanner.getCurrentIdentifierSource();
 
 486   //            outlineInfo.addVariable(new String(ident));
 
 487   //            temp = new PHPFunctionDeclaration(current, new String(ident),
 
 488   //            // chIndx - ident.length
 
 489   //                scanner.getCurrentTokenStartPosition());
 
 490   //            current.add(temp);
 
 492   //            parseDeclarations(outlineInfo, temp, true);
 
 494   //        } else if (token == TokenNameclass) {
 
 496   //          if (token == TokenNameIdentifier
 
 497   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
 
 498   //            ident = scanner.getCurrentIdentifierSource();
 
 499   //            outlineInfo.addVariable(new String(ident));
 
 500   //            temp = new PHPClassDeclaration(current, new String(ident),
 
 501   //            // chIndx - ident.len
 
 502   //                scanner.getCurrentTokenStartPosition());
 
 503   //            current.add(temp);
 
 504   //            // stack.push(temp);
 
 506   //            //skip tokens for classname, extends and others until
 
 507   //            // we have the opening '{'
 
 508   //            while (token != TokenNameLBRACE && token != TokenNameEOF
 
 509   //                && token != TokenNameERROR) {
 
 512   //            parseDeclarations(outlineInfo, temp, true);
 
 515   //        } else if ((token == TokenNameLBRACE)
 
 516   //            || (token == TokenNameDOLLAR_LBRACE)) {
 
 519   //        } else if (token == TokenNameRBRACE) {
 
 522   //          if (counter == 0 && goBack) {
 
 525   //        } else if (token == TokenNamerequire || token == TokenNamerequire_once
 
 526   //            || token == TokenNameinclude || token == TokenNameinclude_once) {
 
 527   //          ident = scanner.getCurrentTokenSource();
 
 529   //          int startPosition = scanner.getCurrentTokenStartPosition();
 
 531   //          char[] expr = scanner.getCurrentTokenSource(startPosition);
 
 532   //          outlineInfo.addVariable(new String(ident));
 
 533   //          current.add(new PHPReqIncDeclaration(current, new String(ident),
 
 534   //          // chIndx - ident.length,
 
 535   //              startPosition, new String(expr)));
 
 541   //    } catch (SyntaxError sytaxErr) {
 
 543   //      // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
 
 544   //      // setMarker(sytaxErr.getMessage(),
 
 545   //      // scanner.getCurrentTokenStartPosition(),
 
 546   //      // scanner.getCurrentTokenEndPosition(), ERROR);
 
 547   //      // } catch (CoreException e) {
 
 551   private void statementList() {
 
 553       statement(TokenNameEOF);
 
 554       if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
 
 555           || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
 
 556           || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
 
 557           || (token == TokenNameEOF) || (token == TokenNameERROR)) {
 
 562   private void functionBody(MethodDeclaration methodDecl) {
 
 563     // '{' [statement-list] '}'
 
 564     if (token == TokenNameLBRACE) {
 
 567       throwSyntaxError("'{' expected in compound-statement.");
 
 569     if (token != TokenNameRBRACE) {
 
 572     if (token == TokenNameRBRACE) {
 
 573       methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
 576       throwSyntaxError("'}' expected in compound-statement.");
 
 579   private void statement(int previousToken) {
 
 580     //   if (token > TokenNameKEYWORD && token != TokenNamelist && token !=
 
 582     //  char[] ident = scanner.getCurrentIdentifierSource();
 
 583     //  String keyword = new String(ident);
 
 584     //    if (token == TokenNameAT) {
 
 586     //      if (token != TokenNamerequire && token != TokenNamerequire_once
 
 587     //          && token != TokenNameinclude && token != TokenNameinclude_once
 
 588     //          && token != TokenNameIdentifier && token != TokenNameVariable
 
 589     //          && token != TokenNameStringInterpolated) {
 
 590     //        throwSyntaxError("identifier expected after '@'.");
 
 593     //    if (token == TokenNameinclude || token == TokenNameinclude_once) {
 
 595     //      if (token == TokenNameLPAREN) {
 
 597     //        if (token == TokenNameSEMICOLON) {
 
 600     //          if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
 
 601     //            throwSyntaxError("';' expected after 'include' or 'include_once'.");
 
 603     //          // getNextToken();
 
 606     //        concatenationExpression();
 
 609     //    } else if (token == TokenNamerequire || token ==
 
 610     // TokenNamerequire_once)
 
 614     //      if (token == TokenNameLPAREN) {
 
 616     //        if (token == TokenNameSEMICOLON) {
 
 619     //          if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
 
 620     //            throwSyntaxError("';' expected after 'require' or 'require_once'.");
 
 622     //          // getNextToken();
 
 625     //        concatenationExpression();
 
 629     if (token == TokenNameif) {
 
 631       if (token == TokenNameLPAREN) {
 
 634         throwSyntaxError("'(' expected after 'if' keyword.");
 
 637       if (token == TokenNameRPAREN) {
 
 640         throwSyntaxError("')' expected after 'if' condition.");
 
 644     } else if (token == TokenNameswitch) {
 
 646       if (token == TokenNameLPAREN) {
 
 649         throwSyntaxError("'(' expected after 'switch' keyword.");
 
 652       if (token == TokenNameRPAREN) {
 
 655         throwSyntaxError("')' expected after 'switch' condition.");
 
 659     } else if (token == TokenNamefor) {
 
 661       if (token == TokenNameLPAREN) {
 
 664         throwSyntaxError("'(' expected after 'for' keyword.");
 
 666       if (token == TokenNameSEMICOLON) {
 
 670         if (token == TokenNameSEMICOLON) {
 
 673           throwSyntaxError("';' expected after 'for'.");
 
 676       if (token == TokenNameSEMICOLON) {
 
 680         if (token == TokenNameSEMICOLON) {
 
 683           throwSyntaxError("';' expected after 'for'.");
 
 686       if (token == TokenNameRPAREN) {
 
 690         if (token == TokenNameRPAREN) {
 
 693           throwSyntaxError("')' expected after 'for'.");
 
 698     } else if (token == TokenNamewhile) {
 
 700       if (token == TokenNameLPAREN) {
 
 703         throwSyntaxError("'(' expected after 'while' keyword.");
 
 706       if (token == TokenNameRPAREN) {
 
 709         throwSyntaxError("')' expected after 'while' condition.");
 
 713     } else if (token == TokenNamedo) {
 
 715       if (token == TokenNameLBRACE) {
 
 717         if (token != TokenNameRBRACE) {
 
 720         if (token == TokenNameRBRACE) {
 
 723           throwSyntaxError("'}' expected after 'do' keyword.");
 
 726         statement(TokenNameEOF);
 
 728       if (token == TokenNamewhile) {
 
 730         if (token == TokenNameLPAREN) {
 
 733           throwSyntaxError("'(' expected after 'while' keyword.");
 
 736         if (token == TokenNameRPAREN) {
 
 739           throwSyntaxError("')' expected after 'while' condition.");
 
 742         throwSyntaxError("'while' expected after 'do' keyword.");
 
 744       if (token == TokenNameSEMICOLON) {
 
 747         if (token != TokenNameINLINE_HTML) {
 
 748           throwSyntaxError("';' expected after do-while statement.");
 
 753     } else if (token == TokenNameforeach) {
 
 755       if (token == TokenNameLPAREN) {
 
 758         throwSyntaxError("'(' expected after 'foreach' keyword.");
 
 761       if (token == TokenNameas) {
 
 764         throwSyntaxError("'as' expected after 'foreach' exxpression.");
 
 768       foreach_optional_arg();
 
 769       if (token == TokenNameEQUAL_GREATER) {
 
 773       if (token == TokenNameRPAREN) {
 
 776         throwSyntaxError("')' expected after 'foreach' expression.");
 
 780     } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
 
 782       if (token != TokenNameSEMICOLON) {
 
 785       if (token == TokenNameSEMICOLON) {
 
 788         if (token != TokenNameINLINE_HTML) {
 
 789           throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
 
 794     } else if (token == TokenNameecho) {
 
 797       if (token == TokenNameSEMICOLON) {
 
 800         if (token != TokenNameINLINE_HTML) {
 
 801           throwSyntaxError("';' expected after 'echo' statement.");
 
 806     } else if (token == TokenNameINLINE_HTML) {
 
 809       //    } else if (token == TokenNameprint) {
 
 812       //      if (token == TokenNameSEMICOLON) {
 
 815       //        if (token != TokenNameStopPHP) {
 
 816       //          throwSyntaxError("';' expected after 'print' statement.");
 
 821     } else if (token == TokenNameglobal) {
 
 824       if (token == TokenNameSEMICOLON) {
 
 827         if (token != TokenNameINLINE_HTML) {
 
 828           throwSyntaxError("';' expected after 'global' statement.");
 
 833     } else if (token == TokenNamestatic) {
 
 836       if (token == TokenNameSEMICOLON) {
 
 839         if (token != TokenNameINLINE_HTML) {
 
 840           throwSyntaxError("';' expected after 'static' statement.");
 
 845     } else if (token == TokenNameunset) {
 
 847       if (token == TokenNameLPAREN) {
 
 850         throwSyntaxError("'(' expected after 'unset' statement.");
 
 853       if (token == TokenNameRPAREN) {
 
 856         throwSyntaxError("')' expected after 'unset' statement.");
 
 858       if (token == TokenNameSEMICOLON) {
 
 861         if (token != TokenNameINLINE_HTML) {
 
 862           throwSyntaxError("';' expected after 'unset' statement.");
 
 867     } else if (token == TokenNamefunction) {
 
 868       MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
 
 869       methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
 870       methodDecl.modifiers = AccDefault;
 
 872       functionDefinition(methodDecl);
 
 874     } else if (token == TokenNametry) {
 
 876       if (token != TokenNameLBRACE) {
 
 877         throwSyntaxError("'{' expected in 'try' statement.");
 
 881       if (token != TokenNameRBRACE) {
 
 882         throwSyntaxError("'}' expected in 'try' statement.");
 
 886     } else if (token == TokenNamecatch) {
 
 888       if (token != TokenNameLPAREN) {
 
 889         throwSyntaxError("'(' expected in 'catch' statement.");
 
 892       fully_qualified_class_name();
 
 893       if (token != TokenNameVariable) {
 
 894         throwSyntaxError("Variable expected in 'catch' statement.");
 
 897       if (token != TokenNameRPAREN) {
 
 898         throwSyntaxError("')' expected in 'catch' statement.");
 
 901       if (token != TokenNameLBRACE) {
 
 902         throwSyntaxError("'{' expected in 'catch' statement.");
 
 905       if (token != TokenNameRBRACE) {
 
 907         if (token != TokenNameRBRACE) {
 
 908           throwSyntaxError("'}' expected in 'catch' statement.");
 
 912       additional_catches();
 
 914     } else if (token == TokenNamethrow) {
 
 917       if (token == TokenNameSEMICOLON) {
 
 920         throwSyntaxError("';' expected after 'throw' exxpression.");
 
 923     } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
 
 924       TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
 
 925       typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
 926       // default super class
 
 927       typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
 
 928       compilationUnit.types.add(typeDecl);
 
 930         pushOnAstStack(typeDecl);
 
 931         unticked_class_declaration_statement(typeDecl);
 
 932         //        classBody(typeDecl);
 
 939       //        throwSyntaxError("Unexpected keyword '" + keyword + "'");
 
 940     } else if (token == TokenNameLBRACE) {
 
 942       if (token != TokenNameRBRACE) {
 
 945       if (token == TokenNameRBRACE) {
 
 949         throwSyntaxError("'}' expected.");
 
 952       if (token != TokenNameSEMICOLON) {
 
 955       if (token == TokenNameSEMICOLON) {
 
 959         if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
 
 960           throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
 
 966   private void additional_catches() {
 
 967     while (token == TokenNamecatch) {
 
 969       if (token != TokenNameLPAREN) {
 
 970         throwSyntaxError("'(' expected in 'catch' statement.");
 
 973       fully_qualified_class_name();
 
 974       if (token != TokenNameVariable) {
 
 975         throwSyntaxError("Variable expected in 'catch' statement.");
 
 978       if (token != TokenNameRPAREN) {
 
 979         throwSyntaxError("')' expected in 'catch' statement.");
 
 982       if (token != TokenNameLBRACE) {
 
 983         throwSyntaxError("'{' expected in 'catch' statement.");
 
 987       if (token != TokenNameRBRACE) {
 
 988         throwSyntaxError("'}' expected in 'catch' statement.");
 
 993   private void foreach_variable() {
 
 996     if (token == TokenNameAND) {
 
1001   private void foreach_optional_arg() {
 
1003     //| T_DOUBLE_ARROW foreach_variable
 
1004     if (token == TokenNameEQUAL_GREATER) {
 
1009   private void global_var_list() {
 
1011     //  global_var_list ',' global_var
 
1015       if (token != TokenNameCOMMA) {
 
1021   private void global_var() {
 
1025     //| '$' '{' expr '}'
 
1026     if (token == TokenNameVariable) {
 
1028     } else if (token == TokenNameDOLLAR) {
 
1030       if (token == TokenNameLPAREN) {
 
1033         if (token != TokenNameLPAREN) {
 
1034           throwSyntaxError("')' expected in global variable.");
 
1042   private void static_var_list() {
 
1044     //  static_var_list ',' T_VARIABLE
 
1045     //| static_var_list ',' T_VARIABLE '=' static_scalar
 
1047     //| T_VARIABLE '=' static_scalar
 
1049       if (token == TokenNameVariable) {
 
1051         if (token == TokenNameEQUAL) {
 
1055         if (token != TokenNameCOMMA) {
 
1064   private void unset_variables() {
 
1067     //          | unset_variables ',' unset_variable
 
1072       if (token != TokenNameCOMMA) {
 
1078   private final void initializeModifiers() {
 
1080     this.modifiersSourceStart = -1;
 
1082   private final void checkAndSetModifiers(int flag) {
 
1083     this.modifiers |= flag;
 
1084     if (this.modifiersSourceStart < 0)
 
1085       this.modifiersSourceStart = this.scanner.startPosition;
 
1087   private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
 
1088     initializeModifiers();
 
1089     if (token == TokenNameinterface) {
 
1090       //      interface_entry T_STRING
 
1091       //                interface_extends_list
 
1092       //                '{' class_statement_list '}'
 
1093       checkAndSetModifiers(AccInterface);
 
1095       typeDecl.modifiers = this.modifiers;
 
1096       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
1097         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1098         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1099         typeDecl.name = scanner.getCurrentIdentifierSource();
 
1100         if (token > TokenNameKEYWORD) {
 
1101           throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
 
1102               typeDecl.sourceStart, typeDecl.sourceEnd);
 
1105         interface_extends_list();
 
1107         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1108         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1109         typeDecl.name = new char[]{' '};
 
1110         throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
 
1114       //      class_entry_type T_STRING extends_from
 
1116       //                '{' class_statement_list'}'
 
1118       typeDecl.modifiers = this.modifiers;
 
1120       //identifier 'extends' identifier
 
1121       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
1122         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1123         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1124         typeDecl.name = scanner.getCurrentIdentifierSource();
 
1125         if (token > TokenNameKEYWORD) {
 
1126           throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
 
1127               typeDecl.sourceStart, typeDecl.sourceEnd);
 
1132         //      | T_EXTENDS fully_qualified_class_name
 
1133         if (token == TokenNameextends) {
 
1134           interface_extends_list();
 
1136           //          if (token != TokenNameIdentifier) {
 
1137           //            throwSyntaxError("Class name expected after keyword
 
1139           //                scanner.getCurrentTokenStartPosition(), scanner
 
1140           //                    .getCurrentTokenEndPosition());
 
1145         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1146         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1147         typeDecl.name = new char[]{' '};
 
1148         throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
 
1152     //  '{' class_statement_list '}'
 
1153     if (token == TokenNameLBRACE) {
 
1155       if (token != TokenNameRBRACE) {
 
1156         ArrayList list = new ArrayList();
 
1157         class_statement_list(list);
 
1158         typeDecl.fields = new FieldDeclaration[list.size()];
 
1159         for (int i = 0; i < list.size(); i++) {
 
1160           typeDecl.fields[i] = (FieldDeclaration) list.get(i);
 
1163       if (token == TokenNameRBRACE) {
 
1164         typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1167         throwSyntaxError("'}' expected at end of class body.");
 
1170       throwSyntaxError("'{' expected at start of class body.");
 
1173   private void class_entry_type() {
 
1175     //  | T_ABSTRACT T_CLASS
 
1176     //  | T_FINAL T_CLASS
 
1177     if (token == TokenNameclass) {
 
1179     } else if (token == TokenNameabstract) {
 
1180       checkAndSetModifiers(AccAbstract);
 
1182       if (token != TokenNameclass) {
 
1183         throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
 
1186     } else if (token == TokenNamefinal) {
 
1187       checkAndSetModifiers(AccFinal);
 
1189       if (token != TokenNameclass) {
 
1190         throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
 
1194       throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
 
1197   private void interface_extends_list() {
 
1199     //  | T_EXTENDS interface_list
 
1200     if (token == TokenNameextends) {
 
1205   private void implements_list() {
 
1207     //  | T_IMPLEMENTS interface_list
 
1208     if (token == TokenNameimplements) {
 
1213   private void interface_list() {
 
1215     //  fully_qualified_class_name
 
1216     //| interface_list ',' fully_qualified_class_name
 
1218       if (token == TokenNameIdentifier) {
 
1221         throwSyntaxError("Interface name expected after keyword 'implements'.");
 
1223       if (token != TokenNameCOMMA) {
 
1229   //  private void classBody(TypeDeclaration typeDecl) {
 
1230   //    //'{' [class-element-list] '}'
 
1231   //    if (token == TokenNameLBRACE) {
 
1233   //      if (token != TokenNameRBRACE) {
 
1234   //        class_statement_list();
 
1236   //      if (token == TokenNameRBRACE) {
 
1237   //        typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1240   //        throwSyntaxError("'}' expected at end of class body.");
 
1243   //      throwSyntaxError("'{' expected at start of class body.");
 
1246   private void class_statement_list(ArrayList list) {
 
1248       class_statement(list);
 
1249     } while (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
 
1250         || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
 
1251         || token == TokenNameconst);
 
1253   private void class_statement(ArrayList list) {
 
1255     //          variable_modifiers class_variable_declaration ';'
 
1256     //  | class_constant_declaration ';'
 
1257     //  | method_modifiers T_FUNCTION is_reference T_STRING
 
1258     //    '(' parameter_list ')' method_body
 
1259     initializeModifiers();
 
1260     int declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
1262     if (token == TokenNamevar) {
 
1263       checkAndSetModifiers(AccPublic);
 
1264       problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
 
1265           referenceContext, compilationUnit.compilationResult);
 
1267       class_variable_declaration(declarationSourceStart, list);
 
1268     } else if (token == TokenNameconst) {
 
1269       checkAndSetModifiers(AccFinal|AccPublic);
 
1270       class_constant_declaration(declarationSourceStart, list);
 
1271       if (token != TokenNameSEMICOLON) {
 
1272         throwSyntaxError("';' expected after class const declaration.");
 
1276       boolean hasModifiers = member_modifiers();
 
1277       if (token == TokenNamefunction) {
 
1278         if (!hasModifiers) {
 
1279           checkAndSetModifiers(AccPublic);
 
1281         MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
 
1282         methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
1283         methodDecl.modifiers = this.modifiers;
 
1285         functionDefinition(methodDecl);
 
1287         if (!hasModifiers) {
 
1288           throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
 
1290         class_variable_declaration(declarationSourceStart, list);
 
1294   private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
 
1295     //  class_constant_declaration ',' T_STRING '=' static_scalar
 
1296     //  | T_CONST T_STRING '=' static_scalar
 
1297     if (token != TokenNameconst) {
 
1298       throwSyntaxError("'const' keyword expected in class declaration.");
 
1303       if (token != TokenNameIdentifier) {
 
1304         throwSyntaxError("Identifier expected in class const declaration.");
 
1306       FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
 
1307           .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
 
1308       fieldDeclaration.modifiers = this.modifiers;
 
1309       fieldDeclaration.declarationSourceStart = declarationSourceStart;
 
1310       fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1311       fieldDeclaration.modifiersSourceStart = declarationSourceStart;
 
1312       //        fieldDeclaration.type
 
1313       list.add(fieldDeclaration);
 
1315       if (token != TokenNameEQUAL) {
 
1316         throwSyntaxError("'=' expected in class const declaration.");
 
1320       if (token != TokenNameCOMMA) {
 
1321         break; // while(true)-loop
 
1326   //  private void variable_modifiers() {
 
1327   //    // variable_modifiers:
 
1328   //    // non_empty_member_modifiers
 
1330   //    initializeModifiers();
 
1331   //    if (token == TokenNamevar) {
 
1332   //      checkAndSetModifiers(AccPublic);
 
1333   //      reportSyntaxError(
 
1334   //          "Keyword 'var' is deprecated. Please use 'public' 'private' or
 
1336   // modifier for field declarations.",
 
1337   //          scanner.getCurrentTokenStartPosition(), scanner
 
1338   //              .getCurrentTokenEndPosition());
 
1341   //      if (!member_modifiers()) {
 
1342   //        throwSyntaxError("'public' 'private' or 'protected' modifier expected for
 
1343   // field declarations.");
 
1347   //  private void method_modifiers() {
 
1348   //    //method_modifiers:
 
1350   //    //| non_empty_member_modifiers
 
1351   //    initializeModifiers();
 
1352   //    if (!member_modifiers()) {
 
1353   //      checkAndSetModifiers(AccPublic);
 
1356   private boolean member_modifiers() {
 
1363     boolean foundToken = false;
 
1365       if (token == TokenNamepublic) {
 
1366         checkAndSetModifiers(AccPublic);
 
1369       } else if (token == TokenNameprotected) {
 
1370         checkAndSetModifiers(AccProtected);
 
1373       } else if (token == TokenNameprivate) {
 
1374         checkAndSetModifiers(AccPrivate);
 
1377       } else if (token == TokenNamestatic) {
 
1378         checkAndSetModifiers(AccStatic);
 
1381       } else if (token == TokenNameabstract) {
 
1382         checkAndSetModifiers(AccAbstract);
 
1385       } else if (token == TokenNamefinal) {
 
1386         checkAndSetModifiers(AccFinal);
 
1395   private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
 
1396     //    class_variable_declaration:
 
1397     //          class_variable_declaration ',' T_VARIABLE
 
1398     //  | class_variable_declaration ',' T_VARIABLE '=' static_scalar
 
1400     //  | T_VARIABLE '=' static_scalar
 
1401     char[] classVariable;
 
1403       if (token == TokenNameVariable) {
 
1404         classVariable = scanner.getCurrentIdentifierSource();
 
1405       //  indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
 
1406         FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner
 
1407             .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
 
1408         fieldDeclaration.modifiers = this.modifiers;
 
1409         fieldDeclaration.declarationSourceStart = declarationSourceStart;
 
1410         fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1411         fieldDeclaration.modifiersSourceStart = declarationSourceStart;
 
1412         //        fieldDeclaration.type
 
1413         list.add(fieldDeclaration);
 
1415         if (token == TokenNameEQUAL) {
 
1420         //        if (token == TokenNamethis) {
 
1421         //          throwSyntaxError("'$this' not allowed after keyword 'public'
 
1422         // 'protected' 'private' 'var'.");
 
1424         throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
 
1426       if (token != TokenNameCOMMA) {
 
1431     if (token != TokenNameSEMICOLON) {
 
1432       throwSyntaxError("';' expected after field declaration.");
 
1436   private void functionDefinition(MethodDeclaration methodDecl) {
 
1437     boolean isAbstract = false;
 
1439       compilationUnit.types.add(methodDecl);
 
1441       AstNode node = astStack[astPtr];
 
1442       if (node instanceof TypeDeclaration) {
 
1443         TypeDeclaration typeDecl = ((TypeDeclaration) node);
 
1444         if (typeDecl.methods == null) {
 
1445           typeDecl.methods = new AbstractMethodDeclaration[]{methodDecl};
 
1447           AbstractMethodDeclaration[] newMethods;
 
1448           System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 1,
 
1449               typeDecl.methods.length);
 
1450           newMethods[0] = methodDecl;
 
1451           typeDecl.methods = newMethods;
 
1453         if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
 
1455         } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
 
1460     functionDeclarator(methodDecl);
 
1461     if (token == TokenNameSEMICOLON) {
 
1463         throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
 
1468     functionBody(methodDecl);
 
1470   private void functionDeclarator(MethodDeclaration methodDecl) {
 
1471     //identifier '(' [parameter-list] ')'
 
1472     if (token == TokenNameAND) {
 
1475     methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1476     methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1477     if (Scanner.isIdentifierOrKeyword(token)) {
 
1478       methodDecl.selector = scanner.getCurrentIdentifierSource();
 
1479       if (token > TokenNameKEYWORD) {
 
1480         reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
 
1481           scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
 
1482 //        throwSyntaxError("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].");
 
1485       if (token == TokenNameLPAREN) {
 
1488         throwSyntaxError("'(' expected in function declaration.");
 
1490       if (token != TokenNameRPAREN) {
 
1493       if (token != TokenNameRPAREN) {
 
1494         throwSyntaxError("')' expected in function declaration.");
 
1496         methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
 
1500       methodDecl.selector = "<undefined>".toCharArray();
 
1501       throwSyntaxError("Function name expected after keyword 'function'.");
 
1505   private void parameter_list() {
 
1506     //  non_empty_parameter_list
 
1508     non_empty_parameter_list(true);
 
1510   private void non_empty_parameter_list(boolean empty_allowed) {
 
1511     //  optional_class_type T_VARIABLE
 
1512     //  | optional_class_type '&' T_VARIABLE
 
1513     //  | optional_class_type '&' T_VARIABLE '=' static_scalar
 
1514     //  | optional_class_type T_VARIABLE '=' static_scalar
 
1515     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE
 
1516     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
 
1517     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
 
1519     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
 
1521     if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
 
1523         if (token == TokenNameIdentifier) {
 
1526         if (token == TokenNameAND) {
 
1529         if (token == TokenNameVariable) {
 
1531           if (token == TokenNameEQUAL) {
 
1536           throwSyntaxError("Variable expected in parameter list.");
 
1538         if (token != TokenNameCOMMA) {
 
1545     if (!empty_allowed) {
 
1546       throwSyntaxError("Identifier expected in parameter list.");
 
1549   private void optional_class_type() {
 
1553   private void parameterDeclaration() {
 
1555     //variable-reference
 
1556     if (token == TokenNameAND) {
 
1561         throwSyntaxError("Variable expected after reference operator '&'.");
 
1564     //variable '=' constant
 
1565     if (token == TokenNameVariable) {
 
1567       if (token == TokenNameEQUAL) {
 
1573     //    if (token == TokenNamethis) {
 
1574     //      throwSyntaxError("Reserved word '$this' not allowed in parameter
 
1578   private void labeledStatementList() {
 
1579     if (token != TokenNamecase && token != TokenNamedefault) {
 
1580       throwSyntaxError("'case' or 'default' expected.");
 
1583       if (token == TokenNamecase) {
 
1585         expr(); //constant();
 
1586         if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
 
1588           if (token == TokenNamecase || token == TokenNamedefault) {
 
1589             // empty case statement ?
 
1594         //        else if (token == TokenNameSEMICOLON) {
 
1596         //            "':' expected after 'case' keyword (Found token: " +
 
1597         // scanner.toStringAction(token) + ")",
 
1598         //            scanner.getCurrentTokenStartPosition(),
 
1599         //            scanner.getCurrentTokenEndPosition(),
 
1602         //          if (token == TokenNamecase) { // empty case statement ?
 
1608           throwSyntaxError("':' character after 'case' constant expected (Found token: " + scanner.toStringAction(token) + ")");
 
1610       } else { // TokenNamedefault
 
1612         if (token == TokenNameCOLON) {
 
1614           if (token == TokenNameRBRACE) {
 
1615             // empty default case
 
1620           throwSyntaxError("':' character after 'default' expected.");
 
1623     } while (token == TokenNamecase || token == TokenNamedefault);
 
1625   //  public void labeledStatement() {
 
1626   //    if (token == TokenNamecase) {
 
1629   //      if (token == TokenNameDDOT) {
 
1633   //        throwSyntaxError("':' character after 'case' constant expected.");
 
1636   //    } else if (token == TokenNamedefault) {
 
1638   //      if (token == TokenNameDDOT) {
 
1642   //        throwSyntaxError("':' character after 'default' expected.");
 
1647   //  public void expressionStatement() {
 
1649   //  private void inclusionStatement() {
 
1651   //  public void compoundStatement() {
 
1653   //  public void selectionStatement() {
 
1656   //  public void iterationStatement() {
 
1659   //  public void jumpStatement() {
 
1662   //  public void outputStatement() {
 
1665   //  public void scopeStatement() {
 
1668   //  public void flowStatement() {
 
1671   //  public void definitionStatement() {
 
1673   private void ifStatement() {
 
1674     // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
 
1675     if (token == TokenNameCOLON) {
 
1677       if (token != TokenNameendif) {
 
1680           case TokenNameelse :
 
1682             if (token == TokenNameCOLON) {
 
1684               if (token != TokenNameendif) {
 
1688               if (token == TokenNameif) { //'else if'
 
1690                 elseifStatementList();
 
1692                 throwSyntaxError("':' expected after 'else'.");
 
1696           case TokenNameelseif :
 
1698             elseifStatementList();
 
1702       if (token != TokenNameendif) {
 
1703         throwSyntaxError("'endif' expected.");
 
1706       if (token != TokenNameSEMICOLON) {
 
1707         throwSyntaxError("';' expected after if-statement.");
 
1711       // statement [else-statement]
 
1712       statement(TokenNameEOF);
 
1713       if (token == TokenNameelseif) {
 
1715         if (token == TokenNameLPAREN) {
 
1718           throwSyntaxError("'(' expected after 'elseif' keyword.");
 
1721         if (token == TokenNameRPAREN) {
 
1724           throwSyntaxError("')' expected after 'elseif' condition.");
 
1727       } else if (token == TokenNameelse) {
 
1729         statement(TokenNameEOF);
 
1733   private void elseifStatementList() {
 
1737         case TokenNameelse :
 
1739           if (token == TokenNameCOLON) {
 
1741             if (token != TokenNameendif) {
 
1746             if (token == TokenNameif) { //'else if'
 
1749               throwSyntaxError("':' expected after 'else'.");
 
1753         case TokenNameelseif :
 
1761   private void elseifStatement() {
 
1762     if (token == TokenNameLPAREN) {
 
1765       if (token != TokenNameRPAREN) {
 
1766         throwSyntaxError("')' expected in else-if-statement.");
 
1769       if (token != TokenNameCOLON) {
 
1770         throwSyntaxError("':' expected in else-if-statement.");
 
1773       if (token != TokenNameendif) {
 
1778   private void switchStatement() {
 
1779     if (token == TokenNameCOLON) {
 
1780       // ':' [labeled-statement-list] 'endswitch' ';'
 
1782       labeledStatementList();
 
1783       if (token != TokenNameendswitch) {
 
1784         throwSyntaxError("'endswitch' expected.");
 
1787       if (token != TokenNameSEMICOLON) {
 
1788         throwSyntaxError("';' expected after switch-statement.");
 
1792       // '{' [labeled-statement-list] '}'
 
1793       if (token != TokenNameLBRACE) {
 
1794         throwSyntaxError("'{' expected in switch statement.");
 
1797       if (token != TokenNameRBRACE) {
 
1798         labeledStatementList();
 
1800       if (token != TokenNameRBRACE) {
 
1801         throwSyntaxError("'}' expected in switch statement.");
 
1806   private void forStatement() {
 
1807     if (token == TokenNameCOLON) {
 
1810       if (token != TokenNameendfor) {
 
1811         throwSyntaxError("'endfor' expected.");
 
1814       if (token != TokenNameSEMICOLON) {
 
1815         throwSyntaxError("';' expected after for-statement.");
 
1819       statement(TokenNameEOF);
 
1822   private void whileStatement() {
 
1823     // ':' statement-list 'endwhile' ';'
 
1824     if (token == TokenNameCOLON) {
 
1827       if (token != TokenNameendwhile) {
 
1828         throwSyntaxError("'endwhile' expected.");
 
1831       if (token != TokenNameSEMICOLON) {
 
1832         throwSyntaxError("';' expected after while-statement.");
 
1836       statement(TokenNameEOF);
 
1839   private void foreachStatement() {
 
1840     if (token == TokenNameCOLON) {
 
1843       if (token != TokenNameendforeach) {
 
1844         throwSyntaxError("'endforeach' expected.");
 
1847       if (token != TokenNameSEMICOLON) {
 
1848         throwSyntaxError("';' expected after foreach-statement.");
 
1852       statement(TokenNameEOF);
 
1855   //  private void exitStatus() {
 
1856   //    if (token == TokenNameLPAREN) {
 
1859   //      throwSyntaxError("'(' expected in 'exit-status'.");
 
1861   //    if (token != TokenNameRPAREN) {
 
1864   //    if (token == TokenNameRPAREN) {
 
1867   //      throwSyntaxError("')' expected after 'exit-status'.");
 
1870   private void expressionList() {
 
1873       if (token == TokenNameCOMMA) {
 
1880   private void expr() {
 
1882     //  | expr_without_variable
 
1883     //    if (token!=TokenNameEOF) {
 
1884     if (Scanner.TRACE) {
 
1885       System.out.println("TRACE: expr()");
 
1887     expr_without_variable(true);
 
1890   private void expr_without_variable(boolean only_variable) {
 
1891     //          internal_functions_in_yacc
 
1900     //  | T_INC rw_variable
 
1901     //  | T_DEC rw_variable
 
1902     //  | T_INT_CAST expr
 
1903     //  | T_DOUBLE_CAST expr
 
1904     //  | T_STRING_CAST expr
 
1905     //  | T_ARRAY_CAST expr
 
1906     //  | T_OBJECT_CAST expr
 
1907     //  | T_BOOL_CAST expr
 
1908     //  | T_UNSET_CAST expr
 
1909     //  | T_EXIT exit_expr
 
1911     //  | T_ARRAY '(' array_pair_list ')'
 
1912     //  | '`' encaps_list '`'
 
1913     //  | T_LIST '(' assignment_list ')' '=' expr
 
1914     //  | T_NEW class_name_reference ctor_arguments
 
1915     //  | variable '=' expr
 
1916     //  | variable '=' '&' variable
 
1917     //  | variable '=' '&' T_NEW class_name_reference ctor_arguments
 
1918     //  | variable T_PLUS_EQUAL expr
 
1919     //  | variable T_MINUS_EQUAL expr
 
1920     //  | variable T_MUL_EQUAL expr
 
1921     //  | variable T_DIV_EQUAL expr
 
1922     //  | variable T_CONCAT_EQUAL expr
 
1923     //  | variable T_MOD_EQUAL expr
 
1924     //  | variable T_AND_EQUAL expr
 
1925     //  | variable T_OR_EQUAL expr
 
1926     //  | variable T_XOR_EQUAL expr
 
1927     //  | variable T_SL_EQUAL expr
 
1928     //  | variable T_SR_EQUAL expr
 
1929     //  | rw_variable T_INC
 
1930     //  | rw_variable T_DEC
 
1931     //  | expr T_BOOLEAN_OR expr
 
1932     //  | expr T_BOOLEAN_AND expr
 
1933     //  | expr T_LOGICAL_OR expr
 
1934     //  | expr T_LOGICAL_AND expr
 
1935     //  | expr T_LOGICAL_XOR expr
 
1947     //  | expr T_IS_IDENTICAL expr
 
1948     //  | expr T_IS_NOT_IDENTICAL expr
 
1949     //  | expr T_IS_EQUAL expr
 
1950     //  | expr T_IS_NOT_EQUAL expr
 
1952     //  | expr T_IS_SMALLER_OR_EQUAL expr
 
1954     //  | expr T_IS_GREATER_OR_EQUAL expr
 
1955     //  | expr T_INSTANCEOF class_name_reference
 
1956     //  | expr '?' expr ':' expr
 
1957     if (Scanner.TRACE) {
 
1958       System.out.println("TRACE: expr_without_variable() PART 1");
 
1961       case TokenNameisset :
 
1962       case TokenNameempty :
 
1963       case TokenNameeval :
 
1964       case TokenNameinclude :
 
1965       case TokenNameinclude_once :
 
1966       case TokenNamerequire :
 
1967       case TokenNamerequire_once :
 
1968         internal_functions_in_yacc();
 
1971       case TokenNameLPAREN :
 
1974         if (token == TokenNameRPAREN) {
 
1977           throwSyntaxError("')' expected in expression.");
 
1987       //    | T_INT_CAST expr
 
1988       //        | T_DOUBLE_CAST expr
 
1989       //        | T_STRING_CAST expr
 
1990       //        | T_ARRAY_CAST expr
 
1991       //        | T_OBJECT_CAST expr
 
1992       //        | T_BOOL_CAST expr
 
1993       //        | T_UNSET_CAST expr
 
1994       case TokenNameclone :
 
1995       case TokenNameprint :
 
1997       case TokenNamePLUS :
 
1998       case TokenNameMINUS :
 
2000       case TokenNameTWIDDLE :
 
2001       case TokenNameintCAST :
 
2002       case TokenNamedoubleCAST :
 
2003       case TokenNamestringCAST :
 
2004       case TokenNamearrayCAST :
 
2005       case TokenNameobjectCAST :
 
2006       case TokenNameboolCAST :
 
2007       case TokenNameunsetCAST :
 
2011       case TokenNameexit :
 
2017       //| T_STRING_VARNAME
 
2019       //| T_START_HEREDOC encaps_list T_END_HEREDOC
 
2020       //        | '`' encaps_list '`'
 
2022       //        | '`' encaps_list '`'
 
2023       case TokenNameEncapsedString0 :
 
2024         scanner.encapsedStringStack.push(new Character('`'));
 
2027           if (token == TokenNameEncapsedString0) {
 
2030             if (token != TokenNameEncapsedString0) {
 
2031               throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2035           scanner.encapsedStringStack.pop();
 
2039       //      | '\'' encaps_list '\''
 
2040       case TokenNameEncapsedString1 :
 
2041         scanner.encapsedStringStack.push(new Character('\''));
 
2044           if (token == TokenNameEncapsedString1) {
 
2047             if (token != TokenNameEncapsedString1) {
 
2048               throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2052           scanner.encapsedStringStack.pop();
 
2056       //| '"' encaps_list '"'
 
2057       case TokenNameEncapsedString2 :
 
2058         scanner.encapsedStringStack.push(new Character('"'));
 
2061           if (token == TokenNameEncapsedString2) {
 
2064             if (token != TokenNameEncapsedString2) {
 
2065               throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2069           scanner.encapsedStringStack.pop();
 
2073       case TokenNameIntegerLiteral :
 
2074       case TokenNameDoubleLiteral :
 
2075       case TokenNameStringDoubleQuote :
 
2076       case TokenNameStringSingleQuote :
 
2077       case TokenNameStringInterpolated :
 
2078       case TokenNameFILE :
 
2079       case TokenNameLINE :
 
2080       case TokenNameCLASS_C :
 
2081       case TokenNameMETHOD_C :
 
2082       case TokenNameFUNC_C :
 
2085       case TokenNameHEREDOC :
 
2088       case TokenNamearray :
 
2089         //    T_ARRAY '(' array_pair_list ')'
 
2091         if (token == TokenNameLPAREN) {
 
2093           if (token == TokenNameRPAREN) {
 
2098           if (token != TokenNameRPAREN) {
 
2099             throwSyntaxError("')' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
 
2103           throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
 
2106       case TokenNamelist :
 
2107         //    | T_LIST '(' assignment_list ')' '=' expr
 
2109         if (token == TokenNameLPAREN) {
 
2112           if (token != TokenNameRPAREN) {
 
2113             throwSyntaxError("')' expected after 'list' keyword.");
 
2116           if (token != TokenNameEQUAL) {
 
2117             throwSyntaxError("'=' expected after 'list' keyword.");
 
2122           throwSyntaxError("'(' expected after 'list' keyword.");
 
2126         //      | T_NEW class_name_reference ctor_arguments
 
2128         class_name_reference();
 
2131       //        | T_INC rw_variable
 
2132       //        | T_DEC rw_variable
 
2133       case TokenNamePLUS_PLUS :
 
2134       case TokenNameMINUS_MINUS :
 
2138       //        | variable '=' expr
 
2139       //        | variable '=' '&' variable
 
2140       //        | variable '=' '&' T_NEW class_name_reference ctor_arguments
 
2141       //        | variable T_PLUS_EQUAL expr
 
2142       //        | variable T_MINUS_EQUAL expr
 
2143       //        | variable T_MUL_EQUAL expr
 
2144       //        | variable T_DIV_EQUAL expr
 
2145       //        | variable T_CONCAT_EQUAL expr
 
2146       //        | variable T_MOD_EQUAL expr
 
2147       //        | variable T_AND_EQUAL expr
 
2148       //        | variable T_OR_EQUAL expr
 
2149       //        | variable T_XOR_EQUAL expr
 
2150       //        | variable T_SL_EQUAL expr
 
2151       //        | variable T_SR_EQUAL expr
 
2152       //        | rw_variable T_INC
 
2153       //        | rw_variable T_DEC
 
2154       case TokenNameIdentifier :
 
2155       case TokenNameVariable :
 
2156       case TokenNameDOLLAR :
 
2159           case TokenNameEQUAL :
 
2161             if (token == TokenNameAND) {
 
2163               if (token == TokenNamenew) {
 
2164                 // | variable '=' '&' T_NEW class_name_reference
 
2167                 class_name_reference();
 
2176           case TokenNamePLUS_EQUAL :
 
2177           case TokenNameMINUS_EQUAL :
 
2178           case TokenNameMULTIPLY_EQUAL :
 
2179           case TokenNameDIVIDE_EQUAL :
 
2180           case TokenNameDOT_EQUAL :
 
2181           case TokenNameREMAINDER_EQUAL :
 
2182           case TokenNameAND_EQUAL :
 
2183           case TokenNameOR_EQUAL :
 
2184           case TokenNameXOR_EQUAL :
 
2185           case TokenNameRIGHT_SHIFT_EQUAL :
 
2186           case TokenNameLEFT_SHIFT_EQUAL :
 
2190           case TokenNamePLUS_PLUS :
 
2191           case TokenNameMINUS_MINUS :
 
2195             if (!only_variable) {
 
2196               throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
 
2201         if (token != TokenNameINLINE_HTML) {
 
2202           if (token > TokenNameKEYWORD) {
 
2206             throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
 
2211     if (Scanner.TRACE) {
 
2212       System.out.println("TRACE: expr_without_variable() PART 2");
 
2214     //  | expr T_BOOLEAN_OR expr
 
2215     //  | expr T_BOOLEAN_AND expr
 
2216     //  | expr T_LOGICAL_OR expr
 
2217     //  | expr T_LOGICAL_AND expr
 
2218     //  | expr T_LOGICAL_XOR expr
 
2230     //  | expr T_IS_IDENTICAL expr
 
2231     //  | expr T_IS_NOT_IDENTICAL expr
 
2232     //  | expr T_IS_EQUAL expr
 
2233     //  | expr T_IS_NOT_EQUAL expr
 
2235     //  | expr T_IS_SMALLER_OR_EQUAL expr
 
2237     //  | expr T_IS_GREATER_OR_EQUAL expr
 
2240         case TokenNameOR_OR :
 
2241         case TokenNameAND_AND :
 
2249         case TokenNamePLUS :
 
2250         case TokenNameMINUS :
 
2251         case TokenNameMULTIPLY :
 
2252         case TokenNameDIVIDE :
 
2253         case TokenNameREMAINDER :
 
2254         case TokenNameLEFT_SHIFT :
 
2255         case TokenNameRIGHT_SHIFT :
 
2256         case TokenNameEQUAL_EQUAL_EQUAL :
 
2257         case TokenNameNOT_EQUAL_EQUAL :
 
2258         case TokenNameEQUAL_EQUAL :
 
2259         case TokenNameNOT_EQUAL :
 
2260         case TokenNameLESS :
 
2261         case TokenNameLESS_EQUAL :
 
2262         case TokenNameGREATER :
 
2263         case TokenNameGREATER_EQUAL :
 
2267         //  | expr T_INSTANCEOF class_name_reference
 
2268         //      | expr '?' expr ':' expr
 
2269         case TokenNameinstanceof :
 
2271           class_name_reference();
 
2273         case TokenNameQUESTION :
 
2276           if (token == TokenNameCOLON) {
 
2286   private void class_name_reference() {
 
2287     //  class_name_reference:
 
2289     //| dynamic_class_name_reference
 
2290     if (Scanner.TRACE) {
 
2291       System.out.println("TRACE: class_name_reference()");
 
2293     if (token == TokenNameIdentifier) {
 
2296       dynamic_class_name_reference();
 
2299   private void dynamic_class_name_reference() {
 
2300     //dynamic_class_name_reference:
 
2301     //  base_variable T_OBJECT_OPERATOR object_property
 
2302     // dynamic_class_name_variable_properties
 
2304     if (Scanner.TRACE) {
 
2305       System.out.println("TRACE: dynamic_class_name_reference()");
 
2308     if (token == TokenNameMINUS_GREATER) {
 
2311       dynamic_class_name_variable_properties();
 
2314   private void dynamic_class_name_variable_properties() {
 
2315     //  dynamic_class_name_variable_properties:
 
2316     //                  dynamic_class_name_variable_properties
 
2317     // dynamic_class_name_variable_property
 
2319     if (Scanner.TRACE) {
 
2320       System.out.println("TRACE: dynamic_class_name_variable_properties()");
 
2322     while (token == TokenNameMINUS_GREATER) {
 
2323       dynamic_class_name_variable_property();
 
2326   private void dynamic_class_name_variable_property() {
 
2327     //  dynamic_class_name_variable_property:
 
2328     //  T_OBJECT_OPERATOR object_property
 
2329     if (Scanner.TRACE) {
 
2330       System.out.println("TRACE: dynamic_class_name_variable_property()");
 
2332     if (token == TokenNameMINUS_GREATER) {
 
2337   private void ctor_arguments() {
 
2340     //| '(' function_call_parameter_list ')'
 
2341     if (token == TokenNameLPAREN) {
 
2343       if (token == TokenNameRPAREN) {
 
2347       non_empty_function_call_parameter_list();
 
2348       if (token != TokenNameRPAREN) {
 
2349         throwSyntaxError("')' expected in ctor_arguments.");
 
2354   private void assignment_list() {
 
2356     //  assignment_list ',' assignment_list_element
 
2357     //| assignment_list_element
 
2359       assignment_list_element();
 
2360       if (token != TokenNameCOMMA) {
 
2366   private void assignment_list_element() {
 
2367     //assignment_list_element:
 
2369     //| T_LIST '(' assignment_list ')'
 
2371     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
 
2374       if (token == TokenNamelist) {
 
2376         if (token == TokenNameLPAREN) {
 
2379           if (token != TokenNameRPAREN) {
 
2380             throwSyntaxError("')' expected after 'list' keyword.");
 
2384           throwSyntaxError("'(' expected after 'list' keyword.");
 
2389   private void array_pair_list() {
 
2392     //| non_empty_array_pair_list possible_comma
 
2393     non_empty_array_pair_list();
 
2394     if (token == TokenNameCOMMA) {
 
2398   private void non_empty_array_pair_list() {
 
2399     //non_empty_array_pair_list:
 
2400     //  non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
 
2401     //| non_empty_array_pair_list ',' expr
 
2402     //| expr T_DOUBLE_ARROW expr
 
2404     //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
 
2405     //| non_empty_array_pair_list ',' '&' w_variable
 
2406     //| expr T_DOUBLE_ARROW '&' w_variable
 
2409       if (token == TokenNameAND) {
 
2414         if (token == TokenNameAND) {
 
2417         } else if (token == TokenNameEQUAL_GREATER) {
 
2419           if (token == TokenNameAND) {
 
2427       if (token != TokenNameCOMMA) {
 
2431       if (token == TokenNameRPAREN) {
 
2436   //  private void variableList() {
 
2439   //      if (token == TokenNameCOMMA) {
 
2446   private void variable_without_objects() {
 
2447     //  variable_without_objects:
 
2448     //                  reference_variable
 
2449     //          | simple_indirect_reference reference_variable
 
2450     if (Scanner.TRACE) {
 
2451       System.out.println("TRACE: variable_without_objects()");
 
2453     while (token == TokenNameDOLLAR) {
 
2456     reference_variable();
 
2458   private void function_call() {
 
2460     //  T_STRING '(' function_call_parameter_list ')'
 
2461     //| class_constant '(' function_call_parameter_list ')'
 
2462     //| static_member '(' function_call_parameter_list ')'
 
2463     //| variable_without_objects '(' function_call_parameter_list ')'
 
2464     if (Scanner.TRACE) {
 
2465       System.out.println("TRACE: function_call()");
 
2467     if (token == TokenNameIdentifier) {
 
2470         case TokenNamePAAMAYIM_NEKUDOTAYIM :
 
2473           if (token == TokenNameIdentifier) {
 
2478             variable_without_objects();
 
2483       variable_without_objects();
 
2485     if (token != TokenNameLPAREN) {
 
2486       // TODO is this ok ?
 
2488       //      throwSyntaxError("'(' expected in function call.");
 
2491     if (token == TokenNameRPAREN) {
 
2495     non_empty_function_call_parameter_list();
 
2496     if (token != TokenNameRPAREN) {
 
2497       throwSyntaxError("')' expected in function call.");
 
2501   //  private void function_call_parameter_list() {
 
2502   //    function_call_parameter_list:
 
2503   //            non_empty_function_call_parameter_list { $$ = $1; }
 
2506   private void non_empty_function_call_parameter_list() {
 
2507     //non_empty_function_call_parameter_list:
 
2508     //          expr_without_variable
 
2511     //  | non_empty_function_call_parameter_list ',' expr_without_variable
 
2512     //  | non_empty_function_call_parameter_list ',' variable
 
2513     //  | non_empty_function_call_parameter_list ',' '&' w_variable
 
2514     if (Scanner.TRACE) {
 
2515       System.out.println("TRACE: non_empty_function_call_parameter_list()");
 
2518       if (token == TokenNameAND) {
 
2522         //        if (token == TokenNameIdentifier || token ==
 
2523         // TokenNameVariable
 
2524         //            || token == TokenNameDOLLAR) {
 
2527         expr_without_variable(true);
 
2530       if (token != TokenNameCOMMA) {
 
2536   private void fully_qualified_class_name() {
 
2537     if (token == TokenNameIdentifier) {
 
2540       throwSyntaxError("Class name expected.");
 
2543   private void static_member() {
 
2545     //  fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
 
2546     // variable_without_objects
 
2547     if (Scanner.TRACE) {
 
2548       System.out.println("TRACE: static_member()");
 
2550     fully_qualified_class_name();
 
2551     if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
 
2552       throwSyntaxError("'::' expected after class name (static_member).");
 
2555     variable_without_objects();
 
2557   private void base_variable_with_function_calls() {
 
2558     //  base_variable_with_function_calls:
 
2561     boolean functionCall = false;
 
2562     if (Scanner.TRACE) {
 
2563       System.out.println("TRACE: base_variable_with_function_calls()");
 
2565     //    if (token == TokenNameIdentifier) {
 
2566     //      functionCall = true;
 
2567     //    } else if (token == TokenNameVariable) {
 
2568     //      int tempToken = token;
 
2569     //      int tempPosition = scanner.currentPosition;
 
2571     //      if (token == TokenNameLPAREN) {
 
2572     //        functionCall = true;
 
2574     //      token = tempToken;
 
2575     //      scanner.currentPosition = tempPosition;
 
2576     //      scanner.phpMode = true;
 
2578     //    if (functionCall) {
 
2584   private void base_variable() {
 
2586     //                  reference_variable
 
2587     //          | simple_indirect_reference reference_variable
 
2589     if (Scanner.TRACE) {
 
2590       System.out.println("TRACE: base_variable()");
 
2592     if (token == TokenNameIdentifier) {
 
2595       while (token == TokenNameDOLLAR) {
 
2598       reference_variable();
 
2601   //  private void simple_indirect_reference() {
 
2602   //    // simple_indirect_reference:
 
2604   //    //| simple_indirect_reference '$'
 
2606   private void reference_variable() {
 
2607     //  reference_variable:
 
2608     //                  reference_variable '[' dim_offset ']'
 
2609     //          | reference_variable '{' expr '}'
 
2610     //          | compound_variable
 
2611     if (Scanner.TRACE) {
 
2612       System.out.println("TRACE: reference_variable()");
 
2614     compound_variable();
 
2616       if (token == TokenNameLBRACE) {
 
2619         if (token != TokenNameRBRACE) {
 
2620           throwSyntaxError("'}' expected in reference variable.");
 
2623       } else if (token == TokenNameLBRACKET) {
 
2625         if (token != TokenNameRBRACKET) {
 
2628           if (token != TokenNameRBRACKET) {
 
2629             throwSyntaxError("']' expected in reference variable.");
 
2638   private void compound_variable() {
 
2639     //  compound_variable:
 
2641     //          | '$' '{' expr '}'
 
2642     if (Scanner.TRACE) {
 
2643       System.out.println("TRACE: compound_variable()");
 
2645     if (token == TokenNameVariable) {
 
2648       // because of simple_indirect_reference
 
2649       while (token == TokenNameDOLLAR) {
 
2652       if (token != TokenNameLBRACE) {
 
2653         throwSyntaxError("'{' expected after compound variable token '$'.");
 
2657       if (token != TokenNameRBRACE) {
 
2658         throwSyntaxError("'}' expected after compound variable token '$'.");
 
2663   //  private void dim_offset() {
 
2669   private void object_property() {
 
2672     //| variable_without_objects
 
2673     if (Scanner.TRACE) {
 
2674       System.out.println("TRACE: object_property()");
 
2676     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
 
2677       variable_without_objects();
 
2682   private void object_dim_list() {
 
2684     //  object_dim_list '[' dim_offset ']'
 
2685     //| object_dim_list '{' expr '}'
 
2687     if (Scanner.TRACE) {
 
2688       System.out.println("TRACE: object_dim_list()");
 
2692       if (token == TokenNameLBRACE) {
 
2695         if (token != TokenNameRBRACE) {
 
2696           throwSyntaxError("'}' expected in object_dim_list.");
 
2699       } else if (token == TokenNameLBRACKET) {
 
2701         if (token == TokenNameRBRACKET) {
 
2706         if (token != TokenNameRBRACKET) {
 
2707           throwSyntaxError("']' expected in object_dim_list.");
 
2715   private void variable_name() {
 
2719     if (Scanner.TRACE) {
 
2720       System.out.println("TRACE: variable_name()");
 
2722     if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
2723       if (token > TokenNameKEYWORD) {
 
2724         // TODO show a warning "Keyword used as variable" ?
 
2728       if (token != TokenNameLBRACE) {
 
2729         throwSyntaxError("'{' expected in variable name.");
 
2733       if (token != TokenNameRBRACE) {
 
2734         throwSyntaxError("'}' expected in variable name.");
 
2739   private void r_variable() {
 
2742   private void w_variable() {
 
2745   private void rw_variable() {
 
2748   private void variable() {
 
2750     //          base_variable_with_function_calls T_OBJECT_OPERATOR
 
2751     //                  object_property method_or_not variable_properties
 
2752     //  | base_variable_with_function_calls
 
2753     base_variable_with_function_calls();
 
2754     if (token == TokenNameMINUS_GREATER) {
 
2758       variable_properties();
 
2760     //    if (token == TokenNameDOLLAR_LBRACE) {
 
2764     //      if (token != TokenNameRBRACE) {
 
2765     //        throwSyntaxError("'}' expected after indirect variable token '${'.");
 
2769     //      if (token == TokenNameVariable) {
 
2771     //        if (token == TokenNameLBRACKET) {
 
2774     //          if (token != TokenNameRBRACKET) {
 
2775     //            throwSyntaxError("']' expected in variable-list.");
 
2778     //        } else if (token == TokenNameEQUAL) {
 
2783     //        throwSyntaxError("$-variable expected in variable-list.");
 
2787   private void variable_properties() {
 
2788     //  variable_properties:
 
2789     //                  variable_properties variable_property
 
2791     while (token == TokenNameMINUS_GREATER) {
 
2792       variable_property();
 
2795   private void variable_property() {
 
2796     //  variable_property:
 
2797     //                  T_OBJECT_OPERATOR object_property method_or_not
 
2798     if (Scanner.TRACE) {
 
2799       System.out.println("TRACE: variable_property()");
 
2801     if (token == TokenNameMINUS_GREATER) {
 
2806       throwSyntaxError("'->' expected in variable_property.");
 
2809   private void method_or_not() {
 
2811     //                  '(' function_call_parameter_list ')'
 
2813     if (Scanner.TRACE) {
 
2814       System.out.println("TRACE: method_or_not()");
 
2816     if (token == TokenNameLPAREN) {
 
2818       if (token == TokenNameRPAREN) {
 
2822       non_empty_function_call_parameter_list();
 
2823       if (token != TokenNameRPAREN) {
 
2824         throwSyntaxError("')' expected in method_or_not.");
 
2829   private void exit_expr() {
 
2833     if (token != TokenNameLPAREN) {
 
2837     if (token == TokenNameRPAREN) {
 
2842     if (token != TokenNameRPAREN) {
 
2843       throwSyntaxError("')' expected after keyword 'exit'");
 
2847   private void encaps_list() {
 
2848     //                  encaps_list encaps_var
 
2849     //          | encaps_list T_STRING
 
2850     //          | encaps_list T_NUM_STRING
 
2851     //          | encaps_list T_ENCAPSED_AND_WHITESPACE
 
2852     //          | encaps_list T_CHARACTER
 
2853     //          | encaps_list T_BAD_CHARACTER
 
2854     //          | encaps_list '['
 
2855     //          | encaps_list ']'
 
2856     //          | encaps_list '{'
 
2857     //          | encaps_list '}'
 
2858     //          | encaps_list T_OBJECT_OPERATOR
 
2862         case TokenNameSTRING :
 
2865         case TokenNameLBRACE :
 
2866           //          scanner.encapsedStringStack.pop();
 
2869         case TokenNameRBRACE :
 
2870           //          scanner.encapsedStringStack.pop();
 
2873         case TokenNameLBRACKET :
 
2874           //          scanner.encapsedStringStack.pop();
 
2877         case TokenNameRBRACKET :
 
2878           //          scanner.encapsedStringStack.pop();
 
2881         case TokenNameMINUS_GREATER :
 
2882           //          scanner.encapsedStringStack.pop();
 
2885         case TokenNameVariable :
 
2886         case TokenNameDOLLAR_LBRACE :
 
2887         case TokenNameCURLY_OPEN :
 
2890         //        case TokenNameDOLLAR :
 
2892         //          if (token == TokenNameLBRACE) {
 
2893         //            token = TokenNameDOLLAR_LBRACE;
 
2898           char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
 
2899           if (encapsedChar == '$') {
 
2900             scanner.encapsedStringStack.pop();
 
2901             encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
 
2902             switch (encapsedChar) {
 
2904                 if (token == TokenNameEncapsedString0) {
 
2907                 token = TokenNameSTRING;
 
2910                 if (token == TokenNameEncapsedString1) {
 
2913                 token = TokenNameSTRING;
 
2916                 if (token == TokenNameEncapsedString2) {
 
2919                 token = TokenNameSTRING;
 
2927   private void encaps_var() {
 
2929     //          | T_VARIABLE '[' encaps_var_offset ']'
 
2930     //          | T_VARIABLE T_OBJECT_OPERATOR T_STRING
 
2931     //          | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
 
2932     //          | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
 
2933     //          | T_CURLY_OPEN variable '}'
 
2935       case TokenNameVariable :
 
2937         if (token == TokenNameLBRACKET) {
 
2939           //          if (token == TokenNameRBRACKET) {
 
2942           expr(); //encaps_var_offset();
 
2943           if (token != TokenNameRBRACKET) {
 
2944             throwSyntaxError("']' expected after variable.");
 
2946           //          scanner.encapsedStringStack.pop();
 
2949         } else if (token == TokenNameMINUS_GREATER) {
 
2951           if (token != TokenNameIdentifier) {
 
2952             throwSyntaxError("Identifier expected after '->'.");
 
2954           //          scanner.encapsedStringStack.pop();
 
2958         //          // scanner.encapsedStringStack.pop();
 
2959         //          int tempToken = TokenNameSTRING;
 
2960         //          if (!scanner.encapsedStringStack.isEmpty()
 
2961         //              && (token == TokenNameEncapsedString0
 
2962         //                  || token == TokenNameEncapsedString1
 
2963         //                  || token == TokenNameEncapsedString2 || token ==
 
2964         // TokenNameERROR)) {
 
2965         //            char encapsedChar = ((Character)
 
2966         // scanner.encapsedStringStack.peek())
 
2969         //              case TokenNameEncapsedString0 :
 
2970         //                if (encapsedChar == '`') {
 
2971         //                  tempToken = TokenNameEncapsedString0;
 
2974         //              case TokenNameEncapsedString1 :
 
2975         //                if (encapsedChar == '\'') {
 
2976         //                  tempToken = TokenNameEncapsedString1;
 
2979         //              case TokenNameEncapsedString2 :
 
2980         //                if (encapsedChar == '"') {
 
2981         //                  tempToken = TokenNameEncapsedString2;
 
2984         //              case TokenNameERROR :
 
2985         //                if (scanner.source[scanner.currentPosition - 1] == '\\') {
 
2986         //                  scanner.currentPosition--;
 
2992         //          token = tempToken;
 
2995       case TokenNameDOLLAR_LBRACE :
 
2997         if (token == TokenNameIdentifier) {
 
2999           if (token == TokenNameLBRACKET) {
 
3001             //            if (token == TokenNameRBRACKET) {
 
3005             if (token != TokenNameRBRACKET) {
 
3006               throwSyntaxError("']' expected after '${'.");
 
3011           if (token != TokenNameRBRACE) {
 
3012             throwSyntaxError("'}' expected after '${'.");
 
3014           //          scanner.encapsedStringStack.pop();
 
3018           if (token != TokenNameRBRACE) {
 
3019             throwSyntaxError("'}' expected.");
 
3021           //          scanner.encapsedStringStack.pop();
 
3025       case TokenNameCURLY_OPEN :
 
3027         if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
3029           if (token == TokenNameLBRACKET) {
 
3031             //            if (token == TokenNameRBRACKET) {
 
3035             if (token != TokenNameRBRACKET) {
 
3036               throwSyntaxError("']' expected after '{$'.");
 
3040           } else if (token == TokenNameMINUS_GREATER) {
 
3042             if (token != TokenNameIdentifier) {
 
3043               throwSyntaxError("String token expected.");
 
3047           //          if (token != TokenNameRBRACE) {
 
3048           //            throwSyntaxError("'}' expected after '{$'.");
 
3050           //          // scanner.encapsedStringStack.pop();
 
3054           if (token != TokenNameRBRACE) {
 
3055             throwSyntaxError("'}' expected.");
 
3057           //          scanner.encapsedStringStack.pop();
 
3063   private void encaps_var_offset() {
 
3068       case TokenNameSTRING :
 
3071       case TokenNameIntegerLiteral :
 
3074       case TokenNameVariable :
 
3077       case TokenNameIdentifier :
 
3081         throwSyntaxError("Variable or String token expected.");
 
3085   private void internal_functions_in_yacc() {
 
3087     ImportReference impt = null;
 
3089       case TokenNameisset :
 
3090         //      T_ISSET '(' isset_variables ')'
 
3092         if (token != TokenNameLPAREN) {
 
3093           throwSyntaxError("'(' expected after keyword 'isset'");
 
3097         if (token != TokenNameRPAREN) {
 
3098           throwSyntaxError("')' expected after keyword 'isset'");
 
3102       case TokenNameempty :
 
3103         //      T_EMPTY '(' variable ')'
 
3105         if (token != TokenNameLPAREN) {
 
3106           throwSyntaxError("'(' expected after keyword 'empty'");
 
3110         if (token != TokenNameRPAREN) {
 
3111           throwSyntaxError("')' expected after keyword 'empty'");
 
3115       case TokenNameinclude :
 
3117         start = scanner.getCurrentTokenStartPosition();
 
3121         impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3122         impt.declarationSourceEnd = impt.sourceEnd;
 
3123         impt.declarationEnd = impt.declarationSourceEnd;
 
3124         //endPosition is just before the ;
 
3125         impt.declarationSourceStart = start;
 
3126         includesList.add(impt);
 
3128       case TokenNameinclude_once :
 
3129         //      T_INCLUDE_ONCE expr
 
3130         start = scanner.getCurrentTokenStartPosition();
 
3133         impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3134         impt.declarationSourceEnd = impt.sourceEnd;
 
3135         impt.declarationEnd = impt.declarationSourceEnd;
 
3136         //endPosition is just before the ;
 
3137         impt.declarationSourceStart = start;
 
3138         includesList.add(impt);
 
3140       case TokenNameeval :
 
3141         //      T_EVAL '(' expr ')'
 
3143         if (token != TokenNameLPAREN) {
 
3144           throwSyntaxError("'(' expected after keyword 'eval'");
 
3148         if (token != TokenNameRPAREN) {
 
3149           throwSyntaxError("')' expected after keyword 'eval'");
 
3153       case TokenNamerequire :
 
3155         start = scanner.getCurrentTokenStartPosition();
 
3158         impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3159         impt.declarationSourceEnd = impt.sourceEnd;
 
3160         impt.declarationEnd = impt.declarationSourceEnd;
 
3161         //endPosition is just before the ;
 
3162         impt.declarationSourceStart = start;
 
3163         includesList.add(impt);
 
3165       case TokenNamerequire_once :
 
3166         //      T_REQUIRE_ONCE expr
 
3167         start = scanner.getCurrentTokenStartPosition();
 
3170         impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3171         impt.declarationSourceEnd = impt.sourceEnd;
 
3172         impt.declarationEnd = impt.declarationSourceEnd;
 
3173         //endPosition is just before the ;
 
3174         impt.declarationSourceStart = start;
 
3175         includesList.add(impt);
 
3179   private void isset_variables() {
 
3181     //  | isset_variables ','
 
3182     if (token == TokenNameRPAREN) {
 
3183       throwSyntaxError("Variable expected after keyword 'isset'");
 
3187       if (token == TokenNameCOMMA) {
 
3194   private boolean common_scalar() {
 
3198     //  | T_CONSTANT_ENCAPSED_STRING
 
3205       case TokenNameIntegerLiteral :
 
3208       case TokenNameDoubleLiteral :
 
3211       case TokenNameStringDoubleQuote :
 
3214       case TokenNameStringSingleQuote :
 
3217       case TokenNameStringInterpolated :
 
3220       case TokenNameFILE :
 
3223       case TokenNameLINE :
 
3226       case TokenNameCLASS_C :
 
3229       case TokenNameMETHOD_C :
 
3232       case TokenNameFUNC_C :
 
3238   private void scalar() {
 
3241     //| T_STRING_VARNAME
 
3244     //| '"' encaps_list '"'
 
3245     //| '\'' encaps_list '\''
 
3246     //| T_START_HEREDOC encaps_list T_END_HEREDOC
 
3247     throwSyntaxError("Not yet implemented (scalar).");
 
3249   private void static_scalar() {
 
3250     //    static_scalar: /* compile-time evaluated scalars */
 
3253     //  | '+' static_scalar
 
3254     //  | '-' static_scalar
 
3255     //  | T_ARRAY '(' static_array_pair_list ')'
 
3256     //  | static_class_constant
 
3257     if (common_scalar()) {
 
3261       case TokenNameIdentifier :
 
3263         //        static_class_constant:
 
3264         //              T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
 
3265         if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
 
3267           if (token == TokenNameIdentifier) {
 
3270             throwSyntaxError("Identifier expected after '::' operator.");
 
3274       case TokenNameEncapsedString0 :
 
3276           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3277           while (scanner.currentCharacter != '`') {
 
3278             if (scanner.currentCharacter == '\\') {
 
3279               scanner.currentPosition++;
 
3281             scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3284         } catch (IndexOutOfBoundsException e) {
 
3285           throwSyntaxError("'`' expected at end of static string.");
 
3288       case TokenNameEncapsedString1 :
 
3290           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3291           while (scanner.currentCharacter != '\'') {
 
3292             if (scanner.currentCharacter == '\\') {
 
3293               scanner.currentPosition++;
 
3295             scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3298         } catch (IndexOutOfBoundsException e) {
 
3299           throwSyntaxError("'\'' expected at end of static string.");
 
3302       case TokenNameEncapsedString2 :
 
3304           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3305           while (scanner.currentCharacter != '"') {
 
3306             if (scanner.currentCharacter == '\\') {
 
3307               scanner.currentPosition++;
 
3309             scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3312         } catch (IndexOutOfBoundsException e) {
 
3313           throwSyntaxError("'\"' expected at end of static string.");
 
3316       case TokenNamePLUS :
 
3320       case TokenNameMINUS :
 
3324       case TokenNamearray :
 
3326         if (token != TokenNameLPAREN) {
 
3327           throwSyntaxError("'(' expected after keyword 'array'");
 
3330         if (token == TokenNameRPAREN) {
 
3334         non_empty_static_array_pair_list();
 
3335         if (token != TokenNameRPAREN) {
 
3336           throwSyntaxError("')' expected after keyword 'array'");
 
3340       //      case TokenNamenull :
 
3343       //      case TokenNamefalse :
 
3346       //      case TokenNametrue :
 
3350         throwSyntaxError("Static scalar/constant expected.");
 
3353   private void non_empty_static_array_pair_list() {
 
3354     //  non_empty_static_array_pair_list:
 
3355     //  non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
 
3357     //| non_empty_static_array_pair_list ',' static_scalar
 
3358     //| static_scalar T_DOUBLE_ARROW static_scalar
 
3362       if (token == TokenNameEQUAL_GREATER) {
 
3366       if (token != TokenNameCOMMA) {
 
3370       if (token == TokenNameRPAREN) {
 
3375   public void reportSyntaxError() { //int act, int currentKind, int
 
3377     /* remember current scanner position */
 
3378     int startPos = scanner.startPosition;
 
3379     int currentPos = scanner.currentPosition;
 
3380     //          String[] expectings;
 
3381     //          String tokenName = name[symbol_index[currentKind]];
 
3382     //fetch all "accurate" possible terminals that could recover the error
 
3383     //          int start, end = start = asi(stack[stateStackTop]);
 
3384     //          while (asr[end] != 0)
 
3386     //          int length = end - start;
 
3387     //          expectings = new String[length];
 
3388     //          if (length != 0) {
 
3389     //                  char[] indexes = new char[length];
 
3390     //                  System.arraycopy(asr, start, indexes, 0, length);
 
3391     //                  for (int i = 0; i < length; i++) {
 
3392     //                          expectings[i] = name[symbol_index[indexes[i]]];
 
3395     //if the pb is an EOF, try to tell the user that they are some
 
3396     //          if (tokenName.equals(UNEXPECTED_EOF)) {
 
3397     //                  if (!this.checkAndReportBracketAnomalies(problemReporter())) {
 
3398     //                          char[] tokenSource;
 
3400     //                                  tokenSource = this.scanner.getCurrentTokenSource();
 
3401     //                          } catch (Exception e) {
 
3402     //                                  tokenSource = new char[] {};
 
3404     //                          problemReporter().parseError(
 
3405     //                                  this.scanner.startPosition,
 
3406     //                                  this.scanner.currentPosition - 1,
 
3411     //          } else { //the next test is HEAVILY grammar DEPENDENT.
 
3412     //                  if ((length == 14)
 
3413     //                          && (expectings[0] == "=") //$NON-NLS-1$
 
3414     //                          && (expectings[1] == "*=") //$NON-NLS-1$
 
3415     //                          && (expressionPtr > -1)) {
 
3416     //                                  switch(currentKind) {
 
3417     //                                          case TokenNameSEMICOLON:
 
3418     //                                          case TokenNamePLUS:
 
3419     //                                          case TokenNameMINUS:
 
3420     //                                          case TokenNameDIVIDE:
 
3421     //                                          case TokenNameREMAINDER:
 
3422     //                                          case TokenNameMULTIPLY:
 
3423     //                                          case TokenNameLEFT_SHIFT:
 
3424     //                                          case TokenNameRIGHT_SHIFT:
 
3425     //// case TokenNameUNSIGNED_RIGHT_SHIFT:
 
3426     //                                          case TokenNameLESS:
 
3427     //                                          case TokenNameGREATER:
 
3428     //                                          case TokenNameLESS_EQUAL:
 
3429     //                                          case TokenNameGREATER_EQUAL:
 
3430     //                                          case TokenNameEQUAL_EQUAL:
 
3431     //                                          case TokenNameNOT_EQUAL:
 
3432     //                                          case TokenNameXOR:
 
3433     //                                          case TokenNameAND:
 
3434     //                                          case TokenNameOR:
 
3435     //                                          case TokenNameOR_OR:
 
3436     //                                          case TokenNameAND_AND:
 
3437     //                                                  // the ; is not the expected token ==> it ends a statement when an
 
3438     // expression is not ended
 
3439     //                                                  problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
 
3441     //                                          case TokenNameRBRACE :
 
3442     //                                                  problemReporter().missingSemiColon(expressionStack[expressionPtr]);
 
3445     //                                                  char[] tokenSource;
 
3447     //                                                          tokenSource = this.scanner.getCurrentTokenSource();
 
3448     //                                                  } catch (Exception e) {
 
3449     //                                                          tokenSource = new char[] {};
 
3451     //                                                  problemReporter().parseError(
 
3452     //                                                          this.scanner.startPosition,
 
3453     //                                                          this.scanner.currentPosition - 1,
 
3457     //                                                  this.checkAndReportBracketAnomalies(problemReporter());
 
3462       tokenSource = this.scanner.getCurrentTokenSource();
 
3463     } catch (Exception e) {
 
3464       tokenSource = new char[]{};
 
3466     //                          problemReporter().parseError(
 
3467     //                                  this.scanner.startPosition,
 
3468     //                                  this.scanner.currentPosition - 1,
 
3472     this.checkAndReportBracketAnomalies(problemReporter());
 
3475     /* reset scanner where it was */
 
3476     scanner.startPosition = startPos;
 
3477     scanner.currentPosition = currentPos;
 
3479   public static final int RoundBracket = 0;
 
3480   public static final int SquareBracket = 1;
 
3481   public static final int CurlyBracket = 2;
 
3482   public static final int BracketKinds = 3;
 
3483   protected int[] nestedMethod; //the ptr is nestedType
 
3484   protected int nestedType, dimensions;
 
3486   final static int AstStackIncrement = 100;
 
3487   protected int astPtr;
 
3488   protected AstNode[] astStack = new AstNode[AstStackIncrement];
 
3489   protected int astLengthPtr;
 
3490   protected int[] astLengthStack;
 
3491   AstNode[] noAstNodes = new AstNode[AstStackIncrement];
 
3492   public CompilationUnitDeclaration compilationUnit; /*
 
3493                                                       * the result from parse()
 
3495   protected ReferenceContext referenceContext;
 
3496   protected ProblemReporter problemReporter;
 
3497   protected CompilerOptions options;
 
3498   private ArrayList includesList;
 
3499   //  protected CompilationResult compilationResult;
 
3501    * Returns this parser's problem reporter initialized with its reference
 
3502    * context. Also it is assumed that a problem is going to be reported, so
 
3503    * initializes the compilation result's line positions.
 
3505   public ProblemReporter problemReporter() {
 
3506     if (scanner.recordLineSeparator) {
 
3507       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
 
3509     problemReporter.referenceContext = referenceContext;
 
3510     return problemReporter;
 
3513    * Reconsider the entire source looking for inconsistencies in {} () []
 
3515   public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
 
3516     scanner.wasAcr = false;
 
3517     boolean anomaliesDetected = false;
 
3519       char[] source = scanner.source;
 
3520       int[] leftCount = {0, 0, 0};
 
3521       int[] rightCount = {0, 0, 0};
 
3522       int[] depths = {0, 0, 0};
 
3523       int[][] leftPositions = new int[][]{new int[10], new int[10], new int[10]};
 
3524       int[][] leftDepths = new int[][]{new int[10], new int[10], new int[10]};
 
3525       int[][] rightPositions = new int[][]{new int[10], new int[10], new int[10]};
 
3526       int[][] rightDepths = new int[][]{new int[10], new int[10], new int[10]};
 
3527       scanner.currentPosition = scanner.initialPosition; //starting
 
3529       // (first-zero-based
 
3531       while (scanner.currentPosition < scanner.eofPosition) { //loop for
 
3536           // ---------Consume white space and handles
 
3537           // startPosition---------
 
3538           boolean isWhiteSpace;
 
3540             scanner.startPosition = scanner.currentPosition;
 
3541             //                                          if (((scanner.currentCharacter =
 
3542             // source[scanner.currentPosition++]) == '\\') &&
 
3543             // (source[scanner.currentPosition] == 'u')) {
 
3544             //                                                  isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
 
3546             if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
 
3547               if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
 
3548                 // only record line positions we have not
 
3550                 scanner.pushLineSeparator();
 
3553             isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
 
3555           } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
 
3556           // -------consume token until } is found---------
 
3557           switch (scanner.currentCharacter) {
 
3559               int index = leftCount[CurlyBracket]++;
 
3560               if (index == leftPositions[CurlyBracket].length) {
 
3561                 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
 
3562                 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
 
3564               leftPositions[CurlyBracket][index] = scanner.startPosition;
 
3565               leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
 
3569               int index = rightCount[CurlyBracket]++;
 
3570               if (index == rightPositions[CurlyBracket].length) {
 
3571                 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
 
3572                 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
 
3574               rightPositions[CurlyBracket][index] = scanner.startPosition;
 
3575               rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
 
3579               int index = leftCount[RoundBracket]++;
 
3580               if (index == leftPositions[RoundBracket].length) {
 
3581                 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
 
3582                 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
 
3584               leftPositions[RoundBracket][index] = scanner.startPosition;
 
3585               leftDepths[RoundBracket][index] = depths[RoundBracket]++;
 
3589               int index = rightCount[RoundBracket]++;
 
3590               if (index == rightPositions[RoundBracket].length) {
 
3591                 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
 
3592                 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
 
3594               rightPositions[RoundBracket][index] = scanner.startPosition;
 
3595               rightDepths[RoundBracket][index] = --depths[RoundBracket];
 
3599               int index = leftCount[SquareBracket]++;
 
3600               if (index == leftPositions[SquareBracket].length) {
 
3601                 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
 
3602                 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
 
3604               leftPositions[SquareBracket][index] = scanner.startPosition;
 
3605               leftDepths[SquareBracket][index] = depths[SquareBracket]++;
 
3609               int index = rightCount[SquareBracket]++;
 
3610               if (index == rightPositions[SquareBracket].length) {
 
3611                 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
 
3612                 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
 
3614               rightPositions[SquareBracket][index] = scanner.startPosition;
 
3615               rightDepths[SquareBracket][index] = --depths[SquareBracket];
 
3619               if (scanner.getNextChar('\\')) {
 
3620                 scanner.scanEscapeCharacter();
 
3621               } else { // consume next character
 
3622                 scanner.unicodeAsBackSlash = false;
 
3623                 //                                                                      if (((scanner.currentCharacter =
 
3624                 // source[scanner.currentPosition++]) ==
 
3626                 // (source[scanner.currentPosition] ==
 
3628                 //                                                                              scanner.getNextUnicodeChar();
 
3630                 if (scanner.withoutUnicodePtr != 0) {
 
3631                   scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3635               scanner.getNextChar('\'');
 
3639               // consume next character
 
3640               scanner.unicodeAsBackSlash = false;
 
3641               //                                                        if (((scanner.currentCharacter =
 
3642               // source[scanner.currentPosition++]) == '\\') &&
 
3643               // (source[scanner.currentPosition] == 'u')) {
 
3644               //                                                                scanner.getNextUnicodeChar();
 
3646               if (scanner.withoutUnicodePtr != 0) {
 
3647                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3650               while (scanner.currentCharacter != '"') {
 
3651                 if (scanner.currentCharacter == '\r') {
 
3652                   if (source[scanner.currentPosition] == '\n')
 
3653                     scanner.currentPosition++;
 
3654                   break; // the string cannot go further that
 
3657                 if (scanner.currentCharacter == '\n') {
 
3658                   break; // the string cannot go further that
 
3661                 if (scanner.currentCharacter == '\\') {
 
3662                   scanner.scanEscapeCharacter();
 
3664                 // consume next character
 
3665                 scanner.unicodeAsBackSlash = false;
 
3666                 //                                                              if (((scanner.currentCharacter =
 
3667                 // source[scanner.currentPosition++]) == '\\')
 
3668                 // && (source[scanner.currentPosition] == 'u'))
 
3670                 //                                                                      scanner.getNextUnicodeChar();
 
3672                 if (scanner.withoutUnicodePtr != 0) {
 
3673                   scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3680               if ((test = scanner.getNextChar('/', '*')) == 0) { //line
 
3683                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3684                     && (source[scanner.currentPosition] == 'u')) {
 
3685                   //-------------unicode traitement
 
3687                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3688                   scanner.currentPosition++;
 
3689                   while (source[scanner.currentPosition] == 'u') {
 
3690                     scanner.currentPosition++;
 
3692                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3693                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3694                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3695                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3699                     scanner.currentCharacter = 'A';
 
3700                   } //something different from \n and \r
 
3702                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
3705                 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
 
3707                   scanner.startPosition = scanner.currentPosition;
 
3708                   if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3709                       && (source[scanner.currentPosition] == 'u')) {
 
3710                     //-------------unicode traitement
 
3712                     int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3713                     scanner.currentPosition++;
 
3714                     while (source[scanner.currentPosition] == 'u') {
 
3715                       scanner.currentPosition++;
 
3717                     if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3718                         || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3719                         || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3720                         || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3724                       scanner.currentCharacter = 'A';
 
3725                     } //something different from \n
 
3728                       scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
3732                 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
 
3733                   if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
 
3734                     // only record line positions we
 
3735                     // have not recorded yet
 
3736                     scanner.pushLineSeparator();
 
3737                     if (this.scanner.taskTags != null) {
 
3738                       this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
 
3739                           .getCurrentTokenEndPosition());
 
3745               if (test > 0) { //traditional and annotation
 
3747                 boolean star = false;
 
3748                 // consume next character
 
3749                 scanner.unicodeAsBackSlash = false;
 
3750                 //                                                                      if (((scanner.currentCharacter =
 
3751                 // source[scanner.currentPosition++]) ==
 
3753                 // (source[scanner.currentPosition] ==
 
3755                 //                                                                              scanner.getNextUnicodeChar();
 
3757                 if (scanner.withoutUnicodePtr != 0) {
 
3758                   scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3761                 if (scanner.currentCharacter == '*') {
 
3765                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3766                     && (source[scanner.currentPosition] == 'u')) {
 
3767                   //-------------unicode traitement
 
3769                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3770                   scanner.currentPosition++;
 
3771                   while (source[scanner.currentPosition] == 'u') {
 
3772                     scanner.currentPosition++;
 
3774                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3775                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3776                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3777                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3781                     scanner.currentCharacter = 'A';
 
3782                   } //something different from * and /
 
3784                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
3787                 //loop until end of comment */
 
3788                 while ((scanner.currentCharacter != '/') || (!star)) {
 
3789                   star = scanner.currentCharacter == '*';
 
3791                   if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3792                       && (source[scanner.currentPosition] == 'u')) {
 
3793                     //-------------unicode traitement
 
3795                     int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3796                     scanner.currentPosition++;
 
3797                     while (source[scanner.currentPosition] == 'u') {
 
3798                       scanner.currentPosition++;
 
3800                     if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3801                         || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3802                         || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3803                         || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3807                       scanner.currentCharacter = 'A';
 
3808                     } //something different from * and
 
3811                       scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
3815                 if (this.scanner.taskTags != null) {
 
3816                   this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
 
3823               if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
 
3824                 scanner.scanIdentifierOrKeyword(false);
 
3827               if (Character.isDigit(scanner.currentCharacter)) {
 
3828                 scanner.scanNumber(false);
 
3832           //-----------------end switch while
 
3833           // try--------------------
 
3834         } catch (IndexOutOfBoundsException e) {
 
3835           break; // read until EOF
 
3836         } catch (InvalidInputException e) {
 
3837           return false; // no clue
 
3840       if (scanner.recordLineSeparator) {
 
3841         //                              compilationUnit.compilationResult.lineSeparatorPositions =
 
3842         // scanner.getLineEnds();
 
3844       // check placement anomalies against other kinds of brackets
 
3845       for (int kind = 0; kind < BracketKinds; kind++) {
 
3846         for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
 
3847           int start = leftPositions[kind][leftIndex]; // deepest
 
3849           // find matching closing bracket
 
3850           int depth = leftDepths[kind][leftIndex];
 
3852           for (int i = 0; i < rightCount[kind]; i++) {
 
3853             int pos = rightPositions[kind][i];
 
3854             // want matching bracket further in source with same
 
3856             if ((pos > start) && (depth == rightDepths[kind][i])) {
 
3861           if (end < 0) { // did not find a good closing match
 
3862             problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
 
3865           // check if even number of opening/closing other brackets
 
3866           // in between this pair of brackets
 
3868           for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
 
3869             for (int i = 0; i < leftCount[otherKind]; i++) {
 
3870               int pos = leftPositions[otherKind][i];
 
3871               if ((pos > start) && (pos < end))
 
3874             for (int i = 0; i < rightCount[otherKind]; i++) {
 
3875               int pos = rightPositions[otherKind][i];
 
3876               if ((pos > start) && (pos < end))
 
3880               problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
 
3886         // too many opening brackets ?
 
3887         for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
 
3888           anomaliesDetected = true;
 
3889           problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
 
3890               compilationUnit.compilationResult);
 
3892         // too many closing brackets ?
 
3893         for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
 
3894           anomaliesDetected = true;
 
3895           problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
 
3897         if (anomaliesDetected)
 
3900       return anomaliesDetected;
 
3901     } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
 
3902       return anomaliesDetected;
 
3903     } catch (NullPointerException e) { // jdk1.2.2 jit bug
 
3904       return anomaliesDetected;
 
3907   protected void pushOnAstLengthStack(int pos) {
 
3909       astLengthStack[++astLengthPtr] = pos;
 
3910     } catch (IndexOutOfBoundsException e) {
 
3911       int oldStackLength = astLengthStack.length;
 
3912       int[] oldPos = astLengthStack;
 
3913       astLengthStack = new int[oldStackLength + StackIncrement];
 
3914       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
 
3915       astLengthStack[astLengthPtr] = pos;
 
3918   protected void pushOnAstStack(AstNode node) {
 
3920      * add a new obj on top of the ast stack
 
3923       astStack[++astPtr] = node;
 
3924     } catch (IndexOutOfBoundsException e) {
 
3925       int oldStackLength = astStack.length;
 
3926       AstNode[] oldStack = astStack;
 
3927       astStack = new AstNode[oldStackLength + AstStackIncrement];
 
3928       System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
 
3929       astPtr = oldStackLength;
 
3930       astStack[astPtr] = node;
 
3933       astLengthStack[++astLengthPtr] = 1;
 
3934     } catch (IndexOutOfBoundsException e) {
 
3935       int oldStackLength = astLengthStack.length;
 
3936       int[] oldPos = astLengthStack;
 
3937       astLengthStack = new int[oldStackLength + AstStackIncrement];
 
3938       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
 
3939       astLengthStack[astLengthPtr] = 1;
 
3943   protected void resetModifiers() {
 
3944     this.modifiers = AccDefault;
 
3945     this.modifiersSourceStart = -1; // <-- see comment into
 
3946     // modifiersFlag(int)
 
3947     this.scanner.commentPtr = -1;