suppress "variable not initialized" error for break statements. In switch-case statem...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Parser.java
1 /***********************************************************************************************************************************
2  * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material are made available under the
3  * terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4  * http://www.eclipse.org/legal/cpl-v10.html
5  *
6  * Contributors: www.phpeclipse.de
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
9
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.HashSet;
13
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
17 import net.sourceforge.phpdt.internal.compiler.ast.AND_AND_Expression;
18 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
19 import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
20 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
21 import net.sourceforge.phpdt.internal.compiler.ast.Block;
22 import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement;
23 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
24 import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression;
25 import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement;
26 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
27 import net.sourceforge.phpdt.internal.compiler.ast.Expression;
28 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
29 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
30 import net.sourceforge.phpdt.internal.compiler.ast.IfStatement;
31 import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
32 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
33 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
34 import net.sourceforge.phpdt.internal.compiler.ast.OR_OR_Expression;
35 import net.sourceforge.phpdt.internal.compiler.ast.OperatorIds;
36 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
37 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
38 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
39 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
40 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralDQ;
41 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralSQ;
42 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
43 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
44 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
45 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
46 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
47 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
48 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
49 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
50 import net.sourceforge.phpdt.internal.compiler.util.Util;
51 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
52 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
53 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
54
55 import org.eclipse.core.resources.IFile;
56 import org.eclipse.core.resources.IProject;
57 import org.eclipse.core.resources.IResource;
58 import org.eclipse.core.runtime.IPath;
59
60 public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
61         protected final static int StackIncrement = 255;
62
63         protected int stateStackTop;
64
65         // protected int[] stack = new int[StackIncrement];
66
67         public int firstToken; // handle for multiple parsing goals
68
69         public int lastAct; // handle for multiple parsing goals
70
71         // protected RecoveredElement currentElement;
72
73         public static boolean VERBOSE_RECOVERY = false;
74
75         protected boolean diet = false; // tells the scanner to jump over some
76
77         /**
78          * the PHP token scanner
79          */
80         public Scanner scanner;
81
82         int token;
83
84         protected int modifiers;
85
86         protected int modifiersSourceStart;
87
88         protected Parser(ProblemReporter problemReporter) {
89                 this.problemReporter = problemReporter;
90                 this.options = problemReporter.options;
91                 this.token = TokenNameEOF;
92                 this.initializeScanner();
93         }
94
95         public void setFileToParse(IFile fileToParse) {
96                 this.token = TokenNameEOF;
97                 this.initializeScanner();
98         }
99
100         /**
101          * ClassDeclaration Constructor.
102          *
103          * @param s
104          * @param sess
105          *          Description of Parameter
106          * @see
107          */
108         public Parser(IFile fileToParse) {
109                 // if (keywordMap == null) {
110                 // keywordMap = new HashMap();
111                 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
112                 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
113                 // }
114                 // }
115                 // this.currentPHPString = 0;
116                 // PHPParserSuperclass.fileToParse = fileToParse;
117                 // this.phpList = null;
118                 this.includesList = null;
119                 // this.str = "";
120                 this.token = TokenNameEOF;
121                 // this.chIndx = 0;
122                 // this.rowCount = 1;
123                 // this.columnCount = 0;
124                 // this.phpEnd = false;
125                 // getNextToken();
126                 this.initializeScanner();
127         }
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 */, true/* isTaskCaseSensitive */);
133         }
134
135         /**
136          * Create marker for the parse error
137          */
138         // private void setMarker(String message, int charStart, int charEnd, int
139         // errorLevel) {
140         // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
141         // }
142         /**
143          * This method will throw the SyntaxError. It will add the good lines and
144          * columns to the Error
145          *
146          * @param error
147          *          the error message
148          * @throws SyntaxError
149          *           the error raised
150          */
151         private void throwSyntaxError(String error) {
152                 int problemStartPosition = scanner.getCurrentTokenStartPosition();
153                 int problemEndPosition = scanner.getCurrentTokenEndPosition() + 1;
154                 if (scanner.source.length <= problemEndPosition && problemEndPosition > 0) {
155                         problemEndPosition = scanner.source.length - 1;
156                         if (problemStartPosition > 0 && problemStartPosition >= problemEndPosition && problemEndPosition > 0) {
157                                 problemStartPosition = problemEndPosition - 1;
158                         }
159                 }
160                 throwSyntaxError(error, problemStartPosition, problemEndPosition);
161         }
162
163         /**
164          * This method will throw the SyntaxError. It will add the good lines and
165          * columns to the Error
166          *
167          * @param error
168          *          the error message
169          * @throws SyntaxError
170          *           the error raised
171          */
172         // private void throwSyntaxError(String error, int startRow) {
173         // throw new SyntaxError(startRow, 0, " ", error);
174         // }
175         private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
176                 if (referenceContext != null) {
177                         problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
178                                         compilationUnit.compilationResult);
179                 }
180                 throw new SyntaxError(1, 0, " ", error);
181         }
182
183         private void reportSyntaxError(String error) {
184                 int problemStartPosition = scanner.getCurrentTokenStartPosition();
185                 int problemEndPosition = scanner.getCurrentTokenEndPosition();
186                 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
187         }
188
189         private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
190                 if (referenceContext != null) {
191                         problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
192                                         compilationUnit.compilationResult);
193                 }
194         }
195
196         // private void reportSyntaxWarning(String error, int problemStartPosition,
197         // int problemEndPosition) {
198         // if (referenceContext != null) {
199         // problemReporter.phpParsingWarning(new String[] { error },
200         // problemStartPosition, problemEndPosition, referenceContext,
201         // compilationUnit.compilationResult);
202         // }
203         // }
204
205         /**
206          * gets the next token from input
207          */
208         private void getNextToken() {
209                 try {
210                         token = scanner.getNextToken();
211                         if (Scanner.DEBUG) {
212                                 int currentEndPosition = scanner.getCurrentTokenEndPosition();
213                                 int currentStartPosition = scanner.getCurrentTokenStartPosition();
214                                 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
215                                 System.out.println(scanner.toStringAction(token));
216                         }
217                 } catch (InvalidInputException e) {
218                         token = TokenNameERROR;
219                         String detailedMessage = e.getMessage();
220
221                         if (detailedMessage == Scanner.UNTERMINATED_STRING) {
222                                 throwSyntaxError("Unterminated string.");
223                         } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
224                                 throwSyntaxError("Unterminated commment.");
225                         }
226                 }
227                 return;
228         }
229
230         public void init(String s) {
231                 // this.str = s;
232                 this.token = TokenNameEOF;
233                 this.includesList = new ArrayList();
234                 // this.chIndx = 0;
235                 // this.rowCount = 1;
236                 // this.columnCount = 0;
237                 // this.phpEnd = false;
238                 // this.phpMode = false;
239                 /* scanner initialization */
240                 scanner.setSource(s.toCharArray());
241                 scanner.setPHPMode(false);
242                 astPtr = 0;
243         }
244
245         protected void initialize(boolean phpMode) {
246                 initialize(phpMode, null);
247         }
248
249         protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
250                 compilationUnit = null;
251                 referenceContext = null;
252                 this.includesList = new ArrayList();
253                 // this.indexManager = indexManager;
254                 // this.str = "";
255                 this.token = TokenNameEOF;
256                 // this.chIndx = 0;
257                 // this.rowCount = 1;
258                 // this.columnCount = 0;
259                 // this.phpEnd = false;
260                 // this.phpMode = phpMode;
261                 scanner.setPHPMode(phpMode);
262                 astPtr = 0;
263         }
264
265         /**
266          * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt;
267          * &lt;/body&gt;'
268          */
269         public void parse(String s) {
270                 parse(s, null);
271         }
272
273         /**
274          * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt;
275          * &lt;/body&gt;'
276          */
277         public void parse(String s, HashMap variables) {
278                 fMethodVariables = variables;
279                 fStackUnassigned = new ArrayList();
280                 init(s);
281                 parse();
282         }
283
284         /**
285          * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt;
286          * &lt;/body&gt;'
287          */
288         protected void parse() {
289                 if (scanner.compilationUnit != null) {
290                         IResource resource = scanner.compilationUnit.getResource();
291                         if (resource != null && resource instanceof IFile) {
292                                 // set the package name
293                                 consumePackageDeclarationName((IFile) resource);
294                         }
295                 }
296                 getNextToken();
297                 do {
298                         try {
299                                 if (token != TokenNameEOF && token != TokenNameERROR) {
300                                         statementList();
301                                 }
302                                 if (token != TokenNameEOF) {
303                                         if (token == TokenNameERROR) {
304                                                 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
305                                         }
306                                         if (token == TokenNameRPAREN) {
307                                                 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
308                                         }
309                                         if (token == TokenNameRBRACE) {
310                                                 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
311                                         }
312                                         if (token == TokenNameRBRACKET) {
313                                                 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
314                                         }
315                                         if (token == TokenNameLPAREN) {
316                                                 throwSyntaxError("Read character '('; end-of-file not reached.");
317                                         }
318                                         if (token == TokenNameLBRACE) {
319                                                 throwSyntaxError("Read character '{';  end-of-file not reached.");
320                                         }
321                                         if (token == TokenNameLBRACKET) {
322                                                 throwSyntaxError("Read character '[';  end-of-file not reached.");
323                                         }
324                                         throwSyntaxError("End-of-file not reached.");
325                                 }
326                                 break;
327                         } catch (SyntaxError syntaxError) {
328                                 // syntaxError.printStackTrace();
329                                 break;
330                         }
331                 } while (true);
332
333                 endParse(0);
334         }
335
336         /**
337          * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt;
338          * &lt;/body&gt;'
339          */
340         public void parseFunction(String s, HashMap variables) {
341                 init(s);
342                 scanner.phpMode = true;
343                 parseFunction(variables);
344         }
345
346         /**
347          * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt;
348          * &lt;/body&gt;'
349          */
350         protected void parseFunction(HashMap variables) {
351                 getNextToken();
352                 boolean hasModifiers = member_modifiers();
353                 if (token == TokenNamefunction) {
354                         if (!hasModifiers) {
355                                 checkAndSetModifiers(AccPublic);
356                         }
357                         this.fMethodVariables = variables;
358
359                         MethodDeclaration methodDecl = new MethodDeclaration(null);
360                         methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
361                         methodDecl.modifiers = this.modifiers;
362                         methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
363                         try {
364                                 getNextToken();
365                                 functionDefinition(methodDecl);
366                         } catch (SyntaxError sytaxErr1) {
367                                 return;
368                         } finally {
369                                 int sourceEnd = methodDecl.sourceEnd;
370                                 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
371                                         sourceEnd = methodDecl.declarationSourceStart + 1;
372                                 }
373                                 methodDecl.sourceEnd = sourceEnd;
374                                 methodDecl.declarationSourceEnd = sourceEnd;
375                         }
376                 }
377         }
378
379         protected CompilationUnitDeclaration endParse(int act) {
380
381                 this.lastAct = act;
382
383                 // if (currentElement != null) {
384                 // currentElement.topElement().updateParseTree();
385                 // if (VERBOSE_RECOVERY) {
386                 // System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
387                 // System.out.println("--------------------------"); //$NON-NLS-1$
388                 // System.out.println(compilationUnit);
389                 // System.out.println("----------------------------------"); //$NON-NLS-1$
390                 // }
391                 // } else {
392                 if (diet & VERBOSE_RECOVERY) {
393                         System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
394                         System.out.println("--------------------------"); //$NON-NLS-1$
395                         System.out.println(compilationUnit);
396                         System.out.println("----------------------------------"); //$NON-NLS-1$
397                 }
398                 // }
399                 if (scanner.recordLineSeparator) {
400                         compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
401                 }
402                 if (scanner.taskTags != null) {
403                         for (int i = 0; i < scanner.foundTaskCount; i++) {
404                                 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
405                                                 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
406                                                 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
407                         }
408                 }
409                 compilationUnit.imports = new ImportReference[includesList.size()];
410                 for (int i = 0; i < includesList.size(); i++) {
411                         compilationUnit.imports[i] = (ImportReference) includesList.get(i);
412                 }
413                 return compilationUnit;
414         }
415
416         private Block statementList() {
417                 boolean branchStatement = false;
418                 Statement statement;
419                 int blockStart = scanner.getCurrentTokenStartPosition();
420                 ArrayList blockStatements = new ArrayList();
421                 do {
422                         try {
423                                 statement = statement();
424                                 blockStatements.add(statement);
425                                 if (token == TokenNameEOF) {
426                                         return null;
427                                 }
428                                 if (branchStatement && statement != null) {
429                                         // reportSyntaxError("Unreachable code", statement.sourceStart,
430                                         // statement.sourceEnd);
431                                         if (! (statement instanceof BreakStatement)) {
432                                                 /* don't give an error for break statement following return statement
433                                                 Technically it's unreachable code, but in switch-case it's recommended to
434                                                 avoid accidental fall-through later when editing the code */
435                                                 problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart,
436                                                         statement.sourceEnd, referenceContext, compilationUnit.compilationResult);
437                                         }
438                                 }
439                                 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
440                                                 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
441                                                 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
442                                                 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
443                                         return createBlock(blockStart, blockStatements);
444                                 }
445                                 branchStatement = checkUnreachableStatements(statement);
446                         } catch (SyntaxError sytaxErr1) {
447                                 // if an error occured,
448                                 // try to find keywords
449                                 // to parse the rest of the string
450                                 boolean tokenize = scanner.tokenizeStrings;
451                                 if (!tokenize) {
452                                         scanner.tokenizeStrings = true;
453                                 }
454                                 try {
455                                         while (token != TokenNameEOF) {
456                                                 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
457                                                                 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
458                                                                 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
459                                                                 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
460                                                         return createBlock(blockStart, blockStatements);
461                                                 }
462                                                 if (token == TokenNameif || token == TokenNameswitch || token == TokenNamefor || token == TokenNamewhile
463                                                                 || token == TokenNamedo || token == TokenNameforeach || token == TokenNamecontinue || token == TokenNamebreak
464                                                                 || token == TokenNamereturn || token == TokenNameexit || token == TokenNameecho || token == TokenNameECHO_INVISIBLE
465                                                                 || token == TokenNameglobal || token == TokenNamestatic || token == TokenNameunset || token == TokenNamefunction
466                                                                 || token == TokenNamedeclare || token == TokenNametry || token == TokenNamecatch || token == TokenNamethrow
467                                                                 || token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
468                                                         break;
469                                                 }
470                                                 // System.out.println(scanner.toStringAction(token));
471                                                 getNextToken();
472                                                 // System.out.println(scanner.toStringAction(token));
473                                         }
474                                         if (token == TokenNameEOF) {
475                                                 throw sytaxErr1;
476                                         }
477                                 } finally {
478                                         scanner.tokenizeStrings = tokenize;
479                                 }
480                         }
481                 } while (true);
482         }
483
484         /**
485          * @param statement
486          * @return
487          */
488         private boolean checkUnreachableStatements(Statement statement) {
489                 if (statement instanceof ReturnStatement || statement instanceof ContinueStatement || statement instanceof BreakStatement) {
490                         return true;
491                 } else if (statement instanceof IfStatement && ((IfStatement) statement).checkUnreachable) {
492                         return true;
493                 }
494                 return false;
495         }
496
497         /**
498          * @param blockStart
499          * @param blockStatements
500          * @return
501          */
502         private Block createBlock(int blockStart, ArrayList blockStatements) {
503                 int blockEnd = scanner.getCurrentTokenEndPosition();
504                 Block b = Block.EmptyWith(blockStart, blockEnd);
505                 b.statements = new Statement[blockStatements.size()];
506                 blockStatements.toArray(b.statements);
507                 return b;
508         }
509
510         private void functionBody(MethodDeclaration methodDecl) {
511                 // '{' [statement-list] '}'
512                 if (token == TokenNameLBRACE) {
513                         getNextToken();
514                 } else {
515                         methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
516                         throwSyntaxError("'{' expected in compound-statement.");
517                 }
518                 if (token != TokenNameRBRACE) {
519                         statementList();
520                 }
521                 if (token == TokenNameRBRACE) {
522                         methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
523                         getNextToken();
524                 } else {
525                         methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
526                         throwSyntaxError("'}' expected in compound-statement.");
527                 }
528         }
529
530         private Statement statement() {
531                 Statement statement = null;
532                 Expression expression;
533                 int sourceStart = scanner.getCurrentTokenStartPosition();
534                 int sourceEnd;
535                 if (token == TokenNameif) {
536                         // T_IF '(' expr ')' statement elseif_list else_single
537                         // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
538                         // new_else_single T_ENDIF ';'
539                         getNextToken();
540                         if (token == TokenNameLPAREN) {
541                                 getNextToken();
542                         } else {
543                                 throwSyntaxError("'(' expected after 'if' keyword.");
544                         }
545                         expression = expr();
546                         if (token == TokenNameRPAREN) {
547                                 getNextToken();
548                         } else {
549                                 throwSyntaxError("')' expected after 'if' condition.");
550                         }
551                         // create basic IfStatement
552                         IfStatement ifStatement = new IfStatement(expression, null, null, sourceStart, -1);
553                         if (token == TokenNameCOLON) {
554                                 getNextToken();
555                                 ifStatementColon(ifStatement);
556                         } else {
557                                 ifStatement(ifStatement);
558                         }
559                         return ifStatement;
560                 } else if (token == TokenNameswitch) {
561                         getNextToken();
562                         if (token == TokenNameLPAREN) {
563                                 getNextToken();
564                         } else {
565                                 throwSyntaxError("'(' expected after 'switch' keyword.");
566                         }
567                         expr();
568                         if (token == TokenNameRPAREN) {
569                                 getNextToken();
570                         } else {
571                                 throwSyntaxError("')' expected after 'switch' condition.");
572                         }
573                         switchStatement();
574                         return statement;
575                 } else if (token == TokenNamefor) {
576                         getNextToken();
577                         if (token == TokenNameLPAREN) {
578                                 getNextToken();
579                         } else {
580                                 throwSyntaxError("'(' expected after 'for' keyword.");
581                         }
582                         if (token == TokenNameSEMICOLON) {
583                                 getNextToken();
584                         } else {
585                                 expressionList();
586                                 if (token == TokenNameSEMICOLON) {
587                                         getNextToken();
588                                 } else {
589                                         throwSyntaxError("';' expected after 'for'.");
590                                 }
591                         }
592                         if (token == TokenNameSEMICOLON) {
593                                 getNextToken();
594                         } else {
595                                 expressionList();
596                                 if (token == TokenNameSEMICOLON) {
597                                         getNextToken();
598                                 } else {
599                                         throwSyntaxError("';' expected after 'for'.");
600                                 }
601                         }
602                         if (token == TokenNameRPAREN) {
603                                 getNextToken();
604                         } else {
605                                 expressionList();
606                                 if (token == TokenNameRPAREN) {
607                                         getNextToken();
608                                 } else {
609                                         throwSyntaxError("')' expected after 'for'.");
610                                 }
611                         }
612                         forStatement();
613                         return statement;
614                 } else if (token == TokenNamewhile) {
615                         getNextToken();
616                         if (token == TokenNameLPAREN) {
617                                 getNextToken();
618                         } else {
619                                 throwSyntaxError("'(' expected after 'while' keyword.");
620                         }
621                         expr();
622                         if (token == TokenNameRPAREN) {
623                                 getNextToken();
624                         } else {
625                                 throwSyntaxError("')' expected after 'while' condition.");
626                         }
627                         whileStatement();
628                         return statement;
629                 } else if (token == TokenNamedo) {
630                         getNextToken();
631                         if (token == TokenNameLBRACE) {
632                                 getNextToken();
633                                 if (token != TokenNameRBRACE) {
634                                         statementList();
635                                 }
636                                 if (token == TokenNameRBRACE) {
637                                         getNextToken();
638                                 } else {
639                                         throwSyntaxError("'}' expected after 'do' keyword.");
640                                 }
641                         } else {
642                                 statement();
643                         }
644                         if (token == TokenNamewhile) {
645                                 getNextToken();
646                                 if (token == TokenNameLPAREN) {
647                                         getNextToken();
648                                 } else {
649                                         throwSyntaxError("'(' expected after 'while' keyword.");
650                                 }
651                                 expr();
652                                 if (token == TokenNameRPAREN) {
653                                         getNextToken();
654                                 } else {
655                                         throwSyntaxError("')' expected after 'while' condition.");
656                                 }
657                         } else {
658                                 throwSyntaxError("'while' expected after 'do' keyword.");
659                         }
660                         if (token == TokenNameSEMICOLON) {
661                                 getNextToken();
662                         } else {
663                                 if (token != TokenNameINLINE_HTML) {
664                                         throwSyntaxError("';' expected after do-while statement.");
665                                 }
666                                 getNextToken();
667                         }
668                         return statement;
669                 } else if (token == TokenNameforeach) {
670                         getNextToken();
671                         if (token == TokenNameLPAREN) {
672                                 getNextToken();
673                         } else {
674                                 throwSyntaxError("'(' expected after 'foreach' keyword.");
675                         }
676                         expr();
677                         if (token == TokenNameas) {
678                                 getNextToken();
679                         } else {
680                                 throwSyntaxError("'as' expected after 'foreach' exxpression.");
681                         }
682                         // variable();
683                         foreach_variable();
684                         foreach_optional_arg();
685                         if (token == TokenNameEQUAL_GREATER) {
686                                 getNextToken();
687                                 variable(false, false);
688                         }
689                         if (token == TokenNameRPAREN) {
690                                 getNextToken();
691                         } else {
692                                 throwSyntaxError("')' expected after 'foreach' expression.");
693                         }
694                         foreachStatement();
695                         return statement;
696                 } else if (token == TokenNamebreak) {
697                         expression = null;
698                         getNextToken();
699                         if (token != TokenNameSEMICOLON) {
700                                 expression = expr();
701                         }
702                         if (token == TokenNameSEMICOLON) {
703                                 sourceEnd = scanner.getCurrentTokenEndPosition();
704                                 getNextToken();
705                         } else {
706                                 if (token != TokenNameINLINE_HTML) {
707                                         throwSyntaxError("';' expected after 'break'.");
708                                 }
709                                 sourceEnd = scanner.getCurrentTokenEndPosition();
710                                 getNextToken();
711                         }
712                         return new BreakStatement(null, sourceStart, sourceEnd);
713                 } else if (token == TokenNamecontinue) {
714                         expression = null;
715                         getNextToken();
716                         if (token != TokenNameSEMICOLON) {
717                                 expression = expr();
718                         }
719                         if (token == TokenNameSEMICOLON) {
720                                 sourceEnd = scanner.getCurrentTokenEndPosition();
721                                 getNextToken();
722                         } else {
723                                 if (token != TokenNameINLINE_HTML) {
724                                         throwSyntaxError("';' expected after 'continue'.");
725                                 }
726                                 sourceEnd = scanner.getCurrentTokenEndPosition();
727                                 getNextToken();
728                         }
729                         return new ContinueStatement(null, sourceStart, sourceEnd);
730                 } else if (token == TokenNamereturn) {
731                         expression = null;
732                         getNextToken();
733                         if (token != TokenNameSEMICOLON) {
734                                 expression = expr();
735                         }
736                         if (token == TokenNameSEMICOLON) {
737                                 sourceEnd = scanner.getCurrentTokenEndPosition();
738                                 getNextToken();
739                         } else {
740                                 if (token != TokenNameINLINE_HTML) {
741                                         throwSyntaxError("';' expected after 'return'.");
742                                 }
743                                 sourceEnd = scanner.getCurrentTokenEndPosition();
744                                 getNextToken();
745                         }
746                         return new ReturnStatement(expression, sourceStart, sourceEnd);
747                 } else if (token == TokenNameecho) {
748                         getNextToken();
749                         expressionList();
750                         if (token == TokenNameSEMICOLON) {
751                                 getNextToken();
752                         } else {
753                                 if (token != TokenNameINLINE_HTML) {
754                                         throwSyntaxError("';' expected after 'echo' statement.");
755                                 }
756                                 getNextToken();
757                         }
758                         return statement;
759                 } else if (token == TokenNameECHO_INVISIBLE) {
760                         // 0-length token directly after PHP short tag &lt;?=
761                         getNextToken();
762                         expressionList();
763                         if (token == TokenNameSEMICOLON) {
764                                 getNextToken();
765                                 // if (token != TokenNameINLINE_HTML) {
766                                 // // TODO should this become a configurable warning?
767                                 // reportSyntaxError("Probably '?>' expected after PHP short tag
768                                 // expression (only the first expression will be echoed).");
769                                 // }
770                         } else {
771                                 if (token != TokenNameINLINE_HTML) {
772                                         throwSyntaxError("';' expected after PHP short tag '<?=' expression.");
773                                 }
774                                 getNextToken();
775                         }
776                         return statement;
777                 } else if (token == TokenNameINLINE_HTML) {
778                         getNextToken();
779                         return statement;
780                 } else if (token == TokenNameglobal) {
781                         getNextToken();
782                         global_var_list();
783                         if (token == TokenNameSEMICOLON) {
784                                 getNextToken();
785                         } else {
786                                 if (token != TokenNameINLINE_HTML) {
787                                         throwSyntaxError("';' expected after 'global' statement.");
788                                 }
789                                 getNextToken();
790                         }
791                         return statement;
792                 } else if (token == TokenNamestatic) {
793                         getNextToken();
794                         static_var_list();
795                         if (token == TokenNameSEMICOLON) {
796                                 getNextToken();
797                         } else {
798                                 if (token != TokenNameINLINE_HTML) {
799                                         throwSyntaxError("';' expected after 'static' statement.");
800                                 }
801                                 getNextToken();
802                         }
803                         return statement;
804                 } else if (token == TokenNameunset) {
805                         getNextToken();
806                         if (token == TokenNameLPAREN) {
807                                 getNextToken();
808                         } else {
809                                 throwSyntaxError("'(' expected after 'unset' statement.");
810                         }
811                         unset_variables();
812                         if (token == TokenNameRPAREN) {
813                                 getNextToken();
814                         } else {
815                                 throwSyntaxError("')' expected after 'unset' statement.");
816                         }
817                         if (token == TokenNameSEMICOLON) {
818                                 getNextToken();
819                         } else {
820                                 if (token != TokenNameINLINE_HTML) {
821                                         throwSyntaxError("';' expected after 'unset' statement.");
822                                 }
823                                 getNextToken();
824                         }
825                         return statement;
826                 } else if (token == TokenNamefunction) {
827                         MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
828                         methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
829                         methodDecl.modifiers = AccDefault;
830                         methodDecl.type = MethodDeclaration.FUNCTION_DEFINITION;
831                         try {
832                                 getNextToken();
833                                 functionDefinition(methodDecl);
834                         } finally {
835                                 sourceEnd = methodDecl.sourceEnd;
836                                 if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
837                                         sourceEnd = methodDecl.declarationSourceStart + 1;
838                                 }
839                                 methodDecl.declarationSourceEnd = sourceEnd;
840                                 methodDecl.sourceEnd = sourceEnd;
841                         }
842                         return statement;
843                 } else if (token == TokenNamedeclare) {
844                         // T_DECLARE '(' declare_list ')' declare_statement
845                         getNextToken();
846                         if (token != TokenNameLPAREN) {
847                                 throwSyntaxError("'(' expected in 'declare' statement.");
848                         }
849                         getNextToken();
850                         declare_list();
851                         if (token != TokenNameRPAREN) {
852                                 throwSyntaxError("')' expected in 'declare' statement.");
853                         }
854                         getNextToken();
855                         declare_statement();
856                         return statement;
857                 } else if (token == TokenNametry) {
858                         getNextToken();
859                         if (token != TokenNameLBRACE) {
860                                 throwSyntaxError("'{' expected in 'try' statement.");
861                         }
862                         getNextToken();
863                         statementList();
864                         if (token != TokenNameRBRACE) {
865                                 throwSyntaxError("'}' expected in 'try' statement.");
866                         }
867                         getNextToken();
868                         return statement;
869                 } else if (token == TokenNamecatch) {
870                         getNextToken();
871                         if (token != TokenNameLPAREN) {
872                                 throwSyntaxError("'(' expected in 'catch' statement.");
873                         }
874                         getNextToken();
875                         fully_qualified_class_name();
876                         if (token != TokenNameVariable) {
877                                 throwSyntaxError("Variable expected in 'catch' statement.");
878                         }
879                         addVariableSet();
880                         getNextToken();
881                         if (token != TokenNameRPAREN) {
882                                 throwSyntaxError("')' expected in 'catch' statement.");
883                         }
884                         getNextToken();
885                         if (token != TokenNameLBRACE) {
886                                 throwSyntaxError("'{' expected in 'catch' statement.");
887                         }
888                         getNextToken();
889                         if (token != TokenNameRBRACE) {
890                                 statementList();
891                                 if (token != TokenNameRBRACE) {
892                                         throwSyntaxError("'}' expected in 'catch' statement.");
893                                 }
894                         }
895                         getNextToken();
896                         additional_catches();
897                         return statement;
898                 } else if (token == TokenNamethrow) {
899                         getNextToken();
900                         expr();
901                         if (token == TokenNameSEMICOLON) {
902                                 getNextToken();
903                         } else {
904                                 throwSyntaxError("';' expected after 'throw' exxpression.");
905                         }
906                         return statement;
907                 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
908                         try {
909                                 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
910                                 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
911                                 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
912                                 typeDecl.name = new char[] { ' ' };
913                                 // default super class
914                                 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
915                                 compilationUnit.types.add(typeDecl);
916                                 pushOnAstStack(typeDecl);
917                                 unticked_class_declaration_statement(typeDecl);
918                         } finally {
919                                 // reduce stack:
920                                 astPtr--;
921                                 astLengthPtr--;
922                         }
923                         return statement;
924                         // } else {
925                         // throwSyntaxError("Unexpected keyword '" + keyword + "'");
926                 } else if (token == TokenNameLBRACE) {
927                         getNextToken();
928                         if (token != TokenNameRBRACE) {
929                                 statement = statementList();
930                         }
931                         if (token == TokenNameRBRACE) {
932                                 getNextToken();
933                                 return statement;
934                         } else {
935                                 throwSyntaxError("'}' expected.");
936                         }
937                 } else {
938                         if (token != TokenNameSEMICOLON) {
939                                 expr();
940                         }
941                         if (token == TokenNameSEMICOLON) {
942                                 getNextToken();
943                                 return statement;
944                         } else {
945                                 if (token == TokenNameRBRACE) {
946                                         reportSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
947                                 } else {
948                                         if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
949                                                 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
950                                         }
951                                         getNextToken();
952                                 }
953                         }
954                 }
955                 // may be null
956                 return statement;
957         }
958
959         private void declare_statement() {
960                 // statement
961                 // | ':' inner_statement_list T_ENDDECLARE ';'
962                 // ;
963                 if (token == TokenNameCOLON) {
964                         getNextToken();
965                         // TODO: implement inner_statement_list();
966                         statementList();
967                         if (token != TokenNameenddeclare) {
968                                 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
969                         }
970                         getNextToken();
971                         if (token != TokenNameSEMICOLON) {
972                                 throwSyntaxError("';' expected after 'enddeclare' keyword.");
973                         }
974                         getNextToken();
975                 } else {
976                         statement();
977                 }
978         }
979
980         private void declare_list() {
981                 // T_STRING '=' static_scalar
982                 // | declare_list ',' T_STRING '=' static_scalar
983                 while (true) {
984                         if (token != TokenNameIdentifier) {
985                                 throwSyntaxError("Identifier expected in 'declare' list.");
986                         }
987                         getNextToken();
988                         if (token != TokenNameEQUAL) {
989                                 throwSyntaxError("'=' expected in 'declare' list.");
990                         }
991                         getNextToken();
992                         static_scalar();
993                         if (token != TokenNameCOMMA) {
994                                 break;
995                         }
996                         getNextToken();
997                 }
998         }
999
1000         private void additional_catches() {
1001                 while (token == TokenNamecatch) {
1002                         getNextToken();
1003                         if (token != TokenNameLPAREN) {
1004                                 throwSyntaxError("'(' expected in 'catch' statement.");
1005                         }
1006                         getNextToken();
1007                         fully_qualified_class_name();
1008                         if (token != TokenNameVariable) {
1009                                 throwSyntaxError("Variable expected in 'catch' statement.");
1010                         }
1011                         addVariableSet();
1012                         getNextToken();
1013                         if (token != TokenNameRPAREN) {
1014                                 throwSyntaxError("')' expected in 'catch' statement.");
1015                         }
1016                         getNextToken();
1017                         if (token != TokenNameLBRACE) {
1018                                 throwSyntaxError("'{' expected in 'catch' statement.");
1019                         }
1020                         getNextToken();
1021                         if (token != TokenNameRBRACE) {
1022                                 statementList();
1023                         }
1024                         if (token != TokenNameRBRACE) {
1025                                 throwSyntaxError("'}' expected in 'catch' statement.");
1026                         }
1027                         getNextToken();
1028                 }
1029         }
1030
1031         private void foreach_variable() {
1032                 // w_variable
1033                 // | '&' w_variable
1034                 if (token == TokenNameAND) {
1035                         getNextToken();
1036                 }
1037                 w_variable(true);
1038         }
1039
1040         private void foreach_optional_arg() {
1041                 // /* empty */
1042                 // | T_DOUBLE_ARROW foreach_variable
1043                 if (token == TokenNameEQUAL_GREATER) {
1044                         getNextToken();
1045                         foreach_variable();
1046                 }
1047         }
1048
1049         private void global_var_list() {
1050                 // global_var_list:
1051                 // global_var_list ',' global_var
1052                 // | global_var
1053                 HashSet set = peekVariableSet();
1054                 while (true) {
1055                         global_var(set);
1056                         if (token != TokenNameCOMMA) {
1057                                 break;
1058                         }
1059                         getNextToken();
1060                 }
1061         }
1062
1063         private void global_var(HashSet set) {
1064                 // global_var:
1065                 // T_VARIABLE
1066                 // | '$' r_variable
1067                 // | '$' '{' expr '}'
1068                 if (token == TokenNameVariable) {
1069                         if (fMethodVariables != null) {
1070                                 VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR);
1071                                 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1072                         }
1073                         addVariableSet(set);
1074                         getNextToken();
1075                 } else if (token == TokenNameDOLLAR) {
1076                         getNextToken();
1077                         if (token == TokenNameLBRACE) {
1078                                 getNextToken();
1079                                 expr();
1080                                 if (token != TokenNameRBRACE) {
1081                                         throwSyntaxError("'}' expected in global variable.");
1082                                 }
1083                                 getNextToken();
1084                         } else {
1085                                 r_variable();
1086                         }
1087                 }
1088         }
1089
1090         private void static_var_list() {
1091                 // static_var_list:
1092                 // static_var_list ',' T_VARIABLE
1093                 // | static_var_list ',' T_VARIABLE '=' static_scalar
1094                 // | T_VARIABLE
1095                 // | T_VARIABLE '=' static_scalar,
1096                 HashSet set = peekVariableSet();
1097                 while (true) {
1098                         if (token == TokenNameVariable) {
1099                                 if (fMethodVariables != null) {
1100                                         VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR);
1101                                         fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1102                                 }
1103                                 addVariableSet(set);
1104                                 getNextToken();
1105                                 if (token == TokenNameEQUAL) {
1106                                         getNextToken();
1107                                         static_scalar();
1108                                 }
1109                                 if (token != TokenNameCOMMA) {
1110                                         break;
1111                                 }
1112                                 getNextToken();
1113                         } else {
1114                                 break;
1115                         }
1116                 }
1117         }
1118
1119         private void unset_variables() {
1120                 // unset_variables:
1121                 // unset_variable
1122                 // | unset_variables ',' unset_variable
1123                 // unset_variable:
1124                 // variable
1125                 while (true) {
1126                         variable(false, false);
1127                         if (token != TokenNameCOMMA) {
1128                                 break;
1129                         }
1130                         getNextToken();
1131                 }
1132         }
1133
1134         private final void initializeModifiers() {
1135                 this.modifiers = 0;
1136                 this.modifiersSourceStart = -1;
1137         }
1138
1139         private final void checkAndSetModifiers(int flag) {
1140                 this.modifiers |= flag;
1141                 if (this.modifiersSourceStart < 0)
1142                         this.modifiersSourceStart = this.scanner.startPosition;
1143         }
1144
1145         private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1146                 initializeModifiers();
1147                 if (token == TokenNameinterface) {
1148                         // interface_entry T_STRING
1149                         // interface_extends_list
1150                         // '{' class_statement_list '}'
1151                         checkAndSetModifiers(AccInterface);
1152                         getNextToken();
1153                         typeDecl.modifiers = this.modifiers;
1154                         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1155                         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1156                         if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1157                                 typeDecl.name = scanner.getCurrentIdentifierSource();
1158                                 if (token > TokenNameKEYWORD) {
1159                                         problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1160                                                         scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1161                                         // throwSyntaxError("Don't use a keyword for interface declaration ["
1162                                         // + scanner.toStringAction(token) + "].",
1163                                         // typeDecl.sourceStart, typeDecl.sourceEnd);
1164                                 }
1165                                 getNextToken();
1166                                 interface_extends_list(typeDecl);
1167                         } else {
1168                                 typeDecl.name = new char[] { ' ' };
1169                                 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1170                                 return;
1171                         }
1172                 } else {
1173                         // class_entry_type T_STRING extends_from
1174                         // implements_list
1175                         // '{' class_statement_list'}'
1176                         class_entry_type();
1177                         typeDecl.modifiers = this.modifiers;
1178                         typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1179                         typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1180                         // identifier
1181                         // identifier 'extends' identifier
1182                         if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1183                                 typeDecl.name = scanner.getCurrentIdentifierSource();
1184                                 if (token > TokenNameKEYWORD) {
1185                                         problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1186                                                         scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1187                                         // throwSyntaxError("Don't use a keyword for class declaration [" +
1188                                         // scanner.toStringAction(token) + "].",
1189                                         // typeDecl.sourceStart, typeDecl.sourceEnd);
1190                                 }
1191                                 getNextToken();
1192                                 // extends_from:
1193                                 // /* empty */
1194                                 // | T_EXTENDS fully_qualified_class_name
1195                                 if (token == TokenNameextends) {
1196                                         interface_extends_list(typeDecl);
1197                                         // getNextToken();
1198                                         // if (token != TokenNameIdentifier) {
1199                                         // throwSyntaxError("Class name expected after keyword
1200                                         // 'extends'.",
1201                                         // scanner.getCurrentTokenStartPosition(), scanner
1202                                         // .getCurrentTokenEndPosition());
1203                                         // }
1204                                 }
1205                                 implements_list(typeDecl);
1206                         } else {
1207                                 typeDecl.name = new char[] { ' ' };
1208                                 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1209                                 return;
1210                         }
1211                 }
1212                 // '{' class_statement_list '}'
1213                 if (token == TokenNameLBRACE) {
1214                         getNextToken();
1215                         if (token != TokenNameRBRACE) {
1216                                 ArrayList list = new ArrayList();
1217                                 class_statement_list(list);
1218                                 typeDecl.fields = new FieldDeclaration[list.size()];
1219                                 for (int i = 0; i < list.size(); i++) {
1220                                         typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1221                                 }
1222                         }
1223                         if (token == TokenNameRBRACE) {
1224                                 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1225                                 getNextToken();
1226                         } else {
1227                                 throwSyntaxError("'}' expected at end of class body.");
1228                         }
1229                 } else {
1230                         throwSyntaxError("'{' expected at start of class body.");
1231                 }
1232         }
1233
1234         private void class_entry_type() {
1235                 // T_CLASS
1236                 // | T_ABSTRACT T_CLASS
1237                 // | T_FINAL T_CLASS
1238                 if (token == TokenNameclass) {
1239                         getNextToken();
1240                 } else if (token == TokenNameabstract) {
1241                         checkAndSetModifiers(AccAbstract);
1242                         getNextToken();
1243                         if (token != TokenNameclass) {
1244                                 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1245                         }
1246                         getNextToken();
1247                 } else if (token == TokenNamefinal) {
1248                         checkAndSetModifiers(AccFinal);
1249                         getNextToken();
1250                         if (token != TokenNameclass) {
1251                                 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1252                         }
1253                         getNextToken();
1254                 } else {
1255                         throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1256                 }
1257         }
1258
1259         // private void class_extends(TypeDeclaration typeDecl) {
1260         // // /* empty */
1261         // // | T_EXTENDS interface_list
1262         // if (token == TokenNameextends) {
1263         // getNextToken();
1264         //
1265         // if (token == TokenNameIdentifier) {
1266         // getNextToken();
1267         // } else {
1268         // throwSyntaxError("Class name expected after keyword 'extends'.");
1269         // }
1270         // }
1271         // }
1272
1273         private void interface_extends_list(TypeDeclaration typeDecl) {
1274                 // /* empty */
1275                 // | T_EXTENDS interface_list
1276                 if (token == TokenNameextends) {
1277                         getNextToken();
1278                         interface_list();
1279                 }
1280         }
1281
1282         private void implements_list(TypeDeclaration typeDecl) {
1283                 // /* empty */
1284                 // | T_IMPLEMENTS interface_list
1285                 if (token == TokenNameimplements) {
1286                         getNextToken();
1287                         interface_list();
1288                 }
1289         }
1290
1291         private void interface_list() {
1292                 // interface_list:
1293                 // fully_qualified_class_name
1294                 // | interface_list ',' fully_qualified_class_name
1295                 do {
1296                         if (token == TokenNameIdentifier) {
1297                                 getNextToken();
1298                         } else {
1299                                 throwSyntaxError("Interface name expected after keyword 'implements'.");
1300                         }
1301                         if (token != TokenNameCOMMA) {
1302                                 return;
1303                         }
1304                         getNextToken();
1305                 } while (true);
1306         }
1307
1308         // private void classBody(TypeDeclaration typeDecl) {
1309         // //'{' [class-element-list] '}'
1310         // if (token == TokenNameLBRACE) {
1311         // getNextToken();
1312         // if (token != TokenNameRBRACE) {
1313         // class_statement_list();
1314         // }
1315         // if (token == TokenNameRBRACE) {
1316         // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1317         // getNextToken();
1318         // } else {
1319         // throwSyntaxError("'}' expected at end of class body.");
1320         // }
1321         // } else {
1322         // throwSyntaxError("'{' expected at start of class body.");
1323         // }
1324         // }
1325         private void class_statement_list(ArrayList list) {
1326                 do {
1327                         try {
1328                                 class_statement(list);
1329                                 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1330                                                 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1331                                                 || token == TokenNameconst) {
1332                                         continue;
1333                                 }
1334                                 if (token == TokenNameRBRACE) {
1335                                         break;
1336                                 }
1337                                 throwSyntaxError("'}' at end of class statement.");
1338                         } catch (SyntaxError sytaxErr1) {
1339                                 boolean tokenize = scanner.tokenizeStrings;
1340                                 if (!tokenize) {
1341                                         scanner.tokenizeStrings = true;
1342                                 }
1343                                 try {
1344                                         // if an error occured,
1345                                         // try to find keywords
1346                                         // to parse the rest of the string
1347                                         while (token != TokenNameEOF) {
1348                                                 if (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1349                                                                 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1350                                                                 || token == TokenNameconst) {
1351                                                         break;
1352                                                 }
1353                                                 // System.out.println(scanner.toStringAction(token));
1354                                                 getNextToken();
1355                                         }
1356                                         if (token == TokenNameEOF) {
1357                                                 throw sytaxErr1;
1358                                         }
1359                                 } finally {
1360                                         scanner.tokenizeStrings = tokenize;
1361                                 }
1362                         }
1363                 } while (true);
1364         }
1365
1366         private void class_statement(ArrayList list) {
1367                 // class_statement:
1368                 // variable_modifiers class_variable_declaration ';'
1369                 // | class_constant_declaration ';'
1370                 // | method_modifiers T_FUNCTION is_reference T_STRING
1371                 // '(' parameter_list ')' method_body
1372                 initializeModifiers();
1373                 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1374
1375                 if (token == TokenNamevar) {
1376                         checkAndSetModifiers(AccPublic);
1377                         problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1378                                         referenceContext, compilationUnit.compilationResult);
1379                         getNextToken();
1380                         class_variable_declaration(declarationSourceStart, list);
1381                 } else if (token == TokenNameconst) {
1382                         checkAndSetModifiers(AccFinal | AccPublic);
1383                         class_constant_declaration(declarationSourceStart, list);
1384                         if (token != TokenNameSEMICOLON) {
1385                                 throwSyntaxError("';' expected after class const declaration.");
1386                         }
1387                         getNextToken();
1388                 } else {
1389                         boolean hasModifiers = member_modifiers();
1390                         if (token == TokenNamefunction) {
1391                                 if (!hasModifiers) {
1392                                         checkAndSetModifiers(AccPublic);
1393                                 }
1394                                 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1395                                 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1396                                 methodDecl.modifiers = this.modifiers;
1397                                 methodDecl.type = MethodDeclaration.METHOD_DEFINITION;
1398                                 try {
1399                                         getNextToken();
1400                                         functionDefinition(methodDecl);
1401                                 } finally {
1402                                         int sourceEnd = methodDecl.sourceEnd;
1403                                         if (sourceEnd <= 0 || methodDecl.declarationSourceStart > sourceEnd) {
1404                                                 sourceEnd = methodDecl.declarationSourceStart + 1;
1405                                         }
1406                                         methodDecl.declarationSourceEnd = sourceEnd;
1407                                         methodDecl.sourceEnd = sourceEnd;
1408                                 }
1409                         } else {
1410                                 if (!hasModifiers) {
1411                                         throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1412                                 }
1413                                 class_variable_declaration(declarationSourceStart, list);
1414                         }
1415                 }
1416         }
1417
1418         private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1419                 // class_constant_declaration ',' T_STRING '=' static_scalar
1420                 // | T_CONST T_STRING '=' static_scalar
1421                 if (token != TokenNameconst) {
1422                         throwSyntaxError("'const' keyword expected in class declaration.");
1423                 } else {
1424                         getNextToken();
1425                 }
1426                 while (true) {
1427                         if (token != TokenNameIdentifier) {
1428                                 throwSyntaxError("Identifier expected in class const declaration.");
1429                         }
1430                         FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1431                                         .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1432                         fieldDeclaration.modifiers = this.modifiers;
1433                         fieldDeclaration.declarationSourceStart = declarationSourceStart;
1434                         fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1435                         fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1436                         // fieldDeclaration.type
1437                         list.add(fieldDeclaration);
1438                         getNextToken();
1439                         if (token != TokenNameEQUAL) {
1440                                 throwSyntaxError("'=' expected in class const declaration.");
1441                         }
1442                         getNextToken();
1443                         static_scalar();
1444                         if (token != TokenNameCOMMA) {
1445                                 break; // while(true)-loop
1446                         }
1447                         getNextToken();
1448                 }
1449         }
1450
1451         // private void variable_modifiers() {
1452         // // variable_modifiers:
1453         // // non_empty_member_modifiers
1454         // //| T_VAR
1455         // initializeModifiers();
1456         // if (token == TokenNamevar) {
1457         // checkAndSetModifiers(AccPublic);
1458         // reportSyntaxError(
1459         // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1460         // 'protected'
1461         // modifier for field declarations.",
1462         // scanner.getCurrentTokenStartPosition(), scanner
1463         // .getCurrentTokenEndPosition());
1464         // getNextToken();
1465         // } else {
1466         // if (!member_modifiers()) {
1467         // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1468         // field declarations.");
1469         // }
1470         // }
1471         // }
1472         // private void method_modifiers() {
1473         // //method_modifiers:
1474         // // /* empty */
1475         // //| non_empty_member_modifiers
1476         // initializeModifiers();
1477         // if (!member_modifiers()) {
1478         // checkAndSetModifiers(AccPublic);
1479         // }
1480         // }
1481         private boolean member_modifiers() {
1482                 // T_PUBLIC
1483                 // | T_PROTECTED
1484                 // | T_PRIVATE
1485                 // | T_STATIC
1486                 // | T_ABSTRACT
1487                 // | T_FINAL
1488                 boolean foundToken = false;
1489                 while (true) {
1490                         if (token == TokenNamepublic) {
1491                                 checkAndSetModifiers(AccPublic);
1492                                 getNextToken();
1493                                 foundToken = true;
1494                         } else if (token == TokenNameprotected) {
1495                                 checkAndSetModifiers(AccProtected);
1496                                 getNextToken();
1497                                 foundToken = true;
1498                         } else if (token == TokenNameprivate) {
1499                                 checkAndSetModifiers(AccPrivate);
1500                                 getNextToken();
1501                                 foundToken = true;
1502                         } else if (token == TokenNamestatic) {
1503                                 checkAndSetModifiers(AccStatic);
1504                                 getNextToken();
1505                                 foundToken = true;
1506                         } else if (token == TokenNameabstract) {
1507                                 checkAndSetModifiers(AccAbstract);
1508                                 getNextToken();
1509                                 foundToken = true;
1510                         } else if (token == TokenNamefinal) {
1511                                 checkAndSetModifiers(AccFinal);
1512                                 getNextToken();
1513                                 foundToken = true;
1514                         } else {
1515                                 break;
1516                         }
1517                 }
1518                 return foundToken;
1519         }
1520
1521         private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1522                 // class_variable_declaration:
1523                 // class_variable_declaration ',' T_VARIABLE
1524                 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1525                 // | T_VARIABLE
1526                 // | T_VARIABLE '=' static_scalar
1527                 char[] classVariable;
1528                 do {
1529                         if (token == TokenNameVariable) {
1530                                 classVariable = scanner.getCurrentIdentifierSource();
1531                                 // indexManager.addIdentifierInformation('v', classVariable, buf, -1,
1532                                 // -1);
1533                                 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1534                                                 .getCurrentTokenEndPosition());
1535                                 fieldDeclaration.modifiers = this.modifiers;
1536                                 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1537                                 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1538                                 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1539                                 list.add(fieldDeclaration);
1540                                 if (fTypeVariables != null) {
1541                                         VariableInfo info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT);
1542                                         fTypeVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1543                                 }
1544                                 getNextToken();
1545                                 if (token == TokenNameEQUAL) {
1546                                         getNextToken();
1547                                         static_scalar();
1548                                 }
1549                         } else {
1550                                 // if (token == TokenNamethis) {
1551                                 // throwSyntaxError("'$this' not allowed after keyword 'public'
1552                                 // 'protected' 'private' 'var'.");
1553                                 // }
1554                                 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1555                         }
1556                         if (token != TokenNameCOMMA) {
1557                                 break;
1558                         }
1559                         getNextToken();
1560                 } while (true);
1561                 if (token != TokenNameSEMICOLON) {
1562                         throwSyntaxError("';' expected after field declaration.");
1563                 }
1564                 getNextToken();
1565         }
1566
1567         private void functionDefinition(MethodDeclaration methodDecl) {
1568                 boolean isAbstract = false;
1569                 if (astPtr == 0) {
1570                         if (compilationUnit != null) {
1571                                 compilationUnit.types.add(methodDecl);
1572                         }
1573                 } else {
1574                         ASTNode node = astStack[astPtr];
1575                         if (node instanceof TypeDeclaration) {
1576                                 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1577                                 if (typeDecl.methods == null) {
1578                                         typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1579                                 } else {
1580                                         AbstractMethodDeclaration[] newMethods;
1581                                         System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 0,
1582                                                         typeDecl.methods.length);
1583                                         newMethods[typeDecl.methods.length] = methodDecl;
1584                                         typeDecl.methods = newMethods;
1585                                 }
1586                                 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1587                                         isAbstract = true;
1588                                 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1589                                         isAbstract = true;
1590                                 }
1591                         }
1592                 }
1593                 try {
1594                         pushFunctionVariableSet();
1595                         functionDeclarator(methodDecl);
1596                         if (token == TokenNameSEMICOLON) {
1597                                 if (!isAbstract) {
1598                                         methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1599                                         throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1600                                 }
1601                                 getNextToken();
1602                                 return;
1603                         }
1604                         functionBody(methodDecl);
1605                 } finally {
1606                         if (!fStackUnassigned.isEmpty()) {
1607                                 fStackUnassigned.remove(fStackUnassigned.size() - 1);
1608                         }
1609                 }
1610         }
1611
1612         private void functionDeclarator(MethodDeclaration methodDecl) {
1613                 // identifier '(' [parameter-list] ')'
1614                 if (token == TokenNameAND) {
1615                         getNextToken();
1616                 }
1617                 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1618                 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1619                 if (Scanner.isIdentifierOrKeyword(token)) {
1620                         methodDecl.selector = scanner.getCurrentIdentifierSource();
1621                         if (token > TokenNameKEYWORD) {
1622                                 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1623                                                 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1624                         }
1625                         getNextToken();
1626                         if (token == TokenNameLPAREN) {
1627                                 getNextToken();
1628                         } else {
1629                                 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1630                                 throwSyntaxError("'(' expected in function declaration.");
1631                         }
1632                         if (token != TokenNameRPAREN) {
1633                                 parameter_list(methodDecl);
1634                         }
1635                         if (token != TokenNameRPAREN) {
1636                                 methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1637                                 throwSyntaxError("')' expected in function declaration.");
1638                         } else {
1639                                 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1640                                 getNextToken();
1641                         }
1642                 } else {
1643                         methodDecl.selector = "<undefined>".toCharArray();
1644                         methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
1645                         throwSyntaxError("Function name expected after keyword 'function'.");
1646                 }
1647         }
1648
1649         //
1650         private void parameter_list(MethodDeclaration methodDecl) {
1651                 // non_empty_parameter_list
1652                 // | /* empty */
1653                 non_empty_parameter_list(methodDecl, true);
1654         }
1655
1656         private void non_empty_parameter_list(MethodDeclaration methodDecl, boolean empty_allowed) {
1657                 // optional_class_type T_VARIABLE
1658                 // | optional_class_type '&' T_VARIABLE
1659                 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1660                 // | optional_class_type T_VARIABLE '=' static_scalar
1661                 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1662                 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1663                 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1664                 // static_scalar
1665                 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1666                 // static_scalar
1667                 char[] typeIdentifier = null;
1668                 if (token == TokenNameIdentifier || token == TokenNamearray || token == TokenNameVariable || token == TokenNameAND) {
1669                         HashSet set = peekVariableSet();
1670                         while (true) {
1671                                 if (token == TokenNameIdentifier || token == TokenNamearray) {// feature req. #1254275
1672                                         typeIdentifier = scanner.getCurrentIdentifierSource();
1673                                         getNextToken();
1674                                 }
1675                                 if (token == TokenNameAND) {
1676                                         getNextToken();
1677                                 }
1678                                 if (token == TokenNameVariable) {
1679                                         if (fMethodVariables != null) {
1680                                                 VariableInfo info;
1681                                                 if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) {
1682                                                         info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION);
1683                                                 } else {
1684                                                         info = new VariableInfo(scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION);
1685                                                 }
1686                                                 info.typeIdentifier = typeIdentifier;
1687                                                 fMethodVariables.put(new String(scanner.getCurrentIdentifierSource()), info);
1688                                         }
1689                                         addVariableSet(set);
1690                                         getNextToken();
1691                                         if (token == TokenNameEQUAL) {
1692                                                 getNextToken();
1693                                                 static_scalar();
1694                                         }
1695                                 } else {
1696                                         throwSyntaxError("Variable expected in parameter list.");
1697                                 }
1698                                 if (token != TokenNameCOMMA) {
1699                                         break;
1700                                 }
1701                                 getNextToken();
1702                         }
1703                         return;
1704                 }
1705                 if (!empty_allowed) {
1706                         throwSyntaxError("Identifier expected in parameter list.");
1707                 }
1708         }
1709
1710         private void optional_class_type() {
1711                 // /* empty */
1712                 // | T_STRING
1713         }
1714
1715         // private void parameterDeclaration() {
1716         // //variable
1717         // //variable-reference
1718         // if (token == TokenNameAND) {
1719         // getNextToken();
1720         // if (isVariable()) {
1721         // getNextToken();
1722         // } else {
1723         // throwSyntaxError("Variable expected after reference operator '&'.");
1724         // }
1725         // }
1726         // //variable '=' constant
1727         // if (token == TokenNameVariable) {
1728         // getNextToken();
1729         // if (token == TokenNameEQUAL) {
1730         // getNextToken();
1731         // static_scalar();
1732         // }
1733         // return;
1734         // }
1735         // // if (token == TokenNamethis) {
1736         // // throwSyntaxError("Reserved word '$this' not allowed in parameter
1737         // // declaration.");
1738         // // }
1739         // }
1740
1741         private void labeledStatementList() {
1742                 if (token != TokenNamecase && token != TokenNamedefault) {
1743                         throwSyntaxError("'case' or 'default' expected.");
1744                 }
1745                 do {
1746                         if (token == TokenNamecase) {
1747                                 getNextToken();
1748                                 expr(); // constant();
1749                                 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1750                                         getNextToken();
1751                                         if (token == TokenNameRBRACE) {
1752                                                 // empty case; assumes that the '}' token belongs to the wrapping
1753                                                 // switch statement - #1371992
1754                                                 break;
1755                                         }
1756                                         if (token == TokenNamecase || token == TokenNamedefault) {
1757                                                 // empty case statement ?
1758                                                 continue;
1759                                         }
1760                                         statementList();
1761                                 }
1762                                 // else if (token == TokenNameSEMICOLON) {
1763                                 // setMarker(
1764                                 // "':' expected after 'case' keyword (Found token: " +
1765                                 // scanner.toStringAction(token) + ")",
1766                                 // scanner.getCurrentTokenStartPosition(),
1767                                 // scanner.getCurrentTokenEndPosition(),
1768                                 // INFO);
1769                                 // getNextToken();
1770                                 // if (token == TokenNamecase) { // empty case statement ?
1771                                 // continue;
1772                                 // }
1773                                 // statementList();
1774                                 // }
1775                                 else {
1776                                         throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1777                                 }
1778                         } else { // TokenNamedefault
1779                                 getNextToken();
1780                                 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1781                                         getNextToken();
1782                                         if (token == TokenNameRBRACE) {
1783                                                 // empty default case; ; assumes that the '}' token belongs to the
1784                                                 // wrapping switch statement - #1371992
1785                                                 break;
1786                                         }
1787                                         if (token != TokenNamecase) {
1788                                                 statementList();
1789                                         }
1790                                 } else {
1791                                         throwSyntaxError("':' character expected after 'default'.");
1792                                 }
1793                         }
1794                 } while (token == TokenNamecase || token == TokenNamedefault);
1795         }
1796
1797         private void ifStatementColon(IfStatement iState) {
1798                 // T_IF '(' expr ')' ':' inner_statement_list new_elseif_list
1799                 // new_else_single T_ENDIF ';'
1800                 HashSet assignedVariableSet = null;
1801                 try {
1802                         Block b = inner_statement_list();
1803                         iState.thenStatement = b;
1804                         checkUnreachable(iState, b);
1805                 } finally {
1806                         assignedVariableSet = removeIfVariableSet();
1807                 }
1808                 if (token == TokenNameelseif) {
1809                         try {
1810                                 pushIfVariableSet();
1811                                 new_elseif_list(iState);
1812                         } finally {
1813                                 HashSet set = removeIfVariableSet();
1814                                 if (assignedVariableSet != null && set != null) {
1815                                         assignedVariableSet.addAll(set);
1816                                 }
1817                         }
1818                 }
1819                 try {
1820                         pushIfVariableSet();
1821                         new_else_single(iState);
1822                 } finally {
1823                         HashSet set = removeIfVariableSet();
1824                         if (assignedVariableSet != null) {
1825                                 HashSet topSet = peekVariableSet();
1826                                 if (topSet != null) {
1827                                         if (set != null) {
1828                                                 topSet.addAll(set);
1829                                         }
1830                                         topSet.addAll(assignedVariableSet);
1831                                 }
1832                         }
1833                 }
1834                 if (token != TokenNameendif) {
1835                         throwSyntaxError("'endif' expected.");
1836                 }
1837                 getNextToken();
1838                 if (token != TokenNameSEMICOLON) {
1839                         reportSyntaxError("';' expected after if-statement.");
1840                         iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1841                 } else {
1842                         iState.sourceEnd = scanner.getCurrentTokenEndPosition();
1843                         getNextToken();
1844                 }
1845         }
1846
1847         private void ifStatement(IfStatement iState) {
1848                 // T_IF '(' expr ')' statement elseif_list else_single
1849                 HashSet assignedVariableSet = null;
1850                 try {
1851                         pushIfVariableSet();
1852                         Statement s = statement();
1853                         iState.thenStatement = s;
1854                         checkUnreachable(iState, s);
1855                 } finally {
1856                         assignedVariableSet = removeIfVariableSet();
1857                 }
1858
1859                 if (token == TokenNameelseif) {
1860                         try {
1861                                 pushIfVariableSet();
1862                                 elseif_list(iState);
1863                         } finally {
1864                                 HashSet set = removeIfVariableSet();
1865                                 if (assignedVariableSet != null && set != null) {
1866                                         assignedVariableSet.addAll(set);
1867                                 }
1868                         }
1869                 }
1870                 try {
1871                         pushIfVariableSet();
1872                         else_single(iState);
1873                 } finally {
1874                         HashSet set = removeIfVariableSet();
1875                         if (assignedVariableSet != null) {
1876                                 HashSet topSet = peekVariableSet();
1877                                 if (topSet != null) {
1878                                         if (set != null) {
1879                                                 topSet.addAll(set);
1880                                         }
1881                                         topSet.addAll(assignedVariableSet);
1882                                 }
1883                         }
1884                 }
1885         }
1886
1887         private void elseif_list(IfStatement iState) {
1888                 // /* empty */
1889                 // | elseif_list T_ELSEIF '(' expr ')' statement
1890                 ArrayList conditionList = new ArrayList();
1891                 ArrayList statementList = new ArrayList();
1892                 Expression e;
1893                 Statement s;
1894                 while (token == TokenNameelseif) {
1895                         getNextToken();
1896                         if (token == TokenNameLPAREN) {
1897                                 getNextToken();
1898                         } else {
1899                                 throwSyntaxError("'(' expected after 'elseif' keyword.");
1900                         }
1901                         e = expr();
1902                         conditionList.add(e);
1903                         if (token == TokenNameRPAREN) {
1904                                 getNextToken();
1905                         } else {
1906                                 throwSyntaxError("')' expected after 'elseif' condition.");
1907                         }
1908                         s = statement();
1909                         statementList.add(s);
1910                         checkUnreachable(iState, s);
1911                 }
1912                 iState.elseifConditions = new Expression[conditionList.size()];
1913                 iState.elseifStatements = new Statement[statementList.size()];
1914                 conditionList.toArray(iState.elseifConditions);
1915                 statementList.toArray(iState.elseifStatements);
1916         }
1917
1918         private void new_elseif_list(IfStatement iState) {
1919                 // /* empty */
1920                 // | new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
1921                 ArrayList conditionList = new ArrayList();
1922                 ArrayList statementList = new ArrayList();
1923                 Expression e;
1924                 Block b;
1925                 while (token == TokenNameelseif) {
1926                         getNextToken();
1927                         if (token == TokenNameLPAREN) {
1928                                 getNextToken();
1929                         } else {
1930                                 throwSyntaxError("'(' expected after 'elseif' keyword.");
1931                         }
1932                         e = expr();
1933                         conditionList.add(e);
1934                         if (token == TokenNameRPAREN) {
1935                                 getNextToken();
1936                         } else {
1937                                 throwSyntaxError("')' expected after 'elseif' condition.");
1938                         }
1939                         if (token == TokenNameCOLON) {
1940                                 getNextToken();
1941                         } else {
1942                                 throwSyntaxError("':' expected after 'elseif' keyword.");
1943                         }
1944                         b = inner_statement_list();
1945                         statementList.add(b);
1946                         checkUnreachable(iState, b);
1947                 }
1948                 iState.elseifConditions = new Expression[conditionList.size()];
1949                 iState.elseifStatements = new Statement[statementList.size()];
1950                 conditionList.toArray(iState.elseifConditions);
1951                 statementList.toArray(iState.elseifStatements);
1952         }
1953
1954         private void else_single(IfStatement iState) {
1955                 // /* empty */
1956                 // T_ELSE statement
1957                 if (token == TokenNameelse) {
1958                         getNextToken();
1959                         Statement s = statement();
1960                         iState.elseStatement = s;
1961                         checkUnreachable(iState, s);
1962                 } else {
1963                         iState.checkUnreachable = false;
1964                 }
1965                 iState.sourceEnd = scanner.getCurrentTokenStartPosition();
1966         }
1967
1968         private void new_else_single(IfStatement iState) {
1969                 // /* empty */
1970                 // | T_ELSE ':' inner_statement_list
1971                 if (token == TokenNameelse) {
1972                         getNextToken();
1973                         if (token == TokenNameCOLON) {
1974                                 getNextToken();
1975                         } else {
1976                                 throwSyntaxError("':' expected after 'else' keyword.");
1977                         }
1978                         Block b = inner_statement_list();
1979                         iState.elseStatement = b;
1980                         checkUnreachable(iState, b);
1981                 } else {
1982                         iState.checkUnreachable = false;
1983                 }
1984         }
1985
1986         private Block inner_statement_list() {
1987                 // inner_statement_list inner_statement
1988                 // /* empty */
1989                 return statementList();
1990         }
1991
1992         /**
1993          * @param iState
1994          * @param b
1995          */
1996         private void checkUnreachable(IfStatement iState, Statement s) {
1997                 if (s instanceof Block) {
1998                         Block b = (Block) s;
1999                         if (b.statements == null || b.statements.length == 0) {
2000                                 iState.checkUnreachable = false;
2001                         } else {
2002                                 int off = b.statements.length - 1;
2003                                 if (!(b.statements[off] instanceof ReturnStatement) && !(b.statements[off] instanceof ContinueStatement)
2004                                                 && !(b.statements[off] instanceof BreakStatement)) {
2005                                         if (!(b.statements[off] instanceof IfStatement) || !((IfStatement) b.statements[off]).checkUnreachable) {
2006                                                 iState.checkUnreachable = false;
2007                                         }
2008                                 }
2009                         }
2010                 } else {
2011                         if (!(s instanceof ReturnStatement) && !(s instanceof ContinueStatement) && !(s instanceof BreakStatement)) {
2012                                 if (!(s instanceof IfStatement) || !((IfStatement) s).checkUnreachable) {
2013                                         iState.checkUnreachable = false;
2014                                 }
2015                         }
2016                 }
2017         }
2018
2019         // private void elseifStatementList() {
2020         // do {
2021         // elseifStatement();
2022         // switch (token) {
2023         // case TokenNameelse:
2024         // getNextToken();
2025         // if (token == TokenNameCOLON) {
2026         // getNextToken();
2027         // if (token != TokenNameendif) {
2028         // statementList();
2029         // }
2030         // return;
2031         // } else {
2032         // if (token == TokenNameif) { //'else if'
2033         // getNextToken();
2034         // } else {
2035         // throwSyntaxError("':' expected after 'else'.");
2036         // }
2037         // }
2038         // break;
2039         // case TokenNameelseif:
2040         // getNextToken();
2041         // break;
2042         // default:
2043         // return;
2044         // }
2045         // } while (true);
2046         // }
2047
2048         // private void elseifStatement() {
2049         // if (token == TokenNameLPAREN) {
2050         // getNextToken();
2051         // expr();
2052         // if (token != TokenNameRPAREN) {
2053         // throwSyntaxError("')' expected in else-if-statement.");
2054         // }
2055         // getNextToken();
2056         // if (token != TokenNameCOLON) {
2057         // throwSyntaxError("':' expected in else-if-statement.");
2058         // }
2059         // getNextToken();
2060         // if (token != TokenNameendif) {
2061         // statementList();
2062         // }
2063         // }
2064         // }
2065
2066         private void switchStatement() {
2067                 if (token == TokenNameCOLON) {
2068                         // ':' [labeled-statement-list] 'endswitch' ';'
2069                         getNextToken();
2070                         labeledStatementList();
2071                         if (token != TokenNameendswitch) {
2072                                 throwSyntaxError("'endswitch' expected.");
2073                         }
2074                         getNextToken();
2075                         if (token != TokenNameSEMICOLON) {
2076                                 throwSyntaxError("';' expected after switch-statement.");
2077                         }
2078                         getNextToken();
2079                 } else {
2080                         // '{' [labeled-statement-list] '}'
2081                         if (token != TokenNameLBRACE) {
2082                                 throwSyntaxError("'{' expected in switch statement.");
2083                         }
2084                         getNextToken();
2085                         if (token != TokenNameRBRACE) {
2086                                 labeledStatementList();
2087                         }
2088                         if (token != TokenNameRBRACE) {
2089                                 throwSyntaxError("'}' expected in switch statement.");
2090                         }
2091                         getNextToken();
2092                 }
2093         }
2094
2095         private void forStatement() {
2096                 if (token == TokenNameCOLON) {
2097                         getNextToken();
2098                         statementList();
2099                         if (token != TokenNameendfor) {
2100                                 throwSyntaxError("'endfor' expected.");
2101                         }
2102                         getNextToken();
2103                         if (token != TokenNameSEMICOLON) {
2104                                 throwSyntaxError("';' expected after for-statement.");
2105                         }
2106                         getNextToken();
2107                 } else {
2108                         statement();
2109                 }
2110         }
2111
2112         private void whileStatement() {
2113                 // ':' statement-list 'endwhile' ';'
2114                 if (token == TokenNameCOLON) {
2115                         getNextToken();
2116                         statementList();
2117                         if (token != TokenNameendwhile) {
2118                                 throwSyntaxError("'endwhile' expected.");
2119                         }
2120                         getNextToken();
2121                         if (token != TokenNameSEMICOLON) {
2122                                 throwSyntaxError("';' expected after while-statement.");
2123                         }
2124                         getNextToken();
2125                 } else {
2126                         statement();
2127                 }
2128         }
2129
2130         private void foreachStatement() {
2131                 if (token == TokenNameCOLON) {
2132                         getNextToken();
2133                         statementList();
2134                         if (token != TokenNameendforeach) {
2135                                 throwSyntaxError("'endforeach' expected.");
2136                         }
2137                         getNextToken();
2138                         if (token != TokenNameSEMICOLON) {
2139                                 throwSyntaxError("';' expected after foreach-statement.");
2140                         }
2141                         getNextToken();
2142                 } else {
2143                         statement();
2144                 }
2145         }
2146
2147         // private void exitStatus() {
2148         // if (token == TokenNameLPAREN) {
2149         // getNextToken();
2150         // } else {
2151         // throwSyntaxError("'(' expected in 'exit-status'.");
2152         // }
2153         // if (token != TokenNameRPAREN) {
2154         // expression();
2155         // }
2156         // if (token == TokenNameRPAREN) {
2157         // getNextToken();
2158         // } else {
2159         // throwSyntaxError("')' expected after 'exit-status'.");
2160         // }
2161         // }
2162         private void expressionList() {
2163                 do {
2164                         expr();
2165                         if (token == TokenNameCOMMA) {
2166                                 getNextToken();
2167                         } else {
2168                                 break;
2169                         }
2170                 } while (true);
2171         }
2172
2173         private Expression expr() {
2174                 // r_variable
2175                 // | expr_without_variable
2176                 // if (token!=TokenNameEOF) {
2177                 if (Scanner.TRACE) {
2178                         System.out.println("TRACE: expr()");
2179                 }
2180                 return expr_without_variable(true,null);
2181                 // }
2182         }
2183
2184         private Expression expr_without_variable(boolean only_variable, UninitializedVariableHandler initHandler) {
2185                 int exprSourceStart = scanner.getCurrentTokenStartPosition();
2186                 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2187                 Expression expression = new Expression();
2188                 expression.sourceStart = exprSourceStart;
2189                 // default, may be overwritten
2190                 expression.sourceEnd = exprSourceEnd;
2191                 try {
2192                         // internal_functions_in_yacc
2193                         // | T_CLONE expr
2194                         // | T_PRINT expr
2195                         // | '(' expr ')'
2196                         // | '@' expr
2197                         // | '+' expr
2198                         // | '-' expr
2199                         // | '!' expr
2200                         // | '~' expr
2201                         // | T_INC rw_variable
2202                         // | T_DEC rw_variable
2203                         // | T_INT_CAST expr
2204                         // | T_DOUBLE_CAST expr
2205                         // | T_STRING_CAST expr
2206                         // | T_ARRAY_CAST expr
2207                         // | T_OBJECT_CAST expr
2208                         // | T_BOOL_CAST expr
2209                         // | T_UNSET_CAST expr
2210                         // | T_EXIT exit_expr
2211                         // | scalar
2212                         // | T_ARRAY '(' array_pair_list ')'
2213                         // | '`' encaps_list '`'
2214                         // | T_LIST '(' assignment_list ')' '=' expr
2215                         // | T_NEW class_name_reference ctor_arguments
2216                         // | variable '=' expr
2217                         // | variable '=' '&' variable
2218                         // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2219                         // | variable T_PLUS_EQUAL expr
2220                         // | variable T_MINUS_EQUAL expr
2221                         // | variable T_MUL_EQUAL expr
2222                         // | variable T_DIV_EQUAL expr
2223                         // | variable T_CONCAT_EQUAL expr
2224                         // | variable T_MOD_EQUAL expr
2225                         // | variable T_AND_EQUAL expr
2226                         // | variable T_OR_EQUAL expr
2227                         // | variable T_XOR_EQUAL expr
2228                         // | variable T_SL_EQUAL expr
2229                         // | variable T_SR_EQUAL expr
2230                         // | rw_variable T_INC
2231                         // | rw_variable T_DEC
2232                         // | expr T_BOOLEAN_OR expr
2233                         // | expr T_BOOLEAN_AND expr
2234                         // | expr T_LOGICAL_OR expr
2235                         // | expr T_LOGICAL_AND expr
2236                         // | expr T_LOGICAL_XOR expr
2237                         // | expr '|' expr
2238                         // | expr '&' expr
2239                         // | expr '^' expr
2240                         // | expr '.' expr
2241                         // | expr '+' expr
2242                         // | expr '-' expr
2243                         // | expr '*' expr
2244                         // | expr '/' expr
2245                         // | expr '%' expr
2246                         // | expr T_SL expr
2247                         // | expr T_SR expr
2248                         // | expr T_IS_IDENTICAL expr
2249                         // | expr T_IS_NOT_IDENTICAL expr
2250                         // | expr T_IS_EQUAL expr
2251                         // | expr T_IS_NOT_EQUAL expr
2252                         // | expr '<' expr
2253                         // | expr T_IS_SMALLER_OR_EQUAL expr
2254                         // | expr '>' expr
2255                         // | expr T_IS_GREATER_OR_EQUAL expr
2256                         // | expr T_INSTANCEOF class_name_reference
2257                         // | expr '?' expr ':' expr
2258                         if (Scanner.TRACE) {
2259                                 System.out.println("TRACE: expr_without_variable() PART 1");
2260                         }
2261                         switch (token) {
2262                         case TokenNameisset:
2263                                 // T_ISSET '(' isset_variables ')'
2264                                 getNextToken();
2265                                 if (token != TokenNameLPAREN) {
2266                                         throwSyntaxError("'(' expected after keyword 'isset'");
2267                                 }
2268                                 getNextToken();
2269                                 isset_variables();
2270                                 if (token != TokenNameRPAREN) {
2271                                         throwSyntaxError("')' expected after keyword 'isset'");
2272                                 }
2273                                 getNextToken();
2274                                 break;
2275                         case TokenNameempty:
2276                                 getNextToken();
2277                                 if (token != TokenNameLPAREN) {
2278                                         throwSyntaxError("'(' expected after keyword 'empty'");
2279                                 }
2280                                 getNextToken();
2281                                 variable(true, false);
2282                                 if (token != TokenNameRPAREN) {
2283                                         throwSyntaxError("')' expected after keyword 'empty'");
2284                                 }
2285                                 getNextToken();
2286                                 break;
2287                         case TokenNameeval:
2288                         case TokenNameinclude:
2289                         case TokenNameinclude_once:
2290                         case TokenNamerequire:
2291                         case TokenNamerequire_once:
2292                                 internal_functions_in_yacc();
2293                                 break;
2294                         // | '(' expr ')'
2295                         case TokenNameLPAREN:
2296                                 getNextToken();
2297                                 expr();
2298                                 if (token == TokenNameRPAREN) {
2299                                         getNextToken();
2300                                 } else {
2301                                         throwSyntaxError("')' expected in expression.");
2302                                 }
2303                                 break;
2304                         // | T_CLONE expr
2305                         // | T_PRINT expr
2306                         // | '@' expr
2307                         // | '+' expr
2308                         // | '-' expr
2309                         // | '!' expr
2310                         // | '~' expr
2311                         // | T_INT_CAST expr
2312                         // | T_DOUBLE_CAST expr
2313                         // | T_STRING_CAST expr
2314                         // | T_ARRAY_CAST expr
2315                         // | T_OBJECT_CAST expr
2316                         // | T_BOOL_CAST expr
2317                         // | T_UNSET_CAST expr
2318                         case TokenNameclone:
2319                         case TokenNameprint:
2320                         case TokenNameAT:
2321                         case TokenNamePLUS:
2322                         case TokenNameMINUS:
2323                         case TokenNameNOT:
2324                         case TokenNameTWIDDLE:
2325                         case TokenNameintCAST:
2326                         case TokenNamedoubleCAST:
2327                         case TokenNamestringCAST:
2328                         case TokenNamearrayCAST:
2329                         case TokenNameobjectCAST:
2330                         case TokenNameboolCAST:
2331                         case TokenNameunsetCAST:
2332                                 getNextToken();
2333                                 expr();
2334                                 break;
2335                         case TokenNameexit:
2336                                 getNextToken();
2337                                 exit_expr();
2338                                 break;
2339                         // scalar:
2340                         // T_STRING
2341                         // | T_STRING_VARNAME
2342                         // | class_constant
2343                         // | T_START_HEREDOC encaps_list T_END_HEREDOC
2344                         // | '`' encaps_list '`'
2345                         // | common_scalar
2346                         // | '`' encaps_list '`'
2347                         // case TokenNameEncapsedString0:
2348                         // scanner.encapsedStringStack.push(new Character('`'));
2349                         // getNextToken();
2350                         // try {
2351                         // if (token == TokenNameEncapsedString0) {
2352                         // } else {
2353                         // encaps_list();
2354                         // if (token != TokenNameEncapsedString0) {
2355                         // throwSyntaxError("\'`\' expected at end of string" + "(Found token: " +
2356                         // scanner.toStringAction(token) + " )");
2357                         // }
2358                         // }
2359                         // } finally {
2360                         // scanner.encapsedStringStack.pop();
2361                         // getNextToken();
2362                         // }
2363                         // break;
2364                         // // | '\'' encaps_list '\''
2365                         // case TokenNameEncapsedString1:
2366                         // scanner.encapsedStringStack.push(new Character('\''));
2367                         // getNextToken();
2368                         // try {
2369                         // exprSourceStart = scanner.getCurrentTokenStartPosition();
2370                         // if (token == TokenNameEncapsedString1) {
2371                         // expression = new
2372                         // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2373                         // exprSourceStart, scanner
2374                         // .getCurrentTokenEndPosition());
2375                         // } else {
2376                         // encaps_list();
2377                         // if (token != TokenNameEncapsedString1) {
2378                         // throwSyntaxError("\'\'\' expected at end of string" + "(Found token: "
2379                         // + scanner.toStringAction(token) + " )");
2380                         // } else {
2381                         // expression = new
2382                         // StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2383                         // exprSourceStart, scanner
2384                         // .getCurrentTokenEndPosition());
2385                         // }
2386                         // }
2387                         // } finally {
2388                         // scanner.encapsedStringStack.pop();
2389                         // getNextToken();
2390                         // }
2391                         // break;
2392                         // //| '"' encaps_list '"'
2393                         // case TokenNameEncapsedString2:
2394                         // scanner.encapsedStringStack.push(new Character('"'));
2395                         // getNextToken();
2396                         // try {
2397                         // exprSourceStart = scanner.getCurrentTokenStartPosition();
2398                         // if (token == TokenNameEncapsedString2) {
2399                         // expression = new
2400                         // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2401                         // exprSourceStart, scanner
2402                         // .getCurrentTokenEndPosition());
2403                         // } else {
2404                         // encaps_list();
2405                         // if (token != TokenNameEncapsedString2) {
2406                         // throwSyntaxError("'\"' expected at end of string" + "(Found token: " +
2407                         // scanner.toStringAction(token) + " )");
2408                         // } else {
2409                         // expression = new
2410                         // StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart),
2411                         // exprSourceStart, scanner
2412                         // .getCurrentTokenEndPosition());
2413                         // }
2414                         // }
2415                         // } finally {
2416                         // scanner.encapsedStringStack.pop();
2417                         // getNextToken();
2418                         // }
2419                         // break;
2420                         case TokenNameStringDoubleQuote:
2421                                 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2422                                                 .getCurrentTokenEndPosition());
2423                                 common_scalar();
2424                                 break;
2425                         case TokenNameStringSingleQuote:
2426                                 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2427                                                 .getCurrentTokenEndPosition());
2428                                 common_scalar();
2429                                 break;
2430                         case TokenNameIntegerLiteral:
2431                         case TokenNameDoubleLiteral:
2432                         case TokenNameStringInterpolated:
2433                         case TokenNameFILE:
2434                         case TokenNameLINE:
2435                         case TokenNameCLASS_C:
2436                         case TokenNameMETHOD_C:
2437                         case TokenNameFUNC_C:
2438                                 common_scalar();
2439                                 break;
2440                         case TokenNameHEREDOC:
2441                                 getNextToken();
2442                                 break;
2443                         case TokenNamearray:
2444                                 // T_ARRAY '(' array_pair_list ')'
2445                                 getNextToken();
2446                                 if (token == TokenNameLPAREN) {
2447                                         getNextToken();
2448                                         if (token == TokenNameRPAREN) {
2449                                                 getNextToken();
2450                                                 break;
2451                                         }
2452                                         array_pair_list();
2453                                         if (token != TokenNameRPAREN) {
2454                                                 throwSyntaxError("')' or ',' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2455                                         }
2456                                         getNextToken();
2457                                 } else {
2458                                         throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2459                                 }
2460                                 break;
2461                         case TokenNamelist:
2462                                 // | T_LIST '(' assignment_list ')' '=' expr
2463                                 getNextToken();
2464                                 if (token == TokenNameLPAREN) {
2465                                         getNextToken();
2466                                         assignment_list();
2467                                         if (token != TokenNameRPAREN) {
2468                                                 throwSyntaxError("')' expected after 'list' keyword.");
2469                                         }
2470                                         getNextToken();
2471                                         if (token != TokenNameEQUAL) {
2472                                                 throwSyntaxError("'=' expected after 'list' keyword.");
2473                                         }
2474                                         getNextToken();
2475                                         expr();
2476                                 } else {
2477                                         throwSyntaxError("'(' expected after 'list' keyword.");
2478                                 }
2479                                 break;
2480                         case TokenNamenew:
2481                                 // | T_NEW class_name_reference ctor_arguments
2482                                 getNextToken();
2483                                 Expression typeRef = class_name_reference();
2484                                 ctor_arguments();
2485                                 if (typeRef != null) {
2486                                         expression = typeRef;
2487                                 }
2488                                 break;
2489                         // | T_INC rw_variable
2490                         // | T_DEC rw_variable
2491                         case TokenNamePLUS_PLUS:
2492                         case TokenNameMINUS_MINUS:
2493                                 getNextToken();
2494                                 rw_variable();
2495                                 break;
2496                         // | variable '=' expr
2497                         // | variable '=' '&' variable
2498                         // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2499                         // | variable T_PLUS_EQUAL expr
2500                         // | variable T_MINUS_EQUAL expr
2501                         // | variable T_MUL_EQUAL expr
2502                         // | variable T_DIV_EQUAL expr
2503                         // | variable T_CONCAT_EQUAL expr
2504                         // | variable T_MOD_EQUAL expr
2505                         // | variable T_AND_EQUAL expr
2506                         // | variable T_OR_EQUAL expr
2507                         // | variable T_XOR_EQUAL expr
2508                         // | variable T_SL_EQUAL expr
2509                         // | variable T_SR_EQUAL expr
2510                         // | rw_variable T_INC
2511                         // | rw_variable T_DEC
2512                         case TokenNameIdentifier:
2513                         case TokenNameVariable:
2514                         case TokenNameDOLLAR:
2515                                 Expression lhs = null;
2516                                 boolean rememberedVar = false;
2517                                 if (token == TokenNameIdentifier) {
2518                                         lhs = identifier(true, true);
2519                                         if (lhs != null) {
2520                                                 expression = lhs;
2521                                         }
2522                                 } else {
2523                                         lhs = variable(true, true);
2524                                         if (lhs != null) {
2525                                                 expression = lhs;
2526                                         }
2527                                         if (lhs != null && lhs instanceof FieldReference && token != TokenNameEQUAL && token != TokenNamePLUS_EQUAL
2528                                                         && token != TokenNameMINUS_EQUAL && token != TokenNameMULTIPLY_EQUAL && token != TokenNameDIVIDE_EQUAL
2529                                                         && token != TokenNameDOT_EQUAL && token != TokenNameREMAINDER_EQUAL && token != TokenNameAND_EQUAL
2530                                                         && token != TokenNameOR_EQUAL && token != TokenNameXOR_EQUAL && token != TokenNameRIGHT_SHIFT_EQUAL
2531                                                         && token != TokenNameLEFT_SHIFT_EQUAL) {
2532                                                 FieldReference ref = (FieldReference) lhs;
2533                                                 if (!containsVariableSet(ref.token)) {
2534                                                         if (null==initHandler || initHandler.reportError()) {
2535                                                                 problemReporter.uninitializedLocalVariable(new String(ref.token), ref.sourceStart, ref.sourceEnd,
2536                                                                         referenceContext, compilationUnit.compilationResult);
2537                                                         }
2538                                                         addVariableSet(ref.token);
2539                                                 }
2540                                         }
2541                                 }
2542                                 switch (token) {
2543                                 case TokenNameEQUAL:
2544                                         if (lhs != null && lhs instanceof FieldReference) {
2545                                                 addVariableSet(((FieldReference) lhs).token);
2546                                         }
2547                                         getNextToken();
2548                                         if (token == TokenNameAND) {
2549                                                 getNextToken();
2550                                                 if (token == TokenNamenew) {
2551                                                         // | variable '=' '&' T_NEW class_name_reference
2552                                                         // ctor_arguments
2553                                                         getNextToken();
2554                                                         SingleTypeReference classRef = class_name_reference();
2555                                                         ctor_arguments();
2556                                                         if (classRef != null) {
2557                                                                 if (lhs != null && lhs instanceof FieldReference) {
2558                                                                         // example:
2559                                                                         // $var = & new Object();
2560                                                                         if (fMethodVariables != null) {
2561                                                                                 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2562                                                                                 lhsInfo.reference = classRef;
2563                                                                                 lhsInfo.typeIdentifier = classRef.token;
2564                                                                                 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2565                                                                                 rememberedVar = true;
2566                                                                         }
2567                                                                 }
2568                                                         }
2569                                                 } else {
2570                                                         Expression rhs = variable(false, false);
2571                                                         if (rhs != null && rhs instanceof FieldReference && lhs != null && lhs instanceof FieldReference) {
2572                                                                 // example:
2573                                                                 // $var = &$ref;
2574                                                                 if (fMethodVariables != null) {
2575                                                                         VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2576                                                                         if (rhsInfo != null && rhsInfo.reference != null) {
2577                                                                                 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2578                                                                                 lhsInfo.reference = rhsInfo.reference;
2579                                                                                 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2580                                                                                 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2581                                                                                 rememberedVar = true;
2582                                                                         }
2583                                                                 }
2584                                                         }
2585                                                 }
2586                                         } else {
2587                                                 Expression rhs = expr();
2588                                                 if (lhs != null && lhs instanceof FieldReference) {
2589                                                         if (rhs != null && rhs instanceof FieldReference) {
2590                                                                 // example:
2591                                                                 // $var = $ref;
2592                                                                 if (fMethodVariables != null) {
2593                                                                         VariableInfo rhsInfo = (VariableInfo) fMethodVariables.get(((FieldReference) rhs).token);
2594                                                                         if (rhsInfo != null && rhsInfo.reference != null) {
2595                                                                                 VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2596                                                                                 lhsInfo.reference = rhsInfo.reference;
2597                                                                                 lhsInfo.typeIdentifier = rhsInfo.typeIdentifier;
2598                                                                                 fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2599                                                                                 rememberedVar = true;
2600                                                                         }
2601                                                                 }
2602                                                         } else if (rhs != null && rhs instanceof SingleTypeReference) {
2603                                                                 // example:
2604                                                                 // $var = new Object();
2605                                                                 if (fMethodVariables != null) {
2606                                                                         VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2607                                                                         lhsInfo.reference = (SingleTypeReference) rhs;
2608                                                                         lhsInfo.typeIdentifier = ((SingleTypeReference) rhs).token;
2609                                                                         fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2610                                                                         rememberedVar = true;
2611                                                                 }
2612                                                         }
2613                                                 }
2614                                         }
2615                                         if (rememberedVar == false && lhs != null && lhs instanceof FieldReference) {
2616                                                 if (fMethodVariables != null) {
2617                                                         VariableInfo lhsInfo = new VariableInfo(((FieldReference) lhs).sourceStart);
2618                                                         fMethodVariables.put(new String(((FieldReference) lhs).token), lhsInfo);
2619                                                 }
2620                                         }
2621                                         break;
2622                                 case TokenNamePLUS_EQUAL:
2623                                 case TokenNameMINUS_EQUAL:
2624                                 case TokenNameMULTIPLY_EQUAL:
2625                                 case TokenNameDIVIDE_EQUAL:
2626                                 case TokenNameDOT_EQUAL:
2627                                 case TokenNameREMAINDER_EQUAL:
2628                                 case TokenNameAND_EQUAL:
2629                                 case TokenNameOR_EQUAL:
2630                                 case TokenNameXOR_EQUAL:
2631                                 case TokenNameRIGHT_SHIFT_EQUAL:
2632                                 case TokenNameLEFT_SHIFT_EQUAL:
2633                                         if (lhs != null && lhs instanceof FieldReference) {
2634                                                 addVariableSet(((FieldReference) lhs).token);
2635                                         }
2636                                         getNextToken();
2637                                         expr();
2638                                         break;
2639                                 case TokenNamePLUS_PLUS:
2640                                 case TokenNameMINUS_MINUS:
2641                                         getNextToken();
2642                                         break;
2643                                 default:
2644                                         if (!only_variable) {
2645                                                 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2646                                         }
2647                                         if (lhs != null) {
2648                                                 expression = lhs;
2649                                         }
2650                                 }
2651                                 break;
2652                         default:
2653                                 if (token != TokenNameINLINE_HTML) {
2654                                         if (token > TokenNameKEYWORD) {
2655                                                 getNextToken();
2656                                                 break;
2657                                         } else {
2658                                                 // System.out.println(scanner.getCurrentTokenStartPosition());
2659                                                 // System.out.println(scanner.getCurrentTokenEndPosition());
2660
2661                                                 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2662                                         }
2663                                 }
2664                                 return expression;
2665                         }
2666                         if (Scanner.TRACE) {
2667                                 System.out.println("TRACE: expr_without_variable() PART 2");
2668                         }
2669                         // | expr T_BOOLEAN_OR expr
2670                         // | expr T_BOOLEAN_AND expr
2671                         // | expr T_LOGICAL_OR expr
2672                         // | expr T_LOGICAL_AND expr
2673                         // | expr T_LOGICAL_XOR expr
2674                         // | expr '|' expr
2675                         // | expr '&' expr
2676                         // | expr '^' expr
2677                         // | expr '.' expr
2678                         // | expr '+' expr
2679                         // | expr '-' expr
2680                         // | expr '*' expr
2681                         // | expr '/' expr
2682                         // | expr '%' expr
2683                         // | expr T_SL expr
2684                         // | expr T_SR expr
2685                         // | expr T_IS_IDENTICAL expr
2686                         // | expr T_IS_NOT_IDENTICAL expr
2687                         // | expr T_IS_EQUAL expr
2688                         // | expr T_IS_NOT_EQUAL expr
2689                         // | expr '<' expr
2690                         // | expr T_IS_SMALLER_OR_EQUAL expr
2691                         // | expr '>' expr
2692                         // | expr T_IS_GREATER_OR_EQUAL expr
2693                         while (true) {
2694                                 switch (token) {
2695                                 case TokenNameOR_OR:
2696                                         getNextToken();
2697                                         expression = new OR_OR_Expression(expression, expr(), token);
2698                                         break;
2699                                 case TokenNameAND_AND:
2700                                         getNextToken();
2701                                         expression = new AND_AND_Expression(expression, expr(), token);
2702                                         break;
2703                                 case TokenNameEQUAL_EQUAL:
2704                                         getNextToken();
2705                                         expression = new EqualExpression(expression, expr(), token);
2706                                         break;
2707                                 case TokenNameand:
2708                                 case TokenNameor:
2709                                 case TokenNamexor:
2710                                 case TokenNameAND:
2711                                 case TokenNameOR:
2712                                 case TokenNameXOR:
2713                                 case TokenNameDOT:
2714                                 case TokenNamePLUS:
2715                                 case TokenNameMINUS:
2716                                 case TokenNameMULTIPLY:
2717                                 case TokenNameDIVIDE:
2718                                 case TokenNameREMAINDER:
2719                                 case TokenNameLEFT_SHIFT:
2720                                 case TokenNameRIGHT_SHIFT:
2721                                 case TokenNameEQUAL_EQUAL_EQUAL:
2722                                 case TokenNameNOT_EQUAL_EQUAL:
2723                                 case TokenNameNOT_EQUAL:
2724                                 case TokenNameLESS:
2725                                 case TokenNameLESS_EQUAL:
2726                                 case TokenNameGREATER:
2727                                 case TokenNameGREATER_EQUAL:
2728                                         getNextToken();
2729                                         expression = new BinaryExpression(expression, expr(), token);
2730                                         break;
2731                                 // | expr T_INSTANCEOF class_name_reference
2732                                 // | expr '?' expr ':' expr
2733                                 case TokenNameinstanceof:
2734                                         getNextToken();
2735                                         TypeReference classRef = class_name_reference();
2736                                         if (classRef != null) {
2737                                                 expression = new InstanceOfExpression(expression, classRef, OperatorIds.INSTANCEOF);
2738                                                 expression.sourceStart = exprSourceStart;
2739                                                 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2740                                         }
2741                                         break;
2742                                 case TokenNameQUESTION:
2743                                         getNextToken();
2744                                         Expression valueIfTrue = expr();
2745                                         if (token != TokenNameCOLON) {
2746                                                 throwSyntaxError("':' expected in conditional expression.");
2747                                         }
2748                                         getNextToken();
2749                                         Expression valueIfFalse = expr();
2750
2751                                         expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2752                                         break;
2753                                 default:
2754                                         return expression;
2755                                 }
2756                         }
2757                 } catch (SyntaxError e) {
2758                         // try to find next token after expression with errors:
2759                         if (token == TokenNameSEMICOLON) {
2760                                 getNextToken();
2761                                 return expression;
2762                         }
2763                         if (token == TokenNameRBRACE || token == TokenNameRPAREN || token == TokenNameRBRACKET) {
2764                                 getNextToken();
2765                                 return expression;
2766                         }
2767                         throw e;
2768                 }
2769         }
2770
2771         private SingleTypeReference class_name_reference() {
2772                 // class_name_reference:
2773                 // T_STRING
2774                 // | dynamic_class_name_reference
2775                 SingleTypeReference ref = null;
2776                 if (Scanner.TRACE) {
2777                         System.out.println("TRACE: class_name_reference()");
2778                 }
2779                 if (token == TokenNameIdentifier) {
2780                         ref = new SingleTypeReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
2781                         getNextToken();
2782                 } else {
2783                         ref = null;
2784                         dynamic_class_name_reference();
2785                 }
2786                 return ref;
2787         }
2788
2789         private void dynamic_class_name_reference() {
2790                 // dynamic_class_name_reference:
2791                 // base_variable T_OBJECT_OPERATOR object_property
2792                 // dynamic_class_name_variable_properties
2793                 // | base_variable
2794                 if (Scanner.TRACE) {
2795                         System.out.println("TRACE: dynamic_class_name_reference()");
2796                 }
2797                 base_variable(true);
2798                 if (token == TokenNameMINUS_GREATER) {
2799                         getNextToken();
2800                         object_property();
2801                         dynamic_class_name_variable_properties();
2802                 }
2803         }
2804
2805         private void dynamic_class_name_variable_properties() {
2806                 // dynamic_class_name_variable_properties:
2807                 // dynamic_class_name_variable_properties
2808                 // dynamic_class_name_variable_property
2809                 // | /* empty */
2810                 if (Scanner.TRACE) {
2811                         System.out.println("TRACE: dynamic_class_name_variable_properties()");
2812                 }
2813                 while (token == TokenNameMINUS_GREATER) {
2814                         dynamic_class_name_variable_property();
2815                 }
2816         }
2817
2818         private void dynamic_class_name_variable_property() {
2819                 // dynamic_class_name_variable_property:
2820                 // T_OBJECT_OPERATOR object_property
2821                 if (Scanner.TRACE) {
2822                         System.out.println("TRACE: dynamic_class_name_variable_property()");
2823                 }
2824                 if (token == TokenNameMINUS_GREATER) {
2825                         getNextToken();
2826                         object_property();
2827                 }
2828         }
2829
2830         private void ctor_arguments() {
2831                 // ctor_arguments:
2832                 // /* empty */
2833                 // | '(' function_call_parameter_list ')'
2834                 if (token == TokenNameLPAREN) {
2835                         getNextToken();
2836                         if (token == TokenNameRPAREN) {
2837                                 getNextToken();
2838                                 return;
2839                         }
2840                         non_empty_function_call_parameter_list();
2841                         if (token != TokenNameRPAREN) {
2842                                 throwSyntaxError("')' expected in ctor_arguments.");
2843                         }
2844                         getNextToken();
2845                 }
2846         }
2847
2848         private void assignment_list() {
2849                 // assignment_list:
2850                 // assignment_list ',' assignment_list_element
2851                 // | assignment_list_element
2852                 while (true) {
2853                         assignment_list_element();
2854                         if (token != TokenNameCOMMA) {
2855                                 break;
2856                         }
2857                         getNextToken();
2858                 }
2859         }
2860
2861         private void assignment_list_element() {
2862                 // assignment_list_element:
2863                 // variable
2864                 // | T_LIST '(' assignment_list ')'
2865                 // | /* empty */
2866                 if (token == TokenNameVariable) {
2867                         variable(true, false);
2868                 } else if (token == TokenNameDOLLAR) {
2869                         variable(false, false);
2870                 } else {
2871                         if (token == TokenNamelist) {
2872                                 getNextToken();
2873                                 if (token == TokenNameLPAREN) {
2874                                         getNextToken();
2875                                         assignment_list();
2876                                         if (token != TokenNameRPAREN) {
2877                                                 throwSyntaxError("')' expected after 'list' keyword.");
2878                                         }
2879                                         getNextToken();
2880                                 } else {
2881                                         throwSyntaxError("'(' expected after 'list' keyword.");
2882                                 }
2883                         }
2884                 }
2885         }
2886
2887         private void array_pair_list() {
2888                 // array_pair_list:
2889                 // /* empty */
2890                 // | non_empty_array_pair_list possible_comma
2891                 non_empty_array_pair_list();
2892                 if (token == TokenNameCOMMA) {
2893                         getNextToken();
2894                 }
2895         }
2896
2897         private void non_empty_array_pair_list() {
2898                 // non_empty_array_pair_list:
2899                 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2900                 // | non_empty_array_pair_list ',' expr
2901                 // | expr T_DOUBLE_ARROW expr
2902                 // | expr
2903                 // | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2904                 // | non_empty_array_pair_list ',' '&' w_variable
2905                 // | expr T_DOUBLE_ARROW '&' w_variable
2906                 // | '&' w_variable
2907                 while (true) {
2908                         if (token == TokenNameAND) {
2909                                 getNextToken();
2910                                 variable(true, false);
2911                         } else {
2912                                 expr();
2913                                 if (token == TokenNameAND) {
2914                                         getNextToken();
2915                                         variable(true, false);
2916                                 } else if (token == TokenNameEQUAL_GREATER) {
2917                                         getNextToken();
2918                                         if (token == TokenNameAND) {
2919                                                 getNextToken();
2920                                                 variable(true, false);
2921                                         } else {
2922                                                 expr();
2923                                         }
2924                                 }
2925                         }
2926                         if (token != TokenNameCOMMA) {
2927                                 return;
2928                         }
2929                         getNextToken();
2930                         if (token == TokenNameRPAREN) {
2931                                 return;
2932                         }
2933                 }
2934         }
2935
2936         // private void variableList() {
2937         // do {
2938         // variable();
2939         // if (token == TokenNameCOMMA) {
2940         // getNextToken();
2941         // } else {
2942         // break;
2943         // }
2944         // } while (true);
2945         // }
2946         private Expression variable_without_objects(boolean lefthandside, boolean ignoreVar) {
2947                 // variable_without_objects:
2948                 // reference_variable
2949                 // | simple_indirect_reference reference_variable
2950                 if (Scanner.TRACE) {
2951                         System.out.println("TRACE: variable_without_objects()");
2952                 }
2953                 while (token == TokenNameDOLLAR) {
2954                         getNextToken();
2955                 }
2956                 return reference_variable(lefthandside, ignoreVar);
2957         }
2958
2959         private Expression function_call(boolean lefthandside, boolean ignoreVar) {
2960                 // function_call:
2961                 // T_STRING '(' function_call_parameter_list ')'
2962                 // | class_constant '(' function_call_parameter_list ')'
2963                 // | static_member '(' function_call_parameter_list ')'
2964                 // | variable_without_objects '(' function_call_parameter_list ')'
2965                 char[] defineName = null;
2966                 char[] ident = null;
2967                 int startPos = 0;
2968                 int endPos = 0;
2969                 Expression ref = null;
2970                 if (Scanner.TRACE) {
2971                         System.out.println("TRACE: function_call()");
2972                 }
2973                 if (token == TokenNameIdentifier) {
2974                         ident = scanner.getCurrentIdentifierSource();
2975                         defineName = ident;
2976                         startPos = scanner.getCurrentTokenStartPosition();
2977                         endPos = scanner.getCurrentTokenEndPosition();
2978                         getNextToken();
2979                         switch (token) {
2980                         case TokenNamePAAMAYIM_NEKUDOTAYIM:
2981                                 // static member:
2982                                 defineName = null;
2983                                 getNextToken();
2984                                 if (token == TokenNameIdentifier) {
2985                                         // class _constant
2986                                         getNextToken();
2987                                 } else {
2988                                         // static member:
2989                                         variable_without_objects(true, false);
2990                                 }
2991                                 break;
2992                         }
2993                 } else {
2994                         ref = variable_without_objects(lefthandside, ignoreVar);
2995                 }
2996                 if (token != TokenNameLPAREN) {
2997                         if (defineName != null) {
2998                                 // does this identifier contain only uppercase characters?
2999                                 if (defineName.length == 3) {
3000                                         if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3001                                                 defineName = null;
3002                                         }
3003                                 } else if (defineName.length == 4) {
3004                                         if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3005                                                 defineName = null;
3006                                         } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3007                                                 defineName = null;
3008                                         }
3009                                 } else if (defineName.length == 5) {
3010                                         if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3011                                                 defineName = null;
3012                                         }
3013                                 }
3014                                 if (defineName != null) {
3015                                         for (int i = 0; i < defineName.length; i++) {
3016                                                 if (Character.isLowerCase(defineName[i])) {
3017                                                         problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3018                                                         break;
3019                                                 }
3020                                         }
3021                                 }
3022                         }
3023                 } else {
3024                         getNextToken();
3025                         if (token == TokenNameRPAREN) {
3026                                 getNextToken();
3027                                 return ref;
3028                         }
3029                         non_empty_function_call_parameter_list();
3030                         if (token != TokenNameRPAREN) {
3031                                 String functionName;
3032                                 if (ident == null) {
3033                                         functionName = new String(" ");
3034                                 } else {
3035                                         functionName = new String(ident);
3036                                 }
3037                                 throwSyntaxError("')' expected in function call (" + functionName + ").");
3038                         }
3039                         getNextToken();
3040                 }
3041                 return ref;
3042         }
3043
3044         private void non_empty_function_call_parameter_list() {
3045                 this.non_empty_function_call_parameter_list(null);
3046         }
3047
3048         // private void function_call_parameter_list() {
3049         // function_call_parameter_list:
3050         // non_empty_function_call_parameter_list { $$ = $1; }
3051         // | /* empty */
3052         // }
3053         private void non_empty_function_call_parameter_list(String functionName) {
3054                 // non_empty_function_call_parameter_list:
3055                 // expr_without_variable
3056                 // | variable
3057                 // | '&' w_variable
3058                 // | non_empty_function_call_parameter_list ',' expr_without_variable
3059                 // | non_empty_function_call_parameter_list ',' variable
3060                 // | non_empty_function_call_parameter_list ',' '&' w_variable
3061                 if (Scanner.TRACE) {
3062                         System.out.println("TRACE: non_empty_function_call_parameter_list()");
3063                 }
3064                 UninitializedVariableHandler initHandler = new UninitializedVariableHandler();
3065                 initHandler.setFunctionName(functionName);
3066                 while (true) {
3067                         initHandler.incrementArgumentCount();
3068                         if (token == TokenNameAND) {
3069                                 getNextToken();
3070                                 w_variable(true);
3071                         } else {
3072                                 // if (token == TokenNameIdentifier || token ==
3073                                 // TokenNameVariable
3074                                 // || token == TokenNameDOLLAR) {
3075                                 // variable();
3076                                 // } else {
3077                                 expr_without_variable(true, initHandler);
3078                                 // }
3079                         }
3080                         if (token != TokenNameCOMMA) {
3081                                 break;
3082                         }
3083                         getNextToken();
3084                 }
3085         }
3086
3087         private void fully_qualified_class_name() {
3088                 if (token == TokenNameIdentifier) {
3089                         getNextToken();
3090                 } else {
3091                         throwSyntaxError("Class name expected.");
3092                 }
3093         }
3094
3095         private void static_member() {
3096                 // static_member:
3097                 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
3098                 // variable_without_objects
3099                 if (Scanner.TRACE) {
3100                         System.out.println("TRACE: static_member()");
3101                 }
3102                 fully_qualified_class_name();
3103                 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
3104                         throwSyntaxError("'::' expected after class name (static_member).");
3105                 }
3106                 getNextToken();
3107                 variable_without_objects(false, false);
3108         }
3109
3110         private Expression base_variable_with_function_calls(boolean lefthandside, boolean ignoreVar) {
3111                 // base_variable_with_function_calls:
3112                 // base_variable
3113                 // | function_call
3114                 if (Scanner.TRACE) {
3115                         System.out.println("TRACE: base_variable_with_function_calls()");
3116                 }
3117                 return function_call(lefthandside, ignoreVar);
3118         }
3119
3120         private Expression base_variable(boolean lefthandside) {
3121                 // base_variable:
3122                 // reference_variable
3123                 // | simple_indirect_reference reference_variable
3124                 // | static_member
3125                 Expression ref = null;
3126                 if (Scanner.TRACE) {
3127                         System.out.println("TRACE: base_variable()");
3128                 }
3129                 if (token == TokenNameIdentifier) {
3130                         static_member();
3131                 } else {
3132                         while (token == TokenNameDOLLAR) {
3133                                 getNextToken();
3134                         }
3135                         reference_variable(lefthandside, false);
3136                 }
3137                 return ref;
3138         }
3139
3140         // private void simple_indirect_reference() {
3141         // // simple_indirect_reference:
3142         // // '$'
3143         // //| simple_indirect_reference '$'
3144         // }
3145         private Expression reference_variable(boolean lefthandside, boolean ignoreVar) {
3146                 // reference_variable:
3147                 // reference_variable '[' dim_offset ']'
3148                 // | reference_variable '{' expr '}'
3149                 // | compound_variable
3150                 Expression ref = null;
3151                 if (Scanner.TRACE) {
3152                         System.out.println("TRACE: reference_variable()");
3153                 }
3154                 ref = compound_variable(lefthandside, ignoreVar);
3155                 while (true) {
3156                         if (token == TokenNameLBRACE) {
3157                                 ref = null;
3158                                 getNextToken();
3159                                 expr();
3160                                 if (token != TokenNameRBRACE) {
3161                                         throwSyntaxError("'}' expected in reference variable.");
3162                                 }
3163                                 getNextToken();
3164                         } else if (token == TokenNameLBRACKET) {
3165                                 // To remove "ref = null;" here, is probably better than the patch
3166                                 // commented in #1368081 - axelcl
3167                                 getNextToken();
3168                                 if (token != TokenNameRBRACKET) {
3169                                         expr();
3170                                         // dim_offset();
3171                                         if (token != TokenNameRBRACKET) {
3172                                                 throwSyntaxError("']' expected in reference variable.");
3173                                         }
3174                                 }
3175                                 getNextToken();
3176                         } else {
3177                                 break;
3178                         }
3179                 }
3180                 return ref;
3181         }
3182
3183         private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
3184                 // compound_variable:
3185                 // T_VARIABLE
3186                 // | '$' '{' expr '}'
3187                 if (Scanner.TRACE) {
3188                         System.out.println("TRACE: compound_variable()");
3189                 }
3190                 if (token == TokenNameVariable) {
3191                         if (!lefthandside) {
3192                                 if (!containsVariableSet()) {
3193                                         // reportSyntaxError("The local variable " + new
3194                                         // String(scanner.getCurrentIdentifierSource())
3195                                         // + " may not have been initialized");
3196                                         problemReporter.uninitializedLocalVariable(new String(scanner.getCurrentIdentifierSource()), scanner
3197                                                         .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), referenceContext,
3198                                                         compilationUnit.compilationResult);
3199                                 }
3200                         } else {
3201                                 if (!ignoreVar) {
3202                                         addVariableSet();
3203                                 }
3204                         }
3205                         FieldReference ref = new FieldReference(scanner.getCurrentIdentifierSource(), scanner.getCurrentTokenStartPosition());
3206                         getNextToken();
3207                         return ref;
3208                 } else {
3209                         // because of simple_indirect_reference
3210                         while (token == TokenNameDOLLAR) {
3211                                 getNextToken();
3212                         }
3213                         if (token != TokenNameLBRACE) {
3214                                 reportSyntaxError("'{' expected after compound variable token '$'.");
3215                                 return null;
3216                         }
3217                         getNextToken();
3218                         expr();
3219                         if (token != TokenNameRBRACE) {
3220                                 throwSyntaxError("'}' expected after compound variable token '$'.");
3221                         }
3222                         getNextToken();
3223                 }
3224                 return null;
3225         } // private void dim_offset() { // // dim_offset: // // /* empty */
3226
3227         // // | expr
3228         // expr();
3229         // }
3230         private void object_property() {
3231                 // object_property:
3232                 // object_dim_list
3233                 // | variable_without_objects
3234                 if (Scanner.TRACE) {
3235                         System.out.println("TRACE: object_property()");
3236                 }
3237                 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
3238                         variable_without_objects(false, false);
3239                 } else {
3240                         object_dim_list();
3241                 }
3242         }
3243
3244         private void object_dim_list() {
3245                 // object_dim_list:
3246                 // object_dim_list '[' dim_offset ']'
3247                 // | object_dim_list '{' expr '}'
3248                 // | variable_name
3249                 if (Scanner.TRACE) {
3250                         System.out.println("TRACE: object_dim_list()");
3251                 }
3252                 variable_name();
3253                 while (true) {
3254                         if (token == TokenNameLBRACE) {
3255                                 getNextToken();
3256                                 expr();
3257                                 if (token != TokenNameRBRACE) {
3258                                         throwSyntaxError("'}' expected in object_dim_list.");
3259                                 }
3260                                 getNextToken();
3261                         } else if (token == TokenNameLBRACKET) {
3262                                 getNextToken();
3263                                 if (token == TokenNameRBRACKET) {
3264                                         getNextToken();
3265                                         continue;
3266                                 }
3267                                 expr();
3268                                 if (token != TokenNameRBRACKET) {
3269                                         throwSyntaxError("']' expected in object_dim_list.");
3270                                 }
3271                                 getNextToken();
3272                         } else {
3273                                 break;
3274                         }
3275                 }
3276         }
3277
3278         private void variable_name() {
3279                 // variable_name:
3280                 // T_STRING
3281                 // | '{' expr '}'
3282                 if (Scanner.TRACE) {
3283                         System.out.println("TRACE: variable_name()");
3284                 }
3285                 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3286                         if (token > TokenNameKEYWORD) {
3287                                 // TODO show a warning "Keyword used as variable" ?
3288                         }
3289                         getNextToken();
3290                 } else {
3291                         if (token != TokenNameLBRACE) {
3292                                 throwSyntaxError("'{' expected in variable name.");
3293                         }
3294                         getNextToken();
3295                         expr();
3296                         if (token != TokenNameRBRACE) {
3297                                 throwSyntaxError("'}' expected in variable name.");
3298                         }
3299                         getNextToken();
3300                 }
3301         }
3302
3303         private void r_variable() {
3304                 variable(false, false);
3305         }
3306
3307         private void w_variable(boolean lefthandside) {
3308                 variable(lefthandside, false);
3309         }
3310
3311         private void rw_variable() {
3312                 variable(false, false);
3313         }
3314
3315         private Expression variable(boolean lefthandside, boolean ignoreVar) {
3316                 // variable:
3317                 // base_variable_with_function_calls T_OBJECT_OPERATOR
3318                 // object_property method_or_not variable_properties
3319                 // | base_variable_with_function_calls
3320                 Expression ref = base_variable_with_function_calls(lefthandside, ignoreVar);
3321                 if (token == TokenNameMINUS_GREATER) {
3322                         ref = null;
3323                         getNextToken();
3324                         object_property();
3325                         method_or_not();
3326                         variable_properties();
3327                 }
3328                 return ref;
3329         }
3330
3331         private void variable_properties() {
3332                 // variable_properties:
3333                 // variable_properties variable_property
3334                 // | /* empty */
3335                 while (token == TokenNameMINUS_GREATER) {
3336                         variable_property();
3337                 }
3338         }
3339
3340         private void variable_property() {
3341                 // variable_property:
3342                 // T_OBJECT_OPERATOR object_property method_or_not
3343                 if (Scanner.TRACE) {
3344                         System.out.println("TRACE: variable_property()");
3345                 }
3346                 if (token == TokenNameMINUS_GREATER) {
3347                         getNextToken();
3348                         object_property();
3349                         method_or_not();
3350                 } else {
3351                         throwSyntaxError("'->' expected in variable_property.");
3352                 }
3353         }
3354
3355         private Expression identifier(boolean lefthandside, boolean ignoreVar) {
3356                 // variable:
3357                 // base_variable_with_function_calls T_OBJECT_OPERATOR
3358                 // object_property method_or_not variable_properties
3359                 // | base_variable_with_function_calls
3360
3361                 // Expression ref = function_call(lefthandside, ignoreVar);
3362
3363                 // function_call:
3364                 // T_STRING '(' function_call_parameter_list ')'
3365                 // | class_constant '(' function_call_parameter_list ')'
3366                 // | static_member '(' function_call_parameter_list ')'
3367                 // | variable_without_objects '(' function_call_parameter_list ')'
3368                 char[] defineName = null;
3369                 char[] ident = null;
3370                 int startPos = 0;
3371                 int endPos = 0;
3372                 Expression ref = null;
3373                 if (Scanner.TRACE) {
3374                         System.out.println("TRACE: function_call()");
3375                 }
3376                 if (token == TokenNameIdentifier) {
3377                         ident = scanner.getCurrentIdentifierSource();
3378                         defineName = ident;
3379                         startPos = scanner.getCurrentTokenStartPosition();
3380                         endPos = scanner.getCurrentTokenEndPosition();
3381                         getNextToken();
3382
3383                         if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL || token == TokenNameMINUS_EQUAL
3384                                         || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL || token == TokenNameDOT_EQUAL
3385                                         || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL || token == TokenNameOR_EQUAL
3386                                         || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL || token == TokenNameLEFT_SHIFT_EQUAL) {
3387                                 String error = "Assignment operator '" + scanner.toStringAction(token) + "' not allowed after identifier '"
3388                                                 + new String(ident) + "' (use 'define(...)' to define constants).";
3389                                 reportSyntaxError(error);
3390                         }
3391
3392                         switch (token) {
3393                         case TokenNamePAAMAYIM_NEKUDOTAYIM:
3394                                 // static member:
3395                                 defineName = null;
3396                                 getNextToken();
3397                                 if (token == TokenNameIdentifier) {
3398                                         // class _constant
3399                                         getNextToken();
3400                                 } else {
3401                                         // static member:
3402                                         variable_without_objects(true, false);
3403                                 }
3404                                 break;
3405                         }
3406                 } else {
3407                         ref = variable_without_objects(lefthandside, ignoreVar);
3408                 }
3409                 if (token != TokenNameLPAREN) {
3410                         if (defineName != null) {
3411                                 // does this identifier contain only uppercase characters?
3412                                 if (defineName.length == 3) {
3413                                         if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
3414                                                 defineName = null;
3415                                         }
3416                                 } else if (defineName.length == 4) {
3417                                         if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
3418                                                 defineName = null;
3419                                         } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
3420                                                 defineName = null;
3421                                         }
3422                                 } else if (defineName.length == 5) {
3423                                         if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
3424                                                 defineName = null;
3425                                         }
3426                                 }
3427                                 if (defineName != null) {
3428                                         for (int i = 0; i < defineName.length; i++) {
3429                                                 if (Character.isLowerCase(defineName[i])) {
3430                                                         problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
3431                                                         break;
3432                                                 }
3433                                         }
3434                                 }
3435                         }
3436                         // TODO is this ok ?
3437                         // return ref;
3438                         // throwSyntaxError("'(' expected in function call.");
3439                 } else {
3440                         getNextToken();
3441
3442                         if (token == TokenNameRPAREN) {
3443                                 getNextToken();
3444                                 ref = null;
3445                         } else {
3446                                 String functionName;
3447                                 if (ident == null) {
3448                                         functionName = new String(" ");
3449                                 } else {
3450                                         functionName = new String(ident);
3451                                 }
3452                                 non_empty_function_call_parameter_list(functionName);
3453                                 if (token != TokenNameRPAREN) {
3454                                         throwSyntaxError("')' expected in function call (" + functionName + ").");
3455                                 }
3456                                 getNextToken();
3457                         }
3458                 }
3459                 if (token == TokenNameMINUS_GREATER) {
3460                         ref = null;
3461                         getNextToken();
3462                         object_property();
3463                         method_or_not();
3464                         variable_properties();
3465                 }
3466                 return ref;
3467         }
3468
3469         private void method_or_not() {
3470                 // method_or_not:
3471                 // '(' function_call_parameter_list ')'
3472                 // | /* empty */
3473                 if (Scanner.TRACE) {
3474                         System.out.println("TRACE: method_or_not()");
3475                 }
3476                 if (token == TokenNameLPAREN) {
3477                         getNextToken();
3478                         if (token == TokenNameRPAREN) {
3479                                 getNextToken();
3480                                 return;
3481                         }
3482                         non_empty_function_call_parameter_list();
3483                         if (token != TokenNameRPAREN) {
3484                                 throwSyntaxError("')' expected in method_or_not.");
3485                         }
3486                         getNextToken();
3487                 }
3488         }
3489
3490         private void exit_expr() {
3491                 // /* empty */
3492                 // | '(' ')'
3493                 // | '(' expr ')'
3494                 if (token != TokenNameLPAREN) {
3495                         return;
3496                 }
3497                 getNextToken();
3498                 if (token == TokenNameRPAREN) {
3499                         getNextToken();
3500                         return;
3501                 }
3502                 expr();
3503                 if (token != TokenNameRPAREN) {
3504                         throwSyntaxError("')' expected after keyword 'exit'");
3505                 }
3506                 getNextToken();
3507         }
3508
3509         // private void encaps_list() {
3510         // // encaps_list encaps_var
3511         // // | encaps_list T_STRING
3512         // // | encaps_list T_NUM_STRING
3513         // // | encaps_list T_ENCAPSED_AND_WHITESPACE
3514         // // | encaps_list T_CHARACTER
3515         // // | encaps_list T_BAD_CHARACTER
3516         // // | encaps_list '['
3517         // // | encaps_list ']'
3518         // // | encaps_list '{'
3519         // // | encaps_list '}'
3520         // // | encaps_list T_OBJECT_OPERATOR
3521         // // | /* empty */
3522         // while (true) {
3523         // switch (token) {
3524         // case TokenNameSTRING:
3525         // getNextToken();
3526         // break;
3527         // case TokenNameLBRACE:
3528         // // scanner.encapsedStringStack.pop();
3529         // getNextToken();
3530         // break;
3531         // case TokenNameRBRACE:
3532         // // scanner.encapsedStringStack.pop();
3533         // getNextToken();
3534         // break;
3535         // case TokenNameLBRACKET:
3536         // // scanner.encapsedStringStack.pop();
3537         // getNextToken();
3538         // break;
3539         // case TokenNameRBRACKET:
3540         // // scanner.encapsedStringStack.pop();
3541         // getNextToken();
3542         // break;
3543         // case TokenNameMINUS_GREATER:
3544         // // scanner.encapsedStringStack.pop();
3545         // getNextToken();
3546         // break;
3547         // case TokenNameVariable:
3548         // case TokenNameDOLLAR_LBRACE:
3549         // case TokenNameLBRACE_DOLLAR:
3550         // encaps_var();
3551         // break;
3552         // default:
3553         // char encapsedChar = ((Character)
3554         // scanner.encapsedStringStack.peek()).charValue();
3555         // if (encapsedChar == '$') {
3556         // scanner.encapsedStringStack.pop();
3557         // encapsedChar = ((Character)
3558         // scanner.encapsedStringStack.peek()).charValue();
3559         // switch (encapsedChar) {
3560         // case '`':
3561         // if (token == TokenNameEncapsedString0) {
3562         // return;
3563         // }
3564         // token = TokenNameSTRING;
3565         // continue;
3566         // case '\'':
3567         // if (token == TokenNameEncapsedString1) {
3568         // return;
3569         // }
3570         // token = TokenNameSTRING;
3571         // continue;
3572         // case '"':
3573         // if (token == TokenNameEncapsedString2) {
3574         // return;
3575         // }
3576         // token = TokenNameSTRING;
3577         // continue;
3578         // }
3579         // }
3580         // return;
3581         // }
3582         // }
3583         // }
3584
3585         // private void encaps_var() {
3586         // // T_VARIABLE
3587         // // | T_VARIABLE '[' encaps_var_offset ']'
3588         // // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3589         // // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3590         // // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3591         // // | T_CURLY_OPEN variable '}'
3592         // switch (token) {
3593         // case TokenNameVariable:
3594         // getNextToken();
3595         // if (token == TokenNameLBRACKET) {
3596         // getNextToken();
3597         // expr(); //encaps_var_offset();
3598         // if (token != TokenNameRBRACKET) {
3599         // throwSyntaxError("']' expected after variable.");
3600         // }
3601         // // scanner.encapsedStringStack.pop();
3602         // getNextToken();
3603         // // }
3604         // } else if (token == TokenNameMINUS_GREATER) {
3605         // getNextToken();
3606         // if (token != TokenNameIdentifier) {
3607         // throwSyntaxError("Identifier expected after '->'.");
3608         // }
3609         // // scanner.encapsedStringStack.pop();
3610         // getNextToken();
3611         // }
3612         // // else {
3613         // // // scanner.encapsedStringStack.pop();
3614         // // int tempToken = TokenNameSTRING;
3615         // // if (!scanner.encapsedStringStack.isEmpty()
3616         // // && (token == TokenNameEncapsedString0
3617         // // || token == TokenNameEncapsedString1
3618         // // || token == TokenNameEncapsedString2 || token ==
3619         // // TokenNameERROR)) {
3620         // // char encapsedChar = ((Character)
3621         // // scanner.encapsedStringStack.peek())
3622         // // .charValue();
3623         // // switch (token) {
3624         // // case TokenNameEncapsedString0 :
3625         // // if (encapsedChar == '`') {
3626         // // tempToken = TokenNameEncapsedString0;
3627         // // }
3628         // // break;
3629         // // case TokenNameEncapsedString1 :
3630         // // if (encapsedChar == '\'') {
3631         // // tempToken = TokenNameEncapsedString1;
3632         // // }
3633         // // break;
3634         // // case TokenNameEncapsedString2 :
3635         // // if (encapsedChar == '"') {
3636         // // tempToken = TokenNameEncapsedString2;
3637         // // }
3638         // // break;
3639         // // case TokenNameERROR :
3640         // // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3641         // // scanner.currentPosition--;
3642         // // getNextToken();
3643         // // }
3644         // // break;
3645         // // }
3646         // // }
3647         // // token = tempToken;
3648         // // }
3649         // break;
3650         // case TokenNameDOLLAR_LBRACE:
3651         // getNextToken();
3652         // if (token == TokenNameDOLLAR_LBRACE) {
3653         // encaps_var();
3654         // } else if (token == TokenNameIdentifier) {
3655         // getNextToken();
3656         // if (token == TokenNameLBRACKET) {
3657         // getNextToken();
3658         // // if (token == TokenNameRBRACKET) {
3659         // // getNextToken();
3660         // // } else {
3661         // expr();
3662         // if (token != TokenNameRBRACKET) {
3663         // throwSyntaxError("']' expected after '${'.");
3664         // }
3665         // getNextToken();
3666         // // }
3667         // }
3668         // } else {
3669         // expr();
3670         // }
3671         // if (token != TokenNameRBRACE) {
3672         // throwSyntaxError("'}' expected.");
3673         // }
3674         // getNextToken();
3675         // break;
3676         // case TokenNameLBRACE_DOLLAR:
3677         // getNextToken();
3678         // if (token == TokenNameLBRACE_DOLLAR) {
3679         // encaps_var();
3680         // } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3681         // getNextToken();
3682         // if (token == TokenNameLBRACKET) {
3683         // getNextToken();
3684         // // if (token == TokenNameRBRACKET) {
3685         // // getNextToken();
3686         // // } else {
3687         // expr();
3688         // if (token != TokenNameRBRACKET) {
3689         // throwSyntaxError("']' expected.");
3690         // }
3691         // getNextToken();
3692         // // }
3693         // } else if (token == TokenNameMINUS_GREATER) {
3694         // getNextToken();
3695         // if (token != TokenNameIdentifier && token != TokenNameVariable) {
3696         // throwSyntaxError("String or Variable token expected.");
3697         // }
3698         // getNextToken();
3699         // if (token == TokenNameLBRACKET) {
3700         // getNextToken();
3701         // // if (token == TokenNameRBRACKET) {
3702         // // getNextToken();
3703         // // } else {
3704         // expr();
3705         // if (token != TokenNameRBRACKET) {
3706         // throwSyntaxError("']' expected after '${'.");
3707         // }
3708         // getNextToken();
3709         // // }
3710         // }
3711         // }
3712         // // if (token != TokenNameRBRACE) {
3713         // // throwSyntaxError("'}' expected after '{$'.");
3714         // // }
3715         // // // scanner.encapsedStringStack.pop();
3716         // // getNextToken();
3717         // } else {
3718         // expr();
3719         // if (token != TokenNameRBRACE) {
3720         // throwSyntaxError("'}' expected.");
3721         // }
3722         // // scanner.encapsedStringStack.pop();
3723         // getNextToken();
3724         // }
3725         // break;
3726         // }
3727         // }
3728
3729         // private void encaps_var_offset() {
3730         // // T_STRING
3731         // // | T_NUM_STRING
3732         // // | T_VARIABLE
3733         // switch (token) {
3734         // case TokenNameSTRING:
3735         // getNextToken();
3736         // break;
3737         // case TokenNameIntegerLiteral:
3738         // getNextToken();
3739         // break;
3740         // case TokenNameVariable:
3741         // getNextToken();
3742         // break;
3743         // case TokenNameIdentifier:
3744         // getNextToken();
3745         // break;
3746         // default:
3747         // throwSyntaxError("Variable or String token expected.");
3748         // break;
3749         // }
3750         // }
3751
3752         private void internal_functions_in_yacc() {
3753                 // int start = 0;
3754                 switch (token) {
3755                 // case TokenNameisset:
3756                 // // T_ISSET '(' isset_variables ')'
3757                 // getNextToken();
3758                 // if (token != TokenNameLPAREN) {
3759                 // throwSyntaxError("'(' expected after keyword 'isset'");
3760                 // }
3761                 // getNextToken();
3762                 // isset_variables();
3763                 // if (token != TokenNameRPAREN) {
3764                 // throwSyntaxError("')' expected after keyword 'isset'");
3765                 // }
3766                 // getNextToken();
3767                 // break;
3768                 // case TokenNameempty:
3769                 // // T_EMPTY '(' variable ')'
3770                 // getNextToken();
3771                 // if (token != TokenNameLPAREN) {
3772                 // throwSyntaxError("'(' expected after keyword 'empty'");
3773                 // }
3774                 // getNextToken();
3775                 // variable(false);
3776                 // if (token != TokenNameRPAREN) {
3777                 // throwSyntaxError("')' expected after keyword 'empty'");
3778                 // }
3779                 // getNextToken();
3780                 // break;
3781                 case TokenNameinclude:
3782                         // T_INCLUDE expr
3783                         checkFileName(token);
3784                         break;
3785                 case TokenNameinclude_once:
3786                         // T_INCLUDE_ONCE expr
3787                         checkFileName(token);
3788                         break;
3789                 case TokenNameeval:
3790                         // T_EVAL '(' expr ')'
3791                         getNextToken();
3792                         if (token != TokenNameLPAREN) {
3793                                 throwSyntaxError("'(' expected after keyword 'eval'");
3794                         }
3795                         getNextToken();
3796                         expr();
3797                         if (token != TokenNameRPAREN) {
3798                                 throwSyntaxError("')' expected after keyword 'eval'");
3799                         }
3800                         getNextToken();
3801                         break;
3802                 case TokenNamerequire:
3803                         // T_REQUIRE expr
3804                         checkFileName(token);
3805                         break;
3806                 case TokenNamerequire_once:
3807                         // T_REQUIRE_ONCE expr
3808                         checkFileName(token);
3809                         break;
3810                 }
3811         }
3812
3813         /**
3814          * Parse and check the include file name
3815          *
3816          * @param includeToken
3817          */
3818         private void checkFileName(int includeToken) {
3819                 // <include-token> expr
3820                 int start = scanner.getCurrentTokenStartPosition();
3821                 boolean hasLPAREN = false;
3822                 getNextToken();
3823                 if (token == TokenNameLPAREN) {
3824                         hasLPAREN = true;
3825                         getNextToken();
3826                 }
3827                 Expression expression = expr();
3828                 if (hasLPAREN) {
3829                         if (token == TokenNameRPAREN) {
3830                                 getNextToken();
3831                         } else {
3832                                 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3833                         }
3834                 }
3835                 char[] currTokenSource = scanner.getCurrentTokenSource(start);
3836                 IFile file = null;
3837                 if (scanner.compilationUnit != null) {
3838                         IResource resource = scanner.compilationUnit.getResource();
3839                         if (resource != null && resource instanceof IFile) {
3840                                 file = (IFile) resource;
3841                         }
3842                 }
3843                 char[][] tokens;
3844                 tokens = new char[1][];
3845                 tokens[0] = currTokenSource;
3846
3847                 ImportReference impt = new ImportReference(tokens, currTokenSource, start, scanner.getCurrentTokenEndPosition(), false);
3848                 impt.declarationSourceEnd = impt.sourceEnd;
3849                 impt.declarationEnd = impt.declarationSourceEnd;
3850                 // endPosition is just before the ;
3851                 impt.declarationSourceStart = start;
3852                 includesList.add(impt);
3853
3854                 if (expression instanceof StringLiteral) {
3855                         StringLiteral literal = (StringLiteral) expression;
3856                         char[] includeName = literal.source();
3857                         if (includeName.length == 0) {
3858                                 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3859                                                 literal.sourceStart + 1);
3860                         }
3861                         String includeNameString = new String(includeName);
3862                         if (literal instanceof StringLiteralDQ) {
3863                                 if (includeNameString.indexOf('$') >= 0) {
3864                                         // assuming that the filename contains a variable => no filename check
3865                                         return;
3866                                 }
3867                         }
3868                         if (includeNameString.startsWith("http://")) {
3869                                 // assuming external include location
3870                                 return;
3871                         }
3872                         if (file != null) {
3873                                 // check the filename:
3874                                 // System.out.println(new String(compilationUnit.getFileName())+" - "+
3875                                 // expression.toStringExpression());
3876                                 IProject project = file.getProject();
3877                                 if (project != null) {
3878                                         IPath path = PHPFileUtil.determineFilePath(includeNameString, file, project);
3879
3880                                         if (path == null) {
3881                                                 // SyntaxError: "File: << >> doesn't exist in project."
3882                                                 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3883                                                 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3884                                                                 compilationUnit.compilationResult);
3885                                         } else {
3886                                                 try {
3887                                                         String filePath = path.toString();
3888                                                         String ext = file.getRawLocation().getFileExtension();
3889                                                         int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
3890
3891                                                         impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
3892                                                         impt.setFile(PHPFileUtil.createFile(path, project));
3893                                                 } catch (Exception e) {
3894                                                         // the file is outside of the workspace
3895                                                 }
3896                                         }
3897                                 }
3898                         }
3899                 }
3900         }
3901
3902         private void isset_variables() {
3903                 // variable
3904                 // | isset_variables ','
3905                 if (token == TokenNameRPAREN) {
3906                         throwSyntaxError("Variable expected after keyword 'isset'");
3907                 }
3908                 while (true) {
3909                         variable(true, false);
3910                         if (token == TokenNameCOMMA) {
3911                                 getNextToken();
3912                         } else {
3913                                 break;
3914                         }
3915                 }
3916         }
3917
3918         private boolean common_scalar() {
3919                 // common_scalar:
3920                 // T_LNUMBER
3921                 // | T_DNUMBER
3922                 // | T_CONSTANT_ENCAPSED_STRING
3923                 // | T_LINE
3924                 // | T_FILE
3925                 // | T_CLASS_C
3926                 // | T_METHOD_C
3927                 // | T_FUNC_C
3928                 switch (token) {
3929                 case TokenNameIntegerLiteral:
3930                         getNextToken();
3931                         return true;
3932                 case TokenNameDoubleLiteral:
3933                         getNextToken();
3934                         return true;
3935                 case TokenNameStringDoubleQuote:
3936                         getNextToken();
3937                         return true;
3938                 case TokenNameStringSingleQuote:
3939                         getNextToken();
3940                         return true;
3941                 case TokenNameStringInterpolated:
3942                         getNextToken();
3943                         return true;
3944                 case TokenNameFILE:
3945                         getNextToken();
3946                         return true;
3947                 case TokenNameLINE:
3948                         getNextToken();
3949                         return true;
3950                 case TokenNameCLASS_C:
3951                         getNextToken();
3952                         return true;
3953                 case TokenNameMETHOD_C:
3954                         getNextToken();
3955                         return true;
3956                 case TokenNameFUNC_C:
3957                         getNextToken();
3958                         return true;
3959                 }
3960                 return false;
3961         }
3962
3963         private void scalar() {
3964                 // scalar:
3965                 // T_STRING
3966                 // | T_STRING_VARNAME
3967                 // | class_constant
3968                 // | common_scalar
3969                 // | '"' encaps_list '"'
3970                 // | '\'' encaps_list '\''
3971                 // | T_START_HEREDOC encaps_list T_END_HEREDOC
3972                 throwSyntaxError("Not yet implemented (scalar).");
3973         }
3974
3975         private void static_scalar() {
3976                 // static_scalar: /* compile-time evaluated scalars */
3977                 // common_scalar
3978                 // | T_STRING
3979                 // | '+' static_scalar
3980                 // | '-' static_scalar
3981                 // | T_ARRAY '(' static_array_pair_list ')'
3982                 // | static_class_constant
3983                 if (common_scalar()) {
3984                         return;
3985                 }
3986                 switch (token) {
3987                 case TokenNameIdentifier:
3988                         getNextToken();
3989                         // static_class_constant:
3990                         // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3991                         if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3992                                 getNextToken();
3993                                 if (token == TokenNameIdentifier) {
3994                                         getNextToken();
3995                                 } else {
3996                                         throwSyntaxError("Identifier expected after '::' operator.");
3997                                 }
3998                         }
3999                         break;
4000                 case TokenNameEncapsedString0:
4001                         try {
4002                                 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4003                                 while (scanner.currentCharacter != '`') {
4004                                         if (scanner.currentCharacter == '\\') {
4005                                                 scanner.currentPosition++;
4006                                         }
4007                                         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4008                                 }
4009                                 getNextToken();
4010                         } catch (IndexOutOfBoundsException e) {
4011                                 throwSyntaxError("'`' expected at end of static string.");
4012                         }
4013                         break;
4014                 // case TokenNameEncapsedString1:
4015                 // try {
4016                 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4017                 // while (scanner.currentCharacter != '\'') {
4018                 // if (scanner.currentCharacter == '\\') {
4019                 // scanner.currentPosition++;
4020                 // }
4021                 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4022                 // }
4023                 // getNextToken();
4024                 // } catch (IndexOutOfBoundsException e) {
4025                 // throwSyntaxError("'\'' expected at end of static string.");
4026                 // }
4027                 // break;
4028                 // case TokenNameEncapsedString2:
4029                 // try {
4030                 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4031                 // while (scanner.currentCharacter != '"') {
4032                 // if (scanner.currentCharacter == '\\') {
4033                 // scanner.currentPosition++;
4034                 // }
4035                 // scanner.currentCharacter = scanner.source[scanner.currentPosition++];
4036                 // }
4037                 // getNextToken();
4038                 // } catch (IndexOutOfBoundsException e) {
4039                 // throwSyntaxError("'\"' expected at end of static string.");
4040                 // }
4041                 // break;
4042                 case TokenNameStringSingleQuote:
4043                         getNextToken();
4044                         break;
4045                 case TokenNameStringDoubleQuote:
4046                         getNextToken();
4047                         break;
4048                 case TokenNamePLUS:
4049                         getNextToken();
4050                         static_scalar();
4051                         break;
4052                 case TokenNameMINUS:
4053                         getNextToken();
4054                         static_scalar();
4055                         break;
4056                 case TokenNamearray:
4057                         getNextToken();
4058                         if (token != TokenNameLPAREN) {
4059                                 throwSyntaxError("'(' expected after keyword 'array'");
4060                         }
4061                         getNextToken();
4062                         if (token == TokenNameRPAREN) {
4063                                 getNextToken();
4064                                 break;
4065                         }
4066                         non_empty_static_array_pair_list();
4067                         if (token != TokenNameRPAREN) {
4068                                 throwSyntaxError("')' or ',' expected after keyword 'array'");
4069                         }
4070                         getNextToken();
4071                         break;
4072                 // case TokenNamenull :
4073                 // getNextToken();
4074                 // break;
4075                 // case TokenNamefalse :
4076                 // getNextToken();
4077                 // break;
4078                 // case TokenNametrue :
4079                 // getNextToken();
4080                 // break;
4081                 default:
4082                         throwSyntaxError("Static scalar/constant expected.");
4083                 }
4084         }
4085
4086         private void non_empty_static_array_pair_list() {
4087                 // non_empty_static_array_pair_list:
4088                 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
4089                 // static_scalar
4090                 // | non_empty_static_array_pair_list ',' static_scalar
4091                 // | static_scalar T_DOUBLE_ARROW static_scalar
4092                 // | static_scalar
4093                 while (true) {
4094                         static_scalar();
4095                         if (token == TokenNameEQUAL_GREATER) {
4096                                 getNextToken();
4097                                 static_scalar();
4098                         }
4099                         if (token != TokenNameCOMMA) {
4100                                 break;
4101                         }
4102                         getNextToken();
4103                         if (token == TokenNameRPAREN) {
4104                                 break;
4105                         }
4106                 }
4107         }
4108
4109         // public void reportSyntaxError() { //int act, int currentKind, int
4110         // // stateStackTop) {
4111         // /* remember current scanner position */
4112         // int startPos = scanner.startPosition;
4113         // int currentPos = scanner.currentPosition;
4114         //
4115         // this.checkAndReportBracketAnomalies(problemReporter());
4116         // /* reset scanner where it was */
4117         // scanner.startPosition = startPos;
4118         // scanner.currentPosition = currentPos;
4119         // }
4120
4121         public static final int RoundBracket = 0;
4122
4123         public static final int SquareBracket = 1;
4124
4125         public static final int CurlyBracket = 2;
4126
4127         public static final int BracketKinds = 3;
4128
4129         protected int[] nestedMethod; // the ptr is nestedType
4130
4131         protected int nestedType, dimensions;
4132
4133         // variable set stack
4134         final static int VariableStackIncrement = 10;
4135
4136         HashMap fTypeVariables = null;
4137
4138         HashMap fMethodVariables = null;
4139
4140         ArrayList fStackUnassigned = new ArrayList();
4141
4142         // ast stack
4143         final static int AstStackIncrement = 100;
4144
4145         protected int astPtr;
4146
4147         protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
4148
4149         protected int astLengthPtr;
4150
4151         protected int[] astLengthStack;
4152
4153         ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
4154
4155         public CompilationUnitDeclaration compilationUnit; /*
4156                                                                                                                                                                                                                          * the result from parse()
4157                                                                                                                                                                                                                          */
4158
4159         protected ReferenceContext referenceContext;
4160
4161         protected ProblemReporter problemReporter;
4162
4163         protected CompilerOptions options;
4164
4165         private ArrayList includesList;
4166
4167         // protected CompilationResult compilationResult;
4168         /**
4169          * Returns this parser's problem reporter initialized with its reference
4170          * context. Also it is assumed that a problem is going to be reported, so
4171          * initializes the compilation result's line positions.
4172          */
4173         public ProblemReporter problemReporter() {
4174                 if (scanner.recordLineSeparator) {
4175                         compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
4176                 }
4177                 problemReporter.referenceContext = referenceContext;
4178                 return problemReporter;
4179         }
4180
4181         /*
4182          * Reconsider the entire source looking for inconsistencies in {} () []
4183          */
4184         // public boolean checkAndReportBracketAnomalies(ProblemReporter
4185         // problemReporter) {
4186         // scanner.wasAcr = false;
4187         // boolean anomaliesDetected = false;
4188         // try {
4189         // char[] source = scanner.source;
4190         // int[] leftCount = { 0, 0, 0 };
4191         // int[] rightCount = { 0, 0, 0 };
4192         // int[] depths = { 0, 0, 0 };
4193         // int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10]
4194         // };
4195         // int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
4196         // int[][] rightPositions = new int[][] { new int[10], new int[10], new
4197         // int[10] };
4198         // int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10]
4199         // };
4200         // scanner.currentPosition = scanner.initialPosition; //starting
4201         // // point
4202         // // (first-zero-based
4203         // // char)
4204         // while (scanner.currentPosition < scanner.eofPosition) { //loop for
4205         // // jumping
4206         // // over
4207         // // comments
4208         // try {
4209         // // ---------Consume white space and handles
4210         // // startPosition---------
4211         // boolean isWhiteSpace;
4212         // do {
4213         // scanner.startPosition = scanner.currentPosition;
4214         // // if (((scanner.currentCharacter =
4215         // // source[scanner.currentPosition++]) == '\\') &&
4216         // // (source[scanner.currentPosition] == 'u')) {
4217         // // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
4218         // // } else {
4219         // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4220         // (scanner.currentCharacter == '\n'))) {
4221         // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4222         // // only record line positions we have not
4223         // // recorded yet
4224         // scanner.pushLineSeparator();
4225         // }
4226         // }
4227         // isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
4228         // // }
4229         // } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
4230         // // -------consume token until } is found---------
4231         // switch (scanner.currentCharacter) {
4232         // case '{': {
4233         // int index = leftCount[CurlyBracket]++;
4234         // if (index == leftPositions[CurlyBracket].length) {
4235         // System.arraycopy(leftPositions[CurlyBracket], 0,
4236         // (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
4237         // System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] =
4238         // new int[index * 2]), 0, index);
4239         // }
4240         // leftPositions[CurlyBracket][index] = scanner.startPosition;
4241         // leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
4242         // }
4243         // break;
4244         // case '}': {
4245         // int index = rightCount[CurlyBracket]++;
4246         // if (index == rightPositions[CurlyBracket].length) {
4247         // System.arraycopy(rightPositions[CurlyBracket], 0,
4248         // (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
4249         // System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] =
4250         // new int[index * 2]), 0, index);
4251         // }
4252         // rightPositions[CurlyBracket][index] = scanner.startPosition;
4253         // rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
4254         // }
4255         // break;
4256         // case '(': {
4257         // int index = leftCount[RoundBracket]++;
4258         // if (index == leftPositions[RoundBracket].length) {
4259         // System.arraycopy(leftPositions[RoundBracket], 0,
4260         // (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
4261         // System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] =
4262         // new int[index * 2]), 0, index);
4263         // }
4264         // leftPositions[RoundBracket][index] = scanner.startPosition;
4265         // leftDepths[RoundBracket][index] = depths[RoundBracket]++;
4266         // }
4267         // break;
4268         // case ')': {
4269         // int index = rightCount[RoundBracket]++;
4270         // if (index == rightPositions[RoundBracket].length) {
4271         // System.arraycopy(rightPositions[RoundBracket], 0,
4272         // (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
4273         // System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] =
4274         // new int[index * 2]), 0, index);
4275         // }
4276         // rightPositions[RoundBracket][index] = scanner.startPosition;
4277         // rightDepths[RoundBracket][index] = --depths[RoundBracket];
4278         // }
4279         // break;
4280         // case '[': {
4281         // int index = leftCount[SquareBracket]++;
4282         // if (index == leftPositions[SquareBracket].length) {
4283         // System.arraycopy(leftPositions[SquareBracket], 0,
4284         // (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
4285         // System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] =
4286         // new int[index * 2]), 0, index);
4287         // }
4288         // leftPositions[SquareBracket][index] = scanner.startPosition;
4289         // leftDepths[SquareBracket][index] = depths[SquareBracket]++;
4290         // }
4291         // break;
4292         // case ']': {
4293         // int index = rightCount[SquareBracket]++;
4294         // if (index == rightPositions[SquareBracket].length) {
4295         // System.arraycopy(rightPositions[SquareBracket], 0,
4296         // (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
4297         // System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket]
4298         // = new int[index * 2]), 0, index);
4299         // }
4300         // rightPositions[SquareBracket][index] = scanner.startPosition;
4301         // rightDepths[SquareBracket][index] = --depths[SquareBracket];
4302         // }
4303         // break;
4304         // case '\'': {
4305         // if (scanner.getNextChar('\\')) {
4306         // scanner.scanEscapeCharacter();
4307         // } else { // consume next character
4308         // scanner.unicodeAsBackSlash = false;
4309         // // if (((scanner.currentCharacter =
4310         // // source[scanner.currentPosition++]) ==
4311         // // '\\') &&
4312         // // (source[scanner.currentPosition] ==
4313         // // 'u')) {
4314         // // scanner.getNextUnicodeChar();
4315         // // } else {
4316         // if (scanner.withoutUnicodePtr != 0) {
4317         // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4318         // scanner.currentCharacter;
4319         // }
4320         // // }
4321         // }
4322         // scanner.getNextChar('\'');
4323         // break;
4324         // }
4325         // case '"':
4326         // // consume next character
4327         // scanner.unicodeAsBackSlash = false;
4328         // // if (((scanner.currentCharacter =
4329         // // source[scanner.currentPosition++]) == '\\') &&
4330         // // (source[scanner.currentPosition] == 'u')) {
4331         // // scanner.getNextUnicodeChar();
4332         // // } else {
4333         // if (scanner.withoutUnicodePtr != 0) {
4334         // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4335         // scanner.currentCharacter;
4336         // }
4337         // // }
4338         // while (scanner.currentCharacter != '"') {
4339         // if (scanner.currentCharacter == '\r') {
4340         // if (source[scanner.currentPosition] == '\n')
4341         // scanner.currentPosition++;
4342         // break; // the string cannot go further that
4343         // // the line
4344         // }
4345         // if (scanner.currentCharacter == '\n') {
4346         // break; // the string cannot go further that
4347         // // the line
4348         // }
4349         // if (scanner.currentCharacter == '\\') {
4350         // scanner.scanEscapeCharacter();
4351         // }
4352         // // consume next character
4353         // scanner.unicodeAsBackSlash = false;
4354         // // if (((scanner.currentCharacter =
4355         // // source[scanner.currentPosition++]) == '\\')
4356         // // && (source[scanner.currentPosition] == 'u'))
4357         // // {
4358         // // scanner.getNextUnicodeChar();
4359         // // } else {
4360         // if (scanner.withoutUnicodePtr != 0) {
4361         // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4362         // scanner.currentCharacter;
4363         // }
4364         // // }
4365         // }
4366         // break;
4367         // case '/': {
4368         // int test;
4369         // if ((test = scanner.getNextChar('/', '*')) == 0) { //line
4370         // // comment
4371         // //get the next char
4372         // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4373         // '\\')
4374         // && (source[scanner.currentPosition] == 'u')) {
4375         // //-------------unicode traitement
4376         // // ------------
4377         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4378         // scanner.currentPosition++;
4379         // while (source[scanner.currentPosition] == 'u') {
4380         // scanner.currentPosition++;
4381         // }
4382         // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4383         // 15 || c1 < 0
4384         // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4385         // || c2 < 0
4386         // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4387         // || c3 < 0
4388         // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4389         // || c4 < 0) { //error
4390         // // don't
4391         // // care of the
4392         // // value
4393         // scanner.currentCharacter = 'A';
4394         // } //something different from \n and \r
4395         // else {
4396         // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4397         // }
4398         // }
4399         // while (scanner.currentCharacter != '\r' && scanner.currentCharacter !=
4400         // '\n') {
4401         // //get the next char
4402         // scanner.startPosition = scanner.currentPosition;
4403         // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4404         // '\\')
4405         // && (source[scanner.currentPosition] == 'u')) {
4406         // //-------------unicode traitement
4407         // // ------------
4408         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4409         // scanner.currentPosition++;
4410         // while (source[scanner.currentPosition] == 'u') {
4411         // scanner.currentPosition++;
4412         // }
4413         // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4414         // 15 || c1 < 0
4415         // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4416         // || c2 < 0
4417         // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4418         // || c3 < 0
4419         // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4420         // || c4 < 0) { //error
4421         // // don't
4422         // // care of the
4423         // // value
4424         // scanner.currentCharacter = 'A';
4425         // } //something different from \n
4426         // // and \r
4427         // else {
4428         // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4429         // }
4430         // }
4431         // }
4432         // if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') ||
4433         // (scanner.currentCharacter == '\n'))) {
4434         // if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4435         // // only record line positions we
4436         // // have not recorded yet
4437         // scanner.pushLineSeparator();
4438         // if (this.scanner.taskTags != null) {
4439         // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4440         // this.scanner
4441         // .getCurrentTokenEndPosition());
4442         // }
4443         // }
4444         // }
4445         // break;
4446         // }
4447         // if (test > 0) { //traditional and annotation
4448         // // comment
4449         // boolean star = false;
4450         // // consume next character
4451         // scanner.unicodeAsBackSlash = false;
4452         // // if (((scanner.currentCharacter =
4453         // // source[scanner.currentPosition++]) ==
4454         // // '\\') &&
4455         // // (source[scanner.currentPosition] ==
4456         // // 'u')) {
4457         // // scanner.getNextUnicodeChar();
4458         // // } else {
4459         // if (scanner.withoutUnicodePtr != 0) {
4460         // scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] =
4461         // scanner.currentCharacter;
4462         // }
4463         // // }
4464         // if (scanner.currentCharacter == '*') {
4465         // star = true;
4466         // }
4467         // //get the next char
4468         // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4469         // '\\')
4470         // && (source[scanner.currentPosition] == 'u')) {
4471         // //-------------unicode traitement
4472         // // ------------
4473         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4474         // scanner.currentPosition++;
4475         // while (source[scanner.currentPosition] == 'u') {
4476         // scanner.currentPosition++;
4477         // }
4478         // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4479         // 15 || c1 < 0
4480         // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4481         // || c2 < 0
4482         // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4483         // || c3 < 0
4484         // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4485         // || c4 < 0) { //error
4486         // // don't
4487         // // care of the
4488         // // value
4489         // scanner.currentCharacter = 'A';
4490         // } //something different from * and /
4491         // else {
4492         // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4493         // }
4494         // }
4495         // //loop until end of comment */
4496         // while ((scanner.currentCharacter != '/') || (!star)) {
4497         // star = scanner.currentCharacter == '*';
4498         // //get next char
4499         // if (((scanner.currentCharacter = source[scanner.currentPosition++]) ==
4500         // '\\')
4501         // && (source[scanner.currentPosition] == 'u')) {
4502         // //-------------unicode traitement
4503         // // ------------
4504         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4505         // scanner.currentPosition++;
4506         // while (source[scanner.currentPosition] == 'u') {
4507         // scanner.currentPosition++;
4508         // }
4509         // if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) >
4510         // 15 || c1 < 0
4511         // || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4512         // || c2 < 0
4513         // || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4514         // || c3 < 0
4515         // || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15
4516         // || c4 < 0) { //error
4517         // // don't
4518         // // care of the
4519         // // value
4520         // scanner.currentCharacter = 'A';
4521         // } //something different from * and
4522         // // /
4523         // else {
4524         // scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4525         // }
4526         // }
4527         // }
4528         // if (this.scanner.taskTags != null) {
4529         // this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(),
4530         // this.scanner.getCurrentTokenEndPosition());
4531         // }
4532         // break;
4533         // }
4534         // break;
4535         // }
4536         // default:
4537         // if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4538         // scanner.scanIdentifierOrKeyword(false);
4539         // break;
4540         // }
4541         // if (Character.isDigit(scanner.currentCharacter)) {
4542         // scanner.scanNumber(false);
4543         // break;
4544         // }
4545         // }
4546         // //-----------------end switch while
4547         // // try--------------------
4548         // } catch (IndexOutOfBoundsException e) {
4549         // break; // read until EOF
4550         // } catch (InvalidInputException e) {
4551         // return false; // no clue
4552         // }
4553         // }
4554         // if (scanner.recordLineSeparator) {
4555         // compilationUnit.compilationResult.lineSeparatorPositions =
4556         // scanner.getLineEnds();
4557         // }
4558         // // check placement anomalies against other kinds of brackets
4559         // for (int kind = 0; kind < BracketKinds; kind++) {
4560         // for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4561         // int start = leftPositions[kind][leftIndex]; // deepest
4562         // // first
4563         // // find matching closing bracket
4564         // int depth = leftDepths[kind][leftIndex];
4565         // int end = -1;
4566         // for (int i = 0; i < rightCount[kind]; i++) {
4567         // int pos = rightPositions[kind][i];
4568         // // want matching bracket further in source with same
4569         // // depth
4570         // if ((pos > start) && (depth == rightDepths[kind][i])) {
4571         // end = pos;
4572         // break;
4573         // }
4574         // }
4575         // if (end < 0) { // did not find a good closing match
4576         // problemReporter.unmatchedBracket(start, referenceContext,
4577         // compilationUnit.compilationResult);
4578         // return true;
4579         // }
4580         // // check if even number of opening/closing other brackets
4581         // // in between this pair of brackets
4582         // int balance = 0;
4583         // for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds);
4584         // otherKind++) {
4585         // for (int i = 0; i < leftCount[otherKind]; i++) {
4586         // int pos = leftPositions[otherKind][i];
4587         // if ((pos > start) && (pos < end))
4588         // balance++;
4589         // }
4590         // for (int i = 0; i < rightCount[otherKind]; i++) {
4591         // int pos = rightPositions[otherKind][i];
4592         // if ((pos > start) && (pos < end))
4593         // balance--;
4594         // }
4595         // if (balance != 0) {
4596         // problemReporter.unmatchedBracket(start, referenceContext,
4597         // compilationUnit.compilationResult); //bracket
4598         // // anomaly
4599         // return true;
4600         // }
4601         // }
4602         // }
4603         // // too many opening brackets ?
4604         // for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4605         // anomaliesDetected = true;
4606         // problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i -
4607         // 1], referenceContext,
4608         // compilationUnit.compilationResult);
4609         // }
4610         // // too many closing brackets ?
4611         // for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4612         // anomaliesDetected = true;
4613         // problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext,
4614         // compilationUnit.compilationResult);
4615         // }
4616         // if (anomaliesDetected)
4617         // return true;
4618         // }
4619         // return anomaliesDetected;
4620         // } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4621         // return anomaliesDetected;
4622         // } catch (NullPointerException e) { // jdk1.2.2 jit bug
4623         // return anomaliesDetected;
4624         // }
4625         // }
4626         protected void pushOnAstLengthStack(int pos) {
4627                 try {
4628                         astLengthStack[++astLengthPtr] = pos;
4629                 } catch (IndexOutOfBoundsException e) {
4630                         int oldStackLength = astLengthStack.length;
4631                         int[] oldPos = astLengthStack;
4632                         astLengthStack = new int[oldStackLength + StackIncrement];
4633                         System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4634                         astLengthStack[astLengthPtr] = pos;
4635                 }
4636         }
4637
4638         protected void pushOnAstStack(ASTNode node) {
4639                 /*
4640                  * add a new obj on top of the ast stack
4641                  */
4642                 try {
4643                         astStack[++astPtr] = node;
4644                 } catch (IndexOutOfBoundsException e) {
4645                         int oldStackLength = astStack.length;
4646                         ASTNode[] oldStack = astStack;
4647                         astStack = new ASTNode[oldStackLength + AstStackIncrement];
4648                         System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4649                         astPtr = oldStackLength;
4650                         astStack[astPtr] = node;
4651                 }
4652                 try {
4653                         astLengthStack[++astLengthPtr] = 1;
4654                 } catch (IndexOutOfBoundsException e) {
4655                         int oldStackLength = astLengthStack.length;
4656                         int[] oldPos = astLengthStack;
4657                         astLengthStack = new int[oldStackLength + AstStackIncrement];
4658                         System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4659                         astLengthStack[astLengthPtr] = 1;
4660                 }
4661         }
4662
4663         protected void resetModifiers() {
4664                 this.modifiers = AccDefault;
4665                 this.modifiersSourceStart = -1; // <-- see comment into
4666                 // modifiersFlag(int)
4667                 this.scanner.commentPtr = -1;
4668         }
4669
4670         protected void consumePackageDeclarationName(IFile file) {
4671                 // create a package name similar to java package names
4672                 String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()).toString();
4673                 String filePath = file.getRawLocation().toString();
4674                 String ext = file.getRawLocation().getFileExtension();
4675                 int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
4676                 ImportReference impt;
4677                 char[][] tokens;
4678                 if (filePath.startsWith(projectPath)) {
4679                         tokens = CharOperation
4680                                         .splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() - fileExtensionLength);
4681                 } else {
4682                         String name = file.getName();
4683                         tokens = new char[1][];
4684                         tokens[0] = name.substring(0, name.length() - fileExtensionLength).toCharArray();
4685                 }
4686
4687                 this.compilationUnit.currentPackage = impt = new ImportReference(tokens, new char[0], 0, 0, true);
4688
4689                 impt.declarationSourceStart = 0;
4690                 impt.declarationSourceEnd = 0;
4691                 impt.declarationEnd = 0;
4692                 // endPosition is just before the ;
4693
4694         }
4695
4696         public final static String[] GLOBALS = { "$this", "$_COOKIE", "$_ENV", "$_FILES", "$_GET", "$GLOBALS", "$_POST", "$_REQUEST",
4697                         "$_SESSION", "$_SERVER" };
4698
4699         /**
4700          *
4701          */
4702         private void pushFunctionVariableSet() {
4703                 HashSet set = new HashSet();
4704                 if (fStackUnassigned.isEmpty()) {
4705                         for (int i = 0; i < GLOBALS.length; i++) {
4706                                 set.add(GLOBALS[i]);
4707                         }
4708                 }
4709                 fStackUnassigned.add(set);
4710         }
4711
4712         private void pushIfVariableSet() {
4713                 if (!fStackUnassigned.isEmpty()) {
4714                         HashSet set = new HashSet();
4715                         fStackUnassigned.add(set);
4716                 }
4717         }
4718
4719         private HashSet removeIfVariableSet() {
4720                 if (!fStackUnassigned.isEmpty()) {
4721                         return (HashSet) fStackUnassigned.remove(fStackUnassigned.size() - 1);
4722                 }
4723                 return null;
4724         }
4725
4726         /**
4727          * Returns the <i>set of assigned variables </i> returns null if no Set is
4728          * defined at the current scanner position
4729          */
4730         private HashSet peekVariableSet() {
4731                 if (!fStackUnassigned.isEmpty()) {
4732                         return (HashSet) fStackUnassigned.get(fStackUnassigned.size() - 1);
4733                 }
4734                 return null;
4735         }
4736
4737         /**
4738          * add the current identifier source to the <i>set of assigned variables </i>
4739          *
4740          * @param set
4741          */
4742         private void addVariableSet(HashSet set) {
4743                 if (set != null) {
4744                         set.add(new String(scanner.getCurrentTokenSource()));
4745                 }
4746         }
4747
4748         /**
4749          * add the current identifier source to the <i>set of assigned variables </i>
4750          *
4751          */
4752         private void addVariableSet() {
4753                 HashSet set = peekVariableSet();
4754                 if (set != null) {
4755                         set.add(new String(scanner.getCurrentTokenSource()));
4756                 }
4757         }
4758
4759         /**
4760          * add the current identifier source to the <i>set of assigned variables </i>
4761          *
4762          */
4763         private void addVariableSet(char[] token) {
4764                 HashSet set = peekVariableSet();
4765                 if (set != null) {
4766                         set.add(new String(token));
4767                 }
4768         }
4769
4770         /**
4771          * check if the current identifier source is in the <i>set of assigned
4772          * variables </i> Returns true, if no set is defined for the current scanner
4773          * position
4774          *
4775          */
4776         private boolean containsVariableSet() {
4777                 return containsVariableSet(scanner.getCurrentTokenSource());
4778         }
4779
4780         private boolean containsVariableSet(char[] token) {
4781
4782                 if (!fStackUnassigned.isEmpty()) {
4783                         HashSet set;
4784                         String str = new String(token);
4785                         for (int i = 0; i < fStackUnassigned.size(); i++) {
4786                                 set = (HashSet) fStackUnassigned.get(i);
4787                                 if (set.contains(str)) {
4788                                         return true;
4789                                 }
4790                         }
4791                         return false;
4792                 }
4793                 return true;
4794         }
4795 }