1 /***********************************************************************************************************************************
 
   2  * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material are made available under the
 
   3  * terms of the Common Public License v1.0 which accompanies this distribution, and is available at
 
   4  * http://www.eclipse.org/legal/cpl-v10.html
 
   6  * Contributors: www.phpeclipse.de
 
   7  **********************************************************************************************************************************/
 
   8 package net.sourceforge.phpdt.internal.compiler.parser;
 
  10 import java.util.ArrayList;
 
  12 import net.sourceforge.phpdt.core.compiler.CharOperation;
 
  13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 
  14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
 
  15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
 
  16 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
 
  17 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
 
  18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
 
  19 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
 
  20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
 
  21 import net.sourceforge.phpdt.internal.compiler.util.Util;
 
  22 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
 
  23 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
 
  24 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
 
  25 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
 
  26 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
 
  27 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
 
  28 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
 
  29 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
 
  30 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
 
  31 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
 
  32 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
 
  33 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
 
  34 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
 
  35 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
 
  36 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
 
  37 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
 
  38 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
 
  39 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
 
  40 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
 
  41 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
 
  42 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
 
  44 import org.eclipse.core.resources.IFile;
 
  45 import org.eclipse.core.resources.IProject;
 
  46 import org.eclipse.core.resources.IResource;
 
  47 import org.eclipse.core.runtime.IPath;
 
  49 public class Parser //extends PHPParserSuperclass
 
  50     implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
 
  51   //internal data for the automat
 
  52   protected final static int StackIncrement = 255;
 
  54   protected int stateStackTop;
 
  56   protected int[] stack = new int[StackIncrement];
 
  58   public int firstToken; // handle for multiple parsing goals
 
  60   public int lastAct; //handle for multiple parsing goals
 
  62   protected RecoveredElement currentElement;
 
  64   public static boolean VERBOSE_RECOVERY = false;
 
  66   protected boolean diet = false; //tells the scanner to jump over some
 
  68   // parts of the code/expressions like
 
  71   public Scanner scanner;
 
  73   private ArrayList phpList;
 
  75   private int currentPHPString;
 
  77   private boolean phpEnd;
 
  79   // private static HashMap keywordMap = null;
 
  87   // row counter for syntax errors:
 
  89   // column counter for syntax errors:
 
  93   //    // current identifier
 
  99   private String stringValue;
 
 101   /** Contains the current expression. */
 
 102   // private StringBuffer expression;
 
 103   //private boolean phpMode;
 
 104   protected int modifiers;
 
 106   protected int modifiersSourceStart;
 
 108   //  protected IdentifierIndexManager indexManager;
 
 110   protected Parser(ProblemReporter problemReporter) {
 
 111     this.problemReporter = problemReporter;
 
 112     this.options = problemReporter.options;
 
 113     this.currentPHPString = 0;
 
 114     //          PHPParserSuperclass.fileToParse = fileToParse;
 
 116     //    this.indexManager = null;
 
 118     this.token = TokenNameEOF;
 
 120     //    this.rowCount = 1;
 
 121     //    this.columnCount = 0;
 
 124     this.initializeScanner();
 
 127   public void setFileToParse(IFile fileToParse) {
 
 128     this.currentPHPString = 0;
 
 129     //    PHPParserSuperclass.fileToParse = fileToParse;
 
 131     //    this.indexManager = null;
 
 133     this.token = TokenNameEOF;
 
 135     this.initializeScanner();
 
 139    * ClassDeclaration Constructor.
 
 143    *          Description of Parameter
 
 146   public Parser(IFile fileToParse) {
 
 147     //    if (keywordMap == null) {
 
 148     //      keywordMap = new HashMap();
 
 149     //      for (int i = 0; i < PHP_KEYWORS.length; i++) {
 
 150     //        keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
 
 153     this.currentPHPString = 0;
 
 154     //    PHPParserSuperclass.fileToParse = fileToParse;
 
 156     this.includesList = null;
 
 158     this.token = TokenNameEOF;
 
 160     //    this.rowCount = 1;
 
 161     //    this.columnCount = 0;
 
 164     this.initializeScanner();
 
 167   public void initializeScanner() {
 
 168     this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
 
 169         .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
 
 170         this.options.taskTags/* taskTags */, 
 
 171         this.options.taskPriorites/* taskPriorities */,
 
 172         true/*isTaskCaseSensitive*/);
 
 176    * Create marker for the parse error
 
 178   //  private void setMarker(String message, int charStart, int charEnd, int
 
 180   //    setMarker(fileToParse, message, charStart, charEnd, errorLevel);
 
 183    * This method will throw the SyntaxError. It will add the good lines and columns to the Error
 
 187    * @throws SyntaxError
 
 190   private void throwSyntaxError(String error) {
 
 191     int problemStartPosition = scanner.getCurrentTokenStartPosition();
 
 192     int problemEndPosition = scanner.getCurrentTokenEndPosition();
 
 193     throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
 
 197    * This method will throw the SyntaxError. It will add the good lines and columns to the Error
 
 201    * @throws SyntaxError
 
 204   //  private void throwSyntaxError(String error, int startRow) {
 
 205   //    throw new SyntaxError(startRow, 0, " ", error);
 
 207   private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
 
 208     problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
 
 209         compilationUnit.compilationResult);
 
 210     throw new SyntaxError(1, 0, " ", error);
 
 213   private void reportSyntaxError(String error) {
 
 214     int problemStartPosition = scanner.getCurrentTokenStartPosition();
 
 215     int problemEndPosition = scanner.getCurrentTokenEndPosition();
 
 216     reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
 
 219   private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
 
 220     problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
 
 221         compilationUnit.compilationResult);
 
 224   private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
 
 225     problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
 
 226         compilationUnit.compilationResult);
 
 230    * gets the next token from input
 
 232   private void getNextToken() {
 
 234       token = scanner.getNextToken();
 
 236         int currentEndPosition = scanner.getCurrentTokenEndPosition();
 
 237         int currentStartPosition = scanner.getCurrentTokenStartPosition();
 
 238         System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
 
 239         System.out.println(scanner.toStringAction(token));
 
 241     } catch (InvalidInputException e) {
 
 242       token = TokenNameERROR;
 
 243       String detailedMessage = e.getMessage();
 
 245       if (detailedMessage == Scanner.UNTERMINATED_STRING) {
 
 246         throwSyntaxError("Unterminated string.");
 
 247       } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
 
 248         throwSyntaxError("Unterminated commment.");
 
 254   public void init(String s) {
 
 256     this.token = TokenNameEOF;
 
 258     //    this.rowCount = 1;
 
 259     //    this.columnCount = 0;
 
 261     //    this.phpMode = false;
 
 262     /* scanner initialization */
 
 263     scanner.setSource(s.toCharArray());
 
 264     scanner.setPHPMode(false);
 
 267   protected void initialize(boolean phpMode) {
 
 268     initialize(phpMode, null);
 
 271   protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
 
 272     compilationUnit = null;
 
 273     referenceContext = null;
 
 274     includesList = new ArrayList();
 
 275     //    this.indexManager = indexManager;
 
 277     this.token = TokenNameEOF;
 
 279     //    this.rowCount = 1;
 
 280     //    this.columnCount = 0;
 
 282     //    this.phpMode = phpMode;
 
 283     scanner.setPHPMode(phpMode);
 
 287    * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
 
 289   public void parse(String s) {
 
 295    * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
 
 297   protected void parse() {
 
 301         if (token != TokenNameEOF && token != TokenNameERROR) {
 
 304         if (token != TokenNameEOF) {
 
 305           if (token == TokenNameERROR) {
 
 306             throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
 
 308           if (token == TokenNameRPAREN) {
 
 309             throwSyntaxError("Too many closing ')'; end-of-file not reached.");
 
 311           if (token == TokenNameRBRACE) {
 
 312             throwSyntaxError("Too many closing '}'; end-of-file not reached.");
 
 314           if (token == TokenNameRBRACKET) {
 
 315             throwSyntaxError("Too many closing ']'; end-of-file not reached.");
 
 317           if (token == TokenNameLPAREN) {
 
 318             throwSyntaxError("Read character '('; end-of-file not reached.");
 
 320           if (token == TokenNameLBRACE) {
 
 321             throwSyntaxError("Read character '{';  end-of-file not reached.");
 
 323           if (token == TokenNameLBRACKET) {
 
 324             throwSyntaxError("Read character '[';  end-of-file not reached.");
 
 326           throwSyntaxError("End-of-file not reached.");
 
 329       } catch (SyntaxError sytaxErr1) {
 
 330         // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
 
 332         //        setMarker(sytaxErr1.getMessage(),
 
 333         // scanner.getCurrentTokenStartPosition(),
 
 334         // scanner.getCurrentTokenEndPosition(), ERROR);
 
 336           // if an error occured,
 
 337           // try to find keywords 'class' or 'function'
 
 338           // to parse the rest of the string
 
 339           while (token != TokenNameEOF && token != TokenNameERROR) {
 
 340             if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
 
 345           if (token == TokenNameEOF || token == TokenNameERROR) {
 
 348         } catch (SyntaxError sytaxErr2) {
 
 349           //    setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
 
 351           //          setMarker(sytaxErr2.getMessage(),
 
 352           // scanner.getCurrentTokenStartPosition(),
 
 353           // scanner.getCurrentTokenEndPosition(), ERROR);
 
 362   protected CompilationUnitDeclaration endParse(int act) {
 
 366     if (currentElement != null) {
 
 367       currentElement.topElement().updateParseTree();
 
 368       if (VERBOSE_RECOVERY) {
 
 369         System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
 
 370         System.out.println("--------------------------"); //$NON-NLS-1$
 
 371         System.out.println(compilationUnit);
 
 372         System.out.println("----------------------------------"); //$NON-NLS-1$
 
 375       if (diet & VERBOSE_RECOVERY) {
 
 376         System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
 
 377         System.out.println("--------------------------"); //$NON-NLS-1$
 
 378         System.out.println(compilationUnit);
 
 379         System.out.println("----------------------------------"); //$NON-NLS-1$
 
 382     if (scanner.recordLineSeparator) {
 
 383       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
 
 385     if (scanner.taskTags != null) {
 
 386       for (int i = 0; i < scanner.foundTaskCount; i++) {
 
 387         problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
 
 388             scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
 
 389             scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
 
 392     compilationUnit.imports = new ImportReference[includesList.size()];
 
 393     for (int i = 0; i < includesList.size(); i++) {
 
 394       compilationUnit.imports[i] = (ImportReference) includesList.get(i);
 
 396     return compilationUnit;
 
 399   //  public PHPOutlineInfo parseInfo(Object parent, String s) {
 
 400   //    PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
 
 401   //    // Stack stack = new Stack();
 
 402   //    // stack.push(outlineInfo.getDeclarations());
 
 404   //    this.token = TokenNameEOF;
 
 405   //    // this.chIndx = 0;
 
 406   //    // this.rowCount = 1;
 
 407   //    // this.columnCount = 0;
 
 408   //    this.phpEnd = false;
 
 409   //    this.phpMode = false;
 
 410   //    scanner.setSource(s.toCharArray());
 
 411   //    scanner.setPHPMode(false);
 
 414   //    parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
 
 416   //    return outlineInfo;
 
 418   private boolean isVariable() {
 
 419     return token == TokenNameVariable; //  || token == TokenNamethis;
 
 422   //  private void parseDeclarations(PHPOutlineInfo outlineInfo,
 
 423   //      OutlineableWithChildren current, boolean goBack) {
 
 425   //    // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
 
 426   //    PHPSegmentWithChildren temp;
 
 428   //    IPreferenceStore store =
 
 429   // PHPeclipsePlugin.getDefault().getPreferenceStore();
 
 431   //      while (token != TokenNameEOF && token != TokenNameERROR) {
 
 432   //        if (token == TokenNameVariable) {
 
 433   //          ident = scanner.getCurrentIdentifierSource();
 
 434   //          outlineInfo.addVariable(new String(ident));
 
 436   //        } else if (token == TokenNamevar) {
 
 438   //          if (token == TokenNameVariable
 
 439   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
 
 440   //            ident = scanner.getCurrentIdentifierSource();
 
 441   //            //substring(1) added because PHPVarDeclaration doesn't
 
 442   //            // need the $ anymore
 
 443   //            String variableName = new String(ident).substring(1);
 
 444   //            outlineInfo.addVariable(variableName);
 
 446   //            if (token != TokenNameSEMICOLON) {
 
 448   //              ident = scanner.getCurrentTokenSource();
 
 449   //              if (token > TokenNameKEYWORD) {
 
 450   //                current.add(new PHPVarDeclaration(current, variableName,
 
 451   //                // chIndx - ident.length,
 
 452   //                    scanner.getCurrentTokenStartPosition(), new String(ident)));
 
 455   //                  case TokenNameVariable :
 
 456   //                  case TokenNamethis :
 
 457   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 460   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 463   //                  case TokenNameIdentifier :
 
 464   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 467   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 470   //                  case TokenNameDoubleLiteral :
 
 471   //                    current.add(new PHPVarDeclaration(current, variableName
 
 475   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 478   //                  case TokenNameIntegerLiteral :
 
 479   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 482   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 485   //                  case TokenNameStringInterpolated :
 
 486   //                  case TokenNameStringLiteral :
 
 487   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 490   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 493   //                  case TokenNameStringConstant :
 
 494   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 497   //                        scanner.getCurrentTokenStartPosition(), new String(
 
 501   //                    current.add(new PHPVarDeclaration(current, variableName,
 
 504   //                        scanner.getCurrentTokenStartPosition()));
 
 509   //              ident = scanner.getCurrentIdentifierSource();
 
 510   //              current.add(new PHPVarDeclaration(current, variableName,
 
 511   //              // chIndx - ident.length
 
 512   //                  scanner.getCurrentTokenStartPosition()));
 
 515   //        } else if (token == TokenNamefunction) {
 
 517   //          if (token == TokenNameAND) {
 
 520   //          if (token == TokenNameIdentifier
 
 521   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
 
 522   //            ident = scanner.getCurrentIdentifierSource();
 
 523   //            outlineInfo.addVariable(new String(ident));
 
 524   //            temp = new PHPFunctionDeclaration(current, new String(ident),
 
 525   //            // chIndx - ident.length
 
 526   //                scanner.getCurrentTokenStartPosition());
 
 527   //            current.add(temp);
 
 529   //            parseDeclarations(outlineInfo, temp, true);
 
 531   //        } else if (token == TokenNameclass) {
 
 533   //          if (token == TokenNameIdentifier
 
 534   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
 
 535   //            ident = scanner.getCurrentIdentifierSource();
 
 536   //            outlineInfo.addVariable(new String(ident));
 
 537   //            temp = new PHPClassDeclaration(current, new String(ident),
 
 538   //            // chIndx - ident.len
 
 539   //                scanner.getCurrentTokenStartPosition());
 
 540   //            current.add(temp);
 
 541   //            // stack.push(temp);
 
 543   //            //skip tokens for classname, extends and others until
 
 544   //            // we have the opening '{'
 
 545   //            while (token != TokenNameLBRACE && token != TokenNameEOF
 
 546   //                && token != TokenNameERROR) {
 
 549   //            parseDeclarations(outlineInfo, temp, true);
 
 552   //        } else if ((token == TokenNameLBRACE)
 
 553   //            || (token == TokenNameDOLLAR_LBRACE)) {
 
 556   //        } else if (token == TokenNameRBRACE) {
 
 559   //          if (counter == 0 && goBack) {
 
 562   //        } else if (token == TokenNamerequire || token == TokenNamerequire_once
 
 563   //            || token == TokenNameinclude || token == TokenNameinclude_once) {
 
 564   //          ident = scanner.getCurrentTokenSource();
 
 566   //          int startPosition = scanner.getCurrentTokenStartPosition();
 
 568   //          char[] expr = scanner.getCurrentTokenSource(startPosition);
 
 569   //          outlineInfo.addVariable(new String(ident));
 
 570   //          current.add(new PHPReqIncDeclaration(current, new String(ident),
 
 571   //          // chIndx - ident.length,
 
 572   //              startPosition, new String(expr)));
 
 578   //    } catch (SyntaxError sytaxErr) {
 
 580   //      // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
 
 581   //      // setMarker(sytaxErr.getMessage(),
 
 582   //      // scanner.getCurrentTokenStartPosition(),
 
 583   //      // scanner.getCurrentTokenEndPosition(), ERROR);
 
 584   //      // } catch (CoreException e) {
 
 588   private void statementList() {
 
 590       statement(TokenNameEOF);
 
 591       if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
 
 592           || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
 
 593           || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
 
 594           || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
 
 600   private void functionBody(MethodDeclaration methodDecl) {
 
 601     // '{' [statement-list] '}'
 
 602     if (token == TokenNameLBRACE) {
 
 605       throwSyntaxError("'{' expected in compound-statement.");
 
 607     if (token != TokenNameRBRACE) {
 
 610     if (token == TokenNameRBRACE) {
 
 611       methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
 614       throwSyntaxError("'}' expected in compound-statement.");
 
 618   private Statement statement(int previousToken) {
 
 619     Statement statement = null;
 
 620     Expression expression;
 
 621     int sourceStart = scanner.getCurrentTokenStartPosition();
 
 622     if (token == TokenNameif) {
 
 624       if (token == TokenNameLPAREN) {
 
 627         throwSyntaxError("'(' expected after 'if' keyword.");
 
 630       if (token == TokenNameRPAREN) {
 
 633         throwSyntaxError("')' expected after 'if' condition.");
 
 636       return new IfStatement(expression, statement, sourceStart, scanner.getCurrentTokenEndPosition());
 
 637     } else if (token == TokenNameswitch) {
 
 639       if (token == TokenNameLPAREN) {
 
 642         throwSyntaxError("'(' expected after 'switch' keyword.");
 
 645       if (token == TokenNameRPAREN) {
 
 648         throwSyntaxError("')' expected after 'switch' condition.");
 
 652     } else if (token == TokenNamefor) {
 
 654       if (token == TokenNameLPAREN) {
 
 657         throwSyntaxError("'(' expected after 'for' keyword.");
 
 659       if (token == TokenNameSEMICOLON) {
 
 663         if (token == TokenNameSEMICOLON) {
 
 666           throwSyntaxError("';' expected after 'for'.");
 
 669       if (token == TokenNameSEMICOLON) {
 
 673         if (token == TokenNameSEMICOLON) {
 
 676           throwSyntaxError("';' expected after 'for'.");
 
 679       if (token == TokenNameRPAREN) {
 
 683         if (token == TokenNameRPAREN) {
 
 686           throwSyntaxError("')' expected after 'for'.");
 
 691     } else if (token == TokenNamewhile) {
 
 693       if (token == TokenNameLPAREN) {
 
 696         throwSyntaxError("'(' expected after 'while' keyword.");
 
 699       if (token == TokenNameRPAREN) {
 
 702         throwSyntaxError("')' expected after 'while' condition.");
 
 706     } else if (token == TokenNamedo) {
 
 708       if (token == TokenNameLBRACE) {
 
 710         if (token != TokenNameRBRACE) {
 
 713         if (token == TokenNameRBRACE) {
 
 716           throwSyntaxError("'}' expected after 'do' keyword.");
 
 719         statement(TokenNameEOF);
 
 721       if (token == TokenNamewhile) {
 
 723         if (token == TokenNameLPAREN) {
 
 726           throwSyntaxError("'(' expected after 'while' keyword.");
 
 729         if (token == TokenNameRPAREN) {
 
 732           throwSyntaxError("')' expected after 'while' condition.");
 
 735         throwSyntaxError("'while' expected after 'do' keyword.");
 
 737       if (token == TokenNameSEMICOLON) {
 
 740         if (token != TokenNameINLINE_HTML) {
 
 741           throwSyntaxError("';' expected after do-while statement.");
 
 746     } else if (token == TokenNameforeach) {
 
 748       if (token == TokenNameLPAREN) {
 
 751         throwSyntaxError("'(' expected after 'foreach' keyword.");
 
 754       if (token == TokenNameas) {
 
 757         throwSyntaxError("'as' expected after 'foreach' exxpression.");
 
 761       foreach_optional_arg();
 
 762       if (token == TokenNameEQUAL_GREATER) {
 
 766       if (token == TokenNameRPAREN) {
 
 769         throwSyntaxError("')' expected after 'foreach' expression.");
 
 773     } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
 
 775       if (token != TokenNameSEMICOLON) {
 
 778       if (token == TokenNameSEMICOLON) {
 
 781         if (token != TokenNameINLINE_HTML) {
 
 782           throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
 
 787     } else if (token == TokenNameecho) {
 
 790       if (token == TokenNameSEMICOLON) {
 
 793         if (token != TokenNameINLINE_HTML) {
 
 794           throwSyntaxError("';' expected after 'echo' statement.");
 
 799     } else if (token == TokenNameINLINE_HTML) {
 
 802       //    } else if (token == TokenNameprint) {
 
 805       //      if (token == TokenNameSEMICOLON) {
 
 808       //        if (token != TokenNameStopPHP) {
 
 809       //          throwSyntaxError("';' expected after 'print' statement.");
 
 814     } else if (token == TokenNameglobal) {
 
 817       if (token == TokenNameSEMICOLON) {
 
 820         if (token != TokenNameINLINE_HTML) {
 
 821           throwSyntaxError("';' expected after 'global' statement.");
 
 826     } else if (token == TokenNamestatic) {
 
 829       if (token == TokenNameSEMICOLON) {
 
 832         if (token != TokenNameINLINE_HTML) {
 
 833           throwSyntaxError("';' expected after 'static' statement.");
 
 838     } else if (token == TokenNameunset) {
 
 840       if (token == TokenNameLPAREN) {
 
 843         throwSyntaxError("'(' expected after 'unset' statement.");
 
 846       if (token == TokenNameRPAREN) {
 
 849         throwSyntaxError("')' expected after 'unset' statement.");
 
 851       if (token == TokenNameSEMICOLON) {
 
 854         if (token != TokenNameINLINE_HTML) {
 
 855           throwSyntaxError("';' expected after 'unset' statement.");
 
 860     } else if (token == TokenNamefunction) {
 
 861       MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
 
 862       methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
 863       methodDecl.modifiers = AccDefault;
 
 865       functionDefinition(methodDecl);
 
 867     } else if (token == TokenNamedeclare) {
 
 868       //T_DECLARE '(' declare_list ')' declare_statement
 
 870       if (token != TokenNameLPAREN) {
 
 871         throwSyntaxError("'(' expected in 'declare' statement.");
 
 875       if (token != TokenNameRPAREN) {
 
 876         throwSyntaxError("')' expected in 'declare' statement.");
 
 881     } else if (token == TokenNametry) {
 
 883       if (token != TokenNameLBRACE) {
 
 884         throwSyntaxError("'{' expected in 'try' statement.");
 
 888       if (token != TokenNameRBRACE) {
 
 889         throwSyntaxError("'}' expected in 'try' statement.");
 
 893     } else if (token == TokenNamecatch) {
 
 895       if (token != TokenNameLPAREN) {
 
 896         throwSyntaxError("'(' expected in 'catch' statement.");
 
 899       fully_qualified_class_name();
 
 900       if (token != TokenNameVariable) {
 
 901         throwSyntaxError("Variable expected in 'catch' statement.");
 
 904       if (token != TokenNameRPAREN) {
 
 905         throwSyntaxError("')' expected in 'catch' statement.");
 
 908       if (token != TokenNameLBRACE) {
 
 909         throwSyntaxError("'{' expected in 'catch' statement.");
 
 912       if (token != TokenNameRBRACE) {
 
 914         if (token != TokenNameRBRACE) {
 
 915           throwSyntaxError("'}' expected in 'catch' statement.");
 
 919       additional_catches();
 
 921     } else if (token == TokenNamethrow) {
 
 924       if (token == TokenNameSEMICOLON) {
 
 927         throwSyntaxError("';' expected after 'throw' exxpression.");
 
 930     } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
 
 931       TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
 
 932       typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
 933       typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
 934       typeDecl.name = new char[] { ' ' };
 
 935       // default super class
 
 936       typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
 
 937       compilationUnit.types.add(typeDecl);
 
 939         pushOnAstStack(typeDecl);
 
 940         unticked_class_declaration_statement(typeDecl);
 
 941         //        classBody(typeDecl);
 
 948       //        throwSyntaxError("Unexpected keyword '" + keyword + "'");
 
 949     } else if (token == TokenNameLBRACE) {
 
 951       if (token != TokenNameRBRACE) {
 
 954       if (token == TokenNameRBRACE) {
 
 958         throwSyntaxError("'}' expected.");
 
 961       if (token != TokenNameSEMICOLON) {
 
 964       if (token == TokenNameSEMICOLON) {
 
 968         if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
 
 969           throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
 
 978   private void declare_statement() {
 
 980     //| ':' inner_statement_list T_ENDDECLARE ';'
 
 982     if (token == TokenNameCOLON) {
 
 984       // TODO: implement inner_statement_list();
 
 986       if (token != TokenNameenddeclare) {
 
 987         throwSyntaxError("'enddeclare' expected in 'declare' statement.");
 
 990       if (token != TokenNameSEMICOLON) {
 
 991         throwSyntaxError("';' expected after 'enddeclare' keyword.");
 
 995       statement(TokenNameRPAREN);
 
 999   private void declare_list() {
 
1000     //  T_STRING '=' static_scalar
 
1001     //| declare_list ',' T_STRING '=' static_scalar
 
1003       if (token != TokenNameIdentifier) {
 
1004         throwSyntaxError("Identifier expected in 'declare' list.");
 
1007       if (token != TokenNameEQUAL) {
 
1008         throwSyntaxError("'=' expected in 'declare' list.");
 
1012       if (token != TokenNameCOMMA) {
 
1019   private void additional_catches() {
 
1020     while (token == TokenNamecatch) {
 
1022       if (token != TokenNameLPAREN) {
 
1023         throwSyntaxError("'(' expected in 'catch' statement.");
 
1026       fully_qualified_class_name();
 
1027       if (token != TokenNameVariable) {
 
1028         throwSyntaxError("Variable expected in 'catch' statement.");
 
1031       if (token != TokenNameRPAREN) {
 
1032         throwSyntaxError("')' expected in 'catch' statement.");
 
1035       if (token != TokenNameLBRACE) {
 
1036         throwSyntaxError("'{' expected in 'catch' statement.");
 
1039       if (token != TokenNameRBRACE) {
 
1042       if (token != TokenNameRBRACE) {
 
1043         throwSyntaxError("'}' expected in 'catch' statement.");
 
1049   private void foreach_variable() {
 
1052     if (token == TokenNameAND) {
 
1058   private void foreach_optional_arg() {
 
1060     //| T_DOUBLE_ARROW foreach_variable
 
1061     if (token == TokenNameEQUAL_GREATER) {
 
1067   private void global_var_list() {
 
1069     //  global_var_list ',' global_var
 
1073       if (token != TokenNameCOMMA) {
 
1080   private void global_var() {
 
1084     //| '$' '{' expr '}'
 
1085     if (token == TokenNameVariable) {
 
1087     } else if (token == TokenNameDOLLAR) {
 
1089       if (token == TokenNameLPAREN) {
 
1092         if (token != TokenNameLPAREN) {
 
1093           throwSyntaxError("')' expected in global variable.");
 
1102   private void static_var_list() {
 
1104     //  static_var_list ',' T_VARIABLE
 
1105     //| static_var_list ',' T_VARIABLE '=' static_scalar
 
1107     //| T_VARIABLE '=' static_scalar
 
1109       if (token == TokenNameVariable) {
 
1111         if (token == TokenNameEQUAL) {
 
1115         if (token != TokenNameCOMMA) {
 
1125   private void unset_variables() {
 
1128     //          | unset_variables ',' unset_variable
 
1133       if (token != TokenNameCOMMA) {
 
1140   private final void initializeModifiers() {
 
1142     this.modifiersSourceStart = -1;
 
1145   private final void checkAndSetModifiers(int flag) {
 
1146     this.modifiers |= flag;
 
1147     if (this.modifiersSourceStart < 0)
 
1148       this.modifiersSourceStart = this.scanner.startPosition;
 
1151   private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
 
1152     initializeModifiers();
 
1153     if (token == TokenNameinterface) {
 
1154       //      interface_entry T_STRING
 
1155       //                interface_extends_list
 
1156       //                '{' class_statement_list '}'
 
1157       checkAndSetModifiers(AccInterface);
 
1159       typeDecl.modifiers = this.modifiers;
 
1160       typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1161       typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1162       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
1163         typeDecl.name = scanner.getCurrentIdentifierSource();
 
1164         if (token > TokenNameKEYWORD) {
 
1165           problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
 
1166               scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
 
1167           //          throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
 
1168           //              typeDecl.sourceStart, typeDecl.sourceEnd);
 
1171         interface_extends_list();
 
1173         typeDecl.name = new char[] { ' ' };
 
1174         throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
 
1178       //      class_entry_type T_STRING extends_from
 
1180       //                '{' class_statement_list'}'
 
1182       typeDecl.modifiers = this.modifiers;
 
1183       typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1184       typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1186       //identifier 'extends' identifier
 
1187       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
1188         typeDecl.name = scanner.getCurrentIdentifierSource();
 
1189         if (token > TokenNameKEYWORD) {
 
1190           problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
 
1191               scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
 
1192           //          throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
 
1193           //              typeDecl.sourceStart, typeDecl.sourceEnd);
 
1198         //      | T_EXTENDS fully_qualified_class_name
 
1199         if (token == TokenNameextends) {
 
1200           interface_extends_list();
 
1202           //          if (token != TokenNameIdentifier) {
 
1203           //            throwSyntaxError("Class name expected after keyword
 
1205           //                scanner.getCurrentTokenStartPosition(), scanner
 
1206           //                    .getCurrentTokenEndPosition());
 
1211         typeDecl.name = new char[] { ' ' };
 
1212         throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
 
1216     //  '{' class_statement_list '}'
 
1217     if (token == TokenNameLBRACE) {
 
1219       if (token != TokenNameRBRACE) {
 
1220         ArrayList list = new ArrayList();
 
1221         class_statement_list(list);
 
1222         typeDecl.fields = new FieldDeclaration[list.size()];
 
1223         for (int i = 0; i < list.size(); i++) {
 
1224           typeDecl.fields[i] = (FieldDeclaration) list.get(i);
 
1227       if (token == TokenNameRBRACE) {
 
1228         typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1231         throwSyntaxError("'}' expected at end of class body.");
 
1234       throwSyntaxError("'{' expected at start of class body.");
 
1238   private void class_entry_type() {
 
1240     //  | T_ABSTRACT T_CLASS
 
1241     //  | T_FINAL T_CLASS
 
1242     if (token == TokenNameclass) {
 
1244     } else if (token == TokenNameabstract) {
 
1245       checkAndSetModifiers(AccAbstract);
 
1247       if (token != TokenNameclass) {
 
1248         throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
 
1251     } else if (token == TokenNamefinal) {
 
1252       checkAndSetModifiers(AccFinal);
 
1254       if (token != TokenNameclass) {
 
1255         throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
 
1259       throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
 
1263   private void interface_extends_list() {
 
1265     //  | T_EXTENDS interface_list
 
1266     if (token == TokenNameextends) {
 
1272   private void implements_list() {
 
1274     //  | T_IMPLEMENTS interface_list
 
1275     if (token == TokenNameimplements) {
 
1281   private void interface_list() {
 
1283     //  fully_qualified_class_name
 
1284     //| interface_list ',' fully_qualified_class_name
 
1286       if (token == TokenNameIdentifier) {
 
1289         throwSyntaxError("Interface name expected after keyword 'implements'.");
 
1291       if (token != TokenNameCOMMA) {
 
1298   //  private void classBody(TypeDeclaration typeDecl) {
 
1299   //    //'{' [class-element-list] '}'
 
1300   //    if (token == TokenNameLBRACE) {
 
1302   //      if (token != TokenNameRBRACE) {
 
1303   //        class_statement_list();
 
1305   //      if (token == TokenNameRBRACE) {
 
1306   //        typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1309   //        throwSyntaxError("'}' expected at end of class body.");
 
1312   //      throwSyntaxError("'{' expected at start of class body.");
 
1315   private void class_statement_list(ArrayList list) {
 
1317       class_statement(list);
 
1318     } while (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
 
1319         || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
 
1320         || token == TokenNameconst);
 
1323   private void class_statement(ArrayList list) {
 
1325     //          variable_modifiers class_variable_declaration ';'
 
1326     //  | class_constant_declaration ';'
 
1327     //  | method_modifiers T_FUNCTION is_reference T_STRING
 
1328     //    '(' parameter_list ')' method_body
 
1329     initializeModifiers();
 
1330     int declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
1332     if (token == TokenNamevar) {
 
1333       checkAndSetModifiers(AccPublic);
 
1334       problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
 
1335           referenceContext, compilationUnit.compilationResult);
 
1337       class_variable_declaration(declarationSourceStart, list);
 
1338     } else if (token == TokenNameconst) {
 
1339       checkAndSetModifiers(AccFinal | AccPublic);
 
1340       class_constant_declaration(declarationSourceStart, list);
 
1341       if (token != TokenNameSEMICOLON) {
 
1342         throwSyntaxError("';' expected after class const declaration.");
 
1346       boolean hasModifiers = member_modifiers();
 
1347       if (token == TokenNamefunction) {
 
1348         if (!hasModifiers) {
 
1349           checkAndSetModifiers(AccPublic);
 
1351         MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
 
1352         methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
 
1353         methodDecl.modifiers = this.modifiers;
 
1355         functionDefinition(methodDecl);
 
1357         if (!hasModifiers) {
 
1358           throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
 
1360         class_variable_declaration(declarationSourceStart, list);
 
1365   private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
 
1366     //  class_constant_declaration ',' T_STRING '=' static_scalar
 
1367     //  | T_CONST T_STRING '=' static_scalar
 
1368     if (token != TokenNameconst) {
 
1369       throwSyntaxError("'const' keyword expected in class declaration.");
 
1374       if (token != TokenNameIdentifier) {
 
1375         throwSyntaxError("Identifier expected in class const declaration.");
 
1377       FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
 
1378           .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
 
1379       fieldDeclaration.modifiers = this.modifiers;
 
1380       fieldDeclaration.declarationSourceStart = declarationSourceStart;
 
1381       fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1382       fieldDeclaration.modifiersSourceStart = declarationSourceStart;
 
1383       //        fieldDeclaration.type
 
1384       list.add(fieldDeclaration);
 
1386       if (token != TokenNameEQUAL) {
 
1387         throwSyntaxError("'=' expected in class const declaration.");
 
1391       if (token != TokenNameCOMMA) {
 
1392         break; // while(true)-loop
 
1398   //  private void variable_modifiers() {
 
1399   //    // variable_modifiers:
 
1400   //    // non_empty_member_modifiers
 
1402   //    initializeModifiers();
 
1403   //    if (token == TokenNamevar) {
 
1404   //      checkAndSetModifiers(AccPublic);
 
1405   //      reportSyntaxError(
 
1406   //          "Keyword 'var' is deprecated. Please use 'public' 'private' or
 
1408   // modifier for field declarations.",
 
1409   //          scanner.getCurrentTokenStartPosition(), scanner
 
1410   //              .getCurrentTokenEndPosition());
 
1413   //      if (!member_modifiers()) {
 
1414   //        throwSyntaxError("'public' 'private' or 'protected' modifier expected for
 
1415   // field declarations.");
 
1419   //  private void method_modifiers() {
 
1420   //    //method_modifiers:
 
1422   //    //| non_empty_member_modifiers
 
1423   //    initializeModifiers();
 
1424   //    if (!member_modifiers()) {
 
1425   //      checkAndSetModifiers(AccPublic);
 
1428   private boolean member_modifiers() {
 
1435     boolean foundToken = false;
 
1437       if (token == TokenNamepublic) {
 
1438         checkAndSetModifiers(AccPublic);
 
1441       } else if (token == TokenNameprotected) {
 
1442         checkAndSetModifiers(AccProtected);
 
1445       } else if (token == TokenNameprivate) {
 
1446         checkAndSetModifiers(AccPrivate);
 
1449       } else if (token == TokenNamestatic) {
 
1450         checkAndSetModifiers(AccStatic);
 
1453       } else if (token == TokenNameabstract) {
 
1454         checkAndSetModifiers(AccAbstract);
 
1457       } else if (token == TokenNamefinal) {
 
1458         checkAndSetModifiers(AccFinal);
 
1468   private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
 
1469     //    class_variable_declaration:
 
1470     //          class_variable_declaration ',' T_VARIABLE
 
1471     //  | class_variable_declaration ',' T_VARIABLE '=' static_scalar
 
1473     //  | T_VARIABLE '=' static_scalar
 
1474     char[] classVariable;
 
1476       if (token == TokenNameVariable) {
 
1477         classVariable = scanner.getCurrentIdentifierSource();
 
1478         //  indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
 
1479         FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
 
1480             .getCurrentTokenEndPosition());
 
1481         fieldDeclaration.modifiers = this.modifiers;
 
1482         fieldDeclaration.declarationSourceStart = declarationSourceStart;
 
1483         fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
 
1484         fieldDeclaration.modifiersSourceStart = declarationSourceStart;
 
1485         //        fieldDeclaration.type
 
1486         list.add(fieldDeclaration);
 
1488         if (token == TokenNameEQUAL) {
 
1493         //        if (token == TokenNamethis) {
 
1494         //          throwSyntaxError("'$this' not allowed after keyword 'public'
 
1495         // 'protected' 'private' 'var'.");
 
1497         throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
 
1499       if (token != TokenNameCOMMA) {
 
1504     if (token != TokenNameSEMICOLON) {
 
1505       throwSyntaxError("';' expected after field declaration.");
 
1510   private void functionDefinition(MethodDeclaration methodDecl) {
 
1511     boolean isAbstract = false;
 
1513       compilationUnit.types.add(methodDecl);
 
1515       ASTNode node = astStack[astPtr];
 
1516       if (node instanceof TypeDeclaration) {
 
1517         TypeDeclaration typeDecl = ((TypeDeclaration) node);
 
1518         if (typeDecl.methods == null) {
 
1519           typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
 
1521           AbstractMethodDeclaration[] newMethods;
 
1522           System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 1,
 
1523               typeDecl.methods.length);
 
1524           newMethods[0] = methodDecl;
 
1525           typeDecl.methods = newMethods;
 
1527         if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
 
1529         } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
 
1534     functionDeclarator(methodDecl);
 
1535     if (token == TokenNameSEMICOLON) {
 
1537         throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
 
1542     functionBody(methodDecl);
 
1545   private void functionDeclarator(MethodDeclaration methodDecl) {
 
1546     //identifier '(' [parameter-list] ')'
 
1547     if (token == TokenNameAND) {
 
1550     methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
 
1551     methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
 
1552     if (Scanner.isIdentifierOrKeyword(token)) {
 
1553       methodDecl.selector = scanner.getCurrentIdentifierSource();
 
1554       if (token > TokenNameKEYWORD) {
 
1555         problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
 
1556             scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
 
1557         //        reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
 
1558         //          scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
 
1561       if (token == TokenNameLPAREN) {
 
1564         throwSyntaxError("'(' expected in function declaration.");
 
1566       if (token != TokenNameRPAREN) {
 
1569       if (token != TokenNameRPAREN) {
 
1570         throwSyntaxError("')' expected in function declaration.");
 
1572         methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
 
1576       methodDecl.selector = "<undefined>".toCharArray();
 
1577       throwSyntaxError("Function name expected after keyword 'function'.");
 
1582   private void parameter_list() {
 
1583     //  non_empty_parameter_list
 
1585     non_empty_parameter_list(true);
 
1588   private void non_empty_parameter_list(boolean empty_allowed) {
 
1589     //  optional_class_type T_VARIABLE
 
1590     //  | optional_class_type '&' T_VARIABLE
 
1591     //  | optional_class_type '&' T_VARIABLE '=' static_scalar
 
1592     //  | optional_class_type T_VARIABLE '=' static_scalar
 
1593     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE
 
1594     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
 
1595     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
 
1597     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
 
1599     if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
 
1601         if (token == TokenNameIdentifier) {
 
1604         if (token == TokenNameAND) {
 
1607         if (token == TokenNameVariable) {
 
1609           if (token == TokenNameEQUAL) {
 
1614           throwSyntaxError("Variable expected in parameter list.");
 
1616         if (token != TokenNameCOMMA) {
 
1623     if (!empty_allowed) {
 
1624       throwSyntaxError("Identifier expected in parameter list.");
 
1628   private void optional_class_type() {
 
1633   private void parameterDeclaration() {
 
1635     //variable-reference
 
1636     if (token == TokenNameAND) {
 
1641         throwSyntaxError("Variable expected after reference operator '&'.");
 
1644     //variable '=' constant
 
1645     if (token == TokenNameVariable) {
 
1647       if (token == TokenNameEQUAL) {
 
1653     //    if (token == TokenNamethis) {
 
1654     //      throwSyntaxError("Reserved word '$this' not allowed in parameter
 
1659   private void labeledStatementList() {
 
1660     if (token != TokenNamecase && token != TokenNamedefault) {
 
1661       throwSyntaxError("'case' or 'default' expected.");
 
1664       if (token == TokenNamecase) {
 
1666         expr(); //constant();
 
1667         if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
 
1669           if (token == TokenNamecase || token == TokenNamedefault) {
 
1670             // empty case statement ?
 
1675         //        else if (token == TokenNameSEMICOLON) {
 
1677         //            "':' expected after 'case' keyword (Found token: " +
 
1678         // scanner.toStringAction(token) + ")",
 
1679         //            scanner.getCurrentTokenStartPosition(),
 
1680         //            scanner.getCurrentTokenEndPosition(),
 
1683         //          if (token == TokenNamecase) { // empty case statement ?
 
1689           throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
 
1691       } else { // TokenNamedefault
 
1693         if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
 
1695           if (token == TokenNameRBRACE) {
 
1696             // empty default case
 
1699           if (token != TokenNamecase) {
 
1703           throwSyntaxError("':' character expected after 'default'.");
 
1706     } while (token == TokenNamecase || token == TokenNamedefault);
 
1709   //  public void labeledStatement() {
 
1710   //    if (token == TokenNamecase) {
 
1713   //      if (token == TokenNameDDOT) {
 
1717   //        throwSyntaxError("':' character after 'case' constant expected.");
 
1720   //    } else if (token == TokenNamedefault) {
 
1722   //      if (token == TokenNameDDOT) {
 
1726   //        throwSyntaxError("':' character after 'default' expected.");
 
1731   //  public void expressionStatement() {
 
1733   //  private void inclusionStatement() {
 
1735   //  public void compoundStatement() {
 
1737   //  public void selectionStatement() {
 
1740   //  public void iterationStatement() {
 
1743   //  public void jumpStatement() {
 
1746   //  public void outputStatement() {
 
1749   //  public void scopeStatement() {
 
1752   //  public void flowStatement() {
 
1755   //  public void definitionStatement() {
 
1757   private void ifStatement() {
 
1758     // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
 
1759     if (token == TokenNameCOLON) {
 
1761       if (token != TokenNameendif) {
 
1766           if (token == TokenNameCOLON) {
 
1768             if (token != TokenNameendif) {
 
1772             if (token == TokenNameif) { //'else if'
 
1774               elseifStatementList();
 
1776               throwSyntaxError("':' expected after 'else'.");
 
1780         case TokenNameelseif:
 
1782           elseifStatementList();
 
1786       if (token != TokenNameendif) {
 
1787         throwSyntaxError("'endif' expected.");
 
1790       if (token != TokenNameSEMICOLON) {
 
1791         throwSyntaxError("';' expected after if-statement.");
 
1795       // statement [else-statement]
 
1796       statement(TokenNameEOF);
 
1797       if (token == TokenNameelseif) {
 
1799         if (token == TokenNameLPAREN) {
 
1802           throwSyntaxError("'(' expected after 'elseif' keyword.");
 
1805         if (token == TokenNameRPAREN) {
 
1808           throwSyntaxError("')' expected after 'elseif' condition.");
 
1811       } else if (token == TokenNameelse) {
 
1813         statement(TokenNameEOF);
 
1818   private void elseifStatementList() {
 
1824         if (token == TokenNameCOLON) {
 
1826           if (token != TokenNameendif) {
 
1831           if (token == TokenNameif) { //'else if'
 
1834             throwSyntaxError("':' expected after 'else'.");
 
1838       case TokenNameelseif:
 
1847   private void elseifStatement() {
 
1848     if (token == TokenNameLPAREN) {
 
1851       if (token != TokenNameRPAREN) {
 
1852         throwSyntaxError("')' expected in else-if-statement.");
 
1855       if (token != TokenNameCOLON) {
 
1856         throwSyntaxError("':' expected in else-if-statement.");
 
1859       if (token != TokenNameendif) {
 
1865   private void switchStatement() {
 
1866     if (token == TokenNameCOLON) {
 
1867       // ':' [labeled-statement-list] 'endswitch' ';'
 
1869       labeledStatementList();
 
1870       if (token != TokenNameendswitch) {
 
1871         throwSyntaxError("'endswitch' expected.");
 
1874       if (token != TokenNameSEMICOLON) {
 
1875         throwSyntaxError("';' expected after switch-statement.");
 
1879       // '{' [labeled-statement-list] '}'
 
1880       if (token != TokenNameLBRACE) {
 
1881         throwSyntaxError("'{' expected in switch statement.");
 
1884       if (token != TokenNameRBRACE) {
 
1885         labeledStatementList();
 
1887       if (token != TokenNameRBRACE) {
 
1888         throwSyntaxError("'}' expected in switch statement.");
 
1894   private void forStatement() {
 
1895     if (token == TokenNameCOLON) {
 
1898       if (token != TokenNameendfor) {
 
1899         throwSyntaxError("'endfor' expected.");
 
1902       if (token != TokenNameSEMICOLON) {
 
1903         throwSyntaxError("';' expected after for-statement.");
 
1907       statement(TokenNameEOF);
 
1911   private void whileStatement() {
 
1912     // ':' statement-list 'endwhile' ';'
 
1913     if (token == TokenNameCOLON) {
 
1916       if (token != TokenNameendwhile) {
 
1917         throwSyntaxError("'endwhile' expected.");
 
1920       if (token != TokenNameSEMICOLON) {
 
1921         throwSyntaxError("';' expected after while-statement.");
 
1925       statement(TokenNameEOF);
 
1929   private void foreachStatement() {
 
1930     if (token == TokenNameCOLON) {
 
1933       if (token != TokenNameendforeach) {
 
1934         throwSyntaxError("'endforeach' expected.");
 
1937       if (token != TokenNameSEMICOLON) {
 
1938         throwSyntaxError("';' expected after foreach-statement.");
 
1942       statement(TokenNameEOF);
 
1946   //  private void exitStatus() {
 
1947   //    if (token == TokenNameLPAREN) {
 
1950   //      throwSyntaxError("'(' expected in 'exit-status'.");
 
1952   //    if (token != TokenNameRPAREN) {
 
1955   //    if (token == TokenNameRPAREN) {
 
1958   //      throwSyntaxError("')' expected after 'exit-status'.");
 
1961   private void expressionList() {
 
1964       if (token == TokenNameCOMMA) {
 
1972   private Expression expr() {
 
1974     //  | expr_without_variable
 
1975     //    if (token!=TokenNameEOF) {
 
1976     if (Scanner.TRACE) {
 
1977       System.out.println("TRACE: expr()");
 
1979     return expr_without_variable(true);
 
1983   private Expression expr_without_variable(boolean only_variable) {
 
1984     int exprSourceStart = scanner.getCurrentTokenStartPosition();
 
1985     int exprSourceEnd = scanner.getCurrentTokenEndPosition();
 
1986     Expression expression = new Expression();
 
1987     expression.sourceStart = exprSourceStart;
 
1988     // default, may be overwritten
 
1989     expression.sourceEnd = exprSourceEnd;
 
1990     //          internal_functions_in_yacc
 
1999     //  | T_INC rw_variable
 
2000     //  | T_DEC rw_variable
 
2001     //  | T_INT_CAST expr
 
2002     //  | T_DOUBLE_CAST expr
 
2003     //  | T_STRING_CAST expr
 
2004     //  | T_ARRAY_CAST expr
 
2005     //  | T_OBJECT_CAST expr
 
2006     //  | T_BOOL_CAST expr
 
2007     //  | T_UNSET_CAST expr
 
2008     //  | T_EXIT exit_expr
 
2010     //  | T_ARRAY '(' array_pair_list ')'
 
2011     //  | '`' encaps_list '`'
 
2012     //  | T_LIST '(' assignment_list ')' '=' expr
 
2013     //  | T_NEW class_name_reference ctor_arguments
 
2014     //  | variable '=' expr
 
2015     //  | variable '=' '&' variable
 
2016     //  | variable '=' '&' T_NEW class_name_reference ctor_arguments
 
2017     //  | variable T_PLUS_EQUAL expr
 
2018     //  | variable T_MINUS_EQUAL expr
 
2019     //  | variable T_MUL_EQUAL expr
 
2020     //  | variable T_DIV_EQUAL expr
 
2021     //  | variable T_CONCAT_EQUAL expr
 
2022     //  | variable T_MOD_EQUAL expr
 
2023     //  | variable T_AND_EQUAL expr
 
2024     //  | variable T_OR_EQUAL expr
 
2025     //  | variable T_XOR_EQUAL expr
 
2026     //  | variable T_SL_EQUAL expr
 
2027     //  | variable T_SR_EQUAL expr
 
2028     //  | rw_variable T_INC
 
2029     //  | rw_variable T_DEC
 
2030     //  | expr T_BOOLEAN_OR expr
 
2031     //  | expr T_BOOLEAN_AND expr
 
2032     //  | expr T_LOGICAL_OR expr
 
2033     //  | expr T_LOGICAL_AND expr
 
2034     //  | expr T_LOGICAL_XOR expr
 
2046     //  | expr T_IS_IDENTICAL expr
 
2047     //  | expr T_IS_NOT_IDENTICAL expr
 
2048     //  | expr T_IS_EQUAL expr
 
2049     //  | expr T_IS_NOT_EQUAL expr
 
2051     //  | expr T_IS_SMALLER_OR_EQUAL expr
 
2053     //  | expr T_IS_GREATER_OR_EQUAL expr
 
2054     //  | expr T_INSTANCEOF class_name_reference
 
2055     //  | expr '?' expr ':' expr
 
2056     if (Scanner.TRACE) {
 
2057       System.out.println("TRACE: expr_without_variable() PART 1");
 
2060     case TokenNameisset:
 
2061     case TokenNameempty:
 
2063     case TokenNameinclude:
 
2064     case TokenNameinclude_once:
 
2065     case TokenNamerequire:
 
2066     case TokenNamerequire_once:
 
2067       internal_functions_in_yacc();
 
2070     case TokenNameLPAREN:
 
2073       if (token == TokenNameRPAREN) {
 
2076         throwSyntaxError("')' expected in expression.");
 
2086     //    | T_INT_CAST expr
 
2087     //  | T_DOUBLE_CAST expr
 
2088     //  | T_STRING_CAST expr
 
2089     //  | T_ARRAY_CAST expr
 
2090     //  | T_OBJECT_CAST expr
 
2091     //  | T_BOOL_CAST expr
 
2092     //  | T_UNSET_CAST expr
 
2093     case TokenNameclone:
 
2094     case TokenNameprint:
 
2097     case TokenNameMINUS:
 
2099     case TokenNameTWIDDLE:
 
2100     case TokenNameintCAST:
 
2101     case TokenNamedoubleCAST:
 
2102     case TokenNamestringCAST:
 
2103     case TokenNamearrayCAST:
 
2104     case TokenNameobjectCAST:
 
2105     case TokenNameboolCAST:
 
2106     case TokenNameunsetCAST:
 
2116     //| T_STRING_VARNAME
 
2118     //| T_START_HEREDOC encaps_list T_END_HEREDOC
 
2119     //          | '`' encaps_list '`'
 
2121     //  | '`' encaps_list '`'
 
2122     case TokenNameEncapsedString0:
 
2123       scanner.encapsedStringStack.push(new Character('`'));
 
2126         if (token == TokenNameEncapsedString0) {
 
2129           if (token != TokenNameEncapsedString0) {
 
2130             throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2134         scanner.encapsedStringStack.pop();
 
2138     //      | '\'' encaps_list '\''
 
2139     case TokenNameEncapsedString1:
 
2140       scanner.encapsedStringStack.push(new Character('\''));
 
2143         exprSourceStart = scanner.getCurrentTokenStartPosition();
 
2144         if (token == TokenNameEncapsedString1) {
 
2145           expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
 
2146               .getCurrentTokenEndPosition());
 
2149           if (token != TokenNameEncapsedString1) {
 
2150             throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2152             expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
 
2153                 .getCurrentTokenEndPosition());
 
2157         scanner.encapsedStringStack.pop();
 
2161     //| '"' encaps_list '"'
 
2162     case TokenNameEncapsedString2:
 
2163       scanner.encapsedStringStack.push(new Character('"'));
 
2166         exprSourceStart = scanner.getCurrentTokenStartPosition();
 
2167         if (token == TokenNameEncapsedString2) {
 
2168           expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
 
2169               .getCurrentTokenEndPosition());
 
2172           if (token != TokenNameEncapsedString2) {
 
2173             throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
 
2175             expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
 
2176                 .getCurrentTokenEndPosition());
 
2180         scanner.encapsedStringStack.pop();
 
2184     case TokenNameStringDoubleQuote:
 
2185       expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
 
2186           .getCurrentTokenEndPosition());
 
2189     case TokenNameStringSingleQuote:
 
2190       expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
 
2191           .getCurrentTokenEndPosition());
 
2194     case TokenNameIntegerLiteral:
 
2195     case TokenNameDoubleLiteral:
 
2196     case TokenNameStringInterpolated:
 
2199     case TokenNameCLASS_C:
 
2200     case TokenNameMETHOD_C:
 
2201     case TokenNameFUNC_C:
 
2204     case TokenNameHEREDOC:
 
2207     case TokenNamearray:
 
2208       //    T_ARRAY '(' array_pair_list ')'
 
2210       if (token == TokenNameLPAREN) {
 
2212         if (token == TokenNameRPAREN) {
 
2217         if (token != TokenNameRPAREN) {
 
2218           throwSyntaxError("')' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
 
2222         throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
 
2226       //    | T_LIST '(' assignment_list ')' '=' expr
 
2228       if (token == TokenNameLPAREN) {
 
2231         if (token != TokenNameRPAREN) {
 
2232           throwSyntaxError("')' expected after 'list' keyword.");
 
2235         if (token != TokenNameEQUAL) {
 
2236           throwSyntaxError("'=' expected after 'list' keyword.");
 
2241         throwSyntaxError("'(' expected after 'list' keyword.");
 
2245       //        | T_NEW class_name_reference ctor_arguments
 
2247       class_name_reference();
 
2250     //          | T_INC rw_variable
 
2251     //          | T_DEC rw_variable
 
2252     case TokenNamePLUS_PLUS:
 
2253     case TokenNameMINUS_MINUS:
 
2257     //  | variable '=' expr
 
2258     //  | variable '=' '&' variable
 
2259     //  | variable '=' '&' T_NEW class_name_reference ctor_arguments
 
2260     //  | variable T_PLUS_EQUAL expr
 
2261     //  | variable T_MINUS_EQUAL expr
 
2262     //  | variable T_MUL_EQUAL expr
 
2263     //  | variable T_DIV_EQUAL expr
 
2264     //  | variable T_CONCAT_EQUAL expr
 
2265     //  | variable T_MOD_EQUAL expr
 
2266     //  | variable T_AND_EQUAL expr
 
2267     //  | variable T_OR_EQUAL expr
 
2268     //  | variable T_XOR_EQUAL expr
 
2269     //  | variable T_SL_EQUAL expr
 
2270     //  | variable T_SR_EQUAL expr
 
2271     //  | rw_variable T_INC
 
2272     //  | rw_variable T_DEC
 
2273     case TokenNameIdentifier:
 
2274     case TokenNameVariable:
 
2275     case TokenNameDOLLAR:
 
2278       case TokenNameEQUAL:
 
2280         if (token == TokenNameAND) {
 
2282           if (token == TokenNamenew) {
 
2283             // | variable '=' '&' T_NEW class_name_reference
 
2286             class_name_reference();
 
2295       case TokenNamePLUS_EQUAL:
 
2296       case TokenNameMINUS_EQUAL:
 
2297       case TokenNameMULTIPLY_EQUAL:
 
2298       case TokenNameDIVIDE_EQUAL:
 
2299       case TokenNameDOT_EQUAL:
 
2300       case TokenNameREMAINDER_EQUAL:
 
2301       case TokenNameAND_EQUAL:
 
2302       case TokenNameOR_EQUAL:
 
2303       case TokenNameXOR_EQUAL:
 
2304       case TokenNameRIGHT_SHIFT_EQUAL:
 
2305       case TokenNameLEFT_SHIFT_EQUAL:
 
2309       case TokenNamePLUS_PLUS:
 
2310       case TokenNameMINUS_MINUS:
 
2314         if (!only_variable) {
 
2315           throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
 
2320       if (token != TokenNameINLINE_HTML) {
 
2321         if (token > TokenNameKEYWORD) {
 
2325           throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
 
2330     if (Scanner.TRACE) {
 
2331       System.out.println("TRACE: expr_without_variable() PART 2");
 
2333     //  | expr T_BOOLEAN_OR expr
 
2334     //  | expr T_BOOLEAN_AND expr
 
2335     //  | expr T_LOGICAL_OR expr
 
2336     //  | expr T_LOGICAL_AND expr
 
2337     //  | expr T_LOGICAL_XOR expr
 
2349     //  | expr T_IS_IDENTICAL expr
 
2350     //  | expr T_IS_NOT_IDENTICAL expr
 
2351     //  | expr T_IS_EQUAL expr
 
2352     //  | expr T_IS_NOT_EQUAL expr
 
2354     //  | expr T_IS_SMALLER_OR_EQUAL expr
 
2356     //  | expr T_IS_GREATER_OR_EQUAL expr
 
2359       case TokenNameOR_OR:
 
2361         expression = new OR_OR_Expression(expression, expr(), token);
 
2363       case TokenNameAND_AND:
 
2365         expression = new AND_AND_Expression(expression, expr(), token);
 
2367       case TokenNameEQUAL_EQUAL:
 
2369         expression = new EqualExpression(expression, expr(), token);
 
2379       case TokenNameMINUS:
 
2380       case TokenNameMULTIPLY:
 
2381       case TokenNameDIVIDE:
 
2382       case TokenNameREMAINDER:
 
2383       case TokenNameLEFT_SHIFT:
 
2384       case TokenNameRIGHT_SHIFT:
 
2385       case TokenNameEQUAL_EQUAL_EQUAL:
 
2386       case TokenNameNOT_EQUAL_EQUAL:
 
2387       case TokenNameNOT_EQUAL:
 
2389       case TokenNameLESS_EQUAL:
 
2390       case TokenNameGREATER:
 
2391       case TokenNameGREATER_EQUAL:
 
2393         expression = new BinaryExpression(expression, expr(), token);
 
2395       //  | expr T_INSTANCEOF class_name_reference
 
2396       //        | expr '?' expr ':' expr
 
2397       case TokenNameinstanceof:
 
2399         class_name_reference();
 
2400         // TODO use InstanceofExpression
 
2401         expression = new Expression();
 
2402         expression.sourceStart = exprSourceStart;
 
2403         expression.sourceEnd = scanner.getCurrentTokenEndPosition();
 
2405       case TokenNameQUESTION:
 
2407         Expression valueIfTrue = expr();
 
2408         if (token != TokenNameCOLON) {
 
2409           throwSyntaxError("':' expected in conditional expression.");
 
2412         Expression valueIfFalse = expr();
 
2414         expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
 
2422   private void class_name_reference() {
 
2423     //  class_name_reference:
 
2425     //| dynamic_class_name_reference
 
2426     if (Scanner.TRACE) {
 
2427       System.out.println("TRACE: class_name_reference()");
 
2429     if (token == TokenNameIdentifier) {
 
2432       dynamic_class_name_reference();
 
2436   private void dynamic_class_name_reference() {
 
2437     //dynamic_class_name_reference:
 
2438     //  base_variable T_OBJECT_OPERATOR object_property
 
2439     // dynamic_class_name_variable_properties
 
2441     if (Scanner.TRACE) {
 
2442       System.out.println("TRACE: dynamic_class_name_reference()");
 
2445     if (token == TokenNameMINUS_GREATER) {
 
2448       dynamic_class_name_variable_properties();
 
2452   private void dynamic_class_name_variable_properties() {
 
2453     //  dynamic_class_name_variable_properties:
 
2454     //                  dynamic_class_name_variable_properties
 
2455     // dynamic_class_name_variable_property
 
2457     if (Scanner.TRACE) {
 
2458       System.out.println("TRACE: dynamic_class_name_variable_properties()");
 
2460     while (token == TokenNameMINUS_GREATER) {
 
2461       dynamic_class_name_variable_property();
 
2465   private void dynamic_class_name_variable_property() {
 
2466     //  dynamic_class_name_variable_property:
 
2467     //  T_OBJECT_OPERATOR object_property
 
2468     if (Scanner.TRACE) {
 
2469       System.out.println("TRACE: dynamic_class_name_variable_property()");
 
2471     if (token == TokenNameMINUS_GREATER) {
 
2477   private void ctor_arguments() {
 
2480     //| '(' function_call_parameter_list ')'
 
2481     if (token == TokenNameLPAREN) {
 
2483       if (token == TokenNameRPAREN) {
 
2487       non_empty_function_call_parameter_list();
 
2488       if (token != TokenNameRPAREN) {
 
2489         throwSyntaxError("')' expected in ctor_arguments.");
 
2495   private void assignment_list() {
 
2497     //  assignment_list ',' assignment_list_element
 
2498     //| assignment_list_element
 
2500       assignment_list_element();
 
2501       if (token != TokenNameCOMMA) {
 
2508   private void assignment_list_element() {
 
2509     //assignment_list_element:
 
2511     //| T_LIST '(' assignment_list ')'
 
2513     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
 
2516       if (token == TokenNamelist) {
 
2518         if (token == TokenNameLPAREN) {
 
2521           if (token != TokenNameRPAREN) {
 
2522             throwSyntaxError("')' expected after 'list' keyword.");
 
2526           throwSyntaxError("'(' expected after 'list' keyword.");
 
2532   private void array_pair_list() {
 
2535     //| non_empty_array_pair_list possible_comma
 
2536     non_empty_array_pair_list();
 
2537     if (token == TokenNameCOMMA) {
 
2542   private void non_empty_array_pair_list() {
 
2543     //non_empty_array_pair_list:
 
2544     //  non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
 
2545     //| non_empty_array_pair_list ',' expr
 
2546     //| expr T_DOUBLE_ARROW expr
 
2548     //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
 
2549     //| non_empty_array_pair_list ',' '&' w_variable
 
2550     //| expr T_DOUBLE_ARROW '&' w_variable
 
2553       if (token == TokenNameAND) {
 
2558         if (token == TokenNameAND) {
 
2561         } else if (token == TokenNameEQUAL_GREATER) {
 
2563           if (token == TokenNameAND) {
 
2571       if (token != TokenNameCOMMA) {
 
2575       if (token == TokenNameRPAREN) {
 
2581   //  private void variableList() {
 
2584   //      if (token == TokenNameCOMMA) {
 
2591   private void variable_without_objects() {
 
2592     //  variable_without_objects:
 
2593     //                  reference_variable
 
2594     //          | simple_indirect_reference reference_variable
 
2595     if (Scanner.TRACE) {
 
2596       System.out.println("TRACE: variable_without_objects()");
 
2598     while (token == TokenNameDOLLAR) {
 
2601     reference_variable();
 
2604   private void function_call() {
 
2606     //  T_STRING '(' function_call_parameter_list ')'
 
2607     //| class_constant '(' function_call_parameter_list ')'
 
2608     //| static_member '(' function_call_parameter_list ')'
 
2609     //| variable_without_objects '(' function_call_parameter_list ')'
 
2610     char[] defineName = null;
 
2611     char[] ident = null;
 
2614     if (Scanner.TRACE) {
 
2615       System.out.println("TRACE: function_call()");
 
2617     if (token == TokenNameIdentifier) {
 
2618       ident = scanner.getCurrentIdentifierSource();
 
2620       startPos = scanner.getCurrentTokenStartPosition();
 
2621       endPos = scanner.getCurrentTokenEndPosition();
 
2624       case TokenNamePAAMAYIM_NEKUDOTAYIM:
 
2628         if (token == TokenNameIdentifier) {
 
2633           variable_without_objects();
 
2638       variable_without_objects();
 
2640     if (token != TokenNameLPAREN) {
 
2641       if (defineName != null) {
 
2642         // does this identifier contain only uppercase characters?
 
2643         if (defineName.length == 3) {
 
2644           if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
 
2647         } else if (defineName.length == 4) {
 
2648           if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
 
2650           } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
 
2653         } else if (defineName.length == 5) {
 
2654           if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
 
2658         if (defineName != null) {
 
2659           for (int i = 0; i < defineName.length; i++) {
 
2660             if (Character.isLowerCase(defineName[i])) {
 
2661               problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
 
2667       // TODO is this ok ?
 
2669       //      throwSyntaxError("'(' expected in function call.");
 
2672     if (token == TokenNameRPAREN) {
 
2676     non_empty_function_call_parameter_list();
 
2677     if (token != TokenNameRPAREN) {
 
2678       String functionName;
 
2679       if (ident == null) {
 
2680         functionName = new String(" ");
 
2682         functionName = new String(ident);
 
2684       throwSyntaxError("')' expected in function call (" + functionName + ").");
 
2689   //  private void function_call_parameter_list() {
 
2690   //    function_call_parameter_list:
 
2691   //            non_empty_function_call_parameter_list { $$ = $1; }
 
2694   private void non_empty_function_call_parameter_list() {
 
2695     //non_empty_function_call_parameter_list:
 
2696     //          expr_without_variable
 
2699     //  | non_empty_function_call_parameter_list ',' expr_without_variable
 
2700     //  | non_empty_function_call_parameter_list ',' variable
 
2701     //  | non_empty_function_call_parameter_list ',' '&' w_variable
 
2702     if (Scanner.TRACE) {
 
2703       System.out.println("TRACE: non_empty_function_call_parameter_list()");
 
2706       if (token == TokenNameAND) {
 
2710         //        if (token == TokenNameIdentifier || token ==
 
2711         // TokenNameVariable
 
2712         //            || token == TokenNameDOLLAR) {
 
2715         expr_without_variable(true);
 
2718       if (token != TokenNameCOMMA) {
 
2725   private void fully_qualified_class_name() {
 
2726     if (token == TokenNameIdentifier) {
 
2729       throwSyntaxError("Class name expected.");
 
2733   private void static_member() {
 
2735     //  fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
 
2736     // variable_without_objects
 
2737     if (Scanner.TRACE) {
 
2738       System.out.println("TRACE: static_member()");
 
2740     fully_qualified_class_name();
 
2741     if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
 
2742       throwSyntaxError("'::' expected after class name (static_member).");
 
2745     variable_without_objects();
 
2748   private void base_variable_with_function_calls() {
 
2749     //  base_variable_with_function_calls:
 
2752     boolean functionCall = false;
 
2753     if (Scanner.TRACE) {
 
2754       System.out.println("TRACE: base_variable_with_function_calls()");
 
2756     //    if (token == TokenNameIdentifier) {
 
2757     //      functionCall = true;
 
2758     //    } else if (token == TokenNameVariable) {
 
2759     //      int tempToken = token;
 
2760     //      int tempPosition = scanner.currentPosition;
 
2762     //      if (token == TokenNameLPAREN) {
 
2763     //        functionCall = true;
 
2765     //      token = tempToken;
 
2766     //      scanner.currentPosition = tempPosition;
 
2767     //      scanner.phpMode = true;
 
2769     //    if (functionCall) {
 
2776   private void base_variable() {
 
2778     //                  reference_variable
 
2779     //          | simple_indirect_reference reference_variable
 
2781     if (Scanner.TRACE) {
 
2782       System.out.println("TRACE: base_variable()");
 
2784     if (token == TokenNameIdentifier) {
 
2787       while (token == TokenNameDOLLAR) {
 
2790       reference_variable();
 
2794   //  private void simple_indirect_reference() {
 
2795   //    // simple_indirect_reference:
 
2797   //    //| simple_indirect_reference '$'
 
2799   private void reference_variable() {
 
2800     //  reference_variable:
 
2801     //                  reference_variable '[' dim_offset ']'
 
2802     //          | reference_variable '{' expr '}'
 
2803     //          | compound_variable
 
2804     if (Scanner.TRACE) {
 
2805       System.out.println("TRACE: reference_variable()");
 
2807     compound_variable();
 
2809       if (token == TokenNameLBRACE) {
 
2812         if (token != TokenNameRBRACE) {
 
2813           throwSyntaxError("'}' expected in reference variable.");
 
2816       } else if (token == TokenNameLBRACKET) {
 
2818         if (token != TokenNameRBRACKET) {
 
2821           if (token != TokenNameRBRACKET) {
 
2822             throwSyntaxError("']' expected in reference variable.");
 
2832   private void compound_variable() {
 
2833     //  compound_variable:
 
2835     //          | '$' '{' expr '}'
 
2836     if (Scanner.TRACE) {
 
2837       System.out.println("TRACE: compound_variable()");
 
2839     if (token == TokenNameVariable) {
 
2842       // because of simple_indirect_reference
 
2843       while (token == TokenNameDOLLAR) {
 
2846       if (token != TokenNameLBRACE) {
 
2847         throwSyntaxError("'{' expected after compound variable token '$'.");
 
2851       if (token != TokenNameRBRACE) {
 
2852         throwSyntaxError("'}' expected after compound variable token '$'.");
 
2858   //  private void dim_offset() {
 
2864   private void object_property() {
 
2867     //| variable_without_objects
 
2868     if (Scanner.TRACE) {
 
2869       System.out.println("TRACE: object_property()");
 
2871     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
 
2872       variable_without_objects();
 
2878   private void object_dim_list() {
 
2880     //  object_dim_list '[' dim_offset ']'
 
2881     //| object_dim_list '{' expr '}'
 
2883     if (Scanner.TRACE) {
 
2884       System.out.println("TRACE: object_dim_list()");
 
2888       if (token == TokenNameLBRACE) {
 
2891         if (token != TokenNameRBRACE) {
 
2892           throwSyntaxError("'}' expected in object_dim_list.");
 
2895       } else if (token == TokenNameLBRACKET) {
 
2897         if (token == TokenNameRBRACKET) {
 
2902         if (token != TokenNameRBRACKET) {
 
2903           throwSyntaxError("']' expected in object_dim_list.");
 
2912   private void variable_name() {
 
2916     if (Scanner.TRACE) {
 
2917       System.out.println("TRACE: variable_name()");
 
2919     if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
2920       if (token > TokenNameKEYWORD) {
 
2921         // TODO show a warning "Keyword used as variable" ?
 
2925       if (token != TokenNameLBRACE) {
 
2926         throwSyntaxError("'{' expected in variable name.");
 
2930       if (token != TokenNameRBRACE) {
 
2931         throwSyntaxError("'}' expected in variable name.");
 
2937   private void r_variable() {
 
2941   private void w_variable() {
 
2945   private void rw_variable() {
 
2949   private void variable() {
 
2951     //          base_variable_with_function_calls T_OBJECT_OPERATOR
 
2952     //                  object_property method_or_not variable_properties
 
2953     //  | base_variable_with_function_calls
 
2954     base_variable_with_function_calls();
 
2955     if (token == TokenNameMINUS_GREATER) {
 
2959       variable_properties();
 
2961     //    if (token == TokenNameDOLLAR_LBRACE) {
 
2965     //      if (token != TokenNameRBRACE) {
 
2966     //        throwSyntaxError("'}' expected after indirect variable token '${'.");
 
2970     //      if (token == TokenNameVariable) {
 
2972     //        if (token == TokenNameLBRACKET) {
 
2975     //          if (token != TokenNameRBRACKET) {
 
2976     //            throwSyntaxError("']' expected in variable-list.");
 
2979     //        } else if (token == TokenNameEQUAL) {
 
2984     //        throwSyntaxError("$-variable expected in variable-list.");
 
2989   private void variable_properties() {
 
2990     //  variable_properties:
 
2991     //                  variable_properties variable_property
 
2993     while (token == TokenNameMINUS_GREATER) {
 
2994       variable_property();
 
2998   private void variable_property() {
 
2999     //  variable_property:
 
3000     //                  T_OBJECT_OPERATOR object_property method_or_not
 
3001     if (Scanner.TRACE) {
 
3002       System.out.println("TRACE: variable_property()");
 
3004     if (token == TokenNameMINUS_GREATER) {
 
3009       throwSyntaxError("'->' expected in variable_property.");
 
3013   private void method_or_not() {
 
3015     //                  '(' function_call_parameter_list ')'
 
3017     if (Scanner.TRACE) {
 
3018       System.out.println("TRACE: method_or_not()");
 
3020     if (token == TokenNameLPAREN) {
 
3022       if (token == TokenNameRPAREN) {
 
3026       non_empty_function_call_parameter_list();
 
3027       if (token != TokenNameRPAREN) {
 
3028         throwSyntaxError("')' expected in method_or_not.");
 
3034   private void exit_expr() {
 
3038     if (token != TokenNameLPAREN) {
 
3042     if (token == TokenNameRPAREN) {
 
3047     if (token != TokenNameRPAREN) {
 
3048       throwSyntaxError("')' expected after keyword 'exit'");
 
3053   private void encaps_list() {
 
3054     //                  encaps_list encaps_var
 
3055     //          | encaps_list T_STRING
 
3056     //          | encaps_list T_NUM_STRING
 
3057     //          | encaps_list T_ENCAPSED_AND_WHITESPACE
 
3058     //          | encaps_list T_CHARACTER
 
3059     //          | encaps_list T_BAD_CHARACTER
 
3060     //          | encaps_list '['
 
3061     //          | encaps_list ']'
 
3062     //          | encaps_list '{'
 
3063     //          | encaps_list '}'
 
3064     //          | encaps_list T_OBJECT_OPERATOR
 
3068       case TokenNameSTRING:
 
3071       case TokenNameLBRACE:
 
3072         //          scanner.encapsedStringStack.pop();
 
3075       case TokenNameRBRACE:
 
3076         //          scanner.encapsedStringStack.pop();
 
3079       case TokenNameLBRACKET:
 
3080         //          scanner.encapsedStringStack.pop();
 
3083       case TokenNameRBRACKET:
 
3084         //          scanner.encapsedStringStack.pop();
 
3087       case TokenNameMINUS_GREATER:
 
3088         //          scanner.encapsedStringStack.pop();
 
3091       case TokenNameVariable:
 
3092       case TokenNameDOLLAR_LBRACE:
 
3093       case TokenNameLBRACE_DOLLAR:
 
3097         char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
 
3098         if (encapsedChar == '$') {
 
3099           scanner.encapsedStringStack.pop();
 
3100           encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
 
3101           switch (encapsedChar) {
 
3103             if (token == TokenNameEncapsedString0) {
 
3106             token = TokenNameSTRING;
 
3109             if (token == TokenNameEncapsedString1) {
 
3112             token = TokenNameSTRING;
 
3115             if (token == TokenNameEncapsedString2) {
 
3118             token = TokenNameSTRING;
 
3127   private void encaps_var() {
 
3129     //          | T_VARIABLE '[' encaps_var_offset ']'
 
3130     //          | T_VARIABLE T_OBJECT_OPERATOR T_STRING
 
3131     //          | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
 
3132     //          | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
 
3133     //          | T_CURLY_OPEN variable '}'
 
3135     case TokenNameVariable:
 
3137       if (token == TokenNameLBRACKET) {
 
3139         expr(); //encaps_var_offset();
 
3140         if (token != TokenNameRBRACKET) {
 
3141           throwSyntaxError("']' expected after variable.");
 
3143         //          scanner.encapsedStringStack.pop();
 
3146       } else if (token == TokenNameMINUS_GREATER) {
 
3148         if (token != TokenNameIdentifier) {
 
3149           throwSyntaxError("Identifier expected after '->'.");
 
3151         //          scanner.encapsedStringStack.pop();
 
3155       //          // scanner.encapsedStringStack.pop();
 
3156       //          int tempToken = TokenNameSTRING;
 
3157       //          if (!scanner.encapsedStringStack.isEmpty()
 
3158       //              && (token == TokenNameEncapsedString0
 
3159       //                  || token == TokenNameEncapsedString1
 
3160       //                  || token == TokenNameEncapsedString2 || token ==
 
3161       // TokenNameERROR)) {
 
3162       //            char encapsedChar = ((Character)
 
3163       // scanner.encapsedStringStack.peek())
 
3166       //              case TokenNameEncapsedString0 :
 
3167       //                if (encapsedChar == '`') {
 
3168       //                  tempToken = TokenNameEncapsedString0;
 
3171       //              case TokenNameEncapsedString1 :
 
3172       //                if (encapsedChar == '\'') {
 
3173       //                  tempToken = TokenNameEncapsedString1;
 
3176       //              case TokenNameEncapsedString2 :
 
3177       //                if (encapsedChar == '"') {
 
3178       //                  tempToken = TokenNameEncapsedString2;
 
3181       //              case TokenNameERROR :
 
3182       //                if (scanner.source[scanner.currentPosition - 1] == '\\') {
 
3183       //                  scanner.currentPosition--;
 
3189       //          token = tempToken;
 
3192     case TokenNameDOLLAR_LBRACE:
 
3194       if (token == TokenNameDOLLAR_LBRACE) {
 
3196       } else if (token == TokenNameIdentifier) {
 
3198         if (token == TokenNameLBRACKET) {
 
3200           //            if (token == TokenNameRBRACKET) {
 
3204           if (token != TokenNameRBRACKET) {
 
3205             throwSyntaxError("']' expected after '${'.");
 
3213       if (token != TokenNameRBRACE) {
 
3214         throwSyntaxError("'}' expected.");
 
3218     case TokenNameLBRACE_DOLLAR:
 
3220       if (token == TokenNameLBRACE_DOLLAR) {
 
3222       } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
 
3224         if (token == TokenNameLBRACKET) {
 
3226           //            if (token == TokenNameRBRACKET) {
 
3230           if (token != TokenNameRBRACKET) {
 
3231             throwSyntaxError("']' expected.");
 
3235         } else if (token == TokenNameMINUS_GREATER) {
 
3237           if (token != TokenNameIdentifier && token != TokenNameVariable) {
 
3238             throwSyntaxError("String or Variable token expected.");
 
3241           if (token == TokenNameLBRACKET) {
 
3243             //            if (token == TokenNameRBRACKET) {
 
3247             if (token != TokenNameRBRACKET) {
 
3248               throwSyntaxError("']' expected after '${'.");
 
3254         //          if (token != TokenNameRBRACE) {
 
3255         //            throwSyntaxError("'}' expected after '{$'.");
 
3257         //          // scanner.encapsedStringStack.pop();
 
3261         if (token != TokenNameRBRACE) {
 
3262           throwSyntaxError("'}' expected.");
 
3264         //          scanner.encapsedStringStack.pop();
 
3271   private void encaps_var_offset() {
 
3276     case TokenNameSTRING:
 
3279     case TokenNameIntegerLiteral:
 
3282     case TokenNameVariable:
 
3285     case TokenNameIdentifier:
 
3289       throwSyntaxError("Variable or String token expected.");
 
3294   private void internal_functions_in_yacc() {
 
3296     ImportReference impt = null;
 
3298     case TokenNameisset:
 
3299       //        T_ISSET '(' isset_variables ')'
 
3301       if (token != TokenNameLPAREN) {
 
3302         throwSyntaxError("'(' expected after keyword 'isset'");
 
3306       if (token != TokenNameRPAREN) {
 
3307         throwSyntaxError("')' expected after keyword 'isset'");
 
3311     case TokenNameempty:
 
3312       //        T_EMPTY '(' variable ')'
 
3314       if (token != TokenNameLPAREN) {
 
3315         throwSyntaxError("'(' expected after keyword 'empty'");
 
3319       if (token != TokenNameRPAREN) {
 
3320         throwSyntaxError("')' expected after keyword 'empty'");
 
3324     case TokenNameinclude:
 
3326       checkFileName(token, impt);
 
3328     case TokenNameinclude_once:
 
3329       //        T_INCLUDE_ONCE expr
 
3330       checkFileName(token, impt);
 
3333       //        T_EVAL '(' expr ')'
 
3335       if (token != TokenNameLPAREN) {
 
3336         throwSyntaxError("'(' expected after keyword 'eval'");
 
3340       if (token != TokenNameRPAREN) {
 
3341         throwSyntaxError("')' expected after keyword 'eval'");
 
3345     case TokenNamerequire:
 
3347       checkFileName(token, impt);
 
3349     case TokenNamerequire_once:
 
3350       //        T_REQUIRE_ONCE expr
 
3351       checkFileName(token, impt);
 
3356   private void checkFileName(int includeToken, ImportReference impt) {
 
3357     //<include-token> expr
 
3358     int start = scanner.getCurrentTokenStartPosition();
 
3359     boolean hasLPAREN = false;
 
3361     if (token == TokenNameLPAREN) {
 
3365     Expression expression = expr();
 
3367       if (token == TokenNameRPAREN) {
 
3370         throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
 
3373     impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
 
3374     impt.declarationSourceEnd = impt.sourceEnd;
 
3375     impt.declarationEnd = impt.declarationSourceEnd;
 
3376     //endPosition is just before the ;
 
3377     impt.declarationSourceStart = start;
 
3378     includesList.add(impt);
 
3380     if (expression instanceof StringLiteral) {
 
3381       StringLiteral literal = (StringLiteral) expression;
 
3382       char[] includeName = literal.source();
 
3383       if (includeName.length == 0) {
 
3384         reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
 
3385             literal.sourceStart + 1);
 
3387       String includeNameString = new String(includeName);
 
3388       if (literal instanceof StringLiteralDQ) {
 
3389         if (includeNameString.indexOf('$') >= 0) {
 
3390           // assuming that the filename contains a variable => no filename check
 
3394       if (includeNameString.startsWith("http://")) {
 
3395         // assuming external include location
 
3398       if (scanner.compilationUnit != null) {
 
3399         IResource resource = scanner.compilationUnit.getResource();
 
3400         //        java.io.File f = new java.io.File(new String(compilationUnit.getFileName()));
 
3401         //        System.out.println(expression.toStringExpression());
 
3403         if (resource != null && resource instanceof IFile) {
 
3404           // check the filename:
 
3405           //      System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
 
3406           IProject project = resource.getProject();
 
3407           if (project != null) {
 
3408             IPath path = PHPFileUtil.determineFilePath(includeNameString, resource, project);
 
3411               //              reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
 
3412               //                  + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
 
3413               String[] args = { expression.toStringExpression(), project.getLocation().toString() };
 
3414               problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
 
3415                   compilationUnit.compilationResult);
 
3417               impt.setFile( PHPFileUtil.createFile(path, project) );
 
3425   private void isset_variables() {
 
3427     //  | isset_variables ','
 
3428     if (token == TokenNameRPAREN) {
 
3429       throwSyntaxError("Variable expected after keyword 'isset'");
 
3433       if (token == TokenNameCOMMA) {
 
3441   private boolean common_scalar() {
 
3445     //  | T_CONSTANT_ENCAPSED_STRING
 
3452     case TokenNameIntegerLiteral:
 
3455     case TokenNameDoubleLiteral:
 
3458     case TokenNameStringDoubleQuote:
 
3461     case TokenNameStringSingleQuote:
 
3464     case TokenNameStringInterpolated:
 
3473     case TokenNameCLASS_C:
 
3476     case TokenNameMETHOD_C:
 
3479     case TokenNameFUNC_C:
 
3486   private void scalar() {
 
3489     //| T_STRING_VARNAME
 
3492     //| '"' encaps_list '"'
 
3493     //| '\'' encaps_list '\''
 
3494     //| T_START_HEREDOC encaps_list T_END_HEREDOC
 
3495     throwSyntaxError("Not yet implemented (scalar).");
 
3498   private void static_scalar() {
 
3499     //    static_scalar: /* compile-time evaluated scalars */
 
3502     //  | '+' static_scalar
 
3503     //  | '-' static_scalar
 
3504     //  | T_ARRAY '(' static_array_pair_list ')'
 
3505     //  | static_class_constant
 
3506     if (common_scalar()) {
 
3510     case TokenNameIdentifier:
 
3512       //        static_class_constant:
 
3513       //                T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
 
3514       if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
 
3516         if (token == TokenNameIdentifier) {
 
3519           throwSyntaxError("Identifier expected after '::' operator.");
 
3523     case TokenNameEncapsedString0:
 
3525         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3526         while (scanner.currentCharacter != '`') {
 
3527           if (scanner.currentCharacter == '\\') {
 
3528             scanner.currentPosition++;
 
3530           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3533       } catch (IndexOutOfBoundsException e) {
 
3534         throwSyntaxError("'`' expected at end of static string.");
 
3537     case TokenNameEncapsedString1:
 
3539         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3540         while (scanner.currentCharacter != '\'') {
 
3541           if (scanner.currentCharacter == '\\') {
 
3542             scanner.currentPosition++;
 
3544           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3547       } catch (IndexOutOfBoundsException e) {
 
3548         throwSyntaxError("'\'' expected at end of static string.");
 
3551     case TokenNameEncapsedString2:
 
3553         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3554         while (scanner.currentCharacter != '"') {
 
3555           if (scanner.currentCharacter == '\\') {
 
3556             scanner.currentPosition++;
 
3558           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
 
3561       } catch (IndexOutOfBoundsException e) {
 
3562         throwSyntaxError("'\"' expected at end of static string.");
 
3569     case TokenNameMINUS:
 
3573     case TokenNamearray:
 
3575       if (token != TokenNameLPAREN) {
 
3576         throwSyntaxError("'(' expected after keyword 'array'");
 
3579       if (token == TokenNameRPAREN) {
 
3583       non_empty_static_array_pair_list();
 
3584       if (token != TokenNameRPAREN) {
 
3585         throwSyntaxError("')' expected after keyword 'array'");
 
3589     //      case TokenNamenull :
 
3592     //      case TokenNamefalse :
 
3595     //      case TokenNametrue :
 
3599       throwSyntaxError("Static scalar/constant expected.");
 
3603   private void non_empty_static_array_pair_list() {
 
3604     //  non_empty_static_array_pair_list:
 
3605     //  non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
 
3607     //| non_empty_static_array_pair_list ',' static_scalar
 
3608     //| static_scalar T_DOUBLE_ARROW static_scalar
 
3612       if (token == TokenNameEQUAL_GREATER) {
 
3616       if (token != TokenNameCOMMA) {
 
3620       if (token == TokenNameRPAREN) {
 
3626   public void reportSyntaxError() { //int act, int currentKind, int
 
3628     /* remember current scanner position */
 
3629     int startPos = scanner.startPosition;
 
3630     int currentPos = scanner.currentPosition;
 
3631     //          String[] expectings;
 
3632     //          String tokenName = name[symbol_index[currentKind]];
 
3633     //fetch all "accurate" possible terminals that could recover the error
 
3634     //          int start, end = start = asi(stack[stateStackTop]);
 
3635     //          while (asr[end] != 0)
 
3637     //          int length = end - start;
 
3638     //          expectings = new String[length];
 
3639     //          if (length != 0) {
 
3640     //                  char[] indexes = new char[length];
 
3641     //                  System.arraycopy(asr, start, indexes, 0, length);
 
3642     //                  for (int i = 0; i < length; i++) {
 
3643     //                          expectings[i] = name[symbol_index[indexes[i]]];
 
3646     //if the pb is an EOF, try to tell the user that they are some
 
3647     //          if (tokenName.equals(UNEXPECTED_EOF)) {
 
3648     //                  if (!this.checkAndReportBracketAnomalies(problemReporter())) {
 
3649     //                          char[] tokenSource;
 
3651     //                                  tokenSource = this.scanner.getCurrentTokenSource();
 
3652     //                          } catch (Exception e) {
 
3653     //                                  tokenSource = new char[] {};
 
3655     //                          problemReporter().parseError(
 
3656     //                                  this.scanner.startPosition,
 
3657     //                                  this.scanner.currentPosition - 1,
 
3662     //          } else { //the next test is HEAVILY grammar DEPENDENT.
 
3663     //                  if ((length == 14)
 
3664     //                          && (expectings[0] == "=") //$NON-NLS-1$
 
3665     //                          && (expectings[1] == "*=") //$NON-NLS-1$
 
3666     //                          && (expressionPtr > -1)) {
 
3667     //                                  switch(currentKind) {
 
3668     //                                          case TokenNameSEMICOLON:
 
3669     //                                          case TokenNamePLUS:
 
3670     //                                          case TokenNameMINUS:
 
3671     //                                          case TokenNameDIVIDE:
 
3672     //                                          case TokenNameREMAINDER:
 
3673     //                                          case TokenNameMULTIPLY:
 
3674     //                                          case TokenNameLEFT_SHIFT:
 
3675     //                                          case TokenNameRIGHT_SHIFT:
 
3676     //// case TokenNameUNSIGNED_RIGHT_SHIFT:
 
3677     //                                          case TokenNameLESS:
 
3678     //                                          case TokenNameGREATER:
 
3679     //                                          case TokenNameLESS_EQUAL:
 
3680     //                                          case TokenNameGREATER_EQUAL:
 
3681     //                                          case TokenNameEQUAL_EQUAL:
 
3682     //                                          case TokenNameNOT_EQUAL:
 
3683     //                                          case TokenNameXOR:
 
3684     //                                          case TokenNameAND:
 
3685     //                                          case TokenNameOR:
 
3686     //                                          case TokenNameOR_OR:
 
3687     //                                          case TokenNameAND_AND:
 
3688     //                                                  // the ; is not the expected token ==> it ends a statement when an
 
3689     // expression is not ended
 
3690     //                                                  problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
 
3692     //                                          case TokenNameRBRACE :
 
3693     //                                                  problemReporter().missingSemiColon(expressionStack[expressionPtr]);
 
3696     //                                                  char[] tokenSource;
 
3698     //                                                          tokenSource = this.scanner.getCurrentTokenSource();
 
3699     //                                                  } catch (Exception e) {
 
3700     //                                                          tokenSource = new char[] {};
 
3702     //                                                  problemReporter().parseError(
 
3703     //                                                          this.scanner.startPosition,
 
3704     //                                                          this.scanner.currentPosition - 1,
 
3708     //                                                  this.checkAndReportBracketAnomalies(problemReporter());
 
3713       tokenSource = this.scanner.getCurrentTokenSource();
 
3714     } catch (Exception e) {
 
3715       tokenSource = new char[] {};
 
3717     //                          problemReporter().parseError(
 
3718     //                                  this.scanner.startPosition,
 
3719     //                                  this.scanner.currentPosition - 1,
 
3723     this.checkAndReportBracketAnomalies(problemReporter());
 
3726     /* reset scanner where it was */
 
3727     scanner.startPosition = startPos;
 
3728     scanner.currentPosition = currentPos;
 
3731   public static final int RoundBracket = 0;
 
3733   public static final int SquareBracket = 1;
 
3735   public static final int CurlyBracket = 2;
 
3737   public static final int BracketKinds = 3;
 
3739   protected int[] nestedMethod; //the ptr is nestedType
 
3741   protected int nestedType, dimensions;
 
3744   final static int AstStackIncrement = 100;
 
3746   protected int astPtr;
 
3748   protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
 
3750   protected int astLengthPtr;
 
3752   protected int[] astLengthStack;
 
3754   ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
 
3756   public CompilationUnitDeclaration compilationUnit; /*
 
3757                                                       * the result from parse()
 
3760   protected ReferenceContext referenceContext;
 
3762   protected ProblemReporter problemReporter;
 
3764   protected CompilerOptions options;
 
3766   private ArrayList includesList;
 
3768   //  protected CompilationResult compilationResult;
 
3770    * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
 
3771    * reported, so initializes the compilation result's line positions.
 
3773   public ProblemReporter problemReporter() {
 
3774     if (scanner.recordLineSeparator) {
 
3775       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
 
3777     problemReporter.referenceContext = referenceContext;
 
3778     return problemReporter;
 
3782    * Reconsider the entire source looking for inconsistencies in {} () []
 
3784   public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
 
3785     scanner.wasAcr = false;
 
3786     boolean anomaliesDetected = false;
 
3788       char[] source = scanner.source;
 
3789       int[] leftCount = { 0, 0, 0 };
 
3790       int[] rightCount = { 0, 0, 0 };
 
3791       int[] depths = { 0, 0, 0 };
 
3792       int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
 
3793       int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
 
3794       int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
 
3795       int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
 
3796       scanner.currentPosition = scanner.initialPosition; //starting
 
3798       // (first-zero-based
 
3800       while (scanner.currentPosition < scanner.eofPosition) { //loop for
 
3805           // ---------Consume white space and handles
 
3806           // startPosition---------
 
3807           boolean isWhiteSpace;
 
3809             scanner.startPosition = scanner.currentPosition;
 
3810             //                                          if (((scanner.currentCharacter =
 
3811             // source[scanner.currentPosition++]) == '\\') &&
 
3812             // (source[scanner.currentPosition] == 'u')) {
 
3813             //                                                  isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
 
3815             if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
 
3816               if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
 
3817                 // only record line positions we have not
 
3819                 scanner.pushLineSeparator();
 
3822             isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
 
3824           } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
 
3825           // -------consume token until } is found---------
 
3826           switch (scanner.currentCharacter) {
 
3828             int index = leftCount[CurlyBracket]++;
 
3829             if (index == leftPositions[CurlyBracket].length) {
 
3830               System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
 
3831               System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
 
3833             leftPositions[CurlyBracket][index] = scanner.startPosition;
 
3834             leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
 
3838             int index = rightCount[CurlyBracket]++;
 
3839             if (index == rightPositions[CurlyBracket].length) {
 
3840               System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
 
3841               System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
 
3843             rightPositions[CurlyBracket][index] = scanner.startPosition;
 
3844             rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
 
3848             int index = leftCount[RoundBracket]++;
 
3849             if (index == leftPositions[RoundBracket].length) {
 
3850               System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
 
3851               System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
 
3853             leftPositions[RoundBracket][index] = scanner.startPosition;
 
3854             leftDepths[RoundBracket][index] = depths[RoundBracket]++;
 
3858             int index = rightCount[RoundBracket]++;
 
3859             if (index == rightPositions[RoundBracket].length) {
 
3860               System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
 
3861               System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
 
3863             rightPositions[RoundBracket][index] = scanner.startPosition;
 
3864             rightDepths[RoundBracket][index] = --depths[RoundBracket];
 
3868             int index = leftCount[SquareBracket]++;
 
3869             if (index == leftPositions[SquareBracket].length) {
 
3870               System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
 
3871               System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
 
3873             leftPositions[SquareBracket][index] = scanner.startPosition;
 
3874             leftDepths[SquareBracket][index] = depths[SquareBracket]++;
 
3878             int index = rightCount[SquareBracket]++;
 
3879             if (index == rightPositions[SquareBracket].length) {
 
3880               System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
 
3881               System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
 
3883             rightPositions[SquareBracket][index] = scanner.startPosition;
 
3884             rightDepths[SquareBracket][index] = --depths[SquareBracket];
 
3888             if (scanner.getNextChar('\\')) {
 
3889               scanner.scanEscapeCharacter();
 
3890             } else { // consume next character
 
3891               scanner.unicodeAsBackSlash = false;
 
3892               //                                                                        if (((scanner.currentCharacter =
 
3893               // source[scanner.currentPosition++]) ==
 
3895               // (source[scanner.currentPosition] ==
 
3897               //                                                                                scanner.getNextUnicodeChar();
 
3899               if (scanner.withoutUnicodePtr != 0) {
 
3900                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3904             scanner.getNextChar('\'');
 
3908             // consume next character
 
3909             scanner.unicodeAsBackSlash = false;
 
3910             //                                                  if (((scanner.currentCharacter =
 
3911             // source[scanner.currentPosition++]) == '\\') &&
 
3912             // (source[scanner.currentPosition] == 'u')) {
 
3913             //                                                          scanner.getNextUnicodeChar();
 
3915             if (scanner.withoutUnicodePtr != 0) {
 
3916               scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3919             while (scanner.currentCharacter != '"') {
 
3920               if (scanner.currentCharacter == '\r') {
 
3921                 if (source[scanner.currentPosition] == '\n')
 
3922                   scanner.currentPosition++;
 
3923                 break; // the string cannot go further that
 
3926               if (scanner.currentCharacter == '\n') {
 
3927                 break; // the string cannot go further that
 
3930               if (scanner.currentCharacter == '\\') {
 
3931                 scanner.scanEscapeCharacter();
 
3933               // consume next character
 
3934               scanner.unicodeAsBackSlash = false;
 
3935               //                                                                if (((scanner.currentCharacter =
 
3936               // source[scanner.currentPosition++]) == '\\')
 
3937               // && (source[scanner.currentPosition] == 'u'))
 
3939               //                                                                        scanner.getNextUnicodeChar();
 
3941               if (scanner.withoutUnicodePtr != 0) {
 
3942                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
3949             if ((test = scanner.getNextChar('/', '*')) == 0) { //line
 
3952               if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3953                   && (source[scanner.currentPosition] == 'u')) {
 
3954                 //-------------unicode traitement
 
3956                 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3957                 scanner.currentPosition++;
 
3958                 while (source[scanner.currentPosition] == 'u') {
 
3959                   scanner.currentPosition++;
 
3961                 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3962                     || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3963                     || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3964                     || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3968                   scanner.currentCharacter = 'A';
 
3969                 } //something different from \n and \r
 
3971                   scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
3974               while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
 
3976                 scanner.startPosition = scanner.currentPosition;
 
3977                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
3978                     && (source[scanner.currentPosition] == 'u')) {
 
3979                   //-------------unicode traitement
 
3981                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
3982                   scanner.currentPosition++;
 
3983                   while (source[scanner.currentPosition] == 'u') {
 
3984                     scanner.currentPosition++;
 
3986                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
3987                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
3988                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
3989                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
3993                     scanner.currentCharacter = 'A';
 
3994                   } //something different from \n
 
3997                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
4001               if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
 
4002                 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
 
4003                   // only record line positions we
 
4004                   // have not recorded yet
 
4005                   scanner.pushLineSeparator();
 
4006                   if (this.scanner.taskTags != null) {
 
4007                     this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
 
4008                         .getCurrentTokenEndPosition());
 
4014             if (test > 0) { //traditional and annotation
 
4016               boolean star = false;
 
4017               // consume next character
 
4018               scanner.unicodeAsBackSlash = false;
 
4019               //                                                                        if (((scanner.currentCharacter =
 
4020               // source[scanner.currentPosition++]) ==
 
4022               // (source[scanner.currentPosition] ==
 
4024               //                                                                                scanner.getNextUnicodeChar();
 
4026               if (scanner.withoutUnicodePtr != 0) {
 
4027                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
 
4030               if (scanner.currentCharacter == '*') {
 
4034               if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
4035                   && (source[scanner.currentPosition] == 'u')) {
 
4036                 //-------------unicode traitement
 
4038                 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
4039                 scanner.currentPosition++;
 
4040                 while (source[scanner.currentPosition] == 'u') {
 
4041                   scanner.currentPosition++;
 
4043                 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
4044                     || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
4045                     || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
4046                     || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
4050                   scanner.currentCharacter = 'A';
 
4051                 } //something different from * and /
 
4053                   scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
4056               //loop until end of comment */
 
4057               while ((scanner.currentCharacter != '/') || (!star)) {
 
4058                 star = scanner.currentCharacter == '*';
 
4060                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
 
4061                     && (source[scanner.currentPosition] == 'u')) {
 
4062                   //-------------unicode traitement
 
4064                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
4065                   scanner.currentPosition++;
 
4066                   while (source[scanner.currentPosition] == 'u') {
 
4067                     scanner.currentPosition++;
 
4069                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
 
4070                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
 
4071                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
 
4072                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
 
4076                     scanner.currentCharacter = 'A';
 
4077                   } //something different from * and
 
4080                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
 
4084               if (this.scanner.taskTags != null) {
 
4085                 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
 
4092             if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
 
4093               scanner.scanIdentifierOrKeyword(false);
 
4096             if (Character.isDigit(scanner.currentCharacter)) {
 
4097               scanner.scanNumber(false);
 
4101           //-----------------end switch while
 
4102           // try--------------------
 
4103         } catch (IndexOutOfBoundsException e) {
 
4104           break; // read until EOF
 
4105         } catch (InvalidInputException e) {
 
4106           return false; // no clue
 
4109       if (scanner.recordLineSeparator) {
 
4110         //                              compilationUnit.compilationResult.lineSeparatorPositions =
 
4111         // scanner.getLineEnds();
 
4113       // check placement anomalies against other kinds of brackets
 
4114       for (int kind = 0; kind < BracketKinds; kind++) {
 
4115         for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
 
4116           int start = leftPositions[kind][leftIndex]; // deepest
 
4118           // find matching closing bracket
 
4119           int depth = leftDepths[kind][leftIndex];
 
4121           for (int i = 0; i < rightCount[kind]; i++) {
 
4122             int pos = rightPositions[kind][i];
 
4123             // want matching bracket further in source with same
 
4125             if ((pos > start) && (depth == rightDepths[kind][i])) {
 
4130           if (end < 0) { // did not find a good closing match
 
4131             problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
 
4134           // check if even number of opening/closing other brackets
 
4135           // in between this pair of brackets
 
4137           for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
 
4138             for (int i = 0; i < leftCount[otherKind]; i++) {
 
4139               int pos = leftPositions[otherKind][i];
 
4140               if ((pos > start) && (pos < end))
 
4143             for (int i = 0; i < rightCount[otherKind]; i++) {
 
4144               int pos = rightPositions[otherKind][i];
 
4145               if ((pos > start) && (pos < end))
 
4149               problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
 
4155         // too many opening brackets ?
 
4156         for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
 
4157           anomaliesDetected = true;
 
4158           problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
 
4159               compilationUnit.compilationResult);
 
4161         // too many closing brackets ?
 
4162         for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
 
4163           anomaliesDetected = true;
 
4164           problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
 
4166         if (anomaliesDetected)
 
4169       return anomaliesDetected;
 
4170     } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
 
4171       return anomaliesDetected;
 
4172     } catch (NullPointerException e) { // jdk1.2.2 jit bug
 
4173       return anomaliesDetected;
 
4177   protected void pushOnAstLengthStack(int pos) {
 
4179       astLengthStack[++astLengthPtr] = pos;
 
4180     } catch (IndexOutOfBoundsException e) {
 
4181       int oldStackLength = astLengthStack.length;
 
4182       int[] oldPos = astLengthStack;
 
4183       astLengthStack = new int[oldStackLength + StackIncrement];
 
4184       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
 
4185       astLengthStack[astLengthPtr] = pos;
 
4189   protected void pushOnAstStack(ASTNode node) {
 
4191      * add a new obj on top of the ast stack
 
4194       astStack[++astPtr] = node;
 
4195     } catch (IndexOutOfBoundsException e) {
 
4196       int oldStackLength = astStack.length;
 
4197       ASTNode[] oldStack = astStack;
 
4198       astStack = new ASTNode[oldStackLength + AstStackIncrement];
 
4199       System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
 
4200       astPtr = oldStackLength;
 
4201       astStack[astPtr] = node;
 
4204       astLengthStack[++astLengthPtr] = 1;
 
4205     } catch (IndexOutOfBoundsException e) {
 
4206       int oldStackLength = astLengthStack.length;
 
4207       int[] oldPos = astLengthStack;
 
4208       astLengthStack = new int[oldStackLength + AstStackIncrement];
 
4209       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
 
4210       astLengthStack[astLengthPtr] = 1;
 
4214   protected void resetModifiers() {
 
4215     this.modifiers = AccDefault;
 
4216     this.modifiersSourceStart = -1; // <-- see comment into
 
4217     // modifiersFlag(int)
 
4218     this.scanner.commentPtr = -1;