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