better error messages for unterminated strings and comments
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Parser.java
1 /*******************************************************************************
2  * Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de All rights
3  * reserved. This program and the accompanying material are made available under
4  * the terms of the Common Public License v1.0 which accompanies this
5  * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
6  * 
7  * Contributors: Klaus Hartlage - www.eclipseproject.de
8  ******************************************************************************/
9 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
16 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
17 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
19 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
21 import net.sourceforge.phpdt.internal.compiler.util.Util;
22 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
23 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
24 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
25 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
31
32 import org.eclipse.core.resources.IFile;
33 public class Parser //extends PHPParserSuperclass
34     implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
35   //internal data for the automat
36   protected final static int StackIncrement = 255;
37   protected int stateStackTop;
38   protected int[] stack = new int[StackIncrement];
39   public int firstToken; // handle for multiple parsing goals
40   public int lastAct; //handle for multiple parsing goals
41   protected RecoveredElement currentElement;
42   public static boolean VERBOSE_RECOVERY = false;
43   protected boolean diet = false; //tells the scanner to jump over some
44   // parts of the code/expressions like
45   // method bodies
46   //scanner token
47   public Scanner scanner;
48   private ArrayList phpList;
49   private int currentPHPString;
50   private boolean phpEnd;
51   // private static HashMap keywordMap = null;
52   private String str;
53   // current character
54   //  char ch;
55   // current token
56   int token;
57   // row counter for syntax errors:
58   //int rowCount;
59   // column counter for syntax errors:
60   //int columnCount;
61   //int chIndx;
62   //
63   //    // current identifier
64   //    String identifier;
65   Long longNumber;
66   Double doubleNumber;
67   private String stringValue;
68   /** Contains the current expression. */
69   // private StringBuffer expression;
70   //private boolean phpMode;
71   protected int modifiers;
72   protected int modifiersSourceStart;
73 //  protected IdentifierIndexManager indexManager;
74   
75   protected Parser(ProblemReporter problemReporter) {
76     this.problemReporter = problemReporter;
77     this.options = problemReporter.options;
78     this.currentPHPString = 0;
79     //          PHPParserSuperclass.fileToParse = fileToParse;
80     this.phpList = null;
81 //    this.indexManager = null;
82     this.str = "";
83     this.token = TokenNameEOF;
84     //    this.chIndx = 0;
85     //    this.rowCount = 1;
86     //    this.columnCount = 0;
87     this.phpEnd = false;
88     //   getNextToken();
89     this.initializeScanner();
90   }
91   public void setFileToParse(IFile fileToParse) {
92     this.currentPHPString = 0;
93     //    PHPParserSuperclass.fileToParse = fileToParse;
94     this.phpList = null;
95 //    this.indexManager = null;
96     this.str = "";
97     this.token = TokenNameEOF;
98     this.phpEnd = false;
99     this.initializeScanner();
100   }
101   /**
102    * ClassDeclaration Constructor.
103    * 
104    * @param s
105    * @param sess
106    *          Description of Parameter
107    * @see
108    */
109   public Parser(IFile fileToParse) {
110     //    if (keywordMap == null) {
111     //      keywordMap = new HashMap();
112     //      for (int i = 0; i < PHP_KEYWORS.length; i++) {
113     //        keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
114     //      }
115     //    }
116     this.currentPHPString = 0;
117     //    PHPParserSuperclass.fileToParse = fileToParse;
118     this.phpList = null;
119     this.includesList = null;
120     this.str = "";
121     this.token = TokenNameEOF;
122     //    this.chIndx = 0;
123     //    this.rowCount = 1;
124     //    this.columnCount = 0;
125     this.phpEnd = false;
126     //   getNextToken();
127     this.initializeScanner();
128   }
129   public void initializeScanner() {
130     this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
131         .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
132         this.options.taskTags/* taskTags */, this.options.taskPriorites/* taskPriorities */);
133   }
134   /**
135    * Create marker for the parse error
136    */
137   //  private void setMarker(String message, int charStart, int charEnd, int
138   // errorLevel) {
139   //    setMarker(fileToParse, message, charStart, charEnd, errorLevel);
140   //  }
141   /**
142    * This method will throw the SyntaxError. It will add the good lines and
143    * columns to the Error
144    * 
145    * @param error
146    *          the error message
147    * @throws SyntaxError
148    *           the error raised
149    */
150   private void throwSyntaxError(String error) {
151     int problemStartPosition = scanner.getCurrentTokenStartPosition();
152     int problemEndPosition = scanner.getCurrentTokenEndPosition();
153     throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
154   }
155   /**
156    * This method will throw the SyntaxError. It will add the good lines and
157    * columns to the Error
158    * 
159    * @param error
160    *          the error message
161    * @throws SyntaxError
162    *           the error raised
163    */
164   //  private void throwSyntaxError(String error, int startRow) {
165   //    throw new SyntaxError(startRow, 0, " ", error);
166   //  }
167   private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
168     problemReporter.phpParsingError(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
169         compilationUnit.compilationResult);
170     throw new SyntaxError(1, 0, " ", error);
171   }
172   private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
173     problemReporter.phpParsingError(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
174         compilationUnit.compilationResult);
175   }
176   private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
177     problemReporter.phpParsingWarning(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
178         compilationUnit.compilationResult);
179   }
180   /**
181    * Method Declaration.
182    * 
183    * @see
184    */
185   //  private void getChar() {
186   //    if (str.length() > chIndx) {
187   //      ch = str.charAt(chIndx++);
188   //
189   //      return;
190   //    }
191   //
192   //    chIndx = str.length() + 1;
193   //    ch = ' ';
194   //    // token = TokenNameEOF;
195   //    phpEnd = true;
196   //  }
197   /**
198    * gets the next token from input
199    */
200   private void getNextToken() {
201     try {
202       token = scanner.getNextToken();
203       if (Scanner.DEBUG) {
204         int currentEndPosition = scanner.getCurrentTokenEndPosition();
205         int currentStartPosition = scanner.getCurrentTokenStartPosition();
206         System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
207         System.out.println(scanner.toStringAction(token));
208       }
209     } catch (InvalidInputException e) {
210       token = TokenNameERROR;
211       String detailedMessage = e.getMessage();
212       
213       if (detailedMessage==Scanner.UNTERMINATED_STRING) {
214         throwSyntaxError("Unterminated string.");
215       } else if (detailedMessage==Scanner.UNTERMINATED_COMMENT) {
216         throwSyntaxError("Unterminated commment.");
217       }
218     }
219     return;
220   }
221   public void init(String s) {
222     this.str = s;
223     this.token = TokenNameEOF;
224     //    this.chIndx = 0;
225     //    this.rowCount = 1;
226     //    this.columnCount = 0;
227     this.phpEnd = false;
228     //    this.phpMode = false;
229     /* scanner initialization */
230     scanner.setSource(s.toCharArray());
231     scanner.setPHPMode(false);
232   }
233   protected void initialize(boolean phpMode) {
234     initialize(phpMode, null);
235   }
236   protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
237     compilationUnit = null;
238     referenceContext = null;
239     includesList = new ArrayList();
240 //    this.indexManager = indexManager;
241     this.str = "";
242     this.token = TokenNameEOF;
243     //    this.chIndx = 0;
244     //    this.rowCount = 1;
245     //    this.columnCount = 0;
246     this.phpEnd = false;
247     //    this.phpMode = phpMode;
248     scanner.setPHPMode(phpMode);
249   }
250   /**
251    * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt;
252    * &lt;/body&gt;'
253    */
254   public void parse(String s) {
255     init(s);
256     parse();
257   }
258   /**
259    * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt;
260    * &lt;/body&gt;'
261    */
262   protected void parse() {
263     getNextToken();
264     do {
265       try {
266         if (token != TokenNameEOF && token != TokenNameERROR) {
267           statementList();
268         }
269         if (token != TokenNameEOF) {
270           if (token == TokenNameERROR) {
271             throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
272           }
273           if (token == TokenNameRPAREN) {
274             throwSyntaxError("Too many closing ')'; end-of-file not reached.");
275           }
276           if (token == TokenNameRBRACE) {
277             throwSyntaxError("Too many closing '}'; end-of-file not reached.");
278           }
279           if (token == TokenNameRBRACKET) {
280             throwSyntaxError("Too many closing ']'; end-of-file not reached.");
281           }
282           if (token == TokenNameLPAREN) {
283             throwSyntaxError("Read character '('; end-of-file not reached.");
284           }
285           if (token == TokenNameLBRACE) {
286             throwSyntaxError("Read character '{';  end-of-file not reached.");
287           }
288           if (token == TokenNameLBRACKET) {
289             throwSyntaxError("Read character '[';  end-of-file not reached.");
290           }
291           throwSyntaxError("End-of-file not reached.");
292         }
293         break;
294       } catch (SyntaxError sytaxErr1) {
295         // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
296         // ERROR);
297         //        setMarker(sytaxErr1.getMessage(),
298         // scanner.getCurrentTokenStartPosition(),
299         // scanner.getCurrentTokenEndPosition(), ERROR);
300         try {
301           // if an error occured,
302           // try to find keywords 'class' or 'function'
303           // to parse the rest of the string
304           while (token != TokenNameEOF && token != TokenNameERROR) {
305             if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
306               break;
307             }
308             getNextToken();
309           }
310           if (token == TokenNameEOF || token == TokenNameERROR) {
311             break;
312           }
313         } catch (SyntaxError sytaxErr2) {
314           //    setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
315           // ERROR);
316           //          setMarker(sytaxErr2.getMessage(),
317           // scanner.getCurrentTokenStartPosition(),
318           // scanner.getCurrentTokenEndPosition(), ERROR);
319           break;
320         }
321       }
322     } while (true);
323
324     endParse(0);
325   }
326
327   protected CompilationUnitDeclaration endParse(int act) {
328
329     this.lastAct = act;
330
331     if (currentElement != null) {
332       currentElement.topElement().updateParseTree();
333       if (VERBOSE_RECOVERY) {
334         System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
335         System.out.println("--------------------------"); //$NON-NLS-1$
336         System.out.println(compilationUnit);
337         System.out.println("----------------------------------"); //$NON-NLS-1$
338       }
339     } else {
340       if (diet & VERBOSE_RECOVERY) {
341         System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
342         System.out.println("--------------------------"); //$NON-NLS-1$
343         System.out.println(compilationUnit);
344         System.out.println("----------------------------------"); //$NON-NLS-1$
345       }
346     }
347     if (scanner.recordLineSeparator) {
348       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
349     }
350     if (scanner.taskTags != null) {
351       for (int i = 0; i < scanner.foundTaskCount; i++) {
352         problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
353             scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
354             scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
355       }
356     }
357     compilationUnit.imports = new ImportReference[includesList.size()];
358     for (int i = 0; i < includesList.size(); i++) {
359       compilationUnit.imports[i] = (ImportReference) includesList.get(i);
360     }
361     return compilationUnit;
362   }
363   //  public PHPOutlineInfo parseInfo(Object parent, String s) {
364   //    PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
365   //    // Stack stack = new Stack();
366   //    // stack.push(outlineInfo.getDeclarations());
367   //    this.str = s;
368   //    this.token = TokenNameEOF;
369   //    // this.chIndx = 0;
370   //    // this.rowCount = 1;
371   //    // this.columnCount = 0;
372   //    this.phpEnd = false;
373   //    this.phpMode = false;
374   //    scanner.setSource(s.toCharArray());
375   //    scanner.setPHPMode(false);
376   //    
377   //    getNextToken();
378   //    parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
379   //    
380   //    return outlineInfo;
381   //  }
382   private boolean isVariable() {
383     return token == TokenNameVariable; //  || token == TokenNamethis;
384   }
385   //  private void parseDeclarations(PHPOutlineInfo outlineInfo,
386   //      OutlineableWithChildren current, boolean goBack) {
387   //    char[] ident;
388   //    // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
389   //    PHPSegmentWithChildren temp;
390   //    int counter = 0;
391   //    IPreferenceStore store =
392   // PHPeclipsePlugin.getDefault().getPreferenceStore();
393   //    try {
394   //      while (token != TokenNameEOF && token != TokenNameERROR) {
395   //        if (token == TokenNameVariable) {
396   //          ident = scanner.getCurrentIdentifierSource();
397   //          outlineInfo.addVariable(new String(ident));
398   //          getNextToken();
399   //        } else if (token == TokenNamevar) {
400   //          getNextToken();
401   //          if (token == TokenNameVariable
402   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
403   //            ident = scanner.getCurrentIdentifierSource();
404   //            //substring(1) added because PHPVarDeclaration doesn't
405   //            // need the $ anymore
406   //            String variableName = new String(ident).substring(1);
407   //            outlineInfo.addVariable(variableName);
408   //            getNextToken();
409   //            if (token != TokenNameSEMICOLON) {
410   //              getNextToken();
411   //              ident = scanner.getCurrentTokenSource();
412   //              if (token > TokenNameKEYWORD) {
413   //                current.add(new PHPVarDeclaration(current, variableName,
414   //                // chIndx - ident.length,
415   //                    scanner.getCurrentTokenStartPosition(), new String(ident)));
416   //              } else {
417   //                switch (token) {
418   //                  case TokenNameVariable :
419   //                  case TokenNamethis :
420   //                    current.add(new PHPVarDeclaration(current, variableName,
421   //                    // chIndx -
422   //                        // ident.length,
423   //                        scanner.getCurrentTokenStartPosition(), new String(
424   //                            ident)));
425   //                    break;
426   //                  case TokenNameIdentifier :
427   //                    current.add(new PHPVarDeclaration(current, variableName,
428   //                    // chIndx -
429   //                        // ident.length,
430   //                        scanner.getCurrentTokenStartPosition(), new String(
431   //                            ident)));
432   //                    break;
433   //                  case TokenNameDoubleLiteral :
434   //                    current.add(new PHPVarDeclaration(current, variableName
435   //                        + doubleNumber,
436   //                    // chIndx -
437   //                        // ident.length,
438   //                        scanner.getCurrentTokenStartPosition(), new String(
439   //                            ident)));
440   //                    break;
441   //                  case TokenNameIntegerLiteral :
442   //                    current.add(new PHPVarDeclaration(current, variableName,
443   //                    // chIndx -
444   //                        // ident.length,
445   //                        scanner.getCurrentTokenStartPosition(), new String(
446   //                            ident)));
447   //                    break;
448   //                  case TokenNameStringInterpolated :
449   //                  case TokenNameStringLiteral :
450   //                    current.add(new PHPVarDeclaration(current, variableName,
451   //                    // chIndx -
452   //                        // ident.length,
453   //                        scanner.getCurrentTokenStartPosition(), new String(
454   //                            ident)));
455   //                    break;
456   //                  case TokenNameStringConstant :
457   //                    current.add(new PHPVarDeclaration(current, variableName,
458   //                    // chIndx -
459   //                        // ident.length,
460   //                        scanner.getCurrentTokenStartPosition(), new String(
461   //                            ident)));
462   //                    break;
463   //                  default :
464   //                    current.add(new PHPVarDeclaration(current, variableName,
465   //                    // chIndx -
466   //                        // ident.length
467   //                        scanner.getCurrentTokenStartPosition()));
468   //                    break;
469   //                }
470   //              }
471   //            } else {
472   //              ident = scanner.getCurrentIdentifierSource();
473   //              current.add(new PHPVarDeclaration(current, variableName,
474   //              // chIndx - ident.length
475   //                  scanner.getCurrentTokenStartPosition()));
476   //            }
477   //          }
478   //        } else if (token == TokenNamefunction) {
479   //          getNextToken();
480   //          if (token == TokenNameAND) {
481   //            getNextToken();
482   //          }
483   //          if (token == TokenNameIdentifier
484   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
485   //            ident = scanner.getCurrentIdentifierSource();
486   //            outlineInfo.addVariable(new String(ident));
487   //            temp = new PHPFunctionDeclaration(current, new String(ident),
488   //            // chIndx - ident.length
489   //                scanner.getCurrentTokenStartPosition());
490   //            current.add(temp);
491   //            getNextToken();
492   //            parseDeclarations(outlineInfo, temp, true);
493   //          }
494   //        } else if (token == TokenNameclass) {
495   //          getNextToken();
496   //          if (token == TokenNameIdentifier
497   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
498   //            ident = scanner.getCurrentIdentifierSource();
499   //            outlineInfo.addVariable(new String(ident));
500   //            temp = new PHPClassDeclaration(current, new String(ident),
501   //            // chIndx - ident.len
502   //                scanner.getCurrentTokenStartPosition());
503   //            current.add(temp);
504   //            // stack.push(temp);
505   //            getNextToken();
506   //            //skip tokens for classname, extends and others until
507   //            // we have the opening '{'
508   //            while (token != TokenNameLBRACE && token != TokenNameEOF
509   //                && token != TokenNameERROR) {
510   //              getNextToken();
511   //            }
512   //            parseDeclarations(outlineInfo, temp, true);
513   //            // stack.pop();
514   //          }
515   //        } else if ((token == TokenNameLBRACE)
516   //            || (token == TokenNameDOLLAR_LBRACE)) {
517   //          getNextToken();
518   //          counter++;
519   //        } else if (token == TokenNameRBRACE) {
520   //          getNextToken();
521   //          --counter;
522   //          if (counter == 0 && goBack) {
523   //            return;
524   //          }
525   //        } else if (token == TokenNamerequire || token == TokenNamerequire_once
526   //            || token == TokenNameinclude || token == TokenNameinclude_once) {
527   //          ident = scanner.getCurrentTokenSource();
528   //          getNextToken();
529   //          int startPosition = scanner.getCurrentTokenStartPosition();
530   //          expr();
531   //          char[] expr = scanner.getCurrentTokenSource(startPosition);
532   //          outlineInfo.addVariable(new String(ident));
533   //          current.add(new PHPReqIncDeclaration(current, new String(ident),
534   //          // chIndx - ident.length,
535   //              startPosition, new String(expr)));
536   //          getNextToken();
537   //        } else {
538   //          getNextToken();
539   //        }
540   //      }
541   //    } catch (SyntaxError sytaxErr) {
542   //      // try {
543   //      // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
544   //      // setMarker(sytaxErr.getMessage(),
545   //      // scanner.getCurrentTokenStartPosition(),
546   //      // scanner.getCurrentTokenEndPosition(), ERROR);
547   //      // } catch (CoreException e) {
548   //      // }
549   //    }
550   //  }
551   private void statementList() {
552     do {
553       statement(TokenNameEOF);
554       if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
555           || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
556           || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
557           || (token == TokenNameEOF) || (token == TokenNameERROR)) {
558         return;
559       }
560     } while (true);
561   }
562   private void functionBody(MethodDeclaration methodDecl) {
563     // '{' [statement-list] '}'
564     if (token == TokenNameLBRACE) {
565       getNextToken();
566     } else {
567       throwSyntaxError("'{' expected in compound-statement.");
568     }
569     if (token != TokenNameRBRACE) {
570       statementList();
571     }
572     if (token == TokenNameRBRACE) {
573       methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
574       getNextToken();
575     } else {
576       throwSyntaxError("'}' expected in compound-statement.");
577     }
578   }
579   private void statement(int previousToken) {
580     //   if (token > TokenNameKEYWORD && token != TokenNamelist && token !=
581     // TokenNamenew) {
582     //  char[] ident = scanner.getCurrentIdentifierSource();
583     //  String keyword = new String(ident);
584     //    if (token == TokenNameAT) {
585     //      getNextToken();
586     //      if (token != TokenNamerequire && token != TokenNamerequire_once
587     //          && token != TokenNameinclude && token != TokenNameinclude_once
588     //          && token != TokenNameIdentifier && token != TokenNameVariable
589     //          && token != TokenNameStringInterpolated) {
590     //        throwSyntaxError("identifier expected after '@'.");
591     //      }
592     //    }
593     //    if (token == TokenNameinclude || token == TokenNameinclude_once) {
594     //      getNextToken();
595     //      if (token == TokenNameLPAREN) {
596     //        expr();
597     //        if (token == TokenNameSEMICOLON) {
598     //          getNextToken();
599     //        } else {
600     //          if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
601     //            throwSyntaxError("';' expected after 'include' or 'include_once'.");
602     //          }
603     //          // getNextToken();
604     //        }
605     //      } else {
606     //        concatenationExpression();
607     //      }
608     //      return;
609     //    } else if (token == TokenNamerequire || token ==
610     // TokenNamerequire_once)
611     // {
612     //      getNextToken();
613     //      //constant();
614     //      if (token == TokenNameLPAREN) {
615     //        expr();
616     //        if (token == TokenNameSEMICOLON) {
617     //          getNextToken();
618     //        } else {
619     //          if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
620     //            throwSyntaxError("';' expected after 'require' or 'require_once'.");
621     //          }
622     //          // getNextToken();
623     //        }
624     //      } else {
625     //        concatenationExpression();
626     //      }
627     //      return;
628     //    } else
629     if (token == TokenNameif) {
630       getNextToken();
631       if (token == TokenNameLPAREN) {
632         getNextToken();
633       } else {
634         throwSyntaxError("'(' expected after 'if' keyword.");
635       }
636       expr();
637       if (token == TokenNameRPAREN) {
638         getNextToken();
639       } else {
640         throwSyntaxError("')' expected after 'if' condition.");
641       }
642       ifStatement();
643       return;
644     } else if (token == TokenNameswitch) {
645       getNextToken();
646       if (token == TokenNameLPAREN) {
647         getNextToken();
648       } else {
649         throwSyntaxError("'(' expected after 'switch' keyword.");
650       }
651       expr();
652       if (token == TokenNameRPAREN) {
653         getNextToken();
654       } else {
655         throwSyntaxError("')' expected after 'switch' condition.");
656       }
657       switchStatement();
658       return;
659     } else if (token == TokenNamefor) {
660       getNextToken();
661       if (token == TokenNameLPAREN) {
662         getNextToken();
663       } else {
664         throwSyntaxError("'(' expected after 'for' keyword.");
665       }
666       if (token == TokenNameSEMICOLON) {
667         getNextToken();
668       } else {
669         expressionList();
670         if (token == TokenNameSEMICOLON) {
671           getNextToken();
672         } else {
673           throwSyntaxError("';' expected after 'for'.");
674         }
675       }
676       if (token == TokenNameSEMICOLON) {
677         getNextToken();
678       } else {
679         expressionList();
680         if (token == TokenNameSEMICOLON) {
681           getNextToken();
682         } else {
683           throwSyntaxError("';' expected after 'for'.");
684         }
685       }
686       if (token == TokenNameRPAREN) {
687         getNextToken();
688       } else {
689         expressionList();
690         if (token == TokenNameRPAREN) {
691           getNextToken();
692         } else {
693           throwSyntaxError("')' expected after 'for'.");
694         }
695       }
696       forStatement();
697       return;
698     } else if (token == TokenNamewhile) {
699       getNextToken();
700       if (token == TokenNameLPAREN) {
701         getNextToken();
702       } else {
703         throwSyntaxError("'(' expected after 'while' keyword.");
704       }
705       expr();
706       if (token == TokenNameRPAREN) {
707         getNextToken();
708       } else {
709         throwSyntaxError("')' expected after 'while' condition.");
710       }
711       whileStatement();
712       return;
713     } else if (token == TokenNamedo) {
714       getNextToken();
715       if (token == TokenNameLBRACE) {
716         getNextToken();
717         if (token != TokenNameRBRACE) {
718           statementList();
719         }
720         if (token == TokenNameRBRACE) {
721           getNextToken();
722         } else {
723           throwSyntaxError("'}' expected after 'do' keyword.");
724         }
725       } else {
726         statement(TokenNameEOF);
727       }
728       if (token == TokenNamewhile) {
729         getNextToken();
730         if (token == TokenNameLPAREN) {
731           getNextToken();
732         } else {
733           throwSyntaxError("'(' expected after 'while' keyword.");
734         }
735         expr();
736         if (token == TokenNameRPAREN) {
737           getNextToken();
738         } else {
739           throwSyntaxError("')' expected after 'while' condition.");
740         }
741       } else {
742         throwSyntaxError("'while' expected after 'do' keyword.");
743       }
744       if (token == TokenNameSEMICOLON) {
745         getNextToken();
746       } else {
747         if (token != TokenNameINLINE_HTML) {
748           throwSyntaxError("';' expected after do-while statement.");
749         }
750         getNextToken();
751       }
752       return;
753     } else if (token == TokenNameforeach) {
754       getNextToken();
755       if (token == TokenNameLPAREN) {
756         getNextToken();
757       } else {
758         throwSyntaxError("'(' expected after 'foreach' keyword.");
759       }
760       expr();
761       if (token == TokenNameas) {
762         getNextToken();
763       } else {
764         throwSyntaxError("'as' expected after 'foreach' exxpression.");
765       }
766       //      variable();
767       foreach_variable();
768       foreach_optional_arg();
769       if (token == TokenNameEQUAL_GREATER) {
770         getNextToken();
771         variable();
772       }
773       if (token == TokenNameRPAREN) {
774         getNextToken();
775       } else {
776         throwSyntaxError("')' expected after 'foreach' expression.");
777       }
778       foreachStatement();
779       return;
780     } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
781       getNextToken();
782       if (token != TokenNameSEMICOLON) {
783         expr();
784       }
785       if (token == TokenNameSEMICOLON) {
786         getNextToken();
787       } else {
788         if (token != TokenNameINLINE_HTML) {
789           throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
790         }
791         getNextToken();
792       }
793       return;
794     } else if (token == TokenNameecho) {
795       getNextToken();
796       expressionList();
797       if (token == TokenNameSEMICOLON) {
798         getNextToken();
799       } else {
800         if (token != TokenNameINLINE_HTML) {
801           throwSyntaxError("';' expected after 'echo' statement.");
802         }
803         getNextToken();
804       }
805       return;
806     } else if (token == TokenNameINLINE_HTML) {
807       getNextToken();
808       return;
809       //    } else if (token == TokenNameprint) {
810       //      getNextToken();
811       //      expression();
812       //      if (token == TokenNameSEMICOLON) {
813       //        getNextToken();
814       //      } else {
815       //        if (token != TokenNameStopPHP) {
816       //          throwSyntaxError("';' expected after 'print' statement.");
817       //        }
818       //        getNextToken();
819       //      }
820       //      return;
821     } else if (token == TokenNameglobal) {
822       getNextToken();
823       global_var_list();
824       if (token == TokenNameSEMICOLON) {
825         getNextToken();
826       } else {
827         if (token != TokenNameINLINE_HTML) {
828           throwSyntaxError("';' expected after 'global' statement.");
829         }
830         getNextToken();
831       }
832       return;
833     } else if (token == TokenNamestatic) {
834       getNextToken();
835       static_var_list();
836       if (token == TokenNameSEMICOLON) {
837         getNextToken();
838       } else {
839         if (token != TokenNameINLINE_HTML) {
840           throwSyntaxError("';' expected after 'static' statement.");
841         }
842         getNextToken();
843       }
844       return;
845     } else if (token == TokenNameunset) {
846       getNextToken();
847       if (token == TokenNameLPAREN) {
848         getNextToken();
849       } else {
850         throwSyntaxError("'(' expected after 'unset' statement.");
851       }
852       unset_variables();
853       if (token == TokenNameRPAREN) {
854         getNextToken();
855       } else {
856         throwSyntaxError("')' expected after 'unset' statement.");
857       }
858       if (token == TokenNameSEMICOLON) {
859         getNextToken();
860       } else {
861         if (token != TokenNameINLINE_HTML) {
862           throwSyntaxError("';' expected after 'unset' statement.");
863         }
864         getNextToken();
865       }
866       return;
867     } else if (token == TokenNamefunction) {
868       MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
869       methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
870       methodDecl.modifiers = AccDefault;
871       getNextToken();
872       functionDefinition(methodDecl);
873       return;
874     } else if (token == TokenNametry) {
875       getNextToken();
876       if (token != TokenNameLBRACE) {
877         throwSyntaxError("'{' expected in 'try' statement.");
878       }
879       getNextToken();
880       statementList();
881       if (token != TokenNameRBRACE) {
882         throwSyntaxError("'}' expected in 'try' statement.");
883       }
884       getNextToken();
885       return;
886     } else if (token == TokenNamecatch) {
887       getNextToken();
888       if (token != TokenNameLPAREN) {
889         throwSyntaxError("'(' expected in 'catch' statement.");
890       }
891       getNextToken();
892       fully_qualified_class_name();
893       if (token != TokenNameVariable) {
894         throwSyntaxError("Variable expected in 'catch' statement.");
895       }
896       getNextToken();
897       if (token != TokenNameRPAREN) {
898         throwSyntaxError("')' expected in 'catch' statement.");
899       }
900       getNextToken();
901       if (token != TokenNameLBRACE) {
902         throwSyntaxError("'{' expected in 'catch' statement.");
903       }
904       getNextToken();
905       if (token != TokenNameRBRACE) {
906         statementList();
907         if (token != TokenNameRBRACE) {
908           throwSyntaxError("'}' expected in 'catch' statement.");
909         }
910       }
911       getNextToken();
912       additional_catches();
913       return;
914     } else if (token == TokenNamethrow) {
915       getNextToken();
916       expr();
917       if (token == TokenNameSEMICOLON) {
918         getNextToken();
919       } else {
920         throwSyntaxError("';' expected after 'throw' exxpression.");
921       }
922       return;
923     } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
924       TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
925       typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
926       // default super class
927       typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
928       compilationUnit.types.add(typeDecl);
929       try {
930         pushOnAstStack(typeDecl);
931         unticked_class_declaration_statement(typeDecl);
932         //        classBody(typeDecl);
933       } finally {
934         astPtr--;
935         astLengthPtr--;
936       }
937       return;
938       //      } else {
939       //        throwSyntaxError("Unexpected keyword '" + keyword + "'");
940     } else if (token == TokenNameLBRACE) {
941       getNextToken();
942       if (token != TokenNameRBRACE) {
943         statementList();
944       }
945       if (token == TokenNameRBRACE) {
946         getNextToken();
947         return;
948       } else {
949         throwSyntaxError("'}' expected.");
950       }
951     } else {
952       if (token != TokenNameSEMICOLON) {
953         expr();
954       }
955       if (token == TokenNameSEMICOLON) {
956         getNextToken();
957         return;
958       } else {
959         if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
960           throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
961         }
962         getNextToken();
963       }
964     }
965   }
966   private void additional_catches() {
967     while (token == TokenNamecatch) {
968       getNextToken();
969       if (token != TokenNameLPAREN) {
970         throwSyntaxError("'(' expected in 'catch' statement.");
971       }
972       getNextToken();
973       fully_qualified_class_name();
974       if (token != TokenNameVariable) {
975         throwSyntaxError("Variable expected in 'catch' statement.");
976       }
977       getNextToken();
978       if (token != TokenNameRPAREN) {
979         throwSyntaxError("')' expected in 'catch' statement.");
980       }
981       getNextToken();
982       if (token != TokenNameLBRACE) {
983         throwSyntaxError("'{' expected in 'catch' statement.");
984       }
985       getNextToken();
986       statementList();
987       if (token != TokenNameRBRACE) {
988         throwSyntaxError("'}' expected in 'catch' statement.");
989       }
990       getNextToken();
991     }
992   }
993   private void foreach_variable() {
994     //  w_variable
995     //| '&' w_variable
996     if (token == TokenNameAND) {
997       getNextToken();
998     }
999     w_variable();
1000   }
1001   private void foreach_optional_arg() {
1002     //  /* empty */
1003     //| T_DOUBLE_ARROW foreach_variable
1004     if (token == TokenNameEQUAL_GREATER) {
1005       getNextToken();
1006       foreach_variable();
1007     }
1008   }
1009   private void global_var_list() {
1010     //  global_var_list:
1011     //  global_var_list ',' global_var
1012     //| global_var
1013     while (true) {
1014       global_var();
1015       if (token != TokenNameCOMMA) {
1016         break;
1017       }
1018       getNextToken();
1019     }
1020   }
1021   private void global_var() {
1022     //global_var:
1023     //  T_VARIABLE
1024     //| '$' r_variable
1025     //| '$' '{' expr '}'
1026     if (token == TokenNameVariable) {
1027       getNextToken();
1028     } else if (token == TokenNameDOLLAR) {
1029       getNextToken();
1030       if (token == TokenNameLPAREN) {
1031         getNextToken();
1032         expr();
1033         if (token != TokenNameLPAREN) {
1034           throwSyntaxError("')' expected in global variable.");
1035         }
1036         getNextToken();
1037       } else {
1038         r_variable();
1039       }
1040     }
1041   }
1042   private void static_var_list() {
1043     //static_var_list:
1044     //  static_var_list ',' T_VARIABLE
1045     //| static_var_list ',' T_VARIABLE '=' static_scalar
1046     //| T_VARIABLE
1047     //| T_VARIABLE '=' static_scalar
1048     while (true) {
1049       if (token == TokenNameVariable) {
1050         getNextToken();
1051         if (token == TokenNameEQUAL) {
1052           getNextToken();
1053           static_scalar();
1054         }
1055         if (token != TokenNameCOMMA) {
1056           break;
1057         }
1058         getNextToken();
1059       } else {
1060         break;
1061       }
1062     }
1063   }
1064   private void unset_variables() {
1065     //    unset_variables:
1066     //                  unset_variable
1067     //          | unset_variables ',' unset_variable
1068     //    unset_variable:
1069     //                  variable
1070     while (true) {
1071       variable();
1072       if (token != TokenNameCOMMA) {
1073         break;
1074       }
1075       getNextToken();
1076     }
1077   }
1078   private final void initializeModifiers() {
1079     this.modifiers = 0;
1080     this.modifiersSourceStart = -1;
1081   }
1082   private final void checkAndSetModifiers(int flag) {
1083     this.modifiers |= flag;
1084     if (this.modifiersSourceStart < 0)
1085       this.modifiersSourceStart = this.scanner.startPosition;
1086   }
1087   private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1088     initializeModifiers();
1089     if (token == TokenNameinterface) {
1090       //      interface_entry T_STRING
1091       //                interface_extends_list
1092       //                '{' class_statement_list '}'
1093       checkAndSetModifiers(AccInterface);
1094       getNextToken();
1095       typeDecl.modifiers = this.modifiers;
1096       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1097         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1098         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1099         typeDecl.name = scanner.getCurrentIdentifierSource();
1100         if (token > TokenNameKEYWORD) {
1101           throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1102               typeDecl.sourceStart, typeDecl.sourceEnd);
1103         }
1104         getNextToken();
1105         interface_extends_list();
1106       } else {
1107         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1108         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1109         typeDecl.name = new char[]{' '};
1110         throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1111         return;
1112       }
1113     } else {
1114       //      class_entry_type T_STRING extends_from
1115       //                implements_list
1116       //                '{' class_statement_list'}'
1117       class_entry_type();
1118       typeDecl.modifiers = this.modifiers;
1119       //identifier
1120       //identifier 'extends' identifier
1121       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1122         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1123         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1124         typeDecl.name = scanner.getCurrentIdentifierSource();
1125         if (token > TokenNameKEYWORD) {
1126           throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1127               typeDecl.sourceStart, typeDecl.sourceEnd);
1128         }
1129         getNextToken();
1130         //    extends_from:
1131         //              /* empty */
1132         //      | T_EXTENDS fully_qualified_class_name
1133         if (token == TokenNameextends) {
1134           interface_extends_list();
1135           //          getNextToken();
1136           //          if (token != TokenNameIdentifier) {
1137           //            throwSyntaxError("Class name expected after keyword
1138           // 'extends'.",
1139           //                scanner.getCurrentTokenStartPosition(), scanner
1140           //                    .getCurrentTokenEndPosition());
1141           //          }
1142         }
1143         implements_list();
1144       } else {
1145         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1146         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1147         typeDecl.name = new char[]{' '};
1148         throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1149         return;
1150       }
1151     }
1152     //  '{' class_statement_list '}'
1153     if (token == TokenNameLBRACE) {
1154       getNextToken();
1155       if (token != TokenNameRBRACE) {
1156         ArrayList list = new ArrayList();
1157         class_statement_list(list);
1158         typeDecl.fields = new FieldDeclaration[list.size()];
1159         for (int i = 0; i < list.size(); i++) {
1160           typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1161         }
1162       }
1163       if (token == TokenNameRBRACE) {
1164         typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1165         getNextToken();
1166       } else {
1167         throwSyntaxError("'}' expected at end of class body.");
1168       }
1169     } else {
1170       throwSyntaxError("'{' expected at start of class body.");
1171     }
1172   }
1173   private void class_entry_type() {
1174     //  T_CLASS
1175     //  | T_ABSTRACT T_CLASS
1176     //  | T_FINAL T_CLASS
1177     if (token == TokenNameclass) {
1178       getNextToken();
1179     } else if (token == TokenNameabstract) {
1180       checkAndSetModifiers(AccAbstract);
1181       getNextToken();
1182       if (token != TokenNameclass) {
1183         throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1184       }
1185       getNextToken();
1186     } else if (token == TokenNamefinal) {
1187       checkAndSetModifiers(AccFinal);
1188       getNextToken();
1189       if (token != TokenNameclass) {
1190         throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1191       }
1192       getNextToken();
1193     } else {
1194       throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1195     }
1196   }
1197   private void interface_extends_list() {
1198     //  /* empty */
1199     //  | T_EXTENDS interface_list
1200     if (token == TokenNameextends) {
1201       getNextToken();
1202       interface_list();
1203     }
1204   }
1205   private void implements_list() {
1206     //  /* empty */
1207     //  | T_IMPLEMENTS interface_list
1208     if (token == TokenNameimplements) {
1209       getNextToken();
1210       interface_list();
1211     }
1212   }
1213   private void interface_list() {
1214     //  interface_list:
1215     //  fully_qualified_class_name
1216     //| interface_list ',' fully_qualified_class_name
1217     do {
1218       if (token == TokenNameIdentifier) {
1219         getNextToken();
1220       } else {
1221         throwSyntaxError("Interface name expected after keyword 'implements'.");
1222       }
1223       if (token != TokenNameCOMMA) {
1224         return;
1225       }
1226       getNextToken();
1227     } while (true);
1228   }
1229   //  private void classBody(TypeDeclaration typeDecl) {
1230   //    //'{' [class-element-list] '}'
1231   //    if (token == TokenNameLBRACE) {
1232   //      getNextToken();
1233   //      if (token != TokenNameRBRACE) {
1234   //        class_statement_list();
1235   //      }
1236   //      if (token == TokenNameRBRACE) {
1237   //        typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1238   //        getNextToken();
1239   //      } else {
1240   //        throwSyntaxError("'}' expected at end of class body.");
1241   //      }
1242   //    } else {
1243   //      throwSyntaxError("'{' expected at start of class body.");
1244   //    }
1245   //  }
1246   private void class_statement_list(ArrayList list) {
1247     do {
1248       class_statement(list);
1249     } while (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1250         || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1251         || token == TokenNameconst);
1252   }
1253   private void class_statement(ArrayList list) {
1254     //    class_statement:
1255     //          variable_modifiers class_variable_declaration ';'
1256     //  | class_constant_declaration ';'
1257     //  | method_modifiers T_FUNCTION is_reference T_STRING
1258     //    '(' parameter_list ')' method_body
1259     initializeModifiers();
1260     int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1261     ;
1262     if (token == TokenNamevar) {
1263       checkAndSetModifiers(AccPublic);
1264       problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1265           referenceContext, compilationUnit.compilationResult);
1266       getNextToken();
1267       class_variable_declaration(declarationSourceStart, list);
1268     } else if (token == TokenNameconst) {
1269       checkAndSetModifiers(AccFinal|AccPublic);
1270       class_constant_declaration(declarationSourceStart, list);
1271       if (token != TokenNameSEMICOLON) {
1272         throwSyntaxError("';' expected after class const declaration.");
1273       }
1274       getNextToken();
1275     } else {
1276       boolean hasModifiers = member_modifiers();
1277       if (token == TokenNamefunction) {
1278         if (!hasModifiers) {
1279           checkAndSetModifiers(AccPublic);
1280         }
1281         MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1282         methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1283         methodDecl.modifiers = this.modifiers;
1284         getNextToken();
1285         functionDefinition(methodDecl);
1286       } else {
1287         if (!hasModifiers) {
1288           throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1289         }
1290         class_variable_declaration(declarationSourceStart, list);
1291       }
1292     }
1293   }
1294   private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1295     //  class_constant_declaration ',' T_STRING '=' static_scalar
1296     //  | T_CONST T_STRING '=' static_scalar
1297     if (token != TokenNameconst) {
1298       throwSyntaxError("'const' keyword expected in class declaration.");
1299     } else {
1300       getNextToken();
1301     }
1302     while (true) {
1303       if (token != TokenNameIdentifier) {
1304         throwSyntaxError("Identifier expected in class const declaration.");
1305       }
1306       FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1307           .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1308       fieldDeclaration.modifiers = this.modifiers;
1309       fieldDeclaration.declarationSourceStart = declarationSourceStart;
1310       fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1311       fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1312       //        fieldDeclaration.type
1313       list.add(fieldDeclaration);
1314       getNextToken();
1315       if (token != TokenNameEQUAL) {
1316         throwSyntaxError("'=' expected in class const declaration.");
1317       }
1318       getNextToken();
1319       static_scalar();
1320       if (token != TokenNameCOMMA) {
1321         break; // while(true)-loop
1322       }
1323       getNextToken();
1324     }
1325   }
1326   //  private void variable_modifiers() {
1327   //    // variable_modifiers:
1328   //    // non_empty_member_modifiers
1329   //    //| T_VAR
1330   //    initializeModifiers();
1331   //    if (token == TokenNamevar) {
1332   //      checkAndSetModifiers(AccPublic);
1333   //      reportSyntaxError(
1334   //          "Keyword 'var' is deprecated. Please use 'public' 'private' or
1335   // 'protected'
1336   // modifier for field declarations.",
1337   //          scanner.getCurrentTokenStartPosition(), scanner
1338   //              .getCurrentTokenEndPosition());
1339   //      getNextToken();
1340   //    } else {
1341   //      if (!member_modifiers()) {
1342   //        throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1343   // field declarations.");
1344   //      }
1345   //    }
1346   //  }
1347   //  private void method_modifiers() {
1348   //    //method_modifiers:
1349   //    // /* empty */
1350   //    //| non_empty_member_modifiers
1351   //    initializeModifiers();
1352   //    if (!member_modifiers()) {
1353   //      checkAndSetModifiers(AccPublic);
1354   //    }
1355   //  }
1356   private boolean member_modifiers() {
1357     //  T_PUBLIC
1358     //| T_PROTECTED
1359     //| T_PRIVATE
1360     //| T_STATIC
1361     //| T_ABSTRACT
1362     //| T_FINAL
1363     boolean foundToken = false;
1364     while (true) {
1365       if (token == TokenNamepublic) {
1366         checkAndSetModifiers(AccPublic);
1367         getNextToken();
1368         foundToken = true;
1369       } else if (token == TokenNameprotected) {
1370         checkAndSetModifiers(AccProtected);
1371         getNextToken();
1372         foundToken = true;
1373       } else if (token == TokenNameprivate) {
1374         checkAndSetModifiers(AccPrivate);
1375         getNextToken();
1376         foundToken = true;
1377       } else if (token == TokenNamestatic) {
1378         checkAndSetModifiers(AccStatic);
1379         getNextToken();
1380         foundToken = true;
1381       } else if (token == TokenNameabstract) {
1382         checkAndSetModifiers(AccAbstract);
1383         getNextToken();
1384         foundToken = true;
1385       } else if (token == TokenNamefinal) {
1386         checkAndSetModifiers(AccFinal);
1387         getNextToken();
1388         foundToken = true;
1389       } else {
1390         break;
1391       }
1392     }
1393     return foundToken;
1394   }
1395   private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1396     //    class_variable_declaration:
1397     //          class_variable_declaration ',' T_VARIABLE
1398     //  | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1399     //  | T_VARIABLE
1400     //  | T_VARIABLE '=' static_scalar
1401     char[] classVariable;
1402     do {
1403       if (token == TokenNameVariable) {
1404         classVariable = scanner.getCurrentIdentifierSource();
1405       //  indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1406         FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner
1407             .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1408         fieldDeclaration.modifiers = this.modifiers;
1409         fieldDeclaration.declarationSourceStart = declarationSourceStart;
1410         fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1411         fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1412         //        fieldDeclaration.type
1413         list.add(fieldDeclaration);
1414         getNextToken();
1415         if (token == TokenNameEQUAL) {
1416           getNextToken();
1417           static_scalar();
1418         }
1419       } else {
1420         //        if (token == TokenNamethis) {
1421         //          throwSyntaxError("'$this' not allowed after keyword 'public'
1422         // 'protected' 'private' 'var'.");
1423         //        }
1424         throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1425       }
1426       if (token != TokenNameCOMMA) {
1427         break;
1428       }
1429       getNextToken();
1430     } while (true);
1431     if (token != TokenNameSEMICOLON) {
1432       throwSyntaxError("';' expected after field declaration.");
1433     }
1434     getNextToken();
1435   }
1436   private void functionDefinition(MethodDeclaration methodDecl) {
1437     boolean isAbstract = false;
1438     if (astPtr == 0) {
1439       compilationUnit.types.add(methodDecl);
1440     } else {
1441       AstNode node = astStack[astPtr];
1442       if (node instanceof TypeDeclaration) {
1443         TypeDeclaration typeDecl = ((TypeDeclaration) node);
1444         if (typeDecl.methods == null) {
1445           typeDecl.methods = new AbstractMethodDeclaration[]{methodDecl};
1446         } else {
1447           AbstractMethodDeclaration[] newMethods;
1448           System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 1,
1449               typeDecl.methods.length);
1450           newMethods[0] = methodDecl;
1451           typeDecl.methods = newMethods;
1452         }
1453         if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1454           isAbstract = true;
1455         } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1456           isAbstract = true;
1457         }
1458       }
1459     }
1460     functionDeclarator(methodDecl);
1461     if (token == TokenNameSEMICOLON) {
1462       if (!isAbstract) {
1463         throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1464       }
1465       getNextToken();
1466       return;
1467     }
1468     functionBody(methodDecl);
1469   }
1470   private void functionDeclarator(MethodDeclaration methodDecl) {
1471     //identifier '(' [parameter-list] ')'
1472     if (token == TokenNameAND) {
1473       getNextToken();
1474     }
1475     methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1476     methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1477     if (Scanner.isIdentifierOrKeyword(token)) {
1478       methodDecl.selector = scanner.getCurrentIdentifierSource();
1479       if (token > TokenNameKEYWORD) {
1480         reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
1481           scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1482 //        throwSyntaxError("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].");
1483       }
1484       getNextToken();
1485       if (token == TokenNameLPAREN) {
1486         getNextToken();
1487       } else {
1488         throwSyntaxError("'(' expected in function declaration.");
1489       }
1490       if (token != TokenNameRPAREN) {
1491         parameter_list();
1492       }
1493       if (token != TokenNameRPAREN) {
1494         throwSyntaxError("')' expected in function declaration.");
1495       } else {
1496         methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1497         getNextToken();
1498       }
1499     } else {
1500       methodDecl.selector = "<undefined>".toCharArray();
1501       throwSyntaxError("Function name expected after keyword 'function'.");
1502     }
1503   }
1504   //
1505   private void parameter_list() {
1506     //  non_empty_parameter_list
1507     //  | /* empty */
1508     non_empty_parameter_list(true);
1509   }
1510   private void non_empty_parameter_list(boolean empty_allowed) {
1511     //  optional_class_type T_VARIABLE
1512     //  | optional_class_type '&' T_VARIABLE
1513     //  | optional_class_type '&' T_VARIABLE '=' static_scalar
1514     //  | optional_class_type T_VARIABLE '=' static_scalar
1515     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1516     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1517     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1518     // static_scalar
1519     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1520     // static_scalar
1521     if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1522       while (true) {
1523         if (token == TokenNameIdentifier) {
1524           getNextToken();
1525         }
1526         if (token == TokenNameAND) {
1527           getNextToken();
1528         }
1529         if (token == TokenNameVariable) {
1530           getNextToken();
1531           if (token == TokenNameEQUAL) {
1532             getNextToken();
1533             static_scalar();
1534           }
1535         } else {
1536           throwSyntaxError("Variable expected in parameter list.");
1537         }
1538         if (token != TokenNameCOMMA) {
1539           break;
1540         }
1541         getNextToken();
1542       }
1543       return;
1544     }
1545     if (!empty_allowed) {
1546       throwSyntaxError("Identifier expected in parameter list.");
1547     }
1548   }
1549   private void optional_class_type() {
1550     //  /* empty */
1551     //| T_STRING
1552   }
1553   private void parameterDeclaration() {
1554     //variable
1555     //variable-reference
1556     if (token == TokenNameAND) {
1557       getNextToken();
1558       if (isVariable()) {
1559         getNextToken();
1560       } else {
1561         throwSyntaxError("Variable expected after reference operator '&'.");
1562       }
1563     }
1564     //variable '=' constant
1565     if (token == TokenNameVariable) {
1566       getNextToken();
1567       if (token == TokenNameEQUAL) {
1568         getNextToken();
1569         static_scalar();
1570       }
1571       return;
1572     }
1573     //    if (token == TokenNamethis) {
1574     //      throwSyntaxError("Reserved word '$this' not allowed in parameter
1575     // declaration.");
1576     //    }
1577   }
1578   private void labeledStatementList() {
1579     if (token != TokenNamecase && token != TokenNamedefault) {
1580       throwSyntaxError("'case' or 'default' expected.");
1581     }
1582     do {
1583       if (token == TokenNamecase) {
1584         getNextToken();
1585         expr(); //constant();
1586         if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1587           getNextToken();
1588           if (token == TokenNamecase || token == TokenNamedefault) {
1589             // empty case statement ?
1590             continue;
1591           }
1592           statementList();
1593         }
1594         //        else if (token == TokenNameSEMICOLON) {
1595         //          setMarker(
1596         //            "':' expected after 'case' keyword (Found token: " +
1597         // scanner.toStringAction(token) + ")",
1598         //            scanner.getCurrentTokenStartPosition(),
1599         //            scanner.getCurrentTokenEndPosition(),
1600         //            INFO);
1601         //          getNextToken();
1602         //          if (token == TokenNamecase) { // empty case statement ?
1603         //            continue;
1604         //          }
1605         //          statementList();
1606         //        }
1607         else {
1608           throwSyntaxError("':' character after 'case' constant expected (Found token: " + scanner.toStringAction(token) + ")");
1609         }
1610       } else { // TokenNamedefault
1611         getNextToken();
1612         if (token == TokenNameCOLON) {
1613           getNextToken();
1614           if (token == TokenNameRBRACE) {
1615             // empty default case
1616             break;
1617           }
1618           statementList();
1619         } else {
1620           throwSyntaxError("':' character after 'default' expected.");
1621         }
1622       }
1623     } while (token == TokenNamecase || token == TokenNamedefault);
1624   }
1625   //  public void labeledStatement() {
1626   //    if (token == TokenNamecase) {
1627   //      getNextToken();
1628   //      constant();
1629   //      if (token == TokenNameDDOT) {
1630   //        getNextToken();
1631   //        statement();
1632   //      } else {
1633   //        throwSyntaxError("':' character after 'case' constant expected.");
1634   //      }
1635   //      return;
1636   //    } else if (token == TokenNamedefault) {
1637   //      getNextToken();
1638   //      if (token == TokenNameDDOT) {
1639   //        getNextToken();
1640   //        statement();
1641   //      } else {
1642   //        throwSyntaxError("':' character after 'default' expected.");
1643   //      }
1644   //      return;
1645   //    }
1646   //  }
1647   //  public void expressionStatement() {
1648   //  }
1649   //  private void inclusionStatement() {
1650   //  }
1651   //  public void compoundStatement() {
1652   //  }
1653   //  public void selectionStatement() {
1654   //  }
1655   //
1656   //  public void iterationStatement() {
1657   //  }
1658   //
1659   //  public void jumpStatement() {
1660   //  }
1661   //
1662   //  public void outputStatement() {
1663   //  }
1664   //
1665   //  public void scopeStatement() {
1666   //  }
1667   //
1668   //  public void flowStatement() {
1669   //  }
1670   //
1671   //  public void definitionStatement() {
1672   //  }
1673   private void ifStatement() {
1674     // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
1675     if (token == TokenNameCOLON) {
1676       getNextToken();
1677       if (token != TokenNameendif) {
1678         statementList();
1679         switch (token) {
1680           case TokenNameelse :
1681             getNextToken();
1682             if (token == TokenNameCOLON) {
1683               getNextToken();
1684               if (token != TokenNameendif) {
1685                 statementList();
1686               }
1687             } else {
1688               if (token == TokenNameif) { //'else if'
1689                 getNextToken();
1690                 elseifStatementList();
1691               } else {
1692                 throwSyntaxError("':' expected after 'else'.");
1693               }
1694             }
1695             break;
1696           case TokenNameelseif :
1697             getNextToken();
1698             elseifStatementList();
1699             break;
1700         }
1701       }
1702       if (token != TokenNameendif) {
1703         throwSyntaxError("'endif' expected.");
1704       }
1705       getNextToken();
1706       if (token != TokenNameSEMICOLON) {
1707         throwSyntaxError("';' expected after if-statement.");
1708       }
1709       getNextToken();
1710     } else {
1711       // statement [else-statement]
1712       statement(TokenNameEOF);
1713       if (token == TokenNameelseif) {
1714         getNextToken();
1715         if (token == TokenNameLPAREN) {
1716           getNextToken();
1717         } else {
1718           throwSyntaxError("'(' expected after 'elseif' keyword.");
1719         }
1720         expr();
1721         if (token == TokenNameRPAREN) {
1722           getNextToken();
1723         } else {
1724           throwSyntaxError("')' expected after 'elseif' condition.");
1725         }
1726         ifStatement();
1727       } else if (token == TokenNameelse) {
1728         getNextToken();
1729         statement(TokenNameEOF);
1730       }
1731     }
1732   }
1733   private void elseifStatementList() {
1734     do {
1735       elseifStatement();
1736       switch (token) {
1737         case TokenNameelse :
1738           getNextToken();
1739           if (token == TokenNameCOLON) {
1740             getNextToken();
1741             if (token != TokenNameendif) {
1742               statementList();
1743             }
1744             return;
1745           } else {
1746             if (token == TokenNameif) { //'else if'
1747               getNextToken();
1748             } else {
1749               throwSyntaxError("':' expected after 'else'.");
1750             }
1751           }
1752           break;
1753         case TokenNameelseif :
1754           getNextToken();
1755           break;
1756         default :
1757           return;
1758       }
1759     } while (true);
1760   }
1761   private void elseifStatement() {
1762     if (token == TokenNameLPAREN) {
1763       getNextToken();
1764       expr();
1765       if (token != TokenNameRPAREN) {
1766         throwSyntaxError("')' expected in else-if-statement.");
1767       }
1768       getNextToken();
1769       if (token != TokenNameCOLON) {
1770         throwSyntaxError("':' expected in else-if-statement.");
1771       }
1772       getNextToken();
1773       if (token != TokenNameendif) {
1774         statementList();
1775       }
1776     }
1777   }
1778   private void switchStatement() {
1779     if (token == TokenNameCOLON) {
1780       // ':' [labeled-statement-list] 'endswitch' ';'
1781       getNextToken();
1782       labeledStatementList();
1783       if (token != TokenNameendswitch) {
1784         throwSyntaxError("'endswitch' expected.");
1785       }
1786       getNextToken();
1787       if (token != TokenNameSEMICOLON) {
1788         throwSyntaxError("';' expected after switch-statement.");
1789       }
1790       getNextToken();
1791     } else {
1792       // '{' [labeled-statement-list] '}'
1793       if (token != TokenNameLBRACE) {
1794         throwSyntaxError("'{' expected in switch statement.");
1795       }
1796       getNextToken();
1797       if (token != TokenNameRBRACE) {
1798         labeledStatementList();
1799       }
1800       if (token != TokenNameRBRACE) {
1801         throwSyntaxError("'}' expected in switch statement.");
1802       }
1803       getNextToken();
1804     }
1805   }
1806   private void forStatement() {
1807     if (token == TokenNameCOLON) {
1808       getNextToken();
1809       statementList();
1810       if (token != TokenNameendfor) {
1811         throwSyntaxError("'endfor' expected.");
1812       }
1813       getNextToken();
1814       if (token != TokenNameSEMICOLON) {
1815         throwSyntaxError("';' expected after for-statement.");
1816       }
1817       getNextToken();
1818     } else {
1819       statement(TokenNameEOF);
1820     }
1821   }
1822   private void whileStatement() {
1823     // ':' statement-list 'endwhile' ';'
1824     if (token == TokenNameCOLON) {
1825       getNextToken();
1826       statementList();
1827       if (token != TokenNameendwhile) {
1828         throwSyntaxError("'endwhile' expected.");
1829       }
1830       getNextToken();
1831       if (token != TokenNameSEMICOLON) {
1832         throwSyntaxError("';' expected after while-statement.");
1833       }
1834       getNextToken();
1835     } else {
1836       statement(TokenNameEOF);
1837     }
1838   }
1839   private void foreachStatement() {
1840     if (token == TokenNameCOLON) {
1841       getNextToken();
1842       statementList();
1843       if (token != TokenNameendforeach) {
1844         throwSyntaxError("'endforeach' expected.");
1845       }
1846       getNextToken();
1847       if (token != TokenNameSEMICOLON) {
1848         throwSyntaxError("';' expected after foreach-statement.");
1849       }
1850       getNextToken();
1851     } else {
1852       statement(TokenNameEOF);
1853     }
1854   }
1855   //  private void exitStatus() {
1856   //    if (token == TokenNameLPAREN) {
1857   //      getNextToken();
1858   //    } else {
1859   //      throwSyntaxError("'(' expected in 'exit-status'.");
1860   //    }
1861   //    if (token != TokenNameRPAREN) {
1862   //      expression();
1863   //    }
1864   //    if (token == TokenNameRPAREN) {
1865   //      getNextToken();
1866   //    } else {
1867   //      throwSyntaxError("')' expected after 'exit-status'.");
1868   //    }
1869   //  }
1870   private void expressionList() {
1871     do {
1872       expr();
1873       if (token == TokenNameCOMMA) {
1874         getNextToken();
1875       } else {
1876         break;
1877       }
1878     } while (true);
1879   }
1880   private void expr() {
1881     //  r_variable
1882     //  | expr_without_variable
1883     //    if (token!=TokenNameEOF) {
1884     if (Scanner.TRACE) {
1885       System.out.println("TRACE: expr()");
1886     }
1887     expr_without_variable(true);
1888     //    }
1889   }
1890   private void expr_without_variable(boolean only_variable) {
1891     //          internal_functions_in_yacc
1892     //  | T_CLONE expr
1893     //  | T_PRINT expr
1894     //  | '(' expr ')'
1895     //  | '@' expr
1896     //  | '+' expr
1897     //  | '-' expr
1898     //  | '!' expr
1899     //  | '~' expr
1900     //  | T_INC rw_variable
1901     //  | T_DEC rw_variable
1902     //  | T_INT_CAST expr
1903     //  | T_DOUBLE_CAST expr
1904     //  | T_STRING_CAST expr
1905     //  | T_ARRAY_CAST expr
1906     //  | T_OBJECT_CAST expr
1907     //  | T_BOOL_CAST expr
1908     //  | T_UNSET_CAST expr
1909     //  | T_EXIT exit_expr
1910     //  | scalar
1911     //  | T_ARRAY '(' array_pair_list ')'
1912     //  | '`' encaps_list '`'
1913     //  | T_LIST '(' assignment_list ')' '=' expr
1914     //  | T_NEW class_name_reference ctor_arguments
1915     //  | variable '=' expr
1916     //  | variable '=' '&' variable
1917     //  | variable '=' '&' T_NEW class_name_reference ctor_arguments
1918     //  | variable T_PLUS_EQUAL expr
1919     //  | variable T_MINUS_EQUAL expr
1920     //  | variable T_MUL_EQUAL expr
1921     //  | variable T_DIV_EQUAL expr
1922     //  | variable T_CONCAT_EQUAL expr
1923     //  | variable T_MOD_EQUAL expr
1924     //  | variable T_AND_EQUAL expr
1925     //  | variable T_OR_EQUAL expr
1926     //  | variable T_XOR_EQUAL expr
1927     //  | variable T_SL_EQUAL expr
1928     //  | variable T_SR_EQUAL expr
1929     //  | rw_variable T_INC
1930     //  | rw_variable T_DEC
1931     //  | expr T_BOOLEAN_OR expr
1932     //  | expr T_BOOLEAN_AND expr
1933     //  | expr T_LOGICAL_OR expr
1934     //  | expr T_LOGICAL_AND expr
1935     //  | expr T_LOGICAL_XOR expr
1936     //  | expr '|' expr
1937     //  | expr '&' expr
1938     //  | expr '^' expr
1939     //  | expr '.' expr
1940     //  | expr '+' expr
1941     //  | expr '-' expr
1942     //  | expr '*' expr
1943     //  | expr '/' expr
1944     //  | expr '%' expr
1945     //  | expr T_SL expr
1946     //  | expr T_SR expr
1947     //  | expr T_IS_IDENTICAL expr
1948     //  | expr T_IS_NOT_IDENTICAL expr
1949     //  | expr T_IS_EQUAL expr
1950     //  | expr T_IS_NOT_EQUAL expr
1951     //  | expr '<' expr
1952     //  | expr T_IS_SMALLER_OR_EQUAL expr
1953     //  | expr '>' expr
1954     //  | expr T_IS_GREATER_OR_EQUAL expr
1955     //  | expr T_INSTANCEOF class_name_reference
1956     //  | expr '?' expr ':' expr
1957     if (Scanner.TRACE) {
1958       System.out.println("TRACE: expr_without_variable() PART 1");
1959     }
1960     switch (token) {
1961       case TokenNameisset :
1962       case TokenNameempty :
1963       case TokenNameeval :
1964       case TokenNameinclude :
1965       case TokenNameinclude_once :
1966       case TokenNamerequire :
1967       case TokenNamerequire_once :
1968         internal_functions_in_yacc();
1969         break;
1970       //        | '(' expr ')'
1971       case TokenNameLPAREN :
1972         getNextToken();
1973         expr();
1974         if (token == TokenNameRPAREN) {
1975           getNextToken();
1976         } else {
1977           throwSyntaxError("')' expected in expression.");
1978         }
1979         break;
1980       //    | T_CLONE expr
1981       //    | T_PRINT expr
1982       //    | '@' expr
1983       //    | '+' expr
1984       //    | '-' expr
1985       //    | '!' expr
1986       //    | '~' expr
1987       //    | T_INT_CAST expr
1988       //        | T_DOUBLE_CAST expr
1989       //        | T_STRING_CAST expr
1990       //        | T_ARRAY_CAST expr
1991       //        | T_OBJECT_CAST expr
1992       //        | T_BOOL_CAST expr
1993       //        | T_UNSET_CAST expr
1994       case TokenNameclone :
1995       case TokenNameprint :
1996       case TokenNameAT :
1997       case TokenNamePLUS :
1998       case TokenNameMINUS :
1999       case TokenNameNOT :
2000       case TokenNameTWIDDLE :
2001       case TokenNameintCAST :
2002       case TokenNamedoubleCAST :
2003       case TokenNamestringCAST :
2004       case TokenNamearrayCAST :
2005       case TokenNameobjectCAST :
2006       case TokenNameboolCAST :
2007       case TokenNameunsetCAST :
2008         getNextToken();
2009         expr();
2010         break;
2011       case TokenNameexit :
2012         getNextToken();
2013         exit_expr();
2014         break;
2015       //  scalar:
2016       //        T_STRING
2017       //| T_STRING_VARNAME
2018       //| class_constant
2019       //| T_START_HEREDOC encaps_list T_END_HEREDOC
2020       //        | '`' encaps_list '`'
2021       //  | common_scalar
2022       //        | '`' encaps_list '`'
2023       case TokenNameEncapsedString0 :
2024         scanner.encapsedStringStack.push(new Character('`'));
2025         getNextToken();
2026         try {
2027           if (token == TokenNameEncapsedString0) {
2028           } else {
2029             encaps_list();
2030             if (token != TokenNameEncapsedString0) {
2031               throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2032             }
2033           }
2034         } finally {
2035           scanner.encapsedStringStack.pop();
2036           getNextToken();
2037         }
2038         break;
2039       //      | '\'' encaps_list '\''
2040       case TokenNameEncapsedString1 :
2041         scanner.encapsedStringStack.push(new Character('\''));
2042         getNextToken();
2043         try {
2044           if (token == TokenNameEncapsedString1) {
2045           } else {
2046             encaps_list();
2047             if (token != TokenNameEncapsedString1) {
2048               throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2049             }
2050           }
2051         } finally {
2052           scanner.encapsedStringStack.pop();
2053           getNextToken();
2054         }
2055         break;
2056       //| '"' encaps_list '"'
2057       case TokenNameEncapsedString2 :
2058         scanner.encapsedStringStack.push(new Character('"'));
2059         getNextToken();
2060         try {
2061           if (token == TokenNameEncapsedString2) {
2062           } else {
2063             encaps_list();
2064             if (token != TokenNameEncapsedString2) {
2065               throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2066             }
2067           }
2068         } finally {
2069           scanner.encapsedStringStack.pop();
2070           getNextToken();
2071         }
2072         break;
2073       case TokenNameIntegerLiteral :
2074       case TokenNameDoubleLiteral :
2075       case TokenNameStringDoubleQuote :
2076       case TokenNameStringSingleQuote :
2077       case TokenNameStringInterpolated :
2078       case TokenNameFILE :
2079       case TokenNameLINE :
2080       case TokenNameCLASS_C :
2081       case TokenNameMETHOD_C :
2082       case TokenNameFUNC_C :
2083         common_scalar();
2084         break;
2085       case TokenNameHEREDOC :
2086         getNextToken();
2087         break;
2088       case TokenNamearray :
2089         //    T_ARRAY '(' array_pair_list ')'
2090         getNextToken();
2091         if (token == TokenNameLPAREN) {
2092           getNextToken();
2093           if (token == TokenNameRPAREN) {
2094             getNextToken();
2095             break;
2096           }
2097           array_pair_list();
2098           if (token != TokenNameRPAREN) {
2099             throwSyntaxError("')' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2100           }
2101           getNextToken();
2102         } else {
2103           throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2104         }
2105         break;
2106       case TokenNamelist :
2107         //    | T_LIST '(' assignment_list ')' '=' expr
2108         getNextToken();
2109         if (token == TokenNameLPAREN) {
2110           getNextToken();
2111           assignment_list();
2112           if (token != TokenNameRPAREN) {
2113             throwSyntaxError("')' expected after 'list' keyword.");
2114           }
2115           getNextToken();
2116           if (token != TokenNameEQUAL) {
2117             throwSyntaxError("'=' expected after 'list' keyword.");
2118           }
2119           getNextToken();
2120           expr();
2121         } else {
2122           throwSyntaxError("'(' expected after 'list' keyword.");
2123         }
2124         break;
2125       case TokenNamenew :
2126         //      | T_NEW class_name_reference ctor_arguments
2127         getNextToken();
2128         class_name_reference();
2129         ctor_arguments();
2130         break;
2131       //        | T_INC rw_variable
2132       //        | T_DEC rw_variable
2133       case TokenNamePLUS_PLUS :
2134       case TokenNameMINUS_MINUS :
2135         getNextToken();
2136         rw_variable();
2137         break;
2138       //        | variable '=' expr
2139       //        | variable '=' '&' variable
2140       //        | variable '=' '&' T_NEW class_name_reference ctor_arguments
2141       //        | variable T_PLUS_EQUAL expr
2142       //        | variable T_MINUS_EQUAL expr
2143       //        | variable T_MUL_EQUAL expr
2144       //        | variable T_DIV_EQUAL expr
2145       //        | variable T_CONCAT_EQUAL expr
2146       //        | variable T_MOD_EQUAL expr
2147       //        | variable T_AND_EQUAL expr
2148       //        | variable T_OR_EQUAL expr
2149       //        | variable T_XOR_EQUAL expr
2150       //        | variable T_SL_EQUAL expr
2151       //        | variable T_SR_EQUAL expr
2152       //        | rw_variable T_INC
2153       //        | rw_variable T_DEC
2154       case TokenNameIdentifier :
2155       case TokenNameVariable :
2156       case TokenNameDOLLAR :
2157         variable();
2158         switch (token) {
2159           case TokenNameEQUAL :
2160             getNextToken();
2161             if (token == TokenNameAND) {
2162               getNextToken();
2163               if (token == TokenNamenew) {
2164                 // | variable '=' '&' T_NEW class_name_reference
2165                 // ctor_arguments
2166                 getNextToken();
2167                 class_name_reference();
2168                 ctor_arguments();
2169               } else {
2170                 variable();
2171               }
2172             } else {
2173               expr();
2174             }
2175             break;
2176           case TokenNamePLUS_EQUAL :
2177           case TokenNameMINUS_EQUAL :
2178           case TokenNameMULTIPLY_EQUAL :
2179           case TokenNameDIVIDE_EQUAL :
2180           case TokenNameDOT_EQUAL :
2181           case TokenNameREMAINDER_EQUAL :
2182           case TokenNameAND_EQUAL :
2183           case TokenNameOR_EQUAL :
2184           case TokenNameXOR_EQUAL :
2185           case TokenNameRIGHT_SHIFT_EQUAL :
2186           case TokenNameLEFT_SHIFT_EQUAL :
2187             getNextToken();
2188             expr();
2189             break;
2190           case TokenNamePLUS_PLUS :
2191           case TokenNameMINUS_MINUS :
2192             getNextToken();
2193             break;
2194           default :
2195             if (!only_variable) {
2196               throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2197             }
2198         }
2199         break;
2200       default :
2201         if (token != TokenNameINLINE_HTML) {
2202           if (token > TokenNameKEYWORD) {
2203             getNextToken();
2204             break;
2205           } else {
2206             throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2207           }
2208         }
2209         return;
2210     }
2211     if (Scanner.TRACE) {
2212       System.out.println("TRACE: expr_without_variable() PART 2");
2213     }
2214     //  | expr T_BOOLEAN_OR expr
2215     //  | expr T_BOOLEAN_AND expr
2216     //  | expr T_LOGICAL_OR expr
2217     //  | expr T_LOGICAL_AND expr
2218     //  | expr T_LOGICAL_XOR expr
2219     //  | expr '|' expr
2220     //  | expr '&' expr
2221     //  | expr '^' expr
2222     //  | expr '.' expr
2223     //  | expr '+' expr
2224     //  | expr '-' expr
2225     //  | expr '*' expr
2226     //  | expr '/' expr
2227     //  | expr '%' expr
2228     //  | expr T_SL expr
2229     //  | expr T_SR expr
2230     //  | expr T_IS_IDENTICAL expr
2231     //  | expr T_IS_NOT_IDENTICAL expr
2232     //  | expr T_IS_EQUAL expr
2233     //  | expr T_IS_NOT_EQUAL expr
2234     //  | expr '<' expr
2235     //  | expr T_IS_SMALLER_OR_EQUAL expr
2236     //  | expr '>' expr
2237     //  | expr T_IS_GREATER_OR_EQUAL expr
2238     while (true) {
2239       switch (token) {
2240         case TokenNameOR_OR :
2241         case TokenNameAND_AND :
2242         case TokenNameand :
2243         case TokenNameor :
2244         case TokenNamexor :
2245         case TokenNameAND :
2246         case TokenNameOR :
2247         case TokenNameXOR :
2248         case TokenNameDOT :
2249         case TokenNamePLUS :
2250         case TokenNameMINUS :
2251         case TokenNameMULTIPLY :
2252         case TokenNameDIVIDE :
2253         case TokenNameREMAINDER :
2254         case TokenNameLEFT_SHIFT :
2255         case TokenNameRIGHT_SHIFT :
2256         case TokenNameEQUAL_EQUAL_EQUAL :
2257         case TokenNameNOT_EQUAL_EQUAL :
2258         case TokenNameEQUAL_EQUAL :
2259         case TokenNameNOT_EQUAL :
2260         case TokenNameLESS :
2261         case TokenNameLESS_EQUAL :
2262         case TokenNameGREATER :
2263         case TokenNameGREATER_EQUAL :
2264           getNextToken();
2265           expr();
2266           break;
2267         //  | expr T_INSTANCEOF class_name_reference
2268         //      | expr '?' expr ':' expr
2269         case TokenNameinstanceof :
2270           getNextToken();
2271           class_name_reference();
2272           break;
2273         case TokenNameQUESTION :
2274           getNextToken();
2275           expr();
2276           if (token == TokenNameCOLON) {
2277             getNextToken();
2278             expr();
2279           }
2280           break;
2281         default :
2282           return;
2283       }
2284     }
2285   }
2286   private void class_name_reference() {
2287     //  class_name_reference:
2288     //  T_STRING
2289     //| dynamic_class_name_reference
2290     if (Scanner.TRACE) {
2291       System.out.println("TRACE: class_name_reference()");
2292     }
2293     if (token == TokenNameIdentifier) {
2294       getNextToken();
2295     } else {
2296       dynamic_class_name_reference();
2297     }
2298   }
2299   private void dynamic_class_name_reference() {
2300     //dynamic_class_name_reference:
2301     //  base_variable T_OBJECT_OPERATOR object_property
2302     // dynamic_class_name_variable_properties
2303     //| base_variable
2304     if (Scanner.TRACE) {
2305       System.out.println("TRACE: dynamic_class_name_reference()");
2306     }
2307     base_variable();
2308     if (token == TokenNameMINUS_GREATER) {
2309       getNextToken();
2310       object_property();
2311       dynamic_class_name_variable_properties();
2312     }
2313   }
2314   private void dynamic_class_name_variable_properties() {
2315     //  dynamic_class_name_variable_properties:
2316     //                  dynamic_class_name_variable_properties
2317     // dynamic_class_name_variable_property
2318     //          | /* empty */
2319     if (Scanner.TRACE) {
2320       System.out.println("TRACE: dynamic_class_name_variable_properties()");
2321     }
2322     while (token == TokenNameMINUS_GREATER) {
2323       dynamic_class_name_variable_property();
2324     }
2325   }
2326   private void dynamic_class_name_variable_property() {
2327     //  dynamic_class_name_variable_property:
2328     //  T_OBJECT_OPERATOR object_property
2329     if (Scanner.TRACE) {
2330       System.out.println("TRACE: dynamic_class_name_variable_property()");
2331     }
2332     if (token == TokenNameMINUS_GREATER) {
2333       getNextToken();
2334       object_property();
2335     }
2336   }
2337   private void ctor_arguments() {
2338     //  ctor_arguments:
2339     //  /* empty */
2340     //| '(' function_call_parameter_list ')'
2341     if (token == TokenNameLPAREN) {
2342       getNextToken();
2343       if (token == TokenNameRPAREN) {
2344         getNextToken();
2345         return;
2346       }
2347       non_empty_function_call_parameter_list();
2348       if (token != TokenNameRPAREN) {
2349         throwSyntaxError("')' expected in ctor_arguments.");
2350       }
2351       getNextToken();
2352     }
2353   }
2354   private void assignment_list() {
2355     //  assignment_list:
2356     //  assignment_list ',' assignment_list_element
2357     //| assignment_list_element
2358     while (true) {
2359       assignment_list_element();
2360       if (token != TokenNameCOMMA) {
2361         break;
2362       }
2363       getNextToken();
2364     }
2365   }
2366   private void assignment_list_element() {
2367     //assignment_list_element:
2368     //  variable
2369     //| T_LIST '(' assignment_list ')'
2370     //| /* empty */
2371     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2372       variable();
2373     } else {
2374       if (token == TokenNamelist) {
2375         getNextToken();
2376         if (token == TokenNameLPAREN) {
2377           getNextToken();
2378           assignment_list();
2379           if (token != TokenNameRPAREN) {
2380             throwSyntaxError("')' expected after 'list' keyword.");
2381           }
2382           getNextToken();
2383         } else {
2384           throwSyntaxError("'(' expected after 'list' keyword.");
2385         }
2386       }
2387     }
2388   }
2389   private void array_pair_list() {
2390     //  array_pair_list:
2391     //  /* empty */
2392     //| non_empty_array_pair_list possible_comma
2393     non_empty_array_pair_list();
2394     if (token == TokenNameCOMMA) {
2395       getNextToken();
2396     }
2397   }
2398   private void non_empty_array_pair_list() {
2399     //non_empty_array_pair_list:
2400     //  non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2401     //| non_empty_array_pair_list ',' expr
2402     //| expr T_DOUBLE_ARROW expr
2403     //| expr
2404     //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2405     //| non_empty_array_pair_list ',' '&' w_variable
2406     //| expr T_DOUBLE_ARROW '&' w_variable
2407     //| '&' w_variable
2408     while (true) {
2409       if (token == TokenNameAND) {
2410         getNextToken();
2411         variable();
2412       } else {
2413         expr();
2414         if (token == TokenNameAND) {
2415           getNextToken();
2416           variable();
2417         } else if (token == TokenNameEQUAL_GREATER) {
2418           getNextToken();
2419           if (token == TokenNameAND) {
2420             getNextToken();
2421             variable();
2422           } else {
2423             expr();
2424           }
2425         }
2426       }
2427       if (token != TokenNameCOMMA) {
2428         return;
2429       }
2430       getNextToken();
2431       if (token == TokenNameRPAREN) {
2432         return;
2433       }
2434     }
2435   }
2436   //  private void variableList() {
2437   //    do {
2438   //      variable();
2439   //      if (token == TokenNameCOMMA) {
2440   //        getNextToken();
2441   //      } else {
2442   //        break;
2443   //      }
2444   //    } while (true);
2445   //  }
2446   private void variable_without_objects() {
2447     //  variable_without_objects:
2448     //                  reference_variable
2449     //          | simple_indirect_reference reference_variable
2450     if (Scanner.TRACE) {
2451       System.out.println("TRACE: variable_without_objects()");
2452     }
2453     while (token == TokenNameDOLLAR) {
2454       getNextToken();
2455     }
2456     reference_variable();
2457   }
2458   private void function_call() {
2459     //  function_call:
2460     //  T_STRING '(' function_call_parameter_list ')'
2461     //| class_constant '(' function_call_parameter_list ')'
2462     //| static_member '(' function_call_parameter_list ')'
2463     //| variable_without_objects '(' function_call_parameter_list ')'
2464     if (Scanner.TRACE) {
2465       System.out.println("TRACE: function_call()");
2466     }
2467     if (token == TokenNameIdentifier) {
2468       getNextToken();
2469       switch (token) {
2470         case TokenNamePAAMAYIM_NEKUDOTAYIM :
2471           // static member:
2472           getNextToken();
2473           if (token == TokenNameIdentifier) {
2474             // class _constant
2475             getNextToken();
2476           } else {
2477             //        static member:
2478             variable_without_objects();
2479           }
2480           break;
2481       }
2482     } else {
2483       variable_without_objects();
2484     }
2485     if (token != TokenNameLPAREN) {
2486       // TODO is this ok ?
2487       return;
2488       //      throwSyntaxError("'(' expected in function call.");
2489     }
2490     getNextToken();
2491     if (token == TokenNameRPAREN) {
2492       getNextToken();
2493       return;
2494     }
2495     non_empty_function_call_parameter_list();
2496     if (token != TokenNameRPAREN) {
2497       throwSyntaxError("')' expected in function call.");
2498     }
2499     getNextToken();
2500   }
2501   //  private void function_call_parameter_list() {
2502   //    function_call_parameter_list:
2503   //            non_empty_function_call_parameter_list { $$ = $1; }
2504   //    | /* empty */
2505   //  }
2506   private void non_empty_function_call_parameter_list() {
2507     //non_empty_function_call_parameter_list:
2508     //          expr_without_variable
2509     //  | variable
2510     //  | '&' w_variable
2511     //  | non_empty_function_call_parameter_list ',' expr_without_variable
2512     //  | non_empty_function_call_parameter_list ',' variable
2513     //  | non_empty_function_call_parameter_list ',' '&' w_variable
2514     if (Scanner.TRACE) {
2515       System.out.println("TRACE: non_empty_function_call_parameter_list()");
2516     }
2517     while (true) {
2518       if (token == TokenNameAND) {
2519         getNextToken();
2520         w_variable();
2521       } else {
2522         //        if (token == TokenNameIdentifier || token ==
2523         // TokenNameVariable
2524         //            || token == TokenNameDOLLAR) {
2525         //          variable();
2526         //        } else {
2527         expr_without_variable(true);
2528         //        }
2529       }
2530       if (token != TokenNameCOMMA) {
2531         break;
2532       }
2533       getNextToken();
2534     }
2535   }
2536   private void fully_qualified_class_name() {
2537     if (token == TokenNameIdentifier) {
2538       getNextToken();
2539     } else {
2540       throwSyntaxError("Class name expected.");
2541     }
2542   }
2543   private void static_member() {
2544     //  static_member:
2545     //  fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2546     // variable_without_objects
2547     if (Scanner.TRACE) {
2548       System.out.println("TRACE: static_member()");
2549     }
2550     fully_qualified_class_name();
2551     if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2552       throwSyntaxError("'::' expected after class name (static_member).");
2553     }
2554     getNextToken();
2555     variable_without_objects();
2556   }
2557   private void base_variable_with_function_calls() {
2558     //  base_variable_with_function_calls:
2559     //  base_variable
2560     //| function_call
2561     boolean functionCall = false;
2562     if (Scanner.TRACE) {
2563       System.out.println("TRACE: base_variable_with_function_calls()");
2564     }
2565     //    if (token == TokenNameIdentifier) {
2566     //      functionCall = true;
2567     //    } else if (token == TokenNameVariable) {
2568     //      int tempToken = token;
2569     //      int tempPosition = scanner.currentPosition;
2570     //      getNextToken();
2571     //      if (token == TokenNameLPAREN) {
2572     //        functionCall = true;
2573     //      }
2574     //      token = tempToken;
2575     //      scanner.currentPosition = tempPosition;
2576     //      scanner.phpMode = true;
2577     //    }
2578     //    if (functionCall) {
2579     function_call();
2580     //    } else {
2581     //      base_variable();
2582     //    }
2583   }
2584   private void base_variable() {
2585     //  base_variable:
2586     //                  reference_variable
2587     //          | simple_indirect_reference reference_variable
2588     //          | static_member
2589     if (Scanner.TRACE) {
2590       System.out.println("TRACE: base_variable()");
2591     }
2592     if (token == TokenNameIdentifier) {
2593       static_member();
2594     } else {
2595       while (token == TokenNameDOLLAR) {
2596         getNextToken();
2597       }
2598       reference_variable();
2599     }
2600   }
2601   //  private void simple_indirect_reference() {
2602   //    // simple_indirect_reference:
2603   //    // '$'
2604   //    //| simple_indirect_reference '$'
2605   //  }
2606   private void reference_variable() {
2607     //  reference_variable:
2608     //                  reference_variable '[' dim_offset ']'
2609     //          | reference_variable '{' expr '}'
2610     //          | compound_variable
2611     if (Scanner.TRACE) {
2612       System.out.println("TRACE: reference_variable()");
2613     }
2614     compound_variable();
2615     while (true) {
2616       if (token == TokenNameLBRACE) {
2617         getNextToken();
2618         expr();
2619         if (token != TokenNameRBRACE) {
2620           throwSyntaxError("'}' expected in reference variable.");
2621         }
2622         getNextToken();
2623       } else if (token == TokenNameLBRACKET) {
2624         getNextToken();
2625         if (token != TokenNameRBRACKET) {
2626           expr();
2627           //        dim_offset();
2628           if (token != TokenNameRBRACKET) {
2629             throwSyntaxError("']' expected in reference variable.");
2630           }
2631         }
2632         getNextToken();
2633       } else {
2634         break;
2635       }
2636     }
2637   }
2638   private void compound_variable() {
2639     //  compound_variable:
2640     //                  T_VARIABLE
2641     //          | '$' '{' expr '}'
2642     if (Scanner.TRACE) {
2643       System.out.println("TRACE: compound_variable()");
2644     }
2645     if (token == TokenNameVariable) {
2646       getNextToken();
2647     } else {
2648       // because of simple_indirect_reference
2649       while (token == TokenNameDOLLAR) {
2650         getNextToken();
2651       }
2652       if (token != TokenNameLBRACE) {
2653         throwSyntaxError("'{' expected after compound variable token '$'.");
2654       }
2655       getNextToken();
2656       expr();
2657       if (token != TokenNameRBRACE) {
2658         throwSyntaxError("'}' expected after compound variable token '$'.");
2659       }
2660       getNextToken();
2661     }
2662   }
2663   //  private void dim_offset() {
2664   //    // dim_offset:
2665   //    // /* empty */
2666   //    // | expr
2667   //    expr();
2668   //  }
2669   private void object_property() {
2670     //  object_property:
2671     //  object_dim_list
2672     //| variable_without_objects
2673     if (Scanner.TRACE) {
2674       System.out.println("TRACE: object_property()");
2675     }
2676     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2677       variable_without_objects();
2678     } else {
2679       object_dim_list();
2680     }
2681   }
2682   private void object_dim_list() {
2683     //object_dim_list:
2684     //  object_dim_list '[' dim_offset ']'
2685     //| object_dim_list '{' expr '}'
2686     //| variable_name
2687     if (Scanner.TRACE) {
2688       System.out.println("TRACE: object_dim_list()");
2689     }
2690     variable_name();
2691     while (true) {
2692       if (token == TokenNameLBRACE) {
2693         getNextToken();
2694         expr();
2695         if (token != TokenNameRBRACE) {
2696           throwSyntaxError("'}' expected in object_dim_list.");
2697         }
2698         getNextToken();
2699       } else if (token == TokenNameLBRACKET) {
2700         getNextToken();
2701         if (token == TokenNameRBRACKET) {
2702           getNextToken();
2703           continue;
2704         }
2705         expr();
2706         if (token != TokenNameRBRACKET) {
2707           throwSyntaxError("']' expected in object_dim_list.");
2708         }
2709         getNextToken();
2710       } else {
2711         break;
2712       }
2713     }
2714   }
2715   private void variable_name() {
2716     //variable_name:
2717     //  T_STRING
2718     //| '{' expr '}'
2719     if (Scanner.TRACE) {
2720       System.out.println("TRACE: variable_name()");
2721     }
2722     if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
2723       if (token > TokenNameKEYWORD) {
2724         // TODO show a warning "Keyword used as variable" ?
2725       }
2726       getNextToken();
2727     } else {
2728       if (token != TokenNameLBRACE) {
2729         throwSyntaxError("'{' expected in variable name.");
2730       }
2731       getNextToken();
2732       expr();
2733       if (token != TokenNameRBRACE) {
2734         throwSyntaxError("'}' expected in variable name.");
2735       }
2736       getNextToken();
2737     }
2738   }
2739   private void r_variable() {
2740     variable();
2741   }
2742   private void w_variable() {
2743     variable();
2744   }
2745   private void rw_variable() {
2746     variable();
2747   }
2748   private void variable() {
2749     //    variable:
2750     //          base_variable_with_function_calls T_OBJECT_OPERATOR
2751     //                  object_property method_or_not variable_properties
2752     //  | base_variable_with_function_calls
2753     base_variable_with_function_calls();
2754     if (token == TokenNameMINUS_GREATER) {
2755       getNextToken();
2756       object_property();
2757       method_or_not();
2758       variable_properties();
2759     }
2760     //    if (token == TokenNameDOLLAR_LBRACE) {
2761     //      getNextToken();
2762     //      expr();
2763     //      ;
2764     //      if (token != TokenNameRBRACE) {
2765     //        throwSyntaxError("'}' expected after indirect variable token '${'.");
2766     //      }
2767     //      getNextToken();
2768     //    } else {
2769     //      if (token == TokenNameVariable) {
2770     //        getNextToken();
2771     //        if (token == TokenNameLBRACKET) {
2772     //          getNextToken();
2773     //          expr();
2774     //          if (token != TokenNameRBRACKET) {
2775     //            throwSyntaxError("']' expected in variable-list.");
2776     //          }
2777     //          getNextToken();
2778     //        } else if (token == TokenNameEQUAL) {
2779     //          getNextToken();
2780     //          static_scalar();
2781     //        }
2782     //      } else {
2783     //        throwSyntaxError("$-variable expected in variable-list.");
2784     //      }
2785     //    }
2786   }
2787   private void variable_properties() {
2788     //  variable_properties:
2789     //                  variable_properties variable_property
2790     //          | /* empty */
2791     while (token == TokenNameMINUS_GREATER) {
2792       variable_property();
2793     }
2794   }
2795   private void variable_property() {
2796     //  variable_property:
2797     //                  T_OBJECT_OPERATOR object_property method_or_not
2798     if (Scanner.TRACE) {
2799       System.out.println("TRACE: variable_property()");
2800     }
2801     if (token == TokenNameMINUS_GREATER) {
2802       getNextToken();
2803       object_property();
2804       method_or_not();
2805     } else {
2806       throwSyntaxError("'->' expected in variable_property.");
2807     }
2808   }
2809   private void method_or_not() {
2810     //  method_or_not:
2811     //                  '(' function_call_parameter_list ')'
2812     //          | /* empty */
2813     if (Scanner.TRACE) {
2814       System.out.println("TRACE: method_or_not()");
2815     }
2816     if (token == TokenNameLPAREN) {
2817       getNextToken();
2818       if (token == TokenNameRPAREN) {
2819         getNextToken();
2820         return;
2821       }
2822       non_empty_function_call_parameter_list();
2823       if (token != TokenNameRPAREN) {
2824         throwSyntaxError("')' expected in method_or_not.");
2825       }
2826       getNextToken();
2827     }
2828   }
2829   private void exit_expr() {
2830     //  /* empty */
2831     //  | '(' ')'
2832     //  | '(' expr ')'
2833     if (token != TokenNameLPAREN) {
2834       return;
2835     }
2836     getNextToken();
2837     if (token == TokenNameRPAREN) {
2838       getNextToken();
2839       return;
2840     }
2841     expr();
2842     if (token != TokenNameRPAREN) {
2843       throwSyntaxError("')' expected after keyword 'exit'");
2844     }
2845     getNextToken();
2846   }
2847   private void encaps_list() {
2848     //                  encaps_list encaps_var
2849     //          | encaps_list T_STRING
2850     //          | encaps_list T_NUM_STRING
2851     //          | encaps_list T_ENCAPSED_AND_WHITESPACE
2852     //          | encaps_list T_CHARACTER
2853     //          | encaps_list T_BAD_CHARACTER
2854     //          | encaps_list '['
2855     //          | encaps_list ']'
2856     //          | encaps_list '{'
2857     //          | encaps_list '}'
2858     //          | encaps_list T_OBJECT_OPERATOR
2859     //          | /* empty */
2860     while (true) {
2861       switch (token) {
2862         case TokenNameSTRING :
2863           getNextToken();
2864           break;
2865         case TokenNameLBRACE :
2866           //          scanner.encapsedStringStack.pop();
2867           getNextToken();
2868           break;
2869         case TokenNameRBRACE :
2870           //          scanner.encapsedStringStack.pop();
2871           getNextToken();
2872           break;
2873         case TokenNameLBRACKET :
2874           //          scanner.encapsedStringStack.pop();
2875           getNextToken();
2876           break;
2877         case TokenNameRBRACKET :
2878           //          scanner.encapsedStringStack.pop();
2879           getNextToken();
2880           break;
2881         case TokenNameMINUS_GREATER :
2882           //          scanner.encapsedStringStack.pop();
2883           getNextToken();
2884           break;
2885         case TokenNameVariable :
2886         case TokenNameDOLLAR_LBRACE :
2887         case TokenNameCURLY_OPEN :
2888           encaps_var();
2889           break;
2890         //        case TokenNameDOLLAR :
2891         //          getNextToken();
2892         //          if (token == TokenNameLBRACE) {
2893         //            token = TokenNameDOLLAR_LBRACE;
2894         //            encaps_var();
2895         //          }
2896         //          break;
2897         default :
2898           char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
2899           if (encapsedChar == '$') {
2900             scanner.encapsedStringStack.pop();
2901             encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
2902             switch (encapsedChar) {
2903               case '`' :
2904                 if (token == TokenNameEncapsedString0) {
2905                   return;
2906                 }
2907                 token = TokenNameSTRING;
2908                 continue;
2909               case '\'' :
2910                 if (token == TokenNameEncapsedString1) {
2911                   return;
2912                 }
2913                 token = TokenNameSTRING;
2914                 continue;
2915               case '"' :
2916                 if (token == TokenNameEncapsedString2) {
2917                   return;
2918                 }
2919                 token = TokenNameSTRING;
2920                 continue;
2921             }
2922           }
2923           return;
2924       }
2925     }
2926   }
2927   private void encaps_var() {
2928     //                  T_VARIABLE
2929     //          | T_VARIABLE '[' encaps_var_offset ']'
2930     //          | T_VARIABLE T_OBJECT_OPERATOR T_STRING
2931     //          | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
2932     //          | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
2933     //          | T_CURLY_OPEN variable '}'
2934     switch (token) {
2935       case TokenNameVariable :
2936         getNextToken();
2937         if (token == TokenNameLBRACKET) {
2938           getNextToken();
2939           //          if (token == TokenNameRBRACKET) {
2940           //            getNextToken();
2941           //          } else {
2942           expr(); //encaps_var_offset();
2943           if (token != TokenNameRBRACKET) {
2944             throwSyntaxError("']' expected after variable.");
2945           }
2946           //          scanner.encapsedStringStack.pop();
2947           getNextToken();
2948           //          }
2949         } else if (token == TokenNameMINUS_GREATER) {
2950           getNextToken();
2951           if (token != TokenNameIdentifier) {
2952             throwSyntaxError("Identifier expected after '->'.");
2953           }
2954           //          scanner.encapsedStringStack.pop();
2955           getNextToken();
2956         }
2957         //        else {
2958         //          // scanner.encapsedStringStack.pop();
2959         //          int tempToken = TokenNameSTRING;
2960         //          if (!scanner.encapsedStringStack.isEmpty()
2961         //              && (token == TokenNameEncapsedString0
2962         //                  || token == TokenNameEncapsedString1
2963         //                  || token == TokenNameEncapsedString2 || token ==
2964         // TokenNameERROR)) {
2965         //            char encapsedChar = ((Character)
2966         // scanner.encapsedStringStack.peek())
2967         //                .charValue();
2968         //            switch (token) {
2969         //              case TokenNameEncapsedString0 :
2970         //                if (encapsedChar == '`') {
2971         //                  tempToken = TokenNameEncapsedString0;
2972         //                }
2973         //                break;
2974         //              case TokenNameEncapsedString1 :
2975         //                if (encapsedChar == '\'') {
2976         //                  tempToken = TokenNameEncapsedString1;
2977         //                }
2978         //                break;
2979         //              case TokenNameEncapsedString2 :
2980         //                if (encapsedChar == '"') {
2981         //                  tempToken = TokenNameEncapsedString2;
2982         //                }
2983         //                break;
2984         //              case TokenNameERROR :
2985         //                if (scanner.source[scanner.currentPosition - 1] == '\\') {
2986         //                  scanner.currentPosition--;
2987         //                  getNextToken();
2988         //                }
2989         //                break;
2990         //            }
2991         //          }
2992         //          token = tempToken;
2993         //        }
2994         break;
2995       case TokenNameDOLLAR_LBRACE :
2996         getNextToken();
2997         if (token == TokenNameIdentifier) {
2998           getNextToken();
2999           if (token == TokenNameLBRACKET) {
3000             getNextToken();
3001             //            if (token == TokenNameRBRACKET) {
3002             //              getNextToken();
3003             //            } else {
3004             expr();
3005             if (token != TokenNameRBRACKET) {
3006               throwSyntaxError("']' expected after '${'.");
3007             }
3008             getNextToken();
3009             //            }
3010           }
3011           if (token != TokenNameRBRACE) {
3012             throwSyntaxError("'}' expected after '${'.");
3013           }
3014           //          scanner.encapsedStringStack.pop();
3015           getNextToken();
3016         } else {
3017           expr();
3018           if (token != TokenNameRBRACE) {
3019             throwSyntaxError("'}' expected.");
3020           }
3021           //          scanner.encapsedStringStack.pop();
3022           getNextToken();
3023         }
3024         break;
3025       case TokenNameCURLY_OPEN :
3026         getNextToken();
3027         if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3028           getNextToken();
3029           if (token == TokenNameLBRACKET) {
3030             getNextToken();
3031             //            if (token == TokenNameRBRACKET) {
3032             //              getNextToken();
3033             //            } else {
3034             expr();
3035             if (token != TokenNameRBRACKET) {
3036               throwSyntaxError("']' expected after '{$'.");
3037             }
3038             getNextToken();
3039             //            }
3040           } else if (token == TokenNameMINUS_GREATER) {
3041             getNextToken();
3042             if (token != TokenNameIdentifier) {
3043               throwSyntaxError("String token expected.");
3044             }
3045             getNextToken();
3046           }
3047           //          if (token != TokenNameRBRACE) {
3048           //            throwSyntaxError("'}' expected after '{$'.");
3049           //          }
3050           //          // scanner.encapsedStringStack.pop();
3051           //          getNextToken();
3052         } else {
3053           expr();
3054           if (token != TokenNameRBRACE) {
3055             throwSyntaxError("'}' expected.");
3056           }
3057           //          scanner.encapsedStringStack.pop();
3058           getNextToken();
3059         }
3060         break;
3061     }
3062   }
3063   private void encaps_var_offset() {
3064     //                  T_STRING
3065     //          | T_NUM_STRING
3066     //          | T_VARIABLE
3067     switch (token) {
3068       case TokenNameSTRING :
3069         getNextToken();
3070         break;
3071       case TokenNameIntegerLiteral :
3072         getNextToken();
3073         break;
3074       case TokenNameVariable :
3075         getNextToken();
3076         break;
3077       case TokenNameIdentifier :
3078         getNextToken();
3079         break;
3080       default :
3081         throwSyntaxError("Variable or String token expected.");
3082         break;
3083     }
3084   }
3085   private void internal_functions_in_yacc() {
3086     int start = 0;
3087     ImportReference impt = null;
3088     switch (token) {
3089       case TokenNameisset :
3090         //      T_ISSET '(' isset_variables ')'
3091         getNextToken();
3092         if (token != TokenNameLPAREN) {
3093           throwSyntaxError("'(' expected after keyword 'isset'");
3094         }
3095         getNextToken();
3096         isset_variables();
3097         if (token != TokenNameRPAREN) {
3098           throwSyntaxError("')' expected after keyword 'isset'");
3099         }
3100         getNextToken();
3101         break;
3102       case TokenNameempty :
3103         //      T_EMPTY '(' variable ')'
3104         getNextToken();
3105         if (token != TokenNameLPAREN) {
3106           throwSyntaxError("'(' expected after keyword 'empty'");
3107         }
3108         getNextToken();
3109         variable();
3110         if (token != TokenNameRPAREN) {
3111           throwSyntaxError("')' expected after keyword 'empty'");
3112         }
3113         getNextToken();
3114         break;
3115       case TokenNameinclude :
3116         //T_INCLUDE expr
3117         start = scanner.getCurrentTokenStartPosition();
3118         getNextToken();
3119         expr();
3120
3121         impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3122         impt.declarationSourceEnd = impt.sourceEnd;
3123         impt.declarationEnd = impt.declarationSourceEnd;
3124         //endPosition is just before the ;
3125         impt.declarationSourceStart = start;
3126         includesList.add(impt);
3127         break;
3128       case TokenNameinclude_once :
3129         //      T_INCLUDE_ONCE expr
3130         start = scanner.getCurrentTokenStartPosition();
3131         getNextToken();
3132         expr();
3133         impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3134         impt.declarationSourceEnd = impt.sourceEnd;
3135         impt.declarationEnd = impt.declarationSourceEnd;
3136         //endPosition is just before the ;
3137         impt.declarationSourceStart = start;
3138         includesList.add(impt);
3139         break;
3140       case TokenNameeval :
3141         //      T_EVAL '(' expr ')'
3142         getNextToken();
3143         if (token != TokenNameLPAREN) {
3144           throwSyntaxError("'(' expected after keyword 'eval'");
3145         }
3146         getNextToken();
3147         expr();
3148         if (token != TokenNameRPAREN) {
3149           throwSyntaxError("')' expected after keyword 'eval'");
3150         }
3151         getNextToken();
3152         break;
3153       case TokenNamerequire :
3154         //T_REQUIRE expr
3155         start = scanner.getCurrentTokenStartPosition();
3156         getNextToken();
3157         expr();
3158         impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3159         impt.declarationSourceEnd = impt.sourceEnd;
3160         impt.declarationEnd = impt.declarationSourceEnd;
3161         //endPosition is just before the ;
3162         impt.declarationSourceStart = start;
3163         includesList.add(impt);
3164         break;
3165       case TokenNamerequire_once :
3166         //      T_REQUIRE_ONCE expr
3167         start = scanner.getCurrentTokenStartPosition();
3168         getNextToken();
3169         expr();
3170         impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3171         impt.declarationSourceEnd = impt.sourceEnd;
3172         impt.declarationEnd = impt.declarationSourceEnd;
3173         //endPosition is just before the ;
3174         impt.declarationSourceStart = start;
3175         includesList.add(impt);
3176         break;
3177     }
3178   }
3179   private void isset_variables() {
3180     //  variable
3181     //  | isset_variables ','
3182     if (token == TokenNameRPAREN) {
3183       throwSyntaxError("Variable expected after keyword 'isset'");
3184     }
3185     while (true) {
3186       variable();
3187       if (token == TokenNameCOMMA) {
3188         getNextToken();
3189       } else {
3190         break;
3191       }
3192     }
3193   }
3194   private boolean common_scalar() {
3195     //  common_scalar:
3196     //  T_LNUMBER
3197     //  | T_DNUMBER
3198     //  | T_CONSTANT_ENCAPSED_STRING
3199     //  | T_LINE
3200     //  | T_FILE
3201     //  | T_CLASS_C
3202     //  | T_METHOD_C
3203     //  | T_FUNC_C
3204     switch (token) {
3205       case TokenNameIntegerLiteral :
3206         getNextToken();
3207         return true;
3208       case TokenNameDoubleLiteral :
3209         getNextToken();
3210         return true;
3211       case TokenNameStringDoubleQuote :
3212         getNextToken();
3213         return true;
3214       case TokenNameStringSingleQuote :
3215         getNextToken();
3216         return true;
3217       case TokenNameStringInterpolated :
3218         getNextToken();
3219         return true;
3220       case TokenNameFILE :
3221         getNextToken();
3222         return true;
3223       case TokenNameLINE :
3224         getNextToken();
3225         return true;
3226       case TokenNameCLASS_C :
3227         getNextToken();
3228         return true;
3229       case TokenNameMETHOD_C :
3230         getNextToken();
3231         return true;
3232       case TokenNameFUNC_C :
3233         getNextToken();
3234         return true;
3235     }
3236     return false;
3237   }
3238   private void scalar() {
3239     //  scalar:
3240     //  T_STRING
3241     //| T_STRING_VARNAME
3242     //| class_constant
3243     //| common_scalar
3244     //| '"' encaps_list '"'
3245     //| '\'' encaps_list '\''
3246     //| T_START_HEREDOC encaps_list T_END_HEREDOC
3247     throwSyntaxError("Not yet implemented (scalar).");
3248   }
3249   private void static_scalar() {
3250     //    static_scalar: /* compile-time evaluated scalars */
3251     //          common_scalar
3252     //  | T_STRING
3253     //  | '+' static_scalar
3254     //  | '-' static_scalar
3255     //  | T_ARRAY '(' static_array_pair_list ')'
3256     //  | static_class_constant
3257     if (common_scalar()) {
3258       return;
3259     }
3260     switch (token) {
3261       case TokenNameIdentifier :
3262         getNextToken();
3263         //        static_class_constant:
3264         //              T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3265         if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3266           getNextToken();
3267           if (token == TokenNameIdentifier) {
3268             getNextToken();
3269           } else {
3270             throwSyntaxError("Identifier expected after '::' operator.");
3271           }
3272         }
3273         break;
3274       case TokenNameEncapsedString0 :
3275         try {
3276           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3277           while (scanner.currentCharacter != '`') {
3278             if (scanner.currentCharacter == '\\') {
3279               scanner.currentPosition++;
3280             }
3281             scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3282           }
3283           getNextToken();
3284         } catch (IndexOutOfBoundsException e) {
3285           throwSyntaxError("'`' expected at end of static string.");
3286         }
3287         break;
3288       case TokenNameEncapsedString1 :
3289         try {
3290           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3291           while (scanner.currentCharacter != '\'') {
3292             if (scanner.currentCharacter == '\\') {
3293               scanner.currentPosition++;
3294             }
3295             scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3296           }
3297           getNextToken();
3298         } catch (IndexOutOfBoundsException e) {
3299           throwSyntaxError("'\'' expected at end of static string.");
3300         }
3301         break;
3302       case TokenNameEncapsedString2 :
3303         try {
3304           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3305           while (scanner.currentCharacter != '"') {
3306             if (scanner.currentCharacter == '\\') {
3307               scanner.currentPosition++;
3308             }
3309             scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3310           }
3311           getNextToken();
3312         } catch (IndexOutOfBoundsException e) {
3313           throwSyntaxError("'\"' expected at end of static string.");
3314         }
3315         break;
3316       case TokenNamePLUS :
3317         getNextToken();
3318         static_scalar();
3319         break;
3320       case TokenNameMINUS :
3321         getNextToken();
3322         static_scalar();
3323         break;
3324       case TokenNamearray :
3325         getNextToken();
3326         if (token != TokenNameLPAREN) {
3327           throwSyntaxError("'(' expected after keyword 'array'");
3328         }
3329         getNextToken();
3330         if (token == TokenNameRPAREN) {
3331           getNextToken();
3332           break;
3333         }
3334         non_empty_static_array_pair_list();
3335         if (token != TokenNameRPAREN) {
3336           throwSyntaxError("')' expected after keyword 'array'");
3337         }
3338         getNextToken();
3339         break;
3340       //      case TokenNamenull :
3341       //        getNextToken();
3342       //        break;
3343       //      case TokenNamefalse :
3344       //        getNextToken();
3345       //        break;
3346       //      case TokenNametrue :
3347       //        getNextToken();
3348       //        break;
3349       default :
3350         throwSyntaxError("Static scalar/constant expected.");
3351     }
3352   }
3353   private void non_empty_static_array_pair_list() {
3354     //  non_empty_static_array_pair_list:
3355     //  non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3356     // static_scalar
3357     //| non_empty_static_array_pair_list ',' static_scalar
3358     //| static_scalar T_DOUBLE_ARROW static_scalar
3359     //| static_scalar
3360     while (true) {
3361       static_scalar();
3362       if (token == TokenNameEQUAL_GREATER) {
3363         getNextToken();
3364         static_scalar();
3365       }
3366       if (token != TokenNameCOMMA) {
3367         break;
3368       }
3369       getNextToken();
3370       if (token == TokenNameRPAREN) {
3371         break;
3372       }
3373     }
3374   }
3375   public void reportSyntaxError() { //int act, int currentKind, int
3376     // stateStackTop) {
3377     /* remember current scanner position */
3378     int startPos = scanner.startPosition;
3379     int currentPos = scanner.currentPosition;
3380     //          String[] expectings;
3381     //          String tokenName = name[symbol_index[currentKind]];
3382     //fetch all "accurate" possible terminals that could recover the error
3383     //          int start, end = start = asi(stack[stateStackTop]);
3384     //          while (asr[end] != 0)
3385     //                  end++;
3386     //          int length = end - start;
3387     //          expectings = new String[length];
3388     //          if (length != 0) {
3389     //                  char[] indexes = new char[length];
3390     //                  System.arraycopy(asr, start, indexes, 0, length);
3391     //                  for (int i = 0; i < length; i++) {
3392     //                          expectings[i] = name[symbol_index[indexes[i]]];
3393     //                  }
3394     //          }
3395     //if the pb is an EOF, try to tell the user that they are some
3396     //          if (tokenName.equals(UNEXPECTED_EOF)) {
3397     //                  if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3398     //                          char[] tokenSource;
3399     //                          try {
3400     //                                  tokenSource = this.scanner.getCurrentTokenSource();
3401     //                          } catch (Exception e) {
3402     //                                  tokenSource = new char[] {};
3403     //                          }
3404     //                          problemReporter().parseError(
3405     //                                  this.scanner.startPosition,
3406     //                                  this.scanner.currentPosition - 1,
3407     //                                  tokenSource,
3408     //                                  tokenName,
3409     //                                  expectings);
3410     //                  }
3411     //          } else { //the next test is HEAVILY grammar DEPENDENT.
3412     //                  if ((length == 14)
3413     //                          && (expectings[0] == "=") //$NON-NLS-1$
3414     //                          && (expectings[1] == "*=") //$NON-NLS-1$
3415     //                          && (expressionPtr > -1)) {
3416     //                                  switch(currentKind) {
3417     //                                          case TokenNameSEMICOLON:
3418     //                                          case TokenNamePLUS:
3419     //                                          case TokenNameMINUS:
3420     //                                          case TokenNameDIVIDE:
3421     //                                          case TokenNameREMAINDER:
3422     //                                          case TokenNameMULTIPLY:
3423     //                                          case TokenNameLEFT_SHIFT:
3424     //                                          case TokenNameRIGHT_SHIFT:
3425     //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3426     //                                          case TokenNameLESS:
3427     //                                          case TokenNameGREATER:
3428     //                                          case TokenNameLESS_EQUAL:
3429     //                                          case TokenNameGREATER_EQUAL:
3430     //                                          case TokenNameEQUAL_EQUAL:
3431     //                                          case TokenNameNOT_EQUAL:
3432     //                                          case TokenNameXOR:
3433     //                                          case TokenNameAND:
3434     //                                          case TokenNameOR:
3435     //                                          case TokenNameOR_OR:
3436     //                                          case TokenNameAND_AND:
3437     //                                                  // the ; is not the expected token ==> it ends a statement when an
3438     // expression is not ended
3439     //                                                  problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3440     //                                                  break;
3441     //                                          case TokenNameRBRACE :
3442     //                                                  problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3443     //                                                  break;
3444     //                                          default:
3445     //                                                  char[] tokenSource;
3446     //                                                  try {
3447     //                                                          tokenSource = this.scanner.getCurrentTokenSource();
3448     //                                                  } catch (Exception e) {
3449     //                                                          tokenSource = new char[] {};
3450     //                                                  }
3451     //                                                  problemReporter().parseError(
3452     //                                                          this.scanner.startPosition,
3453     //                                                          this.scanner.currentPosition - 1,
3454     //                                                          tokenSource,
3455     //                                                          tokenName,
3456     //                                                          expectings);
3457     //                                                  this.checkAndReportBracketAnomalies(problemReporter());
3458     //                                  }
3459     //                  } else {
3460     char[] tokenSource;
3461     try {
3462       tokenSource = this.scanner.getCurrentTokenSource();
3463     } catch (Exception e) {
3464       tokenSource = new char[]{};
3465     }
3466     //                          problemReporter().parseError(
3467     //                                  this.scanner.startPosition,
3468     //                                  this.scanner.currentPosition - 1,
3469     //                                  tokenSource,
3470     //                                  tokenName,
3471     //                                  expectings);
3472     this.checkAndReportBracketAnomalies(problemReporter());
3473     //                  }
3474     //          }
3475     /* reset scanner where it was */
3476     scanner.startPosition = startPos;
3477     scanner.currentPosition = currentPos;
3478   }
3479   public static final int RoundBracket = 0;
3480   public static final int SquareBracket = 1;
3481   public static final int CurlyBracket = 2;
3482   public static final int BracketKinds = 3;
3483   protected int[] nestedMethod; //the ptr is nestedType
3484   protected int nestedType, dimensions;
3485   //ast stack
3486   final static int AstStackIncrement = 100;
3487   protected int astPtr;
3488   protected AstNode[] astStack = new AstNode[AstStackIncrement];
3489   protected int astLengthPtr;
3490   protected int[] astLengthStack;
3491   AstNode[] noAstNodes = new AstNode[AstStackIncrement];
3492   public CompilationUnitDeclaration compilationUnit; /*
3493                                                       * the result from parse()
3494                                                       */
3495   protected ReferenceContext referenceContext;
3496   protected ProblemReporter problemReporter;
3497   protected CompilerOptions options;
3498   private ArrayList includesList;
3499   //  protected CompilationResult compilationResult;
3500   /**
3501    * Returns this parser's problem reporter initialized with its reference
3502    * context. Also it is assumed that a problem is going to be reported, so
3503    * initializes the compilation result's line positions.
3504    */
3505   public ProblemReporter problemReporter() {
3506     if (scanner.recordLineSeparator) {
3507       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
3508     }
3509     problemReporter.referenceContext = referenceContext;
3510     return problemReporter;
3511   }
3512   /*
3513    * Reconsider the entire source looking for inconsistencies in {} () []
3514    */
3515   public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
3516     scanner.wasAcr = false;
3517     boolean anomaliesDetected = false;
3518     try {
3519       char[] source = scanner.source;
3520       int[] leftCount = {0, 0, 0};
3521       int[] rightCount = {0, 0, 0};
3522       int[] depths = {0, 0, 0};
3523       int[][] leftPositions = new int[][]{new int[10], new int[10], new int[10]};
3524       int[][] leftDepths = new int[][]{new int[10], new int[10], new int[10]};
3525       int[][] rightPositions = new int[][]{new int[10], new int[10], new int[10]};
3526       int[][] rightDepths = new int[][]{new int[10], new int[10], new int[10]};
3527       scanner.currentPosition = scanner.initialPosition; //starting
3528       // point
3529       // (first-zero-based
3530       // char)
3531       while (scanner.currentPosition < scanner.eofPosition) { //loop for
3532         // jumping
3533         // over
3534         // comments
3535         try {
3536           // ---------Consume white space and handles
3537           // startPosition---------
3538           boolean isWhiteSpace;
3539           do {
3540             scanner.startPosition = scanner.currentPosition;
3541             //                                          if (((scanner.currentCharacter =
3542             // source[scanner.currentPosition++]) == '\\') &&
3543             // (source[scanner.currentPosition] == 'u')) {
3544             //                                                  isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
3545             //                                          } else {
3546             if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3547               if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3548                 // only record line positions we have not
3549                 // recorded yet
3550                 scanner.pushLineSeparator();
3551               }
3552             }
3553             isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
3554             //                                          }
3555           } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
3556           // -------consume token until } is found---------
3557           switch (scanner.currentCharacter) {
3558             case '{' : {
3559               int index = leftCount[CurlyBracket]++;
3560               if (index == leftPositions[CurlyBracket].length) {
3561                 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
3562                 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
3563               }
3564               leftPositions[CurlyBracket][index] = scanner.startPosition;
3565               leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
3566             }
3567               break;
3568             case '}' : {
3569               int index = rightCount[CurlyBracket]++;
3570               if (index == rightPositions[CurlyBracket].length) {
3571                 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
3572                 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
3573               }
3574               rightPositions[CurlyBracket][index] = scanner.startPosition;
3575               rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
3576             }
3577               break;
3578             case '(' : {
3579               int index = leftCount[RoundBracket]++;
3580               if (index == leftPositions[RoundBracket].length) {
3581                 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
3582                 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
3583               }
3584               leftPositions[RoundBracket][index] = scanner.startPosition;
3585               leftDepths[RoundBracket][index] = depths[RoundBracket]++;
3586             }
3587               break;
3588             case ')' : {
3589               int index = rightCount[RoundBracket]++;
3590               if (index == rightPositions[RoundBracket].length) {
3591                 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
3592                 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
3593               }
3594               rightPositions[RoundBracket][index] = scanner.startPosition;
3595               rightDepths[RoundBracket][index] = --depths[RoundBracket];
3596             }
3597               break;
3598             case '[' : {
3599               int index = leftCount[SquareBracket]++;
3600               if (index == leftPositions[SquareBracket].length) {
3601                 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
3602                 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
3603               }
3604               leftPositions[SquareBracket][index] = scanner.startPosition;
3605               leftDepths[SquareBracket][index] = depths[SquareBracket]++;
3606             }
3607               break;
3608             case ']' : {
3609               int index = rightCount[SquareBracket]++;
3610               if (index == rightPositions[SquareBracket].length) {
3611                 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
3612                 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
3613               }
3614               rightPositions[SquareBracket][index] = scanner.startPosition;
3615               rightDepths[SquareBracket][index] = --depths[SquareBracket];
3616             }
3617               break;
3618             case '\'' : {
3619               if (scanner.getNextChar('\\')) {
3620                 scanner.scanEscapeCharacter();
3621               } else { // consume next character
3622                 scanner.unicodeAsBackSlash = false;
3623                 //                                                                      if (((scanner.currentCharacter =
3624                 // source[scanner.currentPosition++]) ==
3625                 // '\\') &&
3626                 // (source[scanner.currentPosition] ==
3627                 // 'u')) {
3628                 //                                                                              scanner.getNextUnicodeChar();
3629                 //                                                                      } else {
3630                 if (scanner.withoutUnicodePtr != 0) {
3631                   scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3632                 }
3633                 //                                                                      }
3634               }
3635               scanner.getNextChar('\'');
3636               break;
3637             }
3638             case '"' :
3639               // consume next character
3640               scanner.unicodeAsBackSlash = false;
3641               //                                                        if (((scanner.currentCharacter =
3642               // source[scanner.currentPosition++]) == '\\') &&
3643               // (source[scanner.currentPosition] == 'u')) {
3644               //                                                                scanner.getNextUnicodeChar();
3645               //                                                        } else {
3646               if (scanner.withoutUnicodePtr != 0) {
3647                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3648               }
3649               //                                                        }
3650               while (scanner.currentCharacter != '"') {
3651                 if (scanner.currentCharacter == '\r') {
3652                   if (source[scanner.currentPosition] == '\n')
3653                     scanner.currentPosition++;
3654                   break; // the string cannot go further that
3655                   // the line
3656                 }
3657                 if (scanner.currentCharacter == '\n') {
3658                   break; // the string cannot go further that
3659                   // the line
3660                 }
3661                 if (scanner.currentCharacter == '\\') {
3662                   scanner.scanEscapeCharacter();
3663                 }
3664                 // consume next character
3665                 scanner.unicodeAsBackSlash = false;
3666                 //                                                              if (((scanner.currentCharacter =
3667                 // source[scanner.currentPosition++]) == '\\')
3668                 // && (source[scanner.currentPosition] == 'u'))
3669                 // {
3670                 //                                                                      scanner.getNextUnicodeChar();
3671                 //                                                              } else {
3672                 if (scanner.withoutUnicodePtr != 0) {
3673                   scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3674                 }
3675                 //                                                              }
3676               }
3677               break;
3678             case '/' : {
3679               int test;
3680               if ((test = scanner.getNextChar('/', '*')) == 0) { //line
3681                 // comment
3682                 //get the next char
3683                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3684                     && (source[scanner.currentPosition] == 'u')) {
3685                   //-------------unicode traitement
3686                   // ------------
3687                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3688                   scanner.currentPosition++;
3689                   while (source[scanner.currentPosition] == 'u') {
3690                     scanner.currentPosition++;
3691                   }
3692                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3693                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3694                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3695                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3696                                                                                                                // don't
3697                     // care of the
3698                     // value
3699                     scanner.currentCharacter = 'A';
3700                   } //something different from \n and \r
3701                   else {
3702                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3703                   }
3704                 }
3705                 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
3706                   //get the next char
3707                   scanner.startPosition = scanner.currentPosition;
3708                   if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3709                       && (source[scanner.currentPosition] == 'u')) {
3710                     //-------------unicode traitement
3711                     // ------------
3712                     int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3713                     scanner.currentPosition++;
3714                     while (source[scanner.currentPosition] == 'u') {
3715                       scanner.currentPosition++;
3716                     }
3717                     if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3718                         || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3719                         || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3720                         || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3721                                                                                                                  // don't
3722                       // care of the
3723                       // value
3724                       scanner.currentCharacter = 'A';
3725                     } //something different from \n
3726                     // and \r
3727                     else {
3728                       scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3729                     }
3730                   }
3731                 }
3732                 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3733                   if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3734                     // only record line positions we
3735                     // have not recorded yet
3736                     scanner.pushLineSeparator();
3737                     if (this.scanner.taskTags != null) {
3738                       this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
3739                           .getCurrentTokenEndPosition());
3740                     }
3741                   }
3742                 }
3743                 break;
3744               }
3745               if (test > 0) { //traditional and annotation
3746                 // comment
3747                 boolean star = false;
3748                 // consume next character
3749                 scanner.unicodeAsBackSlash = false;
3750                 //                                                                      if (((scanner.currentCharacter =
3751                 // source[scanner.currentPosition++]) ==
3752                 // '\\') &&
3753                 // (source[scanner.currentPosition] ==
3754                 // 'u')) {
3755                 //                                                                              scanner.getNextUnicodeChar();
3756                 //                                                                      } else {
3757                 if (scanner.withoutUnicodePtr != 0) {
3758                   scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3759                 }
3760                 //                                                                      }
3761                 if (scanner.currentCharacter == '*') {
3762                   star = true;
3763                 }
3764                 //get the next char
3765                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3766                     && (source[scanner.currentPosition] == 'u')) {
3767                   //-------------unicode traitement
3768                   // ------------
3769                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3770                   scanner.currentPosition++;
3771                   while (source[scanner.currentPosition] == 'u') {
3772                     scanner.currentPosition++;
3773                   }
3774                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3775                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3776                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3777                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3778                                                                                                                // don't
3779                     // care of the
3780                     // value
3781                     scanner.currentCharacter = 'A';
3782                   } //something different from * and /
3783                   else {
3784                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3785                   }
3786                 }
3787                 //loop until end of comment */
3788                 while ((scanner.currentCharacter != '/') || (!star)) {
3789                   star = scanner.currentCharacter == '*';
3790                   //get next char
3791                   if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3792                       && (source[scanner.currentPosition] == 'u')) {
3793                     //-------------unicode traitement
3794                     // ------------
3795                     int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3796                     scanner.currentPosition++;
3797                     while (source[scanner.currentPosition] == 'u') {
3798                       scanner.currentPosition++;
3799                     }
3800                     if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3801                         || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3802                         || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3803                         || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3804                                                                                                                  // don't
3805                       // care of the
3806                       // value
3807                       scanner.currentCharacter = 'A';
3808                     } //something different from * and
3809                     // /
3810                     else {
3811                       scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3812                     }
3813                   }
3814                 }
3815                 if (this.scanner.taskTags != null) {
3816                   this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
3817                 }
3818                 break;
3819               }
3820               break;
3821             }
3822             default :
3823               if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
3824                 scanner.scanIdentifierOrKeyword(false);
3825                 break;
3826               }
3827               if (Character.isDigit(scanner.currentCharacter)) {
3828                 scanner.scanNumber(false);
3829                 break;
3830               }
3831           }
3832           //-----------------end switch while
3833           // try--------------------
3834         } catch (IndexOutOfBoundsException e) {
3835           break; // read until EOF
3836         } catch (InvalidInputException e) {
3837           return false; // no clue
3838         }
3839       }
3840       if (scanner.recordLineSeparator) {
3841         //                              compilationUnit.compilationResult.lineSeparatorPositions =
3842         // scanner.getLineEnds();
3843       }
3844       // check placement anomalies against other kinds of brackets
3845       for (int kind = 0; kind < BracketKinds; kind++) {
3846         for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
3847           int start = leftPositions[kind][leftIndex]; // deepest
3848           // first
3849           // find matching closing bracket
3850           int depth = leftDepths[kind][leftIndex];
3851           int end = -1;
3852           for (int i = 0; i < rightCount[kind]; i++) {
3853             int pos = rightPositions[kind][i];
3854             // want matching bracket further in source with same
3855             // depth
3856             if ((pos > start) && (depth == rightDepths[kind][i])) {
3857               end = pos;
3858               break;
3859             }
3860           }
3861           if (end < 0) { // did not find a good closing match
3862             problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
3863             return true;
3864           }
3865           // check if even number of opening/closing other brackets
3866           // in between this pair of brackets
3867           int balance = 0;
3868           for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
3869             for (int i = 0; i < leftCount[otherKind]; i++) {
3870               int pos = leftPositions[otherKind][i];
3871               if ((pos > start) && (pos < end))
3872                 balance++;
3873             }
3874             for (int i = 0; i < rightCount[otherKind]; i++) {
3875               int pos = rightPositions[otherKind][i];
3876               if ((pos > start) && (pos < end))
3877                 balance--;
3878             }
3879             if (balance != 0) {
3880               problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
3881               // anomaly
3882               return true;
3883             }
3884           }
3885         }
3886         // too many opening brackets ?
3887         for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
3888           anomaliesDetected = true;
3889           problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
3890               compilationUnit.compilationResult);
3891         }
3892         // too many closing brackets ?
3893         for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
3894           anomaliesDetected = true;
3895           problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
3896         }
3897         if (anomaliesDetected)
3898           return true;
3899       }
3900       return anomaliesDetected;
3901     } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
3902       return anomaliesDetected;
3903     } catch (NullPointerException e) { // jdk1.2.2 jit bug
3904       return anomaliesDetected;
3905     }
3906   }
3907   protected void pushOnAstLengthStack(int pos) {
3908     try {
3909       astLengthStack[++astLengthPtr] = pos;
3910     } catch (IndexOutOfBoundsException e) {
3911       int oldStackLength = astLengthStack.length;
3912       int[] oldPos = astLengthStack;
3913       astLengthStack = new int[oldStackLength + StackIncrement];
3914       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
3915       astLengthStack[astLengthPtr] = pos;
3916     }
3917   }
3918   protected void pushOnAstStack(AstNode node) {
3919     /*
3920      * add a new obj on top of the ast stack
3921      */
3922     try {
3923       astStack[++astPtr] = node;
3924     } catch (IndexOutOfBoundsException e) {
3925       int oldStackLength = astStack.length;
3926       AstNode[] oldStack = astStack;
3927       astStack = new AstNode[oldStackLength + AstStackIncrement];
3928       System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
3929       astPtr = oldStackLength;
3930       astStack[astPtr] = node;
3931     }
3932     try {
3933       astLengthStack[++astLengthPtr] = 1;
3934     } catch (IndexOutOfBoundsException e) {
3935       int oldStackLength = astLengthStack.length;
3936       int[] oldPos = astLengthStack;
3937       astLengthStack = new int[oldStackLength + AstStackIncrement];
3938       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
3939       astLengthStack[astLengthPtr] = 1;
3940     }
3941   }
3942
3943   protected void resetModifiers() {
3944     this.modifiers = AccDefault;
3945     this.modifiersSourceStart = -1; // <-- see comment into
3946     // modifiersFlag(int)
3947     this.scanner.commentPtr = -1;
3948   }
3949 }