1 /*******************************************************************************
2 * Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de All rights
3 * reserved. This program and the accompanying material are made available under
4 * the terms of the Common Public License v1.0 which accompanies this
5 * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
7 * Contributors: Klaus Hartlage - www.eclipseproject.de
8 ******************************************************************************/
9 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
16 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
17 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
19 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
21 import net.sourceforge.phpdt.internal.compiler.util.Util;
22 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
23 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
24 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
25 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
32 import org.eclipse.core.resources.IFile;
33 public class Parser //extends PHPParserSuperclass
34 implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
35 //internal data for the automat
36 protected final static int StackIncrement = 255;
37 protected int stateStackTop;
38 protected int[] stack = new int[StackIncrement];
39 public int firstToken; // handle for multiple parsing goals
40 public int lastAct; //handle for multiple parsing goals
41 protected RecoveredElement currentElement;
42 public static boolean VERBOSE_RECOVERY = false;
43 protected boolean diet = false; //tells the scanner to jump over some
44 // parts of the code/expressions like
47 public Scanner scanner;
48 private ArrayList phpList;
49 private int currentPHPString;
50 private boolean phpEnd;
51 // private static HashMap keywordMap = null;
57 // row counter for syntax errors:
59 // column counter for syntax errors:
63 // // current identifier
67 private String stringValue;
68 /** Contains the current expression. */
69 // private StringBuffer expression;
70 //private boolean phpMode;
71 protected int modifiers;
72 protected int modifiersSourceStart;
73 // protected IdentifierIndexManager indexManager;
75 protected Parser(ProblemReporter problemReporter) {
76 this.problemReporter = problemReporter;
77 this.options = problemReporter.options;
78 this.currentPHPString = 0;
79 // PHPParserSuperclass.fileToParse = fileToParse;
81 // this.indexManager = null;
83 this.token = TokenNameEOF;
86 // this.columnCount = 0;
89 this.initializeScanner();
91 public void setFileToParse(IFile fileToParse) {
92 this.currentPHPString = 0;
93 // PHPParserSuperclass.fileToParse = fileToParse;
95 // this.indexManager = null;
97 this.token = TokenNameEOF;
99 this.initializeScanner();
102 * ClassDeclaration Constructor.
106 * Description of Parameter
109 public Parser(IFile fileToParse) {
110 // if (keywordMap == null) {
111 // keywordMap = new HashMap();
112 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
113 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
116 this.currentPHPString = 0;
117 // PHPParserSuperclass.fileToParse = fileToParse;
119 this.includesList = null;
121 this.token = TokenNameEOF;
123 // this.rowCount = 1;
124 // this.columnCount = 0;
127 this.initializeScanner();
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 */);
135 * Create marker for the parse error
137 // private void setMarker(String message, int charStart, int charEnd, int
139 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
142 * This method will throw the SyntaxError. It will add the good lines and
143 * columns to the Error
147 * @throws SyntaxError
150 private void throwSyntaxError(String error) {
151 int problemStartPosition = scanner.getCurrentTokenStartPosition();
152 int problemEndPosition = scanner.getCurrentTokenEndPosition();
153 throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
156 * This method will throw the SyntaxError. It will add the good lines and
157 * columns to the Error
161 * @throws SyntaxError
164 // private void throwSyntaxError(String error, int startRow) {
165 // throw new SyntaxError(startRow, 0, " ", error);
167 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
168 problemReporter.phpParsingError(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
169 compilationUnit.compilationResult);
170 throw new SyntaxError(1, 0, " ", error);
172 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
173 problemReporter.phpParsingError(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
174 compilationUnit.compilationResult);
176 private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
177 problemReporter.phpParsingWarning(new String[]{error}, problemStartPosition, problemEndPosition, referenceContext,
178 compilationUnit.compilationResult);
181 * Method Declaration.
185 // private void getChar() {
186 // if (str.length() > chIndx) {
187 // ch = str.charAt(chIndx++);
192 // chIndx = str.length() + 1;
194 // // token = TokenNameEOF;
198 * gets the next token from input
200 private void getNextToken() {
202 token = scanner.getNextToken();
204 int currentEndPosition = scanner.getCurrentTokenEndPosition();
205 int currentStartPosition = scanner.getCurrentTokenStartPosition();
206 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
207 System.out.println(scanner.toStringAction(token));
209 } catch (InvalidInputException e) {
210 token = TokenNameERROR;
211 String detailedMessage = e.getMessage();
213 if (detailedMessage==Scanner.UNTERMINATED_STRING) {
214 throwSyntaxError("Unterminated string.");
215 } else if (detailedMessage==Scanner.UNTERMINATED_COMMENT) {
216 throwSyntaxError("Unterminated commment.");
221 public void init(String s) {
223 this.token = TokenNameEOF;
225 // this.rowCount = 1;
226 // this.columnCount = 0;
228 // this.phpMode = false;
229 /* scanner initialization */
230 scanner.setSource(s.toCharArray());
231 scanner.setPHPMode(false);
233 protected void initialize(boolean phpMode) {
234 initialize(phpMode, null);
236 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
237 compilationUnit = null;
238 referenceContext = null;
239 includesList = new ArrayList();
240 // this.indexManager = indexManager;
242 this.token = TokenNameEOF;
244 // this.rowCount = 1;
245 // this.columnCount = 0;
247 // this.phpMode = phpMode;
248 scanner.setPHPMode(phpMode);
251 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
254 public void parse(String s) {
259 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
262 protected void parse() {
266 if (token != TokenNameEOF && token != TokenNameERROR) {
269 if (token != TokenNameEOF) {
270 if (token == TokenNameERROR) {
271 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
273 if (token == TokenNameRPAREN) {
274 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
276 if (token == TokenNameRBRACE) {
277 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
279 if (token == TokenNameRBRACKET) {
280 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
282 if (token == TokenNameLPAREN) {
283 throwSyntaxError("Read character '('; end-of-file not reached.");
285 if (token == TokenNameLBRACE) {
286 throwSyntaxError("Read character '{'; end-of-file not reached.");
288 if (token == TokenNameLBRACKET) {
289 throwSyntaxError("Read character '['; end-of-file not reached.");
291 throwSyntaxError("End-of-file not reached.");
294 } catch (SyntaxError sytaxErr1) {
295 // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
297 // setMarker(sytaxErr1.getMessage(),
298 // scanner.getCurrentTokenStartPosition(),
299 // scanner.getCurrentTokenEndPosition(), ERROR);
301 // if an error occured,
302 // try to find keywords 'class' or 'function'
303 // to parse the rest of the string
304 while (token != TokenNameEOF && token != TokenNameERROR) {
305 if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
310 if (token == TokenNameEOF || token == TokenNameERROR) {
313 } catch (SyntaxError sytaxErr2) {
314 // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
316 // setMarker(sytaxErr2.getMessage(),
317 // scanner.getCurrentTokenStartPosition(),
318 // scanner.getCurrentTokenEndPosition(), ERROR);
327 protected CompilationUnitDeclaration endParse(int act) {
331 if (currentElement != null) {
332 currentElement.topElement().updateParseTree();
333 if (VERBOSE_RECOVERY) {
334 System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
335 System.out.println("--------------------------"); //$NON-NLS-1$
336 System.out.println(compilationUnit);
337 System.out.println("----------------------------------"); //$NON-NLS-1$
340 if (diet & VERBOSE_RECOVERY) {
341 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
342 System.out.println("--------------------------"); //$NON-NLS-1$
343 System.out.println(compilationUnit);
344 System.out.println("----------------------------------"); //$NON-NLS-1$
347 if (scanner.recordLineSeparator) {
348 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
350 if (scanner.taskTags != null) {
351 for (int i = 0; i < scanner.foundTaskCount; i++) {
352 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
353 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
354 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
357 compilationUnit.imports = new ImportReference[includesList.size()];
358 for (int i = 0; i < includesList.size(); i++) {
359 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
361 return compilationUnit;
363 // public PHPOutlineInfo parseInfo(Object parent, String s) {
364 // PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
365 // // Stack stack = new Stack();
366 // // stack.push(outlineInfo.getDeclarations());
368 // this.token = TokenNameEOF;
369 // // this.chIndx = 0;
370 // // this.rowCount = 1;
371 // // this.columnCount = 0;
372 // this.phpEnd = false;
373 // this.phpMode = false;
374 // scanner.setSource(s.toCharArray());
375 // scanner.setPHPMode(false);
378 // parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
380 // return outlineInfo;
382 private boolean isVariable() {
383 return token == TokenNameVariable; // || token == TokenNamethis;
385 // private void parseDeclarations(PHPOutlineInfo outlineInfo,
386 // OutlineableWithChildren current, boolean goBack) {
388 // // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
389 // PHPSegmentWithChildren temp;
391 // IPreferenceStore store =
392 // PHPeclipsePlugin.getDefault().getPreferenceStore();
394 // while (token != TokenNameEOF && token != TokenNameERROR) {
395 // if (token == TokenNameVariable) {
396 // ident = scanner.getCurrentIdentifierSource();
397 // outlineInfo.addVariable(new String(ident));
399 // } else if (token == TokenNamevar) {
401 // if (token == TokenNameVariable
402 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
403 // ident = scanner.getCurrentIdentifierSource();
404 // //substring(1) added because PHPVarDeclaration doesn't
405 // // need the $ anymore
406 // String variableName = new String(ident).substring(1);
407 // outlineInfo.addVariable(variableName);
409 // if (token != TokenNameSEMICOLON) {
411 // ident = scanner.getCurrentTokenSource();
412 // if (token > TokenNameKEYWORD) {
413 // current.add(new PHPVarDeclaration(current, variableName,
414 // // chIndx - ident.length,
415 // scanner.getCurrentTokenStartPosition(), new String(ident)));
418 // case TokenNameVariable :
419 // case TokenNamethis :
420 // current.add(new PHPVarDeclaration(current, variableName,
423 // scanner.getCurrentTokenStartPosition(), new String(
426 // case TokenNameIdentifier :
427 // current.add(new PHPVarDeclaration(current, variableName,
430 // scanner.getCurrentTokenStartPosition(), new String(
433 // case TokenNameDoubleLiteral :
434 // current.add(new PHPVarDeclaration(current, variableName
438 // scanner.getCurrentTokenStartPosition(), new String(
441 // case TokenNameIntegerLiteral :
442 // current.add(new PHPVarDeclaration(current, variableName,
445 // scanner.getCurrentTokenStartPosition(), new String(
448 // case TokenNameStringInterpolated :
449 // case TokenNameStringLiteral :
450 // current.add(new PHPVarDeclaration(current, variableName,
453 // scanner.getCurrentTokenStartPosition(), new String(
456 // case TokenNameStringConstant :
457 // current.add(new PHPVarDeclaration(current, variableName,
460 // scanner.getCurrentTokenStartPosition(), new String(
464 // current.add(new PHPVarDeclaration(current, variableName,
467 // scanner.getCurrentTokenStartPosition()));
472 // ident = scanner.getCurrentIdentifierSource();
473 // current.add(new PHPVarDeclaration(current, variableName,
474 // // chIndx - ident.length
475 // scanner.getCurrentTokenStartPosition()));
478 // } else if (token == TokenNamefunction) {
480 // if (token == TokenNameAND) {
483 // if (token == TokenNameIdentifier
484 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
485 // ident = scanner.getCurrentIdentifierSource();
486 // outlineInfo.addVariable(new String(ident));
487 // temp = new PHPFunctionDeclaration(current, new String(ident),
488 // // chIndx - ident.length
489 // scanner.getCurrentTokenStartPosition());
490 // current.add(temp);
492 // parseDeclarations(outlineInfo, temp, true);
494 // } else if (token == TokenNameclass) {
496 // if (token == TokenNameIdentifier
497 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
498 // ident = scanner.getCurrentIdentifierSource();
499 // outlineInfo.addVariable(new String(ident));
500 // temp = new PHPClassDeclaration(current, new String(ident),
501 // // chIndx - ident.len
502 // scanner.getCurrentTokenStartPosition());
503 // current.add(temp);
504 // // stack.push(temp);
506 // //skip tokens for classname, extends and others until
507 // // we have the opening '{'
508 // while (token != TokenNameLBRACE && token != TokenNameEOF
509 // && token != TokenNameERROR) {
512 // parseDeclarations(outlineInfo, temp, true);
515 // } else if ((token == TokenNameLBRACE)
516 // || (token == TokenNameDOLLAR_LBRACE)) {
519 // } else if (token == TokenNameRBRACE) {
522 // if (counter == 0 && goBack) {
525 // } else if (token == TokenNamerequire || token == TokenNamerequire_once
526 // || token == TokenNameinclude || token == TokenNameinclude_once) {
527 // ident = scanner.getCurrentTokenSource();
529 // int startPosition = scanner.getCurrentTokenStartPosition();
531 // char[] expr = scanner.getCurrentTokenSource(startPosition);
532 // outlineInfo.addVariable(new String(ident));
533 // current.add(new PHPReqIncDeclaration(current, new String(ident),
534 // // chIndx - ident.length,
535 // startPosition, new String(expr)));
541 // } catch (SyntaxError sytaxErr) {
543 // // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
544 // // setMarker(sytaxErr.getMessage(),
545 // // scanner.getCurrentTokenStartPosition(),
546 // // scanner.getCurrentTokenEndPosition(), ERROR);
547 // // } catch (CoreException e) {
551 private void statementList() {
553 statement(TokenNameEOF);
554 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
555 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
556 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
557 || (token == TokenNameEOF) || (token == TokenNameERROR)) {
562 private void functionBody(MethodDeclaration methodDecl) {
563 // '{' [statement-list] '}'
564 if (token == TokenNameLBRACE) {
567 throwSyntaxError("'{' expected in compound-statement.");
569 if (token != TokenNameRBRACE) {
572 if (token == TokenNameRBRACE) {
573 methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
576 throwSyntaxError("'}' expected in compound-statement.");
579 private void statement(int previousToken) {
580 // if (token > TokenNameKEYWORD && token != TokenNamelist && token !=
582 // char[] ident = scanner.getCurrentIdentifierSource();
583 // String keyword = new String(ident);
584 // if (token == TokenNameAT) {
586 // if (token != TokenNamerequire && token != TokenNamerequire_once
587 // && token != TokenNameinclude && token != TokenNameinclude_once
588 // && token != TokenNameIdentifier && token != TokenNameVariable
589 // && token != TokenNameStringInterpolated) {
590 // throwSyntaxError("identifier expected after '@'.");
593 // if (token == TokenNameinclude || token == TokenNameinclude_once) {
595 // if (token == TokenNameLPAREN) {
597 // if (token == TokenNameSEMICOLON) {
600 // if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
601 // throwSyntaxError("';' expected after 'include' or 'include_once'.");
603 // // getNextToken();
606 // concatenationExpression();
609 // } else if (token == TokenNamerequire || token ==
610 // TokenNamerequire_once)
614 // if (token == TokenNameLPAREN) {
616 // if (token == TokenNameSEMICOLON) {
619 // if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
620 // throwSyntaxError("';' expected after 'require' or 'require_once'.");
622 // // getNextToken();
625 // concatenationExpression();
629 if (token == TokenNameif) {
631 if (token == TokenNameLPAREN) {
634 throwSyntaxError("'(' expected after 'if' keyword.");
637 if (token == TokenNameRPAREN) {
640 throwSyntaxError("')' expected after 'if' condition.");
644 } else if (token == TokenNameswitch) {
646 if (token == TokenNameLPAREN) {
649 throwSyntaxError("'(' expected after 'switch' keyword.");
652 if (token == TokenNameRPAREN) {
655 throwSyntaxError("')' expected after 'switch' condition.");
659 } else if (token == TokenNamefor) {
661 if (token == TokenNameLPAREN) {
664 throwSyntaxError("'(' expected after 'for' keyword.");
666 if (token == TokenNameSEMICOLON) {
670 if (token == TokenNameSEMICOLON) {
673 throwSyntaxError("';' expected after 'for'.");
676 if (token == TokenNameSEMICOLON) {
680 if (token == TokenNameSEMICOLON) {
683 throwSyntaxError("';' expected after 'for'.");
686 if (token == TokenNameRPAREN) {
690 if (token == TokenNameRPAREN) {
693 throwSyntaxError("')' expected after 'for'.");
698 } else if (token == TokenNamewhile) {
700 if (token == TokenNameLPAREN) {
703 throwSyntaxError("'(' expected after 'while' keyword.");
706 if (token == TokenNameRPAREN) {
709 throwSyntaxError("')' expected after 'while' condition.");
713 } else if (token == TokenNamedo) {
715 if (token == TokenNameLBRACE) {
717 if (token != TokenNameRBRACE) {
720 if (token == TokenNameRBRACE) {
723 throwSyntaxError("'}' expected after 'do' keyword.");
726 statement(TokenNameEOF);
728 if (token == TokenNamewhile) {
730 if (token == TokenNameLPAREN) {
733 throwSyntaxError("'(' expected after 'while' keyword.");
736 if (token == TokenNameRPAREN) {
739 throwSyntaxError("')' expected after 'while' condition.");
742 throwSyntaxError("'while' expected after 'do' keyword.");
744 if (token == TokenNameSEMICOLON) {
747 if (token != TokenNameINLINE_HTML) {
748 throwSyntaxError("';' expected after do-while statement.");
753 } else if (token == TokenNameforeach) {
755 if (token == TokenNameLPAREN) {
758 throwSyntaxError("'(' expected after 'foreach' keyword.");
761 if (token == TokenNameas) {
764 throwSyntaxError("'as' expected after 'foreach' exxpression.");
768 foreach_optional_arg();
769 if (token == TokenNameEQUAL_GREATER) {
773 if (token == TokenNameRPAREN) {
776 throwSyntaxError("')' expected after 'foreach' expression.");
780 } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
782 if (token != TokenNameSEMICOLON) {
785 if (token == TokenNameSEMICOLON) {
788 if (token != TokenNameINLINE_HTML) {
789 throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
794 } else if (token == TokenNameecho) {
797 if (token == TokenNameSEMICOLON) {
800 if (token != TokenNameINLINE_HTML) {
801 throwSyntaxError("';' expected after 'echo' statement.");
806 } else if (token == TokenNameINLINE_HTML) {
809 // } else if (token == TokenNameprint) {
812 // if (token == TokenNameSEMICOLON) {
815 // if (token != TokenNameStopPHP) {
816 // throwSyntaxError("';' expected after 'print' statement.");
821 } else if (token == TokenNameglobal) {
824 if (token == TokenNameSEMICOLON) {
827 if (token != TokenNameINLINE_HTML) {
828 throwSyntaxError("';' expected after 'global' statement.");
833 } else if (token == TokenNamestatic) {
836 if (token == TokenNameSEMICOLON) {
839 if (token != TokenNameINLINE_HTML) {
840 throwSyntaxError("';' expected after 'static' statement.");
845 } else if (token == TokenNameunset) {
847 if (token == TokenNameLPAREN) {
850 throwSyntaxError("'(' expected after 'unset' statement.");
853 if (token == TokenNameRPAREN) {
856 throwSyntaxError("')' expected after 'unset' statement.");
858 if (token == TokenNameSEMICOLON) {
861 if (token != TokenNameINLINE_HTML) {
862 throwSyntaxError("';' expected after 'unset' statement.");
867 } else if (token == TokenNamefunction) {
868 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
869 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
870 methodDecl.modifiers = AccDefault;
872 functionDefinition(methodDecl);
874 } else if (token == TokenNametry) {
876 if (token != TokenNameLBRACE) {
877 throwSyntaxError("'{' expected in 'try' statement.");
881 if (token != TokenNameRBRACE) {
882 throwSyntaxError("'}' expected in 'try' statement.");
886 } else if (token == TokenNamecatch) {
888 if (token != TokenNameLPAREN) {
889 throwSyntaxError("'(' expected in 'catch' statement.");
892 fully_qualified_class_name();
893 if (token != TokenNameVariable) {
894 throwSyntaxError("Variable expected in 'catch' statement.");
897 if (token != TokenNameRPAREN) {
898 throwSyntaxError("')' expected in 'catch' statement.");
901 if (token != TokenNameLBRACE) {
902 throwSyntaxError("'{' expected in 'catch' statement.");
905 if (token != TokenNameRBRACE) {
907 if (token != TokenNameRBRACE) {
908 throwSyntaxError("'}' expected in 'catch' statement.");
912 additional_catches();
914 } else if (token == TokenNamethrow) {
917 if (token == TokenNameSEMICOLON) {
920 throwSyntaxError("';' expected after 'throw' exxpression.");
923 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
924 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
925 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
926 // default super class
927 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
928 compilationUnit.types.add(typeDecl);
930 pushOnAstStack(typeDecl);
931 unticked_class_declaration_statement(typeDecl);
932 // classBody(typeDecl);
939 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
940 } else if (token == TokenNameLBRACE) {
942 if (token != TokenNameRBRACE) {
945 if (token == TokenNameRBRACE) {
949 throwSyntaxError("'}' expected.");
952 if (token != TokenNameSEMICOLON) {
955 if (token == TokenNameSEMICOLON) {
959 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
960 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
966 private void additional_catches() {
967 while (token == TokenNamecatch) {
969 if (token != TokenNameLPAREN) {
970 throwSyntaxError("'(' expected in 'catch' statement.");
973 fully_qualified_class_name();
974 if (token != TokenNameVariable) {
975 throwSyntaxError("Variable expected in 'catch' statement.");
978 if (token != TokenNameRPAREN) {
979 throwSyntaxError("')' expected in 'catch' statement.");
982 if (token != TokenNameLBRACE) {
983 throwSyntaxError("'{' expected in 'catch' statement.");
987 if (token != TokenNameRBRACE) {
988 throwSyntaxError("'}' expected in 'catch' statement.");
993 private void foreach_variable() {
996 if (token == TokenNameAND) {
1001 private void foreach_optional_arg() {
1003 //| T_DOUBLE_ARROW foreach_variable
1004 if (token == TokenNameEQUAL_GREATER) {
1009 private void global_var_list() {
1011 // global_var_list ',' global_var
1015 if (token != TokenNameCOMMA) {
1021 private void global_var() {
1025 //| '$' '{' expr '}'
1026 if (token == TokenNameVariable) {
1028 } else if (token == TokenNameDOLLAR) {
1030 if (token == TokenNameLPAREN) {
1033 if (token != TokenNameLPAREN) {
1034 throwSyntaxError("')' expected in global variable.");
1042 private void static_var_list() {
1044 // static_var_list ',' T_VARIABLE
1045 //| static_var_list ',' T_VARIABLE '=' static_scalar
1047 //| T_VARIABLE '=' static_scalar
1049 if (token == TokenNameVariable) {
1051 if (token == TokenNameEQUAL) {
1055 if (token != TokenNameCOMMA) {
1064 private void unset_variables() {
1067 // | unset_variables ',' unset_variable
1072 if (token != TokenNameCOMMA) {
1078 private final void initializeModifiers() {
1080 this.modifiersSourceStart = -1;
1082 private final void checkAndSetModifiers(int flag) {
1083 this.modifiers |= flag;
1084 if (this.modifiersSourceStart < 0)
1085 this.modifiersSourceStart = this.scanner.startPosition;
1087 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1088 initializeModifiers();
1089 if (token == TokenNameinterface) {
1090 // interface_entry T_STRING
1091 // interface_extends_list
1092 // '{' class_statement_list '}'
1093 checkAndSetModifiers(AccInterface);
1095 typeDecl.modifiers = this.modifiers;
1096 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1097 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1098 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1099 typeDecl.name = scanner.getCurrentIdentifierSource();
1100 if (token > TokenNameKEYWORD) {
1101 throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1102 typeDecl.sourceStart, typeDecl.sourceEnd);
1105 interface_extends_list();
1107 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1108 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1109 typeDecl.name = new char[]{' '};
1110 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1114 // class_entry_type T_STRING extends_from
1116 // '{' class_statement_list'}'
1118 typeDecl.modifiers = this.modifiers;
1120 //identifier 'extends' identifier
1121 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1122 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1123 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1124 typeDecl.name = scanner.getCurrentIdentifierSource();
1125 if (token > TokenNameKEYWORD) {
1126 throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1127 typeDecl.sourceStart, typeDecl.sourceEnd);
1132 // | T_EXTENDS fully_qualified_class_name
1133 if (token == TokenNameextends) {
1134 interface_extends_list();
1136 // if (token != TokenNameIdentifier) {
1137 // throwSyntaxError("Class name expected after keyword
1139 // scanner.getCurrentTokenStartPosition(), scanner
1140 // .getCurrentTokenEndPosition());
1145 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1146 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1147 typeDecl.name = new char[]{' '};
1148 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1152 // '{' class_statement_list '}'
1153 if (token == TokenNameLBRACE) {
1155 if (token != TokenNameRBRACE) {
1156 ArrayList list = new ArrayList();
1157 class_statement_list(list);
1158 typeDecl.fields = new FieldDeclaration[list.size()];
1159 for (int i = 0; i < list.size(); i++) {
1160 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1163 if (token == TokenNameRBRACE) {
1164 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1167 throwSyntaxError("'}' expected at end of class body.");
1170 throwSyntaxError("'{' expected at start of class body.");
1173 private void class_entry_type() {
1175 // | T_ABSTRACT T_CLASS
1176 // | T_FINAL T_CLASS
1177 if (token == TokenNameclass) {
1179 } else if (token == TokenNameabstract) {
1180 checkAndSetModifiers(AccAbstract);
1182 if (token != TokenNameclass) {
1183 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1186 } else if (token == TokenNamefinal) {
1187 checkAndSetModifiers(AccFinal);
1189 if (token != TokenNameclass) {
1190 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1194 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1197 private void interface_extends_list() {
1199 // | T_EXTENDS interface_list
1200 if (token == TokenNameextends) {
1205 private void implements_list() {
1207 // | T_IMPLEMENTS interface_list
1208 if (token == TokenNameimplements) {
1213 private void interface_list() {
1215 // fully_qualified_class_name
1216 //| interface_list ',' fully_qualified_class_name
1218 if (token == TokenNameIdentifier) {
1221 throwSyntaxError("Interface name expected after keyword 'implements'.");
1223 if (token != TokenNameCOMMA) {
1229 // private void classBody(TypeDeclaration typeDecl) {
1230 // //'{' [class-element-list] '}'
1231 // if (token == TokenNameLBRACE) {
1233 // if (token != TokenNameRBRACE) {
1234 // class_statement_list();
1236 // if (token == TokenNameRBRACE) {
1237 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1240 // throwSyntaxError("'}' expected at end of class body.");
1243 // throwSyntaxError("'{' expected at start of class body.");
1246 private void class_statement_list(ArrayList list) {
1248 class_statement(list);
1249 } while (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1250 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1251 || token == TokenNameconst);
1253 private void class_statement(ArrayList list) {
1255 // variable_modifiers class_variable_declaration ';'
1256 // | class_constant_declaration ';'
1257 // | method_modifiers T_FUNCTION is_reference T_STRING
1258 // '(' parameter_list ')' method_body
1259 initializeModifiers();
1260 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1262 if (token == TokenNamevar) {
1263 checkAndSetModifiers(AccPublic);
1264 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1265 referenceContext, compilationUnit.compilationResult);
1267 class_variable_declaration(declarationSourceStart, list);
1268 } else if (token == TokenNameconst) {
1269 checkAndSetModifiers(AccFinal|AccPublic);
1270 class_constant_declaration(declarationSourceStart, list);
1271 if (token != TokenNameSEMICOLON) {
1272 throwSyntaxError("';' expected after class const declaration.");
1276 boolean hasModifiers = member_modifiers();
1277 if (token == TokenNamefunction) {
1278 if (!hasModifiers) {
1279 checkAndSetModifiers(AccPublic);
1281 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1282 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1283 methodDecl.modifiers = this.modifiers;
1285 functionDefinition(methodDecl);
1287 if (!hasModifiers) {
1288 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1290 class_variable_declaration(declarationSourceStart, list);
1294 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1295 // class_constant_declaration ',' T_STRING '=' static_scalar
1296 // | T_CONST T_STRING '=' static_scalar
1297 if (token != TokenNameconst) {
1298 throwSyntaxError("'const' keyword expected in class declaration.");
1303 if (token != TokenNameIdentifier) {
1304 throwSyntaxError("Identifier expected in class const declaration.");
1306 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1307 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1308 fieldDeclaration.modifiers = this.modifiers;
1309 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1310 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1311 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1312 // fieldDeclaration.type
1313 list.add(fieldDeclaration);
1315 if (token != TokenNameEQUAL) {
1316 throwSyntaxError("'=' expected in class const declaration.");
1320 if (token != TokenNameCOMMA) {
1321 break; // while(true)-loop
1326 // private void variable_modifiers() {
1327 // // variable_modifiers:
1328 // // non_empty_member_modifiers
1330 // initializeModifiers();
1331 // if (token == TokenNamevar) {
1332 // checkAndSetModifiers(AccPublic);
1333 // reportSyntaxError(
1334 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1336 // modifier for field declarations.",
1337 // scanner.getCurrentTokenStartPosition(), scanner
1338 // .getCurrentTokenEndPosition());
1341 // if (!member_modifiers()) {
1342 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1343 // field declarations.");
1347 // private void method_modifiers() {
1348 // //method_modifiers:
1350 // //| non_empty_member_modifiers
1351 // initializeModifiers();
1352 // if (!member_modifiers()) {
1353 // checkAndSetModifiers(AccPublic);
1356 private boolean member_modifiers() {
1363 boolean foundToken = false;
1365 if (token == TokenNamepublic) {
1366 checkAndSetModifiers(AccPublic);
1369 } else if (token == TokenNameprotected) {
1370 checkAndSetModifiers(AccProtected);
1373 } else if (token == TokenNameprivate) {
1374 checkAndSetModifiers(AccPrivate);
1377 } else if (token == TokenNamestatic) {
1378 checkAndSetModifiers(AccStatic);
1381 } else if (token == TokenNameabstract) {
1382 checkAndSetModifiers(AccAbstract);
1385 } else if (token == TokenNamefinal) {
1386 checkAndSetModifiers(AccFinal);
1395 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1396 // class_variable_declaration:
1397 // class_variable_declaration ',' T_VARIABLE
1398 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1400 // | T_VARIABLE '=' static_scalar
1401 char[] classVariable;
1403 if (token == TokenNameVariable) {
1404 classVariable = scanner.getCurrentIdentifierSource();
1405 // indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1406 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner
1407 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1408 fieldDeclaration.modifiers = this.modifiers;
1409 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1410 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1411 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1412 // fieldDeclaration.type
1413 list.add(fieldDeclaration);
1415 if (token == TokenNameEQUAL) {
1420 // if (token == TokenNamethis) {
1421 // throwSyntaxError("'$this' not allowed after keyword 'public'
1422 // 'protected' 'private' 'var'.");
1424 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1426 if (token != TokenNameCOMMA) {
1431 if (token != TokenNameSEMICOLON) {
1432 throwSyntaxError("';' expected after field declaration.");
1436 private void functionDefinition(MethodDeclaration methodDecl) {
1437 boolean isAbstract = false;
1439 compilationUnit.types.add(methodDecl);
1441 AstNode node = astStack[astPtr];
1442 if (node instanceof TypeDeclaration) {
1443 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1444 if (typeDecl.methods == null) {
1445 typeDecl.methods = new AbstractMethodDeclaration[]{methodDecl};
1447 AbstractMethodDeclaration[] newMethods;
1448 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 1,
1449 typeDecl.methods.length);
1450 newMethods[0] = methodDecl;
1451 typeDecl.methods = newMethods;
1453 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1455 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1460 functionDeclarator(methodDecl);
1461 if (token == TokenNameSEMICOLON) {
1463 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1468 functionBody(methodDecl);
1470 private void functionDeclarator(MethodDeclaration methodDecl) {
1471 //identifier '(' [parameter-list] ')'
1472 if (token == TokenNameAND) {
1475 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1476 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1477 if (Scanner.isIdentifierOrKeyword(token)) {
1478 methodDecl.selector = scanner.getCurrentIdentifierSource();
1479 if (token > TokenNameKEYWORD) {
1480 problemReporter.phpKeywordWarning(new String[]{scanner.toStringAction(token)}, scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1481 referenceContext, compilationUnit.compilationResult);
1482 // reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
1483 // scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1486 if (token == TokenNameLPAREN) {
1489 throwSyntaxError("'(' expected in function declaration.");
1491 if (token != TokenNameRPAREN) {
1494 if (token != TokenNameRPAREN) {
1495 throwSyntaxError("')' expected in function declaration.");
1497 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1501 methodDecl.selector = "<undefined>".toCharArray();
1502 throwSyntaxError("Function name expected after keyword 'function'.");
1506 private void parameter_list() {
1507 // non_empty_parameter_list
1509 non_empty_parameter_list(true);
1511 private void non_empty_parameter_list(boolean empty_allowed) {
1512 // optional_class_type T_VARIABLE
1513 // | optional_class_type '&' T_VARIABLE
1514 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1515 // | optional_class_type T_VARIABLE '=' static_scalar
1516 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1517 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1518 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1520 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1522 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1524 if (token == TokenNameIdentifier) {
1527 if (token == TokenNameAND) {
1530 if (token == TokenNameVariable) {
1532 if (token == TokenNameEQUAL) {
1537 throwSyntaxError("Variable expected in parameter list.");
1539 if (token != TokenNameCOMMA) {
1546 if (!empty_allowed) {
1547 throwSyntaxError("Identifier expected in parameter list.");
1550 private void optional_class_type() {
1554 private void parameterDeclaration() {
1556 //variable-reference
1557 if (token == TokenNameAND) {
1562 throwSyntaxError("Variable expected after reference operator '&'.");
1565 //variable '=' constant
1566 if (token == TokenNameVariable) {
1568 if (token == TokenNameEQUAL) {
1574 // if (token == TokenNamethis) {
1575 // throwSyntaxError("Reserved word '$this' not allowed in parameter
1579 private void labeledStatementList() {
1580 if (token != TokenNamecase && token != TokenNamedefault) {
1581 throwSyntaxError("'case' or 'default' expected.");
1584 if (token == TokenNamecase) {
1586 expr(); //constant();
1587 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1589 if (token == TokenNamecase || token == TokenNamedefault) {
1590 // empty case statement ?
1595 // else if (token == TokenNameSEMICOLON) {
1597 // "':' expected after 'case' keyword (Found token: " +
1598 // scanner.toStringAction(token) + ")",
1599 // scanner.getCurrentTokenStartPosition(),
1600 // scanner.getCurrentTokenEndPosition(),
1603 // if (token == TokenNamecase) { // empty case statement ?
1609 throwSyntaxError("':' character after 'case' constant expected (Found token: " + scanner.toStringAction(token) + ")");
1611 } else { // TokenNamedefault
1613 if (token == TokenNameCOLON) {
1615 if (token == TokenNameRBRACE) {
1616 // empty default case
1621 throwSyntaxError("':' character after 'default' expected.");
1624 } while (token == TokenNamecase || token == TokenNamedefault);
1626 // public void labeledStatement() {
1627 // if (token == TokenNamecase) {
1630 // if (token == TokenNameDDOT) {
1634 // throwSyntaxError("':' character after 'case' constant expected.");
1637 // } else if (token == TokenNamedefault) {
1639 // if (token == TokenNameDDOT) {
1643 // throwSyntaxError("':' character after 'default' expected.");
1648 // public void expressionStatement() {
1650 // private void inclusionStatement() {
1652 // public void compoundStatement() {
1654 // public void selectionStatement() {
1657 // public void iterationStatement() {
1660 // public void jumpStatement() {
1663 // public void outputStatement() {
1666 // public void scopeStatement() {
1669 // public void flowStatement() {
1672 // public void definitionStatement() {
1674 private void ifStatement() {
1675 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
1676 if (token == TokenNameCOLON) {
1678 if (token != TokenNameendif) {
1681 case TokenNameelse :
1683 if (token == TokenNameCOLON) {
1685 if (token != TokenNameendif) {
1689 if (token == TokenNameif) { //'else if'
1691 elseifStatementList();
1693 throwSyntaxError("':' expected after 'else'.");
1697 case TokenNameelseif :
1699 elseifStatementList();
1703 if (token != TokenNameendif) {
1704 throwSyntaxError("'endif' expected.");
1707 if (token != TokenNameSEMICOLON) {
1708 throwSyntaxError("';' expected after if-statement.");
1712 // statement [else-statement]
1713 statement(TokenNameEOF);
1714 if (token == TokenNameelseif) {
1716 if (token == TokenNameLPAREN) {
1719 throwSyntaxError("'(' expected after 'elseif' keyword.");
1722 if (token == TokenNameRPAREN) {
1725 throwSyntaxError("')' expected after 'elseif' condition.");
1728 } else if (token == TokenNameelse) {
1730 statement(TokenNameEOF);
1734 private void elseifStatementList() {
1738 case TokenNameelse :
1740 if (token == TokenNameCOLON) {
1742 if (token != TokenNameendif) {
1747 if (token == TokenNameif) { //'else if'
1750 throwSyntaxError("':' expected after 'else'.");
1754 case TokenNameelseif :
1762 private void elseifStatement() {
1763 if (token == TokenNameLPAREN) {
1766 if (token != TokenNameRPAREN) {
1767 throwSyntaxError("')' expected in else-if-statement.");
1770 if (token != TokenNameCOLON) {
1771 throwSyntaxError("':' expected in else-if-statement.");
1774 if (token != TokenNameendif) {
1779 private void switchStatement() {
1780 if (token == TokenNameCOLON) {
1781 // ':' [labeled-statement-list] 'endswitch' ';'
1783 labeledStatementList();
1784 if (token != TokenNameendswitch) {
1785 throwSyntaxError("'endswitch' expected.");
1788 if (token != TokenNameSEMICOLON) {
1789 throwSyntaxError("';' expected after switch-statement.");
1793 // '{' [labeled-statement-list] '}'
1794 if (token != TokenNameLBRACE) {
1795 throwSyntaxError("'{' expected in switch statement.");
1798 if (token != TokenNameRBRACE) {
1799 labeledStatementList();
1801 if (token != TokenNameRBRACE) {
1802 throwSyntaxError("'}' expected in switch statement.");
1807 private void forStatement() {
1808 if (token == TokenNameCOLON) {
1811 if (token != TokenNameendfor) {
1812 throwSyntaxError("'endfor' expected.");
1815 if (token != TokenNameSEMICOLON) {
1816 throwSyntaxError("';' expected after for-statement.");
1820 statement(TokenNameEOF);
1823 private void whileStatement() {
1824 // ':' statement-list 'endwhile' ';'
1825 if (token == TokenNameCOLON) {
1828 if (token != TokenNameendwhile) {
1829 throwSyntaxError("'endwhile' expected.");
1832 if (token != TokenNameSEMICOLON) {
1833 throwSyntaxError("';' expected after while-statement.");
1837 statement(TokenNameEOF);
1840 private void foreachStatement() {
1841 if (token == TokenNameCOLON) {
1844 if (token != TokenNameendforeach) {
1845 throwSyntaxError("'endforeach' expected.");
1848 if (token != TokenNameSEMICOLON) {
1849 throwSyntaxError("';' expected after foreach-statement.");
1853 statement(TokenNameEOF);
1856 // private void exitStatus() {
1857 // if (token == TokenNameLPAREN) {
1860 // throwSyntaxError("'(' expected in 'exit-status'.");
1862 // if (token != TokenNameRPAREN) {
1865 // if (token == TokenNameRPAREN) {
1868 // throwSyntaxError("')' expected after 'exit-status'.");
1871 private void expressionList() {
1874 if (token == TokenNameCOMMA) {
1881 private void expr() {
1883 // | expr_without_variable
1884 // if (token!=TokenNameEOF) {
1885 if (Scanner.TRACE) {
1886 System.out.println("TRACE: expr()");
1888 expr_without_variable(true);
1891 private void expr_without_variable(boolean only_variable) {
1892 // internal_functions_in_yacc
1901 // | T_INC rw_variable
1902 // | T_DEC rw_variable
1903 // | T_INT_CAST expr
1904 // | T_DOUBLE_CAST expr
1905 // | T_STRING_CAST expr
1906 // | T_ARRAY_CAST expr
1907 // | T_OBJECT_CAST expr
1908 // | T_BOOL_CAST expr
1909 // | T_UNSET_CAST expr
1910 // | T_EXIT exit_expr
1912 // | T_ARRAY '(' array_pair_list ')'
1913 // | '`' encaps_list '`'
1914 // | T_LIST '(' assignment_list ')' '=' expr
1915 // | T_NEW class_name_reference ctor_arguments
1916 // | variable '=' expr
1917 // | variable '=' '&' variable
1918 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
1919 // | variable T_PLUS_EQUAL expr
1920 // | variable T_MINUS_EQUAL expr
1921 // | variable T_MUL_EQUAL expr
1922 // | variable T_DIV_EQUAL expr
1923 // | variable T_CONCAT_EQUAL expr
1924 // | variable T_MOD_EQUAL expr
1925 // | variable T_AND_EQUAL expr
1926 // | variable T_OR_EQUAL expr
1927 // | variable T_XOR_EQUAL expr
1928 // | variable T_SL_EQUAL expr
1929 // | variable T_SR_EQUAL expr
1930 // | rw_variable T_INC
1931 // | rw_variable T_DEC
1932 // | expr T_BOOLEAN_OR expr
1933 // | expr T_BOOLEAN_AND expr
1934 // | expr T_LOGICAL_OR expr
1935 // | expr T_LOGICAL_AND expr
1936 // | expr T_LOGICAL_XOR expr
1948 // | expr T_IS_IDENTICAL expr
1949 // | expr T_IS_NOT_IDENTICAL expr
1950 // | expr T_IS_EQUAL expr
1951 // | expr T_IS_NOT_EQUAL expr
1953 // | expr T_IS_SMALLER_OR_EQUAL expr
1955 // | expr T_IS_GREATER_OR_EQUAL expr
1956 // | expr T_INSTANCEOF class_name_reference
1957 // | expr '?' expr ':' expr
1958 if (Scanner.TRACE) {
1959 System.out.println("TRACE: expr_without_variable() PART 1");
1962 case TokenNameisset :
1963 case TokenNameempty :
1964 case TokenNameeval :
1965 case TokenNameinclude :
1966 case TokenNameinclude_once :
1967 case TokenNamerequire :
1968 case TokenNamerequire_once :
1969 internal_functions_in_yacc();
1972 case TokenNameLPAREN :
1975 if (token == TokenNameRPAREN) {
1978 throwSyntaxError("')' expected in expression.");
1988 // | T_INT_CAST expr
1989 // | T_DOUBLE_CAST expr
1990 // | T_STRING_CAST expr
1991 // | T_ARRAY_CAST expr
1992 // | T_OBJECT_CAST expr
1993 // | T_BOOL_CAST expr
1994 // | T_UNSET_CAST expr
1995 case TokenNameclone :
1996 case TokenNameprint :
1998 case TokenNamePLUS :
1999 case TokenNameMINUS :
2001 case TokenNameTWIDDLE :
2002 case TokenNameintCAST :
2003 case TokenNamedoubleCAST :
2004 case TokenNamestringCAST :
2005 case TokenNamearrayCAST :
2006 case TokenNameobjectCAST :
2007 case TokenNameboolCAST :
2008 case TokenNameunsetCAST :
2012 case TokenNameexit :
2018 //| T_STRING_VARNAME
2020 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2021 // | '`' encaps_list '`'
2023 // | '`' encaps_list '`'
2024 case TokenNameEncapsedString0 :
2025 scanner.encapsedStringStack.push(new Character('`'));
2028 if (token == TokenNameEncapsedString0) {
2031 if (token != TokenNameEncapsedString0) {
2032 throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2036 scanner.encapsedStringStack.pop();
2040 // | '\'' encaps_list '\''
2041 case TokenNameEncapsedString1 :
2042 scanner.encapsedStringStack.push(new Character('\''));
2045 if (token == TokenNameEncapsedString1) {
2048 if (token != TokenNameEncapsedString1) {
2049 throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2053 scanner.encapsedStringStack.pop();
2057 //| '"' encaps_list '"'
2058 case TokenNameEncapsedString2 :
2059 scanner.encapsedStringStack.push(new Character('"'));
2062 if (token == TokenNameEncapsedString2) {
2065 if (token != TokenNameEncapsedString2) {
2066 throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2070 scanner.encapsedStringStack.pop();
2074 case TokenNameIntegerLiteral :
2075 case TokenNameDoubleLiteral :
2076 case TokenNameStringDoubleQuote :
2077 case TokenNameStringSingleQuote :
2078 case TokenNameStringInterpolated :
2079 case TokenNameFILE :
2080 case TokenNameLINE :
2081 case TokenNameCLASS_C :
2082 case TokenNameMETHOD_C :
2083 case TokenNameFUNC_C :
2086 case TokenNameHEREDOC :
2089 case TokenNamearray :
2090 // T_ARRAY '(' array_pair_list ')'
2092 if (token == TokenNameLPAREN) {
2094 if (token == TokenNameRPAREN) {
2099 if (token != TokenNameRPAREN) {
2100 throwSyntaxError("')' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2104 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2107 case TokenNamelist :
2108 // | T_LIST '(' assignment_list ')' '=' expr
2110 if (token == TokenNameLPAREN) {
2113 if (token != TokenNameRPAREN) {
2114 throwSyntaxError("')' expected after 'list' keyword.");
2117 if (token != TokenNameEQUAL) {
2118 throwSyntaxError("'=' expected after 'list' keyword.");
2123 throwSyntaxError("'(' expected after 'list' keyword.");
2127 // | T_NEW class_name_reference ctor_arguments
2129 class_name_reference();
2132 // | T_INC rw_variable
2133 // | T_DEC rw_variable
2134 case TokenNamePLUS_PLUS :
2135 case TokenNameMINUS_MINUS :
2139 // | variable '=' expr
2140 // | variable '=' '&' variable
2141 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2142 // | variable T_PLUS_EQUAL expr
2143 // | variable T_MINUS_EQUAL expr
2144 // | variable T_MUL_EQUAL expr
2145 // | variable T_DIV_EQUAL expr
2146 // | variable T_CONCAT_EQUAL expr
2147 // | variable T_MOD_EQUAL expr
2148 // | variable T_AND_EQUAL expr
2149 // | variable T_OR_EQUAL expr
2150 // | variable T_XOR_EQUAL expr
2151 // | variable T_SL_EQUAL expr
2152 // | variable T_SR_EQUAL expr
2153 // | rw_variable T_INC
2154 // | rw_variable T_DEC
2155 case TokenNameIdentifier :
2156 case TokenNameVariable :
2157 case TokenNameDOLLAR :
2160 case TokenNameEQUAL :
2162 if (token == TokenNameAND) {
2164 if (token == TokenNamenew) {
2165 // | variable '=' '&' T_NEW class_name_reference
2168 class_name_reference();
2177 case TokenNamePLUS_EQUAL :
2178 case TokenNameMINUS_EQUAL :
2179 case TokenNameMULTIPLY_EQUAL :
2180 case TokenNameDIVIDE_EQUAL :
2181 case TokenNameDOT_EQUAL :
2182 case TokenNameREMAINDER_EQUAL :
2183 case TokenNameAND_EQUAL :
2184 case TokenNameOR_EQUAL :
2185 case TokenNameXOR_EQUAL :
2186 case TokenNameRIGHT_SHIFT_EQUAL :
2187 case TokenNameLEFT_SHIFT_EQUAL :
2191 case TokenNamePLUS_PLUS :
2192 case TokenNameMINUS_MINUS :
2196 if (!only_variable) {
2197 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2202 if (token != TokenNameINLINE_HTML) {
2203 if (token > TokenNameKEYWORD) {
2207 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2212 if (Scanner.TRACE) {
2213 System.out.println("TRACE: expr_without_variable() PART 2");
2215 // | expr T_BOOLEAN_OR expr
2216 // | expr T_BOOLEAN_AND expr
2217 // | expr T_LOGICAL_OR expr
2218 // | expr T_LOGICAL_AND expr
2219 // | expr T_LOGICAL_XOR expr
2231 // | expr T_IS_IDENTICAL expr
2232 // | expr T_IS_NOT_IDENTICAL expr
2233 // | expr T_IS_EQUAL expr
2234 // | expr T_IS_NOT_EQUAL expr
2236 // | expr T_IS_SMALLER_OR_EQUAL expr
2238 // | expr T_IS_GREATER_OR_EQUAL expr
2241 case TokenNameOR_OR :
2242 case TokenNameAND_AND :
2250 case TokenNamePLUS :
2251 case TokenNameMINUS :
2252 case TokenNameMULTIPLY :
2253 case TokenNameDIVIDE :
2254 case TokenNameREMAINDER :
2255 case TokenNameLEFT_SHIFT :
2256 case TokenNameRIGHT_SHIFT :
2257 case TokenNameEQUAL_EQUAL_EQUAL :
2258 case TokenNameNOT_EQUAL_EQUAL :
2259 case TokenNameEQUAL_EQUAL :
2260 case TokenNameNOT_EQUAL :
2261 case TokenNameLESS :
2262 case TokenNameLESS_EQUAL :
2263 case TokenNameGREATER :
2264 case TokenNameGREATER_EQUAL :
2268 // | expr T_INSTANCEOF class_name_reference
2269 // | expr '?' expr ':' expr
2270 case TokenNameinstanceof :
2272 class_name_reference();
2274 case TokenNameQUESTION :
2277 if (token == TokenNameCOLON) {
2287 private void class_name_reference() {
2288 // class_name_reference:
2290 //| dynamic_class_name_reference
2291 if (Scanner.TRACE) {
2292 System.out.println("TRACE: class_name_reference()");
2294 if (token == TokenNameIdentifier) {
2297 dynamic_class_name_reference();
2300 private void dynamic_class_name_reference() {
2301 //dynamic_class_name_reference:
2302 // base_variable T_OBJECT_OPERATOR object_property
2303 // dynamic_class_name_variable_properties
2305 if (Scanner.TRACE) {
2306 System.out.println("TRACE: dynamic_class_name_reference()");
2309 if (token == TokenNameMINUS_GREATER) {
2312 dynamic_class_name_variable_properties();
2315 private void dynamic_class_name_variable_properties() {
2316 // dynamic_class_name_variable_properties:
2317 // dynamic_class_name_variable_properties
2318 // dynamic_class_name_variable_property
2320 if (Scanner.TRACE) {
2321 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2323 while (token == TokenNameMINUS_GREATER) {
2324 dynamic_class_name_variable_property();
2327 private void dynamic_class_name_variable_property() {
2328 // dynamic_class_name_variable_property:
2329 // T_OBJECT_OPERATOR object_property
2330 if (Scanner.TRACE) {
2331 System.out.println("TRACE: dynamic_class_name_variable_property()");
2333 if (token == TokenNameMINUS_GREATER) {
2338 private void ctor_arguments() {
2341 //| '(' function_call_parameter_list ')'
2342 if (token == TokenNameLPAREN) {
2344 if (token == TokenNameRPAREN) {
2348 non_empty_function_call_parameter_list();
2349 if (token != TokenNameRPAREN) {
2350 throwSyntaxError("')' expected in ctor_arguments.");
2355 private void assignment_list() {
2357 // assignment_list ',' assignment_list_element
2358 //| assignment_list_element
2360 assignment_list_element();
2361 if (token != TokenNameCOMMA) {
2367 private void assignment_list_element() {
2368 //assignment_list_element:
2370 //| T_LIST '(' assignment_list ')'
2372 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2375 if (token == TokenNamelist) {
2377 if (token == TokenNameLPAREN) {
2380 if (token != TokenNameRPAREN) {
2381 throwSyntaxError("')' expected after 'list' keyword.");
2385 throwSyntaxError("'(' expected after 'list' keyword.");
2390 private void array_pair_list() {
2393 //| non_empty_array_pair_list possible_comma
2394 non_empty_array_pair_list();
2395 if (token == TokenNameCOMMA) {
2399 private void non_empty_array_pair_list() {
2400 //non_empty_array_pair_list:
2401 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2402 //| non_empty_array_pair_list ',' expr
2403 //| expr T_DOUBLE_ARROW expr
2405 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2406 //| non_empty_array_pair_list ',' '&' w_variable
2407 //| expr T_DOUBLE_ARROW '&' w_variable
2410 if (token == TokenNameAND) {
2415 if (token == TokenNameAND) {
2418 } else if (token == TokenNameEQUAL_GREATER) {
2420 if (token == TokenNameAND) {
2428 if (token != TokenNameCOMMA) {
2432 if (token == TokenNameRPAREN) {
2437 // private void variableList() {
2440 // if (token == TokenNameCOMMA) {
2447 private void variable_without_objects() {
2448 // variable_without_objects:
2449 // reference_variable
2450 // | simple_indirect_reference reference_variable
2451 if (Scanner.TRACE) {
2452 System.out.println("TRACE: variable_without_objects()");
2454 while (token == TokenNameDOLLAR) {
2457 reference_variable();
2459 private void function_call() {
2461 // T_STRING '(' function_call_parameter_list ')'
2462 //| class_constant '(' function_call_parameter_list ')'
2463 //| static_member '(' function_call_parameter_list ')'
2464 //| variable_without_objects '(' function_call_parameter_list ')'
2465 char[] defineName = null;
2468 if (Scanner.TRACE) {
2469 System.out.println("TRACE: function_call()");
2471 if (token == TokenNameIdentifier) {
2472 defineName = scanner.getCurrentIdentifierSource();
2473 startPos = scanner.getCurrentTokenStartPosition();
2474 endPos = scanner.getCurrentTokenEndPosition();
2477 case TokenNamePAAMAYIM_NEKUDOTAYIM :
2481 if (token == TokenNameIdentifier) {
2486 variable_without_objects();
2491 variable_without_objects();
2493 if (token != TokenNameLPAREN) {
2494 if (defineName!=null) {
2495 // does this identifier contain only uppercase characters?
2496 if (defineName.length==3) {
2497 if (defineName[0]=='d' &&
2498 defineName[1]=='i' &&
2499 defineName[2]=='e' ) {
2502 } else if (defineName.length==4) {
2503 if (defineName[0]=='t' &&
2504 defineName[1]=='r' &&
2505 defineName[2]=='u' &&
2506 defineName[3]=='e' ) {
2508 } else if (defineName[0]=='n' &&
2509 defineName[1]=='u' &&
2510 defineName[2]=='l' &&
2511 defineName[3]=='l' ) {
2514 } else if (defineName.length==5) {
2515 if (defineName[0]=='f' &&
2516 defineName[1]=='a' &&
2517 defineName[2]=='l' &&
2518 defineName[3]=='s' &&
2519 defineName[4]=='e' ) {
2523 if (defineName!=null) {
2524 for (int i=0; i<defineName.length;i++) {
2525 if (Character.isLowerCase(defineName[i])) {
2526 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos,
2527 referenceContext, compilationUnit.compilationResult);
2533 // TODO is this ok ?
2535 // throwSyntaxError("'(' expected in function call.");
2538 if (token == TokenNameRPAREN) {
2542 non_empty_function_call_parameter_list();
2543 if (token != TokenNameRPAREN) {
2544 throwSyntaxError("')' expected in function call.");
2548 // private void function_call_parameter_list() {
2549 // function_call_parameter_list:
2550 // non_empty_function_call_parameter_list { $$ = $1; }
2553 private void non_empty_function_call_parameter_list() {
2554 //non_empty_function_call_parameter_list:
2555 // expr_without_variable
2558 // | non_empty_function_call_parameter_list ',' expr_without_variable
2559 // | non_empty_function_call_parameter_list ',' variable
2560 // | non_empty_function_call_parameter_list ',' '&' w_variable
2561 if (Scanner.TRACE) {
2562 System.out.println("TRACE: non_empty_function_call_parameter_list()");
2565 if (token == TokenNameAND) {
2569 // if (token == TokenNameIdentifier || token ==
2570 // TokenNameVariable
2571 // || token == TokenNameDOLLAR) {
2574 expr_without_variable(true);
2577 if (token != TokenNameCOMMA) {
2583 private void fully_qualified_class_name() {
2584 if (token == TokenNameIdentifier) {
2587 throwSyntaxError("Class name expected.");
2590 private void static_member() {
2592 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2593 // variable_without_objects
2594 if (Scanner.TRACE) {
2595 System.out.println("TRACE: static_member()");
2597 fully_qualified_class_name();
2598 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2599 throwSyntaxError("'::' expected after class name (static_member).");
2602 variable_without_objects();
2604 private void base_variable_with_function_calls() {
2605 // base_variable_with_function_calls:
2608 boolean functionCall = false;
2609 if (Scanner.TRACE) {
2610 System.out.println("TRACE: base_variable_with_function_calls()");
2612 // if (token == TokenNameIdentifier) {
2613 // functionCall = true;
2614 // } else if (token == TokenNameVariable) {
2615 // int tempToken = token;
2616 // int tempPosition = scanner.currentPosition;
2618 // if (token == TokenNameLPAREN) {
2619 // functionCall = true;
2621 // token = tempToken;
2622 // scanner.currentPosition = tempPosition;
2623 // scanner.phpMode = true;
2625 // if (functionCall) {
2631 private void base_variable() {
2633 // reference_variable
2634 // | simple_indirect_reference reference_variable
2636 if (Scanner.TRACE) {
2637 System.out.println("TRACE: base_variable()");
2639 if (token == TokenNameIdentifier) {
2642 while (token == TokenNameDOLLAR) {
2645 reference_variable();
2648 // private void simple_indirect_reference() {
2649 // // simple_indirect_reference:
2651 // //| simple_indirect_reference '$'
2653 private void reference_variable() {
2654 // reference_variable:
2655 // reference_variable '[' dim_offset ']'
2656 // | reference_variable '{' expr '}'
2657 // | compound_variable
2658 if (Scanner.TRACE) {
2659 System.out.println("TRACE: reference_variable()");
2661 compound_variable();
2663 if (token == TokenNameLBRACE) {
2666 if (token != TokenNameRBRACE) {
2667 throwSyntaxError("'}' expected in reference variable.");
2670 } else if (token == TokenNameLBRACKET) {
2672 if (token != TokenNameRBRACKET) {
2675 if (token != TokenNameRBRACKET) {
2676 throwSyntaxError("']' expected in reference variable.");
2685 private void compound_variable() {
2686 // compound_variable:
2688 // | '$' '{' expr '}'
2689 if (Scanner.TRACE) {
2690 System.out.println("TRACE: compound_variable()");
2692 if (token == TokenNameVariable) {
2695 // because of simple_indirect_reference
2696 while (token == TokenNameDOLLAR) {
2699 if (token != TokenNameLBRACE) {
2700 throwSyntaxError("'{' expected after compound variable token '$'.");
2704 if (token != TokenNameRBRACE) {
2705 throwSyntaxError("'}' expected after compound variable token '$'.");
2710 // private void dim_offset() {
2716 private void object_property() {
2719 //| variable_without_objects
2720 if (Scanner.TRACE) {
2721 System.out.println("TRACE: object_property()");
2723 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2724 variable_without_objects();
2729 private void object_dim_list() {
2731 // object_dim_list '[' dim_offset ']'
2732 //| object_dim_list '{' expr '}'
2734 if (Scanner.TRACE) {
2735 System.out.println("TRACE: object_dim_list()");
2739 if (token == TokenNameLBRACE) {
2742 if (token != TokenNameRBRACE) {
2743 throwSyntaxError("'}' expected in object_dim_list.");
2746 } else if (token == TokenNameLBRACKET) {
2748 if (token == TokenNameRBRACKET) {
2753 if (token != TokenNameRBRACKET) {
2754 throwSyntaxError("']' expected in object_dim_list.");
2762 private void variable_name() {
2766 if (Scanner.TRACE) {
2767 System.out.println("TRACE: variable_name()");
2769 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
2770 if (token > TokenNameKEYWORD) {
2771 // TODO show a warning "Keyword used as variable" ?
2775 if (token != TokenNameLBRACE) {
2776 throwSyntaxError("'{' expected in variable name.");
2780 if (token != TokenNameRBRACE) {
2781 throwSyntaxError("'}' expected in variable name.");
2786 private void r_variable() {
2789 private void w_variable() {
2792 private void rw_variable() {
2795 private void variable() {
2797 // base_variable_with_function_calls T_OBJECT_OPERATOR
2798 // object_property method_or_not variable_properties
2799 // | base_variable_with_function_calls
2800 base_variable_with_function_calls();
2801 if (token == TokenNameMINUS_GREATER) {
2805 variable_properties();
2807 // if (token == TokenNameDOLLAR_LBRACE) {
2811 // if (token != TokenNameRBRACE) {
2812 // throwSyntaxError("'}' expected after indirect variable token '${'.");
2816 // if (token == TokenNameVariable) {
2818 // if (token == TokenNameLBRACKET) {
2821 // if (token != TokenNameRBRACKET) {
2822 // throwSyntaxError("']' expected in variable-list.");
2825 // } else if (token == TokenNameEQUAL) {
2830 // throwSyntaxError("$-variable expected in variable-list.");
2834 private void variable_properties() {
2835 // variable_properties:
2836 // variable_properties variable_property
2838 while (token == TokenNameMINUS_GREATER) {
2839 variable_property();
2842 private void variable_property() {
2843 // variable_property:
2844 // T_OBJECT_OPERATOR object_property method_or_not
2845 if (Scanner.TRACE) {
2846 System.out.println("TRACE: variable_property()");
2848 if (token == TokenNameMINUS_GREATER) {
2853 throwSyntaxError("'->' expected in variable_property.");
2856 private void method_or_not() {
2858 // '(' function_call_parameter_list ')'
2860 if (Scanner.TRACE) {
2861 System.out.println("TRACE: method_or_not()");
2863 if (token == TokenNameLPAREN) {
2865 if (token == TokenNameRPAREN) {
2869 non_empty_function_call_parameter_list();
2870 if (token != TokenNameRPAREN) {
2871 throwSyntaxError("')' expected in method_or_not.");
2876 private void exit_expr() {
2880 if (token != TokenNameLPAREN) {
2884 if (token == TokenNameRPAREN) {
2889 if (token != TokenNameRPAREN) {
2890 throwSyntaxError("')' expected after keyword 'exit'");
2894 private void encaps_list() {
2895 // encaps_list encaps_var
2896 // | encaps_list T_STRING
2897 // | encaps_list T_NUM_STRING
2898 // | encaps_list T_ENCAPSED_AND_WHITESPACE
2899 // | encaps_list T_CHARACTER
2900 // | encaps_list T_BAD_CHARACTER
2901 // | encaps_list '['
2902 // | encaps_list ']'
2903 // | encaps_list '{'
2904 // | encaps_list '}'
2905 // | encaps_list T_OBJECT_OPERATOR
2909 case TokenNameSTRING :
2912 case TokenNameLBRACE :
2913 // scanner.encapsedStringStack.pop();
2916 case TokenNameRBRACE :
2917 // scanner.encapsedStringStack.pop();
2920 case TokenNameLBRACKET :
2921 // scanner.encapsedStringStack.pop();
2924 case TokenNameRBRACKET :
2925 // scanner.encapsedStringStack.pop();
2928 case TokenNameMINUS_GREATER :
2929 // scanner.encapsedStringStack.pop();
2932 case TokenNameVariable :
2933 case TokenNameDOLLAR_LBRACE :
2934 case TokenNameCURLY_OPEN :
2937 // case TokenNameDOLLAR :
2939 // if (token == TokenNameLBRACE) {
2940 // token = TokenNameDOLLAR_LBRACE;
2945 char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
2946 if (encapsedChar == '$') {
2947 scanner.encapsedStringStack.pop();
2948 encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
2949 switch (encapsedChar) {
2951 if (token == TokenNameEncapsedString0) {
2954 token = TokenNameSTRING;
2957 if (token == TokenNameEncapsedString1) {
2960 token = TokenNameSTRING;
2963 if (token == TokenNameEncapsedString2) {
2966 token = TokenNameSTRING;
2974 private void encaps_var() {
2976 // | T_VARIABLE '[' encaps_var_offset ']'
2977 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
2978 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
2979 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
2980 // | T_CURLY_OPEN variable '}'
2982 case TokenNameVariable :
2984 if (token == TokenNameLBRACKET) {
2986 // if (token == TokenNameRBRACKET) {
2989 expr(); //encaps_var_offset();
2990 if (token != TokenNameRBRACKET) {
2991 throwSyntaxError("']' expected after variable.");
2993 // scanner.encapsedStringStack.pop();
2996 } else if (token == TokenNameMINUS_GREATER) {
2998 if (token != TokenNameIdentifier) {
2999 throwSyntaxError("Identifier expected after '->'.");
3001 // scanner.encapsedStringStack.pop();
3005 // // scanner.encapsedStringStack.pop();
3006 // int tempToken = TokenNameSTRING;
3007 // if (!scanner.encapsedStringStack.isEmpty()
3008 // && (token == TokenNameEncapsedString0
3009 // || token == TokenNameEncapsedString1
3010 // || token == TokenNameEncapsedString2 || token ==
3011 // TokenNameERROR)) {
3012 // char encapsedChar = ((Character)
3013 // scanner.encapsedStringStack.peek())
3016 // case TokenNameEncapsedString0 :
3017 // if (encapsedChar == '`') {
3018 // tempToken = TokenNameEncapsedString0;
3021 // case TokenNameEncapsedString1 :
3022 // if (encapsedChar == '\'') {
3023 // tempToken = TokenNameEncapsedString1;
3026 // case TokenNameEncapsedString2 :
3027 // if (encapsedChar == '"') {
3028 // tempToken = TokenNameEncapsedString2;
3031 // case TokenNameERROR :
3032 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3033 // scanner.currentPosition--;
3039 // token = tempToken;
3042 case TokenNameDOLLAR_LBRACE :
3044 if (token == TokenNameIdentifier) {
3046 if (token == TokenNameLBRACKET) {
3048 // if (token == TokenNameRBRACKET) {
3052 if (token != TokenNameRBRACKET) {
3053 throwSyntaxError("']' expected after '${'.");
3058 if (token != TokenNameRBRACE) {
3059 throwSyntaxError("'}' expected after '${'.");
3061 // scanner.encapsedStringStack.pop();
3065 if (token != TokenNameRBRACE) {
3066 throwSyntaxError("'}' expected.");
3068 // scanner.encapsedStringStack.pop();
3072 case TokenNameCURLY_OPEN :
3074 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3076 if (token == TokenNameLBRACKET) {
3078 // if (token == TokenNameRBRACKET) {
3082 if (token != TokenNameRBRACKET) {
3083 throwSyntaxError("']' expected after '{$'.");
3087 } else if (token == TokenNameMINUS_GREATER) {
3089 if (token != TokenNameIdentifier) {
3090 throwSyntaxError("String token expected.");
3094 // if (token != TokenNameRBRACE) {
3095 // throwSyntaxError("'}' expected after '{$'.");
3097 // // scanner.encapsedStringStack.pop();
3101 if (token != TokenNameRBRACE) {
3102 throwSyntaxError("'}' expected.");
3104 // scanner.encapsedStringStack.pop();
3110 private void encaps_var_offset() {
3115 case TokenNameSTRING :
3118 case TokenNameIntegerLiteral :
3121 case TokenNameVariable :
3124 case TokenNameIdentifier :
3128 throwSyntaxError("Variable or String token expected.");
3132 private void internal_functions_in_yacc() {
3134 ImportReference impt = null;
3136 case TokenNameisset :
3137 // T_ISSET '(' isset_variables ')'
3139 if (token != TokenNameLPAREN) {
3140 throwSyntaxError("'(' expected after keyword 'isset'");
3144 if (token != TokenNameRPAREN) {
3145 throwSyntaxError("')' expected after keyword 'isset'");
3149 case TokenNameempty :
3150 // T_EMPTY '(' variable ')'
3152 if (token != TokenNameLPAREN) {
3153 throwSyntaxError("'(' expected after keyword 'empty'");
3157 if (token != TokenNameRPAREN) {
3158 throwSyntaxError("')' expected after keyword 'empty'");
3162 case TokenNameinclude :
3164 start = scanner.getCurrentTokenStartPosition();
3168 impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3169 impt.declarationSourceEnd = impt.sourceEnd;
3170 impt.declarationEnd = impt.declarationSourceEnd;
3171 //endPosition is just before the ;
3172 impt.declarationSourceStart = start;
3173 includesList.add(impt);
3175 case TokenNameinclude_once :
3176 // T_INCLUDE_ONCE expr
3177 start = scanner.getCurrentTokenStartPosition();
3180 impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3181 impt.declarationSourceEnd = impt.sourceEnd;
3182 impt.declarationEnd = impt.declarationSourceEnd;
3183 //endPosition is just before the ;
3184 impt.declarationSourceStart = start;
3185 includesList.add(impt);
3187 case TokenNameeval :
3188 // T_EVAL '(' expr ')'
3190 if (token != TokenNameLPAREN) {
3191 throwSyntaxError("'(' expected after keyword 'eval'");
3195 if (token != TokenNameRPAREN) {
3196 throwSyntaxError("')' expected after keyword 'eval'");
3200 case TokenNamerequire :
3202 start = scanner.getCurrentTokenStartPosition();
3205 impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3206 impt.declarationSourceEnd = impt.sourceEnd;
3207 impt.declarationEnd = impt.declarationSourceEnd;
3208 //endPosition is just before the ;
3209 impt.declarationSourceStart = start;
3210 includesList.add(impt);
3212 case TokenNamerequire_once :
3213 // T_REQUIRE_ONCE expr
3214 start = scanner.getCurrentTokenStartPosition();
3217 impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3218 impt.declarationSourceEnd = impt.sourceEnd;
3219 impt.declarationEnd = impt.declarationSourceEnd;
3220 //endPosition is just before the ;
3221 impt.declarationSourceStart = start;
3222 includesList.add(impt);
3226 private void isset_variables() {
3228 // | isset_variables ','
3229 if (token == TokenNameRPAREN) {
3230 throwSyntaxError("Variable expected after keyword 'isset'");
3234 if (token == TokenNameCOMMA) {
3241 private boolean common_scalar() {
3245 // | T_CONSTANT_ENCAPSED_STRING
3252 case TokenNameIntegerLiteral :
3255 case TokenNameDoubleLiteral :
3258 case TokenNameStringDoubleQuote :
3261 case TokenNameStringSingleQuote :
3264 case TokenNameStringInterpolated :
3267 case TokenNameFILE :
3270 case TokenNameLINE :
3273 case TokenNameCLASS_C :
3276 case TokenNameMETHOD_C :
3279 case TokenNameFUNC_C :
3285 private void scalar() {
3288 //| T_STRING_VARNAME
3291 //| '"' encaps_list '"'
3292 //| '\'' encaps_list '\''
3293 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3294 throwSyntaxError("Not yet implemented (scalar).");
3296 private void static_scalar() {
3297 // static_scalar: /* compile-time evaluated scalars */
3300 // | '+' static_scalar
3301 // | '-' static_scalar
3302 // | T_ARRAY '(' static_array_pair_list ')'
3303 // | static_class_constant
3304 if (common_scalar()) {
3308 case TokenNameIdentifier :
3310 // static_class_constant:
3311 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3312 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3314 if (token == TokenNameIdentifier) {
3317 throwSyntaxError("Identifier expected after '::' operator.");
3321 case TokenNameEncapsedString0 :
3323 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3324 while (scanner.currentCharacter != '`') {
3325 if (scanner.currentCharacter == '\\') {
3326 scanner.currentPosition++;
3328 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3331 } catch (IndexOutOfBoundsException e) {
3332 throwSyntaxError("'`' expected at end of static string.");
3335 case TokenNameEncapsedString1 :
3337 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3338 while (scanner.currentCharacter != '\'') {
3339 if (scanner.currentCharacter == '\\') {
3340 scanner.currentPosition++;
3342 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3345 } catch (IndexOutOfBoundsException e) {
3346 throwSyntaxError("'\'' expected at end of static string.");
3349 case TokenNameEncapsedString2 :
3351 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3352 while (scanner.currentCharacter != '"') {
3353 if (scanner.currentCharacter == '\\') {
3354 scanner.currentPosition++;
3356 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3359 } catch (IndexOutOfBoundsException e) {
3360 throwSyntaxError("'\"' expected at end of static string.");
3363 case TokenNamePLUS :
3367 case TokenNameMINUS :
3371 case TokenNamearray :
3373 if (token != TokenNameLPAREN) {
3374 throwSyntaxError("'(' expected after keyword 'array'");
3377 if (token == TokenNameRPAREN) {
3381 non_empty_static_array_pair_list();
3382 if (token != TokenNameRPAREN) {
3383 throwSyntaxError("')' expected after keyword 'array'");
3387 // case TokenNamenull :
3390 // case TokenNamefalse :
3393 // case TokenNametrue :
3397 throwSyntaxError("Static scalar/constant expected.");
3400 private void non_empty_static_array_pair_list() {
3401 // non_empty_static_array_pair_list:
3402 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3404 //| non_empty_static_array_pair_list ',' static_scalar
3405 //| static_scalar T_DOUBLE_ARROW static_scalar
3409 if (token == TokenNameEQUAL_GREATER) {
3413 if (token != TokenNameCOMMA) {
3417 if (token == TokenNameRPAREN) {
3422 public void reportSyntaxError() { //int act, int currentKind, int
3424 /* remember current scanner position */
3425 int startPos = scanner.startPosition;
3426 int currentPos = scanner.currentPosition;
3427 // String[] expectings;
3428 // String tokenName = name[symbol_index[currentKind]];
3429 //fetch all "accurate" possible terminals that could recover the error
3430 // int start, end = start = asi(stack[stateStackTop]);
3431 // while (asr[end] != 0)
3433 // int length = end - start;
3434 // expectings = new String[length];
3435 // if (length != 0) {
3436 // char[] indexes = new char[length];
3437 // System.arraycopy(asr, start, indexes, 0, length);
3438 // for (int i = 0; i < length; i++) {
3439 // expectings[i] = name[symbol_index[indexes[i]]];
3442 //if the pb is an EOF, try to tell the user that they are some
3443 // if (tokenName.equals(UNEXPECTED_EOF)) {
3444 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3445 // char[] tokenSource;
3447 // tokenSource = this.scanner.getCurrentTokenSource();
3448 // } catch (Exception e) {
3449 // tokenSource = new char[] {};
3451 // problemReporter().parseError(
3452 // this.scanner.startPosition,
3453 // this.scanner.currentPosition - 1,
3458 // } else { //the next test is HEAVILY grammar DEPENDENT.
3459 // if ((length == 14)
3460 // && (expectings[0] == "=") //$NON-NLS-1$
3461 // && (expectings[1] == "*=") //$NON-NLS-1$
3462 // && (expressionPtr > -1)) {
3463 // switch(currentKind) {
3464 // case TokenNameSEMICOLON:
3465 // case TokenNamePLUS:
3466 // case TokenNameMINUS:
3467 // case TokenNameDIVIDE:
3468 // case TokenNameREMAINDER:
3469 // case TokenNameMULTIPLY:
3470 // case TokenNameLEFT_SHIFT:
3471 // case TokenNameRIGHT_SHIFT:
3472 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3473 // case TokenNameLESS:
3474 // case TokenNameGREATER:
3475 // case TokenNameLESS_EQUAL:
3476 // case TokenNameGREATER_EQUAL:
3477 // case TokenNameEQUAL_EQUAL:
3478 // case TokenNameNOT_EQUAL:
3479 // case TokenNameXOR:
3480 // case TokenNameAND:
3481 // case TokenNameOR:
3482 // case TokenNameOR_OR:
3483 // case TokenNameAND_AND:
3484 // // the ; is not the expected token ==> it ends a statement when an
3485 // expression is not ended
3486 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3488 // case TokenNameRBRACE :
3489 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3492 // char[] tokenSource;
3494 // tokenSource = this.scanner.getCurrentTokenSource();
3495 // } catch (Exception e) {
3496 // tokenSource = new char[] {};
3498 // problemReporter().parseError(
3499 // this.scanner.startPosition,
3500 // this.scanner.currentPosition - 1,
3504 // this.checkAndReportBracketAnomalies(problemReporter());
3509 tokenSource = this.scanner.getCurrentTokenSource();
3510 } catch (Exception e) {
3511 tokenSource = new char[]{};
3513 // problemReporter().parseError(
3514 // this.scanner.startPosition,
3515 // this.scanner.currentPosition - 1,
3519 this.checkAndReportBracketAnomalies(problemReporter());
3522 /* reset scanner where it was */
3523 scanner.startPosition = startPos;
3524 scanner.currentPosition = currentPos;
3526 public static final int RoundBracket = 0;
3527 public static final int SquareBracket = 1;
3528 public static final int CurlyBracket = 2;
3529 public static final int BracketKinds = 3;
3530 protected int[] nestedMethod; //the ptr is nestedType
3531 protected int nestedType, dimensions;
3533 final static int AstStackIncrement = 100;
3534 protected int astPtr;
3535 protected AstNode[] astStack = new AstNode[AstStackIncrement];
3536 protected int astLengthPtr;
3537 protected int[] astLengthStack;
3538 AstNode[] noAstNodes = new AstNode[AstStackIncrement];
3539 public CompilationUnitDeclaration compilationUnit; /*
3540 * the result from parse()
3542 protected ReferenceContext referenceContext;
3543 protected ProblemReporter problemReporter;
3544 protected CompilerOptions options;
3545 private ArrayList includesList;
3546 // protected CompilationResult compilationResult;
3548 * Returns this parser's problem reporter initialized with its reference
3549 * context. Also it is assumed that a problem is going to be reported, so
3550 * initializes the compilation result's line positions.
3552 public ProblemReporter problemReporter() {
3553 if (scanner.recordLineSeparator) {
3554 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
3556 problemReporter.referenceContext = referenceContext;
3557 return problemReporter;
3560 * Reconsider the entire source looking for inconsistencies in {} () []
3562 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
3563 scanner.wasAcr = false;
3564 boolean anomaliesDetected = false;
3566 char[] source = scanner.source;
3567 int[] leftCount = {0, 0, 0};
3568 int[] rightCount = {0, 0, 0};
3569 int[] depths = {0, 0, 0};
3570 int[][] leftPositions = new int[][]{new int[10], new int[10], new int[10]};
3571 int[][] leftDepths = new int[][]{new int[10], new int[10], new int[10]};
3572 int[][] rightPositions = new int[][]{new int[10], new int[10], new int[10]};
3573 int[][] rightDepths = new int[][]{new int[10], new int[10], new int[10]};
3574 scanner.currentPosition = scanner.initialPosition; //starting
3576 // (first-zero-based
3578 while (scanner.currentPosition < scanner.eofPosition) { //loop for
3583 // ---------Consume white space and handles
3584 // startPosition---------
3585 boolean isWhiteSpace;
3587 scanner.startPosition = scanner.currentPosition;
3588 // if (((scanner.currentCharacter =
3589 // source[scanner.currentPosition++]) == '\\') &&
3590 // (source[scanner.currentPosition] == 'u')) {
3591 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
3593 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3594 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3595 // only record line positions we have not
3597 scanner.pushLineSeparator();
3600 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
3602 } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
3603 // -------consume token until } is found---------
3604 switch (scanner.currentCharacter) {
3606 int index = leftCount[CurlyBracket]++;
3607 if (index == leftPositions[CurlyBracket].length) {
3608 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
3609 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
3611 leftPositions[CurlyBracket][index] = scanner.startPosition;
3612 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
3616 int index = rightCount[CurlyBracket]++;
3617 if (index == rightPositions[CurlyBracket].length) {
3618 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
3619 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
3621 rightPositions[CurlyBracket][index] = scanner.startPosition;
3622 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
3626 int index = leftCount[RoundBracket]++;
3627 if (index == leftPositions[RoundBracket].length) {
3628 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
3629 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
3631 leftPositions[RoundBracket][index] = scanner.startPosition;
3632 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
3636 int index = rightCount[RoundBracket]++;
3637 if (index == rightPositions[RoundBracket].length) {
3638 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
3639 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
3641 rightPositions[RoundBracket][index] = scanner.startPosition;
3642 rightDepths[RoundBracket][index] = --depths[RoundBracket];
3646 int index = leftCount[SquareBracket]++;
3647 if (index == leftPositions[SquareBracket].length) {
3648 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
3649 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
3651 leftPositions[SquareBracket][index] = scanner.startPosition;
3652 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
3656 int index = rightCount[SquareBracket]++;
3657 if (index == rightPositions[SquareBracket].length) {
3658 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
3659 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
3661 rightPositions[SquareBracket][index] = scanner.startPosition;
3662 rightDepths[SquareBracket][index] = --depths[SquareBracket];
3666 if (scanner.getNextChar('\\')) {
3667 scanner.scanEscapeCharacter();
3668 } else { // consume next character
3669 scanner.unicodeAsBackSlash = false;
3670 // if (((scanner.currentCharacter =
3671 // source[scanner.currentPosition++]) ==
3673 // (source[scanner.currentPosition] ==
3675 // scanner.getNextUnicodeChar();
3677 if (scanner.withoutUnicodePtr != 0) {
3678 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3682 scanner.getNextChar('\'');
3686 // consume next character
3687 scanner.unicodeAsBackSlash = false;
3688 // if (((scanner.currentCharacter =
3689 // source[scanner.currentPosition++]) == '\\') &&
3690 // (source[scanner.currentPosition] == 'u')) {
3691 // scanner.getNextUnicodeChar();
3693 if (scanner.withoutUnicodePtr != 0) {
3694 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3697 while (scanner.currentCharacter != '"') {
3698 if (scanner.currentCharacter == '\r') {
3699 if (source[scanner.currentPosition] == '\n')
3700 scanner.currentPosition++;
3701 break; // the string cannot go further that
3704 if (scanner.currentCharacter == '\n') {
3705 break; // the string cannot go further that
3708 if (scanner.currentCharacter == '\\') {
3709 scanner.scanEscapeCharacter();
3711 // consume next character
3712 scanner.unicodeAsBackSlash = false;
3713 // if (((scanner.currentCharacter =
3714 // source[scanner.currentPosition++]) == '\\')
3715 // && (source[scanner.currentPosition] == 'u'))
3717 // scanner.getNextUnicodeChar();
3719 if (scanner.withoutUnicodePtr != 0) {
3720 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3727 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
3730 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3731 && (source[scanner.currentPosition] == 'u')) {
3732 //-------------unicode traitement
3734 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3735 scanner.currentPosition++;
3736 while (source[scanner.currentPosition] == 'u') {
3737 scanner.currentPosition++;
3739 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3740 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3741 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3742 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3746 scanner.currentCharacter = 'A';
3747 } //something different from \n and \r
3749 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3752 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
3754 scanner.startPosition = scanner.currentPosition;
3755 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3756 && (source[scanner.currentPosition] == 'u')) {
3757 //-------------unicode traitement
3759 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3760 scanner.currentPosition++;
3761 while (source[scanner.currentPosition] == 'u') {
3762 scanner.currentPosition++;
3764 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3765 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3766 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3767 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3771 scanner.currentCharacter = 'A';
3772 } //something different from \n
3775 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3779 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3780 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3781 // only record line positions we
3782 // have not recorded yet
3783 scanner.pushLineSeparator();
3784 if (this.scanner.taskTags != null) {
3785 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
3786 .getCurrentTokenEndPosition());
3792 if (test > 0) { //traditional and annotation
3794 boolean star = false;
3795 // consume next character
3796 scanner.unicodeAsBackSlash = false;
3797 // if (((scanner.currentCharacter =
3798 // source[scanner.currentPosition++]) ==
3800 // (source[scanner.currentPosition] ==
3802 // scanner.getNextUnicodeChar();
3804 if (scanner.withoutUnicodePtr != 0) {
3805 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3808 if (scanner.currentCharacter == '*') {
3812 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3813 && (source[scanner.currentPosition] == 'u')) {
3814 //-------------unicode traitement
3816 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3817 scanner.currentPosition++;
3818 while (source[scanner.currentPosition] == 'u') {
3819 scanner.currentPosition++;
3821 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3822 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3823 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3824 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3828 scanner.currentCharacter = 'A';
3829 } //something different from * and /
3831 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3834 //loop until end of comment */
3835 while ((scanner.currentCharacter != '/') || (!star)) {
3836 star = scanner.currentCharacter == '*';
3838 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3839 && (source[scanner.currentPosition] == 'u')) {
3840 //-------------unicode traitement
3842 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3843 scanner.currentPosition++;
3844 while (source[scanner.currentPosition] == 'u') {
3845 scanner.currentPosition++;
3847 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3848 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3849 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3850 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3854 scanner.currentCharacter = 'A';
3855 } //something different from * and
3858 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3862 if (this.scanner.taskTags != null) {
3863 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
3870 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
3871 scanner.scanIdentifierOrKeyword(false);
3874 if (Character.isDigit(scanner.currentCharacter)) {
3875 scanner.scanNumber(false);
3879 //-----------------end switch while
3880 // try--------------------
3881 } catch (IndexOutOfBoundsException e) {
3882 break; // read until EOF
3883 } catch (InvalidInputException e) {
3884 return false; // no clue
3887 if (scanner.recordLineSeparator) {
3888 // compilationUnit.compilationResult.lineSeparatorPositions =
3889 // scanner.getLineEnds();
3891 // check placement anomalies against other kinds of brackets
3892 for (int kind = 0; kind < BracketKinds; kind++) {
3893 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
3894 int start = leftPositions[kind][leftIndex]; // deepest
3896 // find matching closing bracket
3897 int depth = leftDepths[kind][leftIndex];
3899 for (int i = 0; i < rightCount[kind]; i++) {
3900 int pos = rightPositions[kind][i];
3901 // want matching bracket further in source with same
3903 if ((pos > start) && (depth == rightDepths[kind][i])) {
3908 if (end < 0) { // did not find a good closing match
3909 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
3912 // check if even number of opening/closing other brackets
3913 // in between this pair of brackets
3915 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
3916 for (int i = 0; i < leftCount[otherKind]; i++) {
3917 int pos = leftPositions[otherKind][i];
3918 if ((pos > start) && (pos < end))
3921 for (int i = 0; i < rightCount[otherKind]; i++) {
3922 int pos = rightPositions[otherKind][i];
3923 if ((pos > start) && (pos < end))
3927 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
3933 // too many opening brackets ?
3934 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
3935 anomaliesDetected = true;
3936 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
3937 compilationUnit.compilationResult);
3939 // too many closing brackets ?
3940 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
3941 anomaliesDetected = true;
3942 problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
3944 if (anomaliesDetected)
3947 return anomaliesDetected;
3948 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
3949 return anomaliesDetected;
3950 } catch (NullPointerException e) { // jdk1.2.2 jit bug
3951 return anomaliesDetected;
3954 protected void pushOnAstLengthStack(int pos) {
3956 astLengthStack[++astLengthPtr] = pos;
3957 } catch (IndexOutOfBoundsException e) {
3958 int oldStackLength = astLengthStack.length;
3959 int[] oldPos = astLengthStack;
3960 astLengthStack = new int[oldStackLength + StackIncrement];
3961 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
3962 astLengthStack[astLengthPtr] = pos;
3965 protected void pushOnAstStack(AstNode node) {
3967 * add a new obj on top of the ast stack
3970 astStack[++astPtr] = node;
3971 } catch (IndexOutOfBoundsException e) {
3972 int oldStackLength = astStack.length;
3973 AstNode[] oldStack = astStack;
3974 astStack = new AstNode[oldStackLength + AstStackIncrement];
3975 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
3976 astPtr = oldStackLength;
3977 astStack[astPtr] = node;
3980 astLengthStack[++astLengthPtr] = 1;
3981 } catch (IndexOutOfBoundsException e) {
3982 int oldStackLength = astLengthStack.length;
3983 int[] oldPos = astLengthStack;
3984 astLengthStack = new int[oldStackLength + AstStackIncrement];
3985 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
3986 astLengthStack[astLengthPtr] = 1;
3990 protected void resetModifiers() {
3991 this.modifiers = AccDefault;
3992 this.modifiersSourceStart = -1; // <-- see comment into
3993 // modifiersFlag(int)
3994 this.scanner.commentPtr = -1;