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