1 /**********************************************************************
2 Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de
3 All rights reserved. This program and the accompanying material
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 Klaus Hartlage - www.eclipseproject.de
10 **********************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.parser;
12 import java.util.ArrayList;
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
17 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
18 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
19 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
20 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
21 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
22 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
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.MethodDeclaration;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
30 import net.sourceforge.phpdt.internal.compiler.util.Util;
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 Parser(ProblemReporter problemReporter) {
74 this.problemReporter = problemReporter;
75 this.options = problemReporter.options;
76 this.currentPHPString = 0;
77 // PHPParserSuperclass.fileToParse = fileToParse;
80 this.token = TokenNameEOF;
83 // this.columnCount = 0;
86 this.initializeScanner();
88 public void setFileToParse(IFile fileToParse) {
89 this.currentPHPString = 0;
90 // PHPParserSuperclass.fileToParse = fileToParse;
93 this.token = TokenNameEOF;
95 this.initializeScanner();
98 * ClassDeclaration Constructor.
102 * Description of Parameter
105 public Parser(IFile fileToParse) {
106 // if (keywordMap == null) {
107 // keywordMap = new HashMap();
108 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
109 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
112 this.currentPHPString = 0;
113 // PHPParserSuperclass.fileToParse = fileToParse;
116 this.token = TokenNameEOF;
118 // this.rowCount = 1;
119 // this.columnCount = 0;
122 this.initializeScanner();
124 public void initializeScanner() {
125 this.scanner = new Scanner(
127 false /*whitespace*/,
128 this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/,
131 this.options.taskTags/*taskTags*/,
132 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,
168 int problemEndPosition) {
170 .phpParsingError(new String[]{error}, problemStartPosition,
171 problemEndPosition, referenceContext,
172 compilationUnit.compilationResult);
173 throw new SyntaxError(1, 0, " ", error);
175 private void reportSyntaxError(String error, int problemStartPosition,
176 int problemEndPosition) {
178 .phpParsingError(new String[]{error}, problemStartPosition,
179 problemEndPosition, referenceContext,
180 compilationUnit.compilationResult);
182 private void reportSyntaxWarning(String error, int problemStartPosition,
183 int problemEndPosition) {
184 problemReporter.phpParsingWarning(new String[]{error},
185 problemStartPosition, problemEndPosition, referenceContext,
186 compilationUnit.compilationResult);
189 * Method Declaration.
193 // private void getChar() {
194 // if (str.length() > chIndx) {
195 // ch = str.charAt(chIndx++);
200 // chIndx = str.length() + 1;
202 // // token = TokenNameEOF;
206 * gets the next token from input
208 private void getNextToken() {
210 token = scanner.getNextToken();
212 int currentEndPosition = scanner.getCurrentTokenEndPosition();
213 int currentStartPosition = scanner.getCurrentTokenStartPosition();
215 .print(currentStartPosition + "," + currentEndPosition + ": ");
216 System.out.println(scanner.toStringAction(token));
218 } catch (InvalidInputException e) {
219 token = TokenNameERROR;
223 public void init(String s) {
225 this.token = TokenNameEOF;
227 // this.rowCount = 1;
228 // this.columnCount = 0;
230 // this.phpMode = false;
231 /* scanner initialization */
232 scanner.setSource(s.toCharArray());
233 scanner.setPHPMode(false);
235 protected void initialize(boolean phpMode) {
236 compilationUnit = null;
237 referenceContext = null;
239 this.token = TokenNameEOF;
241 // this.rowCount = 1;
242 // this.columnCount = 0;
244 // this.phpMode = phpMode;
245 scanner.setPHPMode(phpMode);
248 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
251 public void parse(String s) {
256 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
259 protected void parse() {
263 if (token != TokenNameEOF && token != TokenNameERROR) {
266 if (token != TokenNameEOF) {
267 if (token == TokenNameERROR) {
268 throwSyntaxError("Scanner error (Found unknown token: "
269 + scanner.toStringAction(token) + ")");
271 if (token == TokenNameRPAREN) {
272 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
274 if (token == TokenNameRBRACE) {
275 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
277 if (token == TokenNameRBRACKET) {
278 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
280 if (token == TokenNameLPAREN) {
281 throwSyntaxError("Read character '('; end-of-file not reached.");
283 if (token == TokenNameLBRACE) {
284 throwSyntaxError("Read character '{'; end-of-file not reached.");
286 if (token == TokenNameLBRACKET) {
287 throwSyntaxError("Read character '['; end-of-file not reached.");
289 throwSyntaxError("End-of-file not reached.");
292 } catch (SyntaxError sytaxErr1) {
293 // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
295 // setMarker(sytaxErr1.getMessage(),
296 // scanner.getCurrentTokenStartPosition(),
297 // scanner.getCurrentTokenEndPosition(), ERROR);
299 // if an error occured,
300 // try to find keywords 'class' or 'function'
301 // to parse the rest of the string
302 while (token != TokenNameEOF && token != TokenNameERROR) {
303 if (token == TokenNameabstract || token == TokenNamefinal
304 || token == TokenNameclass || token == TokenNamefunction) {
309 if (token == TokenNameEOF || token == TokenNameERROR) {
312 } catch (SyntaxError sytaxErr2) {
313 // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
315 // setMarker(sytaxErr2.getMessage(),
316 // scanner.getCurrentTokenStartPosition(),
317 // scanner.getCurrentTokenEndPosition(), ERROR);
326 protected CompilationUnitDeclaration endParse(int act) {
330 if (currentElement != null) {
331 currentElement.topElement().updateParseTree();
332 if (VERBOSE_RECOVERY) {
333 System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
334 System.out.println("--------------------------"); //$NON-NLS-1$
335 System.out.println(compilationUnit);
336 System.out.println("----------------------------------"); //$NON-NLS-1$
339 if (diet & VERBOSE_RECOVERY) {
340 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
341 System.out.println("--------------------------"); //$NON-NLS-1$
342 System.out.println(compilationUnit);
343 System.out.println("----------------------------------"); //$NON-NLS-1$
346 if (scanner.recordLineSeparator) {
347 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
349 if (scanner.taskTags != null) {
350 for (int i = 0; i < scanner.foundTaskCount; i++) {
351 problemReporter().task(
352 new String(scanner.foundTaskTags[i]),
353 new String(scanner.foundTaskMessages[i]),
354 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
355 scanner.foundTaskPositions[i][0],
356 scanner.foundTaskPositions[i][1]);
359 return compilationUnit;
361 // public PHPOutlineInfo parseInfo(Object parent, String s) {
362 // PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
363 // // Stack stack = new Stack();
364 // // stack.push(outlineInfo.getDeclarations());
366 // this.token = TokenNameEOF;
367 // // this.chIndx = 0;
368 // // this.rowCount = 1;
369 // // this.columnCount = 0;
370 // this.phpEnd = false;
371 // this.phpMode = false;
372 // scanner.setSource(s.toCharArray());
373 // scanner.setPHPMode(false);
376 // parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
378 // return outlineInfo;
380 private boolean isVariable() {
381 return token == TokenNameVariable; // || token == TokenNamethis;
383 // private void parseDeclarations(PHPOutlineInfo outlineInfo,
384 // OutlineableWithChildren current, boolean goBack) {
386 // // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
387 // PHPSegmentWithChildren temp;
389 // IPreferenceStore store =
390 // PHPeclipsePlugin.getDefault().getPreferenceStore();
392 // while (token != TokenNameEOF && token != TokenNameERROR) {
393 // if (token == TokenNameVariable) {
394 // ident = scanner.getCurrentIdentifierSource();
395 // outlineInfo.addVariable(new String(ident));
397 // } else if (token == TokenNamevar) {
399 // if (token == TokenNameVariable
400 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
401 // ident = scanner.getCurrentIdentifierSource();
402 // //substring(1) added because PHPVarDeclaration doesn't
403 // // need the $ anymore
404 // String variableName = new String(ident).substring(1);
405 // outlineInfo.addVariable(variableName);
407 // if (token != TokenNameSEMICOLON) {
409 // ident = scanner.getCurrentTokenSource();
410 // if (token > TokenNameKEYWORD) {
411 // current.add(new PHPVarDeclaration(current, variableName,
412 // // chIndx - ident.length,
413 // scanner.getCurrentTokenStartPosition(), new String(ident)));
416 // case TokenNameVariable :
417 // case TokenNamethis :
418 // current.add(new PHPVarDeclaration(current, variableName,
421 // scanner.getCurrentTokenStartPosition(), new String(
424 // case TokenNameIdentifier :
425 // current.add(new PHPVarDeclaration(current, variableName,
428 // scanner.getCurrentTokenStartPosition(), new String(
431 // case TokenNameDoubleLiteral :
432 // current.add(new PHPVarDeclaration(current, variableName
436 // scanner.getCurrentTokenStartPosition(), new String(
439 // case TokenNameIntegerLiteral :
440 // current.add(new PHPVarDeclaration(current, variableName,
443 // scanner.getCurrentTokenStartPosition(), new String(
446 // case TokenNameStringInterpolated :
447 // case TokenNameStringLiteral :
448 // current.add(new PHPVarDeclaration(current, variableName,
451 // scanner.getCurrentTokenStartPosition(), new String(
454 // case TokenNameStringConstant :
455 // current.add(new PHPVarDeclaration(current, variableName,
458 // scanner.getCurrentTokenStartPosition(), new String(
462 // current.add(new PHPVarDeclaration(current, variableName,
465 // scanner.getCurrentTokenStartPosition()));
470 // ident = scanner.getCurrentIdentifierSource();
471 // current.add(new PHPVarDeclaration(current, variableName,
472 // // chIndx - ident.length
473 // scanner.getCurrentTokenStartPosition()));
476 // } else if (token == TokenNamefunction) {
478 // if (token == TokenNameAND) {
481 // if (token == TokenNameIdentifier
482 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
483 // ident = scanner.getCurrentIdentifierSource();
484 // outlineInfo.addVariable(new String(ident));
485 // temp = new PHPFunctionDeclaration(current, new String(ident),
486 // // chIndx - ident.length
487 // scanner.getCurrentTokenStartPosition());
488 // current.add(temp);
490 // parseDeclarations(outlineInfo, temp, true);
492 // } else if (token == TokenNameclass) {
494 // if (token == TokenNameIdentifier
495 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
496 // ident = scanner.getCurrentIdentifierSource();
497 // outlineInfo.addVariable(new String(ident));
498 // temp = new PHPClassDeclaration(current, new String(ident),
499 // // chIndx - ident.len
500 // scanner.getCurrentTokenStartPosition());
501 // current.add(temp);
502 // // stack.push(temp);
504 // //skip tokens for classname, extends and others until
505 // // we have the opening '{'
506 // while (token != TokenNameLBRACE && token != TokenNameEOF
507 // && token != TokenNameERROR) {
510 // parseDeclarations(outlineInfo, temp, true);
513 // } else if ((token == TokenNameLBRACE)
514 // || (token == TokenNameDOLLAR_LBRACE)) {
517 // } else if (token == TokenNameRBRACE) {
520 // if (counter == 0 && goBack) {
523 // } else if (token == TokenNamerequire || token == TokenNamerequire_once
524 // || token == TokenNameinclude || token == TokenNameinclude_once) {
525 // ident = scanner.getCurrentTokenSource();
527 // int startPosition = scanner.getCurrentTokenStartPosition();
529 // char[] expr = scanner.getCurrentTokenSource(startPosition);
530 // outlineInfo.addVariable(new String(ident));
531 // current.add(new PHPReqIncDeclaration(current, new String(ident),
532 // // chIndx - ident.length,
533 // startPosition, new String(expr)));
539 // } catch (SyntaxError sytaxErr) {
541 // // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
542 // // setMarker(sytaxErr.getMessage(),
543 // // scanner.getCurrentTokenStartPosition(),
544 // // scanner.getCurrentTokenEndPosition(), ERROR);
545 // // } catch (CoreException e) {
549 private void statementList() {
551 statement(TokenNameEOF);
552 if ((token == TokenNameRBRACE) || (token == TokenNamecase)
553 || (token == TokenNamedefault) || (token == TokenNameelse)
554 || (token == TokenNameelseif) || (token == TokenNameendif)
555 || (token == TokenNameendfor) || (token == TokenNameendforeach)
556 || (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 == TokenNamerequire_once)
613 // if (token == TokenNameLPAREN) {
615 // if (token == TokenNameSEMICOLON) {
618 // if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
619 // throwSyntaxError("';' expected after 'require' or 'require_once'.");
621 // // getNextToken();
624 // concatenationExpression();
628 if (token == TokenNameif) {
630 if (token == TokenNameLPAREN) {
633 throwSyntaxError("'(' expected after 'if' keyword.");
636 if (token == TokenNameRPAREN) {
639 throwSyntaxError("')' expected after 'if' condition.");
643 } else if (token == TokenNameswitch) {
645 if (token == TokenNameLPAREN) {
648 throwSyntaxError("'(' expected after 'switch' keyword.");
651 if (token == TokenNameRPAREN) {
654 throwSyntaxError("')' expected after 'switch' condition.");
658 } else if (token == TokenNamefor) {
660 if (token == TokenNameLPAREN) {
663 throwSyntaxError("'(' expected after 'for' keyword.");
665 if (token == TokenNameSEMICOLON) {
669 if (token == TokenNameSEMICOLON) {
672 throwSyntaxError("';' expected after 'for'.");
675 if (token == TokenNameSEMICOLON) {
679 if (token == TokenNameSEMICOLON) {
682 throwSyntaxError("';' expected after 'for'.");
685 if (token == TokenNameRPAREN) {
689 if (token == TokenNameRPAREN) {
692 throwSyntaxError("')' expected after 'for'.");
697 } else if (token == TokenNamewhile) {
699 if (token == TokenNameLPAREN) {
702 throwSyntaxError("'(' expected after 'while' keyword.");
705 if (token == TokenNameRPAREN) {
708 throwSyntaxError("')' expected after 'while' condition.");
712 } else if (token == TokenNamedo) {
714 if (token == TokenNameLBRACE) {
716 if (token != TokenNameRBRACE) {
719 if (token == TokenNameRBRACE) {
722 throwSyntaxError("'}' expected after 'do' keyword.");
725 statement(TokenNameEOF);
727 if (token == TokenNamewhile) {
729 if (token == TokenNameLPAREN) {
732 throwSyntaxError("'(' expected after 'while' keyword.");
735 if (token == TokenNameRPAREN) {
738 throwSyntaxError("')' expected after 'while' condition.");
741 throwSyntaxError("'while' expected after 'do' keyword.");
743 if (token == TokenNameSEMICOLON) {
746 if (token != TokenNameINLINE_HTML) {
747 throwSyntaxError("';' expected after do-while statement.");
752 } else if (token == TokenNameforeach) {
754 if (token == TokenNameLPAREN) {
757 throwSyntaxError("'(' expected after 'foreach' keyword.");
760 if (token == TokenNameas) {
763 throwSyntaxError("'as' expected after 'foreach' exxpression.");
767 foreach_optional_arg();
768 if (token == TokenNameEQUAL_GREATER) {
772 if (token == TokenNameRPAREN) {
775 throwSyntaxError("')' expected after 'foreach' expression.");
779 } else if (token == TokenNamecontinue || token == TokenNamebreak
780 || 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(
869 this.compilationUnit.compilationResult);
870 methodDecl.declarationSourceStart = scanner
871 .getCurrentTokenStartPosition();
873 functionDefinition(methodDecl);
875 } else if (token == TokenNametry) {
877 if (token != TokenNameLBRACE) {
878 throwSyntaxError("'{' expected in 'try' statement.");
882 if (token != TokenNameRBRACE) {
883 throwSyntaxError("'}' expected in 'try' statement.");
887 } else if (token == TokenNamecatch) {
889 if (token != TokenNameLPAREN) {
890 throwSyntaxError("'(' expected in 'catch' statement.");
893 fully_qualified_class_name();
894 if (token != TokenNameVariable) {
895 throwSyntaxError("Variable expected in 'catch' statement.");
898 if (token != TokenNameRPAREN) {
899 throwSyntaxError("')' expected in 'catch' statement.");
902 if (token != TokenNameLBRACE) {
903 throwSyntaxError("'{' expected in 'catch' statement.");
906 if (token != TokenNameRBRACE) {
908 if (token != TokenNameRBRACE) {
909 throwSyntaxError("'}' expected in 'catch' statement.");
913 additional_catches();
915 } else if (token == TokenNamethrow) {
918 if (token == TokenNameSEMICOLON) {
921 throwSyntaxError("';' expected after 'throw' exxpression.");
924 } else if (token == TokenNamefinal || token == TokenNameabstract
925 || token == TokenNameclass || token == TokenNameinterface) {
926 TypeDeclaration typeDecl = new TypeDeclaration(
927 this.compilationUnit.compilationResult);
928 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
929 // default super class
930 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
931 compilationUnit.types.add(typeDecl);
933 pushOnAstStack(typeDecl);
934 unticked_class_declaration_statement(typeDecl);
935 // classBody(typeDecl);
942 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
943 } else if (token == TokenNameLBRACE) {
945 if (token != TokenNameRBRACE) {
948 if (token == TokenNameRBRACE) {
952 throwSyntaxError("'}' expected.");
955 if (token != TokenNameSEMICOLON) {
958 if (token == TokenNameSEMICOLON) {
962 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
963 throwSyntaxError("';' expected after expression (Found token: "
964 + scanner.toStringAction(token) + ")");
970 private void additional_catches() {
971 while (token == TokenNamecatch) {
973 if (token != TokenNameLPAREN) {
974 throwSyntaxError("'(' expected in 'catch' statement.");
977 fully_qualified_class_name();
978 if (token != TokenNameVariable) {
979 throwSyntaxError("Variable expected in 'catch' statement.");
982 if (token != TokenNameRPAREN) {
983 throwSyntaxError("')' expected in 'catch' statement.");
986 if (token != TokenNameLBRACE) {
987 throwSyntaxError("'{' expected in 'catch' statement.");
991 if (token != TokenNameRBRACE) {
992 throwSyntaxError("'}' expected in 'catch' statement.");
997 private void foreach_variable() {
1000 if (token == TokenNameAND) {
1005 private void foreach_optional_arg() {
1007 //| T_DOUBLE_ARROW foreach_variable
1008 if (token == TokenNameEQUAL_GREATER) {
1013 private void global_var_list() {
1015 // global_var_list ',' global_var
1019 if (token != TokenNameCOMMA) {
1025 private void global_var() {
1029 //| '$' '{' expr '}'
1030 if (token == TokenNameVariable) {
1032 } else if (token == TokenNameDOLLAR) {
1034 if (token == TokenNameLPAREN) {
1037 if (token != TokenNameLPAREN) {
1038 throwSyntaxError("')' expected in global variable.");
1046 private void static_var_list() {
1048 // static_var_list ',' T_VARIABLE
1049 //| static_var_list ',' T_VARIABLE '=' static_scalar
1051 //| T_VARIABLE '=' static_scalar
1053 if (token == TokenNameVariable) {
1055 if (token == TokenNameEQUAL) {
1059 if (token != TokenNameCOMMA) {
1068 private void unset_variables() {
1071 // | unset_variables ',' unset_variable
1076 if (token != TokenNameCOMMA) {
1082 private final void initializeModifiers() {
1084 this.modifiersSourceStart = -1;
1086 private final void checkAndSetModifiers(int flag) {
1087 this.modifiers |= flag;
1088 if (this.modifiersSourceStart < 0)
1089 this.modifiersSourceStart = this.scanner.startPosition;
1091 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1092 initializeModifiers();
1093 if (token == TokenNameinterface) {
1094 // interface_entry T_STRING
1095 // interface_extends_list
1096 // '{' class_statement_list '}'
1097 checkAndSetModifiers(AccInterface);
1099 typeDecl.modifiers = this.modifiers;
1100 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1101 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1102 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1103 typeDecl.name = scanner.getCurrentIdentifierSource();
1104 if (token > TokenNameKEYWORD) {
1105 throwSyntaxError("Don't use a keyword for interface declaration ["
1106 + scanner.toStringAction(token) + "].", typeDecl.sourceStart,
1107 typeDecl.sourceEnd);
1110 interface_extends_list();
1112 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1113 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1114 typeDecl.name = new char[]{' '};
1115 throwSyntaxError("Interface name expected after keyword 'interface'.",
1116 typeDecl.sourceStart, typeDecl.sourceEnd);
1120 // class_entry_type T_STRING extends_from
1122 // '{' class_statement_list'}'
1124 typeDecl.modifiers = this.modifiers;
1126 //identifier 'extends' identifier
1127 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1128 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1129 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1130 typeDecl.name = scanner.getCurrentIdentifierSource();
1131 if (token > TokenNameKEYWORD) {
1132 throwSyntaxError("Don't use a keyword for class declaration ["
1133 + scanner.toStringAction(token) + "].", typeDecl.sourceStart,
1134 typeDecl.sourceEnd);
1139 // | T_EXTENDS fully_qualified_class_name
1140 if (token == TokenNameextends) {
1141 interface_extends_list();
1143 // if (token != TokenNameIdentifier) {
1144 // throwSyntaxError("Class name expected after keyword 'extends'.",
1145 // scanner.getCurrentTokenStartPosition(), scanner
1146 // .getCurrentTokenEndPosition());
1151 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1152 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1153 typeDecl.name = new char[]{' '};
1154 throwSyntaxError("Class name expected after keyword 'class'.",
1155 typeDecl.sourceStart, typeDecl.sourceEnd);
1159 // '{' class_statement_list '}'
1160 if (token == TokenNameLBRACE) {
1162 if (token != TokenNameRBRACE) {
1163 class_statement_list();
1165 if (token == TokenNameRBRACE) {
1166 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1169 throwSyntaxError("'}' expected at end of class body.");
1172 throwSyntaxError("'{' expected at start of class body.");
1175 private void class_entry_type() {
1177 // | T_ABSTRACT T_CLASS
1178 // | T_FINAL T_CLASS
1179 if (token == TokenNameclass) {
1181 } else if (token == TokenNameabstract) {
1182 checkAndSetModifiers(AccAbstract);
1184 if (token != TokenNameclass) {
1185 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1188 } else if (token == TokenNamefinal) {
1189 checkAndSetModifiers(AccFinal);
1191 if (token != TokenNameclass) {
1192 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1196 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1199 private void interface_extends_list() {
1201 // | T_EXTENDS interface_list
1202 if (token == TokenNameextends) {
1207 private void implements_list() {
1209 // | T_IMPLEMENTS interface_list
1210 if (token == TokenNameimplements) {
1215 private void interface_list() {
1217 // fully_qualified_class_name
1218 //| interface_list ',' fully_qualified_class_name
1220 if (token == TokenNameIdentifier) {
1223 throwSyntaxError("Interface name expected after keyword 'implements'.");
1225 if (token != TokenNameCOMMA) {
1231 // private void classBody(TypeDeclaration typeDecl) {
1232 // //'{' [class-element-list] '}'
1233 // if (token == TokenNameLBRACE) {
1235 // if (token != TokenNameRBRACE) {
1236 // class_statement_list();
1238 // if (token == TokenNameRBRACE) {
1239 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1242 // throwSyntaxError("'}' expected at end of class body.");
1245 // throwSyntaxError("'{' expected at start of class body.");
1248 private void class_statement_list() {
1251 } while (token == TokenNamepublic || token == TokenNameprotected
1252 || token == TokenNameprivate || token == TokenNamestatic
1253 || token == TokenNameabstract || token == TokenNamefinal
1254 || token == TokenNamefunction || token == TokenNamevar
1255 || token == TokenNameconst);
1257 private void class_statement() {
1259 // variable_modifiers class_variable_declaration ';'
1260 // | class_constant_declaration ';'
1261 // | method_modifiers T_FUNCTION is_reference T_STRING
1262 // '(' parameter_list ')' method_body
1263 initializeModifiers();
1264 if (token == TokenNamevar) {
1265 checkAndSetModifiers(AccPublic);
1266 problemReporter.phpVarDeprecatedWarning(scanner
1267 .getCurrentTokenStartPosition(),
1268 scanner.getCurrentTokenEndPosition(), referenceContext,
1269 compilationUnit.compilationResult);
1271 class_variable_declaration();
1272 } else if (token == TokenNameconst) {
1273 class_constant_declaration();
1274 if (token != TokenNameSEMICOLON) {
1275 throwSyntaxError("';' expected after class const declaration.");
1279 boolean hasModifiers = member_modifiers();
1280 if (token == TokenNamefunction) {
1281 if (!hasModifiers) {
1282 checkAndSetModifiers(AccPublic);
1284 MethodDeclaration methodDecl = new MethodDeclaration(
1285 this.compilationUnit.compilationResult);
1286 methodDecl.declarationSourceStart = scanner
1287 .getCurrentTokenStartPosition();
1288 methodDecl.modifiers = this.modifiers;
1290 functionDefinition(methodDecl);
1292 if (!hasModifiers) {
1293 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1295 class_variable_declaration();
1298 // if (token == TokenNamefunction) {
1299 // MethodDeclaration methodDecl = new MethodDeclaration(
1300 // this.compilationUnit.compilationResult);
1301 // methodDecl.declarationSourceStart = scanner
1302 // .getCurrentTokenStartPosition();
1304 // functionDefinition(methodDecl);
1305 // } else if (token == TokenNamevar) {
1309 // throwSyntaxError("'function' or 'var' expected.");
1312 private void class_constant_declaration() {
1313 // class_constant_declaration ',' T_STRING '=' static_scalar
1314 // | T_CONST T_STRING '=' static_scalar
1315 if (token != TokenNameconst) {
1316 throwSyntaxError("'const' keyword expected in class declaration.");
1321 if (token != TokenNameIdentifier) {
1322 throwSyntaxError("Identifier expected in class const declaration.");
1325 if (token != TokenNameEQUAL) {
1326 throwSyntaxError("'=' expected in class const declaration.");
1330 if (token != TokenNameCOMMA) {
1331 break; // while(true)-loop
1336 // private void variable_modifiers() {
1337 // // variable_modifiers:
1338 // // non_empty_member_modifiers
1340 // initializeModifiers();
1341 // if (token == TokenNamevar) {
1342 // checkAndSetModifiers(AccPublic);
1343 // reportSyntaxError(
1344 // "Keyword 'var' is deprecated. Please use 'public' 'private' or 'protected'
1345 // modifier for field declarations.",
1346 // scanner.getCurrentTokenStartPosition(), scanner
1347 // .getCurrentTokenEndPosition());
1350 // if (!member_modifiers()) {
1351 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1352 // field declarations.");
1356 // private void method_modifiers() {
1357 // //method_modifiers:
1359 // //| non_empty_member_modifiers
1360 // initializeModifiers();
1361 // if (!member_modifiers()) {
1362 // checkAndSetModifiers(AccPublic);
1365 private boolean member_modifiers() {
1372 boolean foundToken = false;
1374 if (token == TokenNamepublic) {
1375 checkAndSetModifiers(AccPublic);
1378 } else if (token == TokenNameprotected) {
1379 checkAndSetModifiers(AccProtected);
1382 } else if (token == TokenNameprivate) {
1383 checkAndSetModifiers(AccPrivate);
1386 } else if (token == TokenNamestatic) {
1387 checkAndSetModifiers(AccStatic);
1390 } else if (token == TokenNameabstract) {
1391 checkAndSetModifiers(AccAbstract);
1394 } else if (token == TokenNamefinal) {
1395 checkAndSetModifiers(AccFinal);
1404 private void class_variable_declaration() {
1405 // class_variable_declaration:
1406 // class_variable_declaration ',' T_VARIABLE
1407 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1409 // | T_VARIABLE '=' static_scalar
1411 if (token == TokenNameVariable) {
1412 FieldDeclaration fieldDeclaration = new FieldDeclaration(null, scanner
1413 .getCurrentIdentifierSource(), scanner
1414 .getCurrentTokenStartPosition(), scanner
1415 .getCurrentTokenEndPosition());
1417 if (token == TokenNameEQUAL) {
1422 // if (token == TokenNamethis) {
1423 // throwSyntaxError("'$this' not allowed after keyword 'public'
1424 // 'protected' 'private' 'var'.");
1426 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1428 if (token != TokenNameCOMMA) {
1433 if (token != TokenNameSEMICOLON) {
1434 throwSyntaxError("';' expected after field declaration.");
1438 private void functionDefinition(MethodDeclaration methodDecl) {
1439 boolean isAbstract = false;
1441 compilationUnit.types.add(methodDecl);
1443 AstNode node = astStack[astPtr];
1444 if (node instanceof TypeDeclaration) {
1445 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1446 if (typeDecl.methods == null) {
1447 typeDecl.methods = new AbstractMethodDeclaration[]{methodDecl};
1449 AbstractMethodDeclaration[] newMethods;
1454 newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1],
1455 1, typeDecl.methods.length);
1456 newMethods[0] = methodDecl;
1457 typeDecl.methods = newMethods;
1459 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1461 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1466 functionDeclarator(methodDecl);
1467 if (token == TokenNameSEMICOLON) {
1469 throwSyntaxError("Body declaration expected for method: "
1470 + new String(methodDecl.selector));
1475 functionBody(methodDecl);
1477 private void functionDeclarator(MethodDeclaration methodDecl) {
1478 //identifier '(' [parameter-list] ')'
1479 if (token == TokenNameAND) {
1482 if (token == TokenNameIdentifier) {
1483 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1484 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1485 methodDecl.selector = scanner.getCurrentIdentifierSource();
1487 if (token == TokenNameLPAREN) {
1490 throwSyntaxError("'(' expected in function declaration.");
1492 if (token != TokenNameRPAREN) {
1495 if (token != TokenNameRPAREN) {
1496 throwSyntaxError("')' expected in function declaration.");
1498 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1502 if (token > TokenNameKEYWORD) {
1503 throwSyntaxError("Don't use keyword for function declaration [" + token
1506 throwSyntaxError("Function name expected after keyword 'function'.");
1510 private void parameter_list() {
1511 // non_empty_parameter_list
1513 non_empty_parameter_list(true);
1515 private void non_empty_parameter_list(boolean empty_allowed) {
1516 // optional_class_type T_VARIABLE
1517 // | optional_class_type '&' T_VARIABLE
1518 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1519 // | optional_class_type T_VARIABLE '=' static_scalar
1520 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1521 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1522 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1524 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1526 if (token == TokenNameIdentifier || token == TokenNameVariable
1527 || token == TokenNameAND) {
1529 if (token == TokenNameIdentifier) {
1532 if (token == TokenNameAND) {
1535 if (token == TokenNameVariable) {
1537 if (token == TokenNameEQUAL) {
1542 throwSyntaxError("Variable expected in parameter list.");
1544 if (token != TokenNameCOMMA) {
1551 if (!empty_allowed) {
1552 throwSyntaxError("Identifier expected in parameter list.");
1555 private void optional_class_type() {
1559 private void parameterDeclaration() {
1561 //variable-reference
1562 if (token == TokenNameAND) {
1567 throwSyntaxError("Variable expected after reference operator '&'.");
1570 //variable '=' constant
1571 if (token == TokenNameVariable) {
1573 if (token == TokenNameEQUAL) {
1579 // if (token == TokenNamethis) {
1580 // throwSyntaxError("Reserved word '$this' not allowed in parameter
1584 private void labeledStatementList() {
1585 if (token != TokenNamecase && token != TokenNamedefault) {
1586 throwSyntaxError("'case' or 'default' expected.");
1589 if (token == TokenNamecase) {
1591 expr(); //constant();
1592 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1594 if (token == TokenNamecase || token == TokenNamedefault) {
1595 // empty case statement ?
1600 // else if (token == TokenNameSEMICOLON) {
1602 // "':' expected after 'case' keyword (Found token: " +
1603 // scanner.toStringAction(token) + ")",
1604 // scanner.getCurrentTokenStartPosition(),
1605 // scanner.getCurrentTokenEndPosition(),
1608 // if (token == TokenNamecase) { // empty case statement ?
1614 throwSyntaxError("':' character after 'case' constant expected (Found token: "
1615 + scanner.toStringAction(token) + ")");
1617 } else { // TokenNamedefault
1619 if (token == TokenNameCOLON) {
1621 if (token==TokenNameRBRACE) {
1622 // empty default case
1627 throwSyntaxError("':' character after 'default' expected.");
1630 } while (token == TokenNamecase || token == TokenNamedefault);
1632 // public void labeledStatement() {
1633 // if (token == TokenNamecase) {
1636 // if (token == TokenNameDDOT) {
1640 // throwSyntaxError("':' character after 'case' constant expected.");
1643 // } else if (token == TokenNamedefault) {
1645 // if (token == TokenNameDDOT) {
1649 // throwSyntaxError("':' character after 'default' expected.");
1654 // public void expressionStatement() {
1656 // private void inclusionStatement() {
1658 // public void compoundStatement() {
1660 // public void selectionStatement() {
1663 // public void iterationStatement() {
1666 // public void jumpStatement() {
1669 // public void outputStatement() {
1672 // public void scopeStatement() {
1675 // public void flowStatement() {
1678 // public void definitionStatement() {
1680 private void ifStatement() {
1681 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
1682 if (token == TokenNameCOLON) {
1684 if (token != TokenNameendif) {
1687 case TokenNameelse :
1689 if (token == TokenNameCOLON) {
1691 if (token != TokenNameendif) {
1695 if (token == TokenNameif) { //'else if'
1697 elseifStatementList();
1699 throwSyntaxError("':' expected after 'else'.");
1703 case TokenNameelseif :
1705 elseifStatementList();
1709 if (token != TokenNameendif) {
1710 throwSyntaxError("'endif' expected.");
1713 if (token != TokenNameSEMICOLON) {
1714 throwSyntaxError("';' expected after if-statement.");
1718 // statement [else-statement]
1719 statement(TokenNameEOF);
1720 if (token == TokenNameelseif) {
1722 if (token == TokenNameLPAREN) {
1725 throwSyntaxError("'(' expected after 'elseif' keyword.");
1728 if (token == TokenNameRPAREN) {
1731 throwSyntaxError("')' expected after 'elseif' condition.");
1734 } else if (token == TokenNameelse) {
1736 statement(TokenNameEOF);
1740 private void elseifStatementList() {
1744 case TokenNameelse :
1746 if (token == TokenNameCOLON) {
1748 if (token != TokenNameendif) {
1753 if (token == TokenNameif) { //'else if'
1756 throwSyntaxError("':' expected after 'else'.");
1760 case TokenNameelseif :
1768 private void elseifStatement() {
1769 if (token == TokenNameLPAREN) {
1772 if (token != TokenNameRPAREN) {
1773 throwSyntaxError("')' expected in else-if-statement.");
1776 if (token != TokenNameCOLON) {
1777 throwSyntaxError("':' expected in else-if-statement.");
1780 if (token != TokenNameendif) {
1785 private void switchStatement() {
1786 if (token == TokenNameCOLON) {
1787 // ':' [labeled-statement-list] 'endswitch' ';'
1789 labeledStatementList();
1790 if (token != TokenNameendswitch) {
1791 throwSyntaxError("'endswitch' expected.");
1794 if (token != TokenNameSEMICOLON) {
1795 throwSyntaxError("';' expected after switch-statement.");
1799 // '{' [labeled-statement-list] '}'
1800 if (token != TokenNameLBRACE) {
1801 throwSyntaxError("'{' expected in switch statement.");
1804 if (token != TokenNameRBRACE) {
1805 labeledStatementList();
1807 if (token != TokenNameRBRACE) {
1808 throwSyntaxError("'}' expected in switch statement.");
1813 private void forStatement() {
1814 if (token == TokenNameCOLON) {
1817 if (token != TokenNameendfor) {
1818 throwSyntaxError("'endfor' expected.");
1821 if (token != TokenNameSEMICOLON) {
1822 throwSyntaxError("';' expected after for-statement.");
1826 statement(TokenNameEOF);
1829 private void whileStatement() {
1830 // ':' statement-list 'endwhile' ';'
1831 if (token == TokenNameCOLON) {
1834 if (token != TokenNameendwhile) {
1835 throwSyntaxError("'endwhile' expected.");
1838 if (token != TokenNameSEMICOLON) {
1839 throwSyntaxError("';' expected after while-statement.");
1843 statement(TokenNameEOF);
1846 private void foreachStatement() {
1847 if (token == TokenNameCOLON) {
1850 if (token != TokenNameendforeach) {
1851 throwSyntaxError("'endforeach' expected.");
1854 if (token != TokenNameSEMICOLON) {
1855 throwSyntaxError("';' expected after foreach-statement.");
1859 statement(TokenNameEOF);
1862 // private void exitStatus() {
1863 // if (token == TokenNameLPAREN) {
1866 // throwSyntaxError("'(' expected in 'exit-status'.");
1868 // if (token != TokenNameRPAREN) {
1871 // if (token == TokenNameRPAREN) {
1874 // throwSyntaxError("')' expected after 'exit-status'.");
1877 private void expressionList() {
1880 if (token == TokenNameCOMMA) {
1887 private void expr() {
1889 // | expr_without_variable
1890 // if (token!=TokenNameEOF) {
1891 if (Scanner.TRACE) {
1892 System.out.println("TRACE: expr()");
1894 expr_without_variable(true);
1897 private void expr_without_variable(boolean only_variable) {
1898 // internal_functions_in_yacc
1907 // | T_INC rw_variable
1908 // | T_DEC rw_variable
1909 // | T_INT_CAST expr
1910 // | T_DOUBLE_CAST expr
1911 // | T_STRING_CAST expr
1912 // | T_ARRAY_CAST expr
1913 // | T_OBJECT_CAST expr
1914 // | T_BOOL_CAST expr
1915 // | T_UNSET_CAST expr
1916 // | T_EXIT exit_expr
1918 // | T_ARRAY '(' array_pair_list ')'
1919 // | '`' encaps_list '`'
1920 // | T_LIST '(' assignment_list ')' '=' expr
1921 // | T_NEW class_name_reference ctor_arguments
1922 // | variable '=' expr
1923 // | variable '=' '&' variable
1924 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
1925 // | variable T_PLUS_EQUAL expr
1926 // | variable T_MINUS_EQUAL expr
1927 // | variable T_MUL_EQUAL expr
1928 // | variable T_DIV_EQUAL expr
1929 // | variable T_CONCAT_EQUAL expr
1930 // | variable T_MOD_EQUAL expr
1931 // | variable T_AND_EQUAL expr
1932 // | variable T_OR_EQUAL expr
1933 // | variable T_XOR_EQUAL expr
1934 // | variable T_SL_EQUAL expr
1935 // | variable T_SR_EQUAL expr
1936 // | rw_variable T_INC
1937 // | rw_variable T_DEC
1938 // | expr T_BOOLEAN_OR expr
1939 // | expr T_BOOLEAN_AND expr
1940 // | expr T_LOGICAL_OR expr
1941 // | expr T_LOGICAL_AND expr
1942 // | expr T_LOGICAL_XOR expr
1954 // | expr T_IS_IDENTICAL expr
1955 // | expr T_IS_NOT_IDENTICAL expr
1956 // | expr T_IS_EQUAL expr
1957 // | expr T_IS_NOT_EQUAL expr
1959 // | expr T_IS_SMALLER_OR_EQUAL expr
1961 // | expr T_IS_GREATER_OR_EQUAL expr
1962 // | expr T_INSTANCEOF class_name_reference
1963 // | expr '?' expr ':' expr
1964 if (Scanner.TRACE) {
1965 System.out.println("TRACE: expr_without_variable() PART 1");
1968 case TokenNameisset :
1969 case TokenNameempty :
1970 case TokenNameeval :
1971 case TokenNameinclude :
1972 case TokenNameinclude_once :
1973 case TokenNamerequire :
1974 case TokenNamerequire_once :
1975 internal_functions_in_yacc();
1978 case TokenNameLPAREN :
1981 if (token == TokenNameRPAREN) {
1984 throwSyntaxError("')' expected in expression.");
1994 // | T_INT_CAST expr
1995 // | T_DOUBLE_CAST expr
1996 // | T_STRING_CAST expr
1997 // | T_ARRAY_CAST expr
1998 // | T_OBJECT_CAST expr
1999 // | T_BOOL_CAST expr
2000 // | T_UNSET_CAST expr
2001 case TokenNameclone :
2002 case TokenNameprint :
2004 case TokenNamePLUS :
2005 case TokenNameMINUS :
2007 case TokenNameTWIDDLE :
2008 case TokenNameintCAST :
2009 case TokenNamedoubleCAST :
2010 case TokenNamestringCAST :
2011 case TokenNamearrayCAST :
2012 case TokenNameobjectCAST :
2013 case TokenNameboolCAST :
2014 case TokenNameunsetCAST :
2018 case TokenNameexit :
2024 //| T_STRING_VARNAME
2026 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2027 // | '`' encaps_list '`'
2029 // | '`' encaps_list '`'
2030 case TokenNameEncapsedString0 :
2031 scanner.encapsedStringStack.push(new Character('`'));
2034 if (token == TokenNameEncapsedString0) {
2037 if (token != TokenNameEncapsedString0) {
2038 throwSyntaxError("\'`\' expected at end of string"
2039 + "(Found token: " + scanner.toStringAction(token) + " )");
2043 scanner.encapsedStringStack.pop();
2047 // | '\'' encaps_list '\''
2048 case TokenNameEncapsedString1 :
2049 scanner.encapsedStringStack.push(new Character('\''));
2052 if (token == TokenNameEncapsedString1) {
2055 if (token != TokenNameEncapsedString1) {
2056 throwSyntaxError("\'\'\' expected at end of string"
2057 + "(Found token: " + scanner.toStringAction(token) + " )");
2061 scanner.encapsedStringStack.pop();
2065 //| '"' encaps_list '"'
2066 case TokenNameEncapsedString2 :
2067 scanner.encapsedStringStack.push(new Character('"'));
2070 if (token == TokenNameEncapsedString2) {
2073 if (token != TokenNameEncapsedString2) {
2074 throwSyntaxError("'\"' expected at end of string"
2075 + "(Found token: " + scanner.toStringAction(token) + " )");
2079 scanner.encapsedStringStack.pop();
2083 case TokenNameIntegerLiteral :
2084 case TokenNameDoubleLiteral :
2085 case TokenNameStringLiteral :
2086 case TokenNameStringConstant :
2087 case TokenNameStringInterpolated :
2088 case TokenNameFILE :
2089 case TokenNameLINE :
2090 case TokenNameCLASS_C :
2091 case TokenNameMETHOD_C :
2092 case TokenNameFUNC_C :
2095 case TokenNameHEREDOC :
2098 case TokenNamearray :
2099 // T_ARRAY '(' array_pair_list ')'
2101 if (token == TokenNameLPAREN) {
2103 if (token == TokenNameRPAREN) {
2108 if (token != TokenNameRPAREN) {
2109 throwSyntaxError("')' expected after keyword 'array'"
2110 + "(Found token: " + scanner.toStringAction(token) + ")");
2114 throwSyntaxError("'(' expected after keyword 'array'"
2115 + "(Found token: " + scanner.toStringAction(token) + ")");
2118 case TokenNamelist :
2119 // | T_LIST '(' assignment_list ')' '=' expr
2121 if (token == TokenNameLPAREN) {
2124 if (token != TokenNameRPAREN) {
2125 throwSyntaxError("')' expected after 'list' keyword.");
2128 if (token != TokenNameEQUAL) {
2129 throwSyntaxError("'=' expected after 'list' keyword.");
2134 throwSyntaxError("'(' expected after 'list' keyword.");
2138 // | T_NEW class_name_reference ctor_arguments
2140 class_name_reference();
2143 // | T_INC rw_variable
2144 // | T_DEC rw_variable
2145 case TokenNamePLUS_PLUS :
2146 case TokenNameMINUS_MINUS :
2150 // | variable '=' expr
2151 // | variable '=' '&' variable
2152 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2153 // | variable T_PLUS_EQUAL expr
2154 // | variable T_MINUS_EQUAL expr
2155 // | variable T_MUL_EQUAL expr
2156 // | variable T_DIV_EQUAL expr
2157 // | variable T_CONCAT_EQUAL expr
2158 // | variable T_MOD_EQUAL expr
2159 // | variable T_AND_EQUAL expr
2160 // | variable T_OR_EQUAL expr
2161 // | variable T_XOR_EQUAL expr
2162 // | variable T_SL_EQUAL expr
2163 // | variable T_SR_EQUAL expr
2164 // | rw_variable T_INC
2165 // | rw_variable T_DEC
2166 case TokenNameIdentifier :
2167 case TokenNameVariable :
2168 case TokenNameDOLLAR :
2171 case TokenNameEQUAL :
2173 if (token == TokenNameAND) {
2175 if (token == TokenNamenew) {
2176 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2178 class_name_reference();
2187 case TokenNamePLUS_EQUAL :
2188 case TokenNameMINUS_EQUAL :
2189 case TokenNameMULTIPLY_EQUAL :
2190 case TokenNameDIVIDE_EQUAL :
2191 case TokenNameDOT_EQUAL :
2192 case TokenNameREMAINDER_EQUAL :
2193 case TokenNameAND_EQUAL :
2194 case TokenNameOR_EQUAL :
2195 case TokenNameXOR_EQUAL :
2196 case TokenNameRIGHT_SHIFT_EQUAL :
2197 case TokenNameLEFT_SHIFT_EQUAL :
2201 case TokenNamePLUS_PLUS :
2202 case TokenNameMINUS_MINUS :
2206 if (!only_variable) {
2207 throwSyntaxError("Variable expression not allowed (found token '"
2208 + scanner.toStringAction(token) + "').");
2213 if (token != TokenNameINLINE_HTML) {
2214 throwSyntaxError("Error in expression (found token '"
2215 + scanner.toStringAction(token) + "').");
2219 if (Scanner.TRACE) {
2220 System.out.println("TRACE: expr_without_variable() PART 2");
2222 // | expr T_BOOLEAN_OR expr
2223 // | expr T_BOOLEAN_AND expr
2224 // | expr T_LOGICAL_OR expr
2225 // | expr T_LOGICAL_AND expr
2226 // | expr T_LOGICAL_XOR expr
2238 // | expr T_IS_IDENTICAL expr
2239 // | expr T_IS_NOT_IDENTICAL expr
2240 // | expr T_IS_EQUAL expr
2241 // | expr T_IS_NOT_EQUAL expr
2243 // | expr T_IS_SMALLER_OR_EQUAL expr
2245 // | expr T_IS_GREATER_OR_EQUAL expr
2248 case TokenNameOR_OR :
2249 case TokenNameAND_AND :
2257 case TokenNamePLUS :
2258 case TokenNameMINUS :
2259 case TokenNameMULTIPLY :
2260 case TokenNameDIVIDE :
2261 case TokenNameREMAINDER :
2262 case TokenNameLEFT_SHIFT :
2263 case TokenNameRIGHT_SHIFT :
2264 case TokenNameEQUAL_EQUAL_EQUAL :
2265 case TokenNameNOT_EQUAL_EQUAL :
2266 case TokenNameEQUAL_EQUAL :
2267 case TokenNameNOT_EQUAL :
2268 case TokenNameLESS :
2269 case TokenNameLESS_EQUAL :
2270 case TokenNameGREATER :
2271 case TokenNameGREATER_EQUAL :
2275 // | expr T_INSTANCEOF class_name_reference
2276 // | expr '?' expr ':' expr
2277 case TokenNameinstanceof :
2279 class_name_reference();
2281 case TokenNameQUESTION :
2284 if (token == TokenNameCOLON) {
2294 private void class_name_reference() {
2295 // class_name_reference:
2297 //| dynamic_class_name_reference
2298 if (Scanner.TRACE) {
2299 System.out.println("TRACE: class_name_reference()");
2301 if (token == TokenNameIdentifier) {
2304 dynamic_class_name_reference();
2307 private void dynamic_class_name_reference() {
2308 //dynamic_class_name_reference:
2309 // base_variable T_OBJECT_OPERATOR object_property
2310 // dynamic_class_name_variable_properties
2312 if (Scanner.TRACE) {
2313 System.out.println("TRACE: dynamic_class_name_reference()");
2316 if (token == TokenNameMINUS_GREATER) {
2319 dynamic_class_name_variable_properties();
2322 private void dynamic_class_name_variable_properties() {
2323 // dynamic_class_name_variable_properties:
2324 // dynamic_class_name_variable_properties
2325 // dynamic_class_name_variable_property
2327 if (Scanner.TRACE) {
2328 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2330 while (token == TokenNameMINUS_GREATER) {
2331 dynamic_class_name_variable_property();
2334 private void dynamic_class_name_variable_property() {
2335 // dynamic_class_name_variable_property:
2336 // T_OBJECT_OPERATOR object_property
2337 if (Scanner.TRACE) {
2338 System.out.println("TRACE: dynamic_class_name_variable_property()");
2340 if (token == TokenNameMINUS_GREATER) {
2345 private void ctor_arguments() {
2348 //| '(' function_call_parameter_list ')'
2349 if (token == TokenNameLPAREN) {
2351 if (token == TokenNameRPAREN) {
2355 non_empty_function_call_parameter_list();
2356 if (token != TokenNameRPAREN) {
2357 throwSyntaxError("')' expected in ctor_arguments.");
2362 private void assignment_list() {
2364 // assignment_list ',' assignment_list_element
2365 //| assignment_list_element
2367 assignment_list_element();
2368 if (token != TokenNameCOMMA) {
2374 private void assignment_list_element() {
2375 //assignment_list_element:
2377 //| T_LIST '(' assignment_list ')'
2379 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2382 if (token == TokenNamelist) {
2384 if (token == TokenNameLPAREN) {
2387 if (token != TokenNameRPAREN) {
2388 throwSyntaxError("')' expected after 'list' keyword.");
2392 throwSyntaxError("'(' expected after 'list' keyword.");
2397 private void array_pair_list() {
2400 //| non_empty_array_pair_list possible_comma
2401 non_empty_array_pair_list();
2402 if (token == TokenNameCOMMA) {
2406 private void non_empty_array_pair_list() {
2407 //non_empty_array_pair_list:
2408 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2409 //| non_empty_array_pair_list ',' expr
2410 //| expr T_DOUBLE_ARROW expr
2412 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2413 //| non_empty_array_pair_list ',' '&' w_variable
2414 //| expr T_DOUBLE_ARROW '&' w_variable
2417 if (token == TokenNameAND) {
2422 if (token == TokenNameAND) {
2425 } else if (token == TokenNameEQUAL_GREATER) {
2427 if (token == TokenNameAND) {
2435 if (token != TokenNameCOMMA) {
2439 if (token == TokenNameRPAREN) {
2444 // private void variableList() {
2447 // if (token == TokenNameCOMMA) {
2454 private void variable_without_objects() {
2455 // variable_without_objects:
2456 // reference_variable
2457 // | simple_indirect_reference reference_variable
2458 if (Scanner.TRACE) {
2459 System.out.println("TRACE: variable_without_objects()");
2461 while (token == TokenNameDOLLAR) {
2464 reference_variable();
2466 private void function_call() {
2468 // T_STRING '(' function_call_parameter_list ')'
2469 //| class_constant '(' function_call_parameter_list ')'
2470 //| static_member '(' function_call_parameter_list ')'
2471 //| variable_without_objects '(' function_call_parameter_list ')'
2472 if (Scanner.TRACE) {
2473 System.out.println("TRACE: function_call()");
2475 if (token == TokenNameIdentifier) {
2478 case TokenNamePAAMAYIM_NEKUDOTAYIM :
2481 if (token == TokenNameIdentifier) {
2486 variable_without_objects();
2491 variable_without_objects();
2493 if (token != TokenNameLPAREN) {
2494 // TODO is this ok ?
2496 // throwSyntaxError("'(' expected in function call.");
2499 if (token == TokenNameRPAREN) {
2503 non_empty_function_call_parameter_list();
2504 if (token != TokenNameRPAREN) {
2505 throwSyntaxError("')' expected in function call.");
2509 // private void function_call_parameter_list() {
2510 // function_call_parameter_list:
2511 // non_empty_function_call_parameter_list { $$ = $1; }
2514 private void non_empty_function_call_parameter_list() {
2515 //non_empty_function_call_parameter_list:
2516 // expr_without_variable
2519 // | non_empty_function_call_parameter_list ',' expr_without_variable
2520 // | non_empty_function_call_parameter_list ',' variable
2521 // | non_empty_function_call_parameter_list ',' '&' w_variable
2522 if (Scanner.TRACE) {
2523 System.out.println("TRACE: non_empty_function_call_parameter_list()");
2526 if (token == TokenNameAND) {
2530 // if (token == TokenNameIdentifier || token == TokenNameVariable
2531 // || token == TokenNameDOLLAR) {
2534 expr_without_variable(true);
2537 if (token != TokenNameCOMMA) {
2543 private void fully_qualified_class_name() {
2544 if (token == TokenNameIdentifier) {
2547 throwSyntaxError("Class name expected.");
2550 private void static_member() {
2552 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2553 // variable_without_objects
2554 if (Scanner.TRACE) {
2555 System.out.println("TRACE: static_member()");
2557 fully_qualified_class_name();
2558 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2559 throwSyntaxError("'::' expected after class name (static_member).");
2562 variable_without_objects();
2564 private void base_variable_with_function_calls() {
2565 // base_variable_with_function_calls:
2568 boolean functionCall = false;
2569 if (Scanner.TRACE) {
2570 System.out.println("TRACE: base_variable_with_function_calls()");
2572 // if (token == TokenNameIdentifier) {
2573 // functionCall = true;
2574 // } else if (token == TokenNameVariable) {
2575 // int tempToken = token;
2576 // int tempPosition = scanner.currentPosition;
2578 // if (token == TokenNameLPAREN) {
2579 // functionCall = true;
2581 // token = tempToken;
2582 // scanner.currentPosition = tempPosition;
2583 // scanner.phpMode = true;
2585 // if (functionCall) {
2591 private void base_variable() {
2593 // reference_variable
2594 // | simple_indirect_reference reference_variable
2596 if (Scanner.TRACE) {
2597 System.out.println("TRACE: base_variable()");
2599 if (token == TokenNameIdentifier) {
2602 while (token == TokenNameDOLLAR) {
2605 reference_variable();
2608 // private void simple_indirect_reference() {
2609 // // simple_indirect_reference:
2611 // //| simple_indirect_reference '$'
2613 private void reference_variable() {
2614 // reference_variable:
2615 // reference_variable '[' dim_offset ']'
2616 // | reference_variable '{' expr '}'
2617 // | compound_variable
2618 if (Scanner.TRACE) {
2619 System.out.println("TRACE: reference_variable()");
2621 compound_variable();
2623 if (token == TokenNameLBRACE) {
2626 if (token != TokenNameRBRACE) {
2627 throwSyntaxError("'}' expected in reference variable.");
2630 } else if (token == TokenNameLBRACKET) {
2632 if (token != TokenNameRBRACKET) {
2635 if (token != TokenNameRBRACKET) {
2636 throwSyntaxError("']' expected in reference variable.");
2645 private void compound_variable() {
2646 // compound_variable:
2648 // | '$' '{' expr '}'
2649 if (Scanner.TRACE) {
2650 System.out.println("TRACE: compound_variable()");
2652 if (token == TokenNameVariable) {
2655 // because of simple_indirect_reference
2656 while (token == TokenNameDOLLAR) {
2659 if (token != TokenNameLBRACE) {
2660 throwSyntaxError("'{' expected after compound variable token '$'.");
2664 if (token != TokenNameRBRACE) {
2665 throwSyntaxError("'}' expected after compound variable token '$'.");
2670 // private void dim_offset() {
2676 private void object_property() {
2679 //| variable_without_objects
2680 if (Scanner.TRACE) {
2681 System.out.println("TRACE: object_property()");
2683 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2684 variable_without_objects();
2689 private void object_dim_list() {
2691 // object_dim_list '[' dim_offset ']'
2692 //| object_dim_list '{' expr '}'
2694 if (Scanner.TRACE) {
2695 System.out.println("TRACE: object_dim_list()");
2699 if (token == TokenNameLBRACE) {
2702 if (token != TokenNameRBRACE) {
2703 throwSyntaxError("'}' expected in object_dim_list.");
2706 } else if (token == TokenNameLBRACKET) {
2708 if (token == TokenNameRBRACKET) {
2713 if (token != TokenNameRBRACKET) {
2714 throwSyntaxError("']' expected in object_dim_list.");
2722 private void variable_name() {
2726 if (Scanner.TRACE) {
2727 System.out.println("TRACE: variable_name()");
2729 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
2730 if (token > TokenNameKEYWORD) {
2731 // TODO show a warning "Keyword used as variable" ?
2735 if (token != TokenNameLBRACE) {
2736 throwSyntaxError("'{' expected in variable name.");
2740 if (token != TokenNameRBRACE) {
2741 throwSyntaxError("'}' expected in variable name.");
2746 private void r_variable() {
2749 private void w_variable() {
2752 private void rw_variable() {
2755 private void variable() {
2757 // base_variable_with_function_calls T_OBJECT_OPERATOR
2758 // object_property method_or_not variable_properties
2759 // | base_variable_with_function_calls
2760 base_variable_with_function_calls();
2761 if (token == TokenNameMINUS_GREATER) {
2765 variable_properties();
2767 // if (token == TokenNameDOLLAR_LBRACE) {
2771 // if (token != TokenNameRBRACE) {
2772 // throwSyntaxError("'}' expected after indirect variable token '${'.");
2776 // if (token == TokenNameVariable) {
2778 // if (token == TokenNameLBRACKET) {
2781 // if (token != TokenNameRBRACKET) {
2782 // throwSyntaxError("']' expected in variable-list.");
2785 // } else if (token == TokenNameEQUAL) {
2790 // throwSyntaxError("$-variable expected in variable-list.");
2794 private void variable_properties() {
2795 // variable_properties:
2796 // variable_properties variable_property
2798 while (token == TokenNameMINUS_GREATER) {
2799 variable_property();
2802 private void variable_property() {
2803 // variable_property:
2804 // T_OBJECT_OPERATOR object_property method_or_not
2805 if (Scanner.TRACE) {
2806 System.out.println("TRACE: variable_property()");
2808 if (token == TokenNameMINUS_GREATER) {
2813 throwSyntaxError("'->' expected in variable_property.");
2816 private void method_or_not() {
2818 // '(' function_call_parameter_list ')'
2820 if (Scanner.TRACE) {
2821 System.out.println("TRACE: method_or_not()");
2823 if (token == TokenNameLPAREN) {
2825 if (token == TokenNameRPAREN) {
2829 non_empty_function_call_parameter_list();
2830 if (token != TokenNameRPAREN) {
2831 throwSyntaxError("')' expected in method_or_not.");
2836 private void exit_expr() {
2840 if (token != TokenNameLPAREN) {
2844 if (token == TokenNameRPAREN) {
2849 if (token != TokenNameRPAREN) {
2850 throwSyntaxError("')' expected after keyword 'exit'");
2854 private void encaps_list() {
2855 // encaps_list encaps_var
2856 // | encaps_list T_STRING
2857 // | encaps_list T_NUM_STRING
2858 // | encaps_list T_ENCAPSED_AND_WHITESPACE
2859 // | encaps_list T_CHARACTER
2860 // | encaps_list T_BAD_CHARACTER
2861 // | encaps_list '['
2862 // | encaps_list ']'
2863 // | encaps_list '{'
2864 // | encaps_list '}'
2865 // | encaps_list T_OBJECT_OPERATOR
2869 case TokenNameSTRING :
2872 case TokenNameLBRACE :
2873 // scanner.encapsedStringStack.pop();
2876 case TokenNameRBRACE :
2877 // scanner.encapsedStringStack.pop();
2880 case TokenNameLBRACKET :
2881 // scanner.encapsedStringStack.pop();
2884 case TokenNameRBRACKET :
2885 // scanner.encapsedStringStack.pop();
2888 case TokenNameMINUS_GREATER :
2889 // scanner.encapsedStringStack.pop();
2892 case TokenNameVariable :
2893 case TokenNameDOLLAR_LBRACE :
2894 case TokenNameCURLY_OPEN :
2897 // case TokenNameDOLLAR :
2899 // if (token == TokenNameLBRACE) {
2900 // token = TokenNameDOLLAR_LBRACE;
2905 char encapsedChar = ((Character) scanner.encapsedStringStack.peek())
2907 if (encapsedChar == '$') {
2908 scanner.encapsedStringStack.pop();
2909 encapsedChar = ((Character) scanner.encapsedStringStack.peek())
2911 switch (encapsedChar) {
2913 if (token == TokenNameEncapsedString0) {
2916 token = TokenNameSTRING;
2919 if (token == TokenNameEncapsedString1) {
2922 token = TokenNameSTRING;
2925 if (token == TokenNameEncapsedString2) {
2928 token = TokenNameSTRING;
2936 private void encaps_var() {
2938 // | T_VARIABLE '[' encaps_var_offset ']'
2939 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
2940 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
2941 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
2942 // | T_CURLY_OPEN variable '}'
2944 case TokenNameVariable :
2946 if (token == TokenNameLBRACKET) {
2948 // if (token == TokenNameRBRACKET) {
2951 expr(); //encaps_var_offset();
2952 if (token != TokenNameRBRACKET) {
2953 throwSyntaxError("']' expected after variable.");
2955 // scanner.encapsedStringStack.pop();
2958 } else if (token == TokenNameMINUS_GREATER) {
2960 if (token != TokenNameIdentifier) {
2961 throwSyntaxError("Identifier expected after '->'.");
2963 // scanner.encapsedStringStack.pop();
2967 // // scanner.encapsedStringStack.pop();
2968 // int tempToken = TokenNameSTRING;
2969 // if (!scanner.encapsedStringStack.isEmpty()
2970 // && (token == TokenNameEncapsedString0
2971 // || token == TokenNameEncapsedString1
2972 // || token == TokenNameEncapsedString2 || token == TokenNameERROR)) {
2973 // char encapsedChar = ((Character) scanner.encapsedStringStack.peek())
2976 // case TokenNameEncapsedString0 :
2977 // if (encapsedChar == '`') {
2978 // tempToken = TokenNameEncapsedString0;
2981 // case TokenNameEncapsedString1 :
2982 // if (encapsedChar == '\'') {
2983 // tempToken = TokenNameEncapsedString1;
2986 // case TokenNameEncapsedString2 :
2987 // if (encapsedChar == '"') {
2988 // tempToken = TokenNameEncapsedString2;
2991 // case TokenNameERROR :
2992 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
2993 // scanner.currentPosition--;
2999 // token = tempToken;
3002 case TokenNameDOLLAR_LBRACE :
3004 if (token == TokenNameIdentifier) {
3006 if (token == TokenNameLBRACKET) {
3008 // if (token == TokenNameRBRACKET) {
3012 if (token != TokenNameRBRACKET) {
3013 throwSyntaxError("']' expected after '${'.");
3018 if (token != TokenNameRBRACE) {
3019 throwSyntaxError("'}' expected after '${'.");
3021 // scanner.encapsedStringStack.pop();
3025 if (token != TokenNameRBRACE) {
3026 throwSyntaxError("'}' expected.");
3028 // scanner.encapsedStringStack.pop();
3032 case TokenNameCURLY_OPEN :
3034 if (token == TokenNameIdentifier) {
3036 if (token == TokenNameLBRACKET) {
3038 // if (token == TokenNameRBRACKET) {
3042 if (token != TokenNameRBRACKET) {
3043 throwSyntaxError("']' expected after '{$'.");
3047 } else if (token == TokenNameMINUS_GREATER) {
3049 if (token != TokenNameIdentifier) {
3050 throwSyntaxError("String token expected.");
3054 // if (token != TokenNameRBRACE) {
3055 // throwSyntaxError("'}' expected after '{$'.");
3057 // // scanner.encapsedStringStack.pop();
3061 if (token != TokenNameRBRACE) {
3062 throwSyntaxError("'}' expected.");
3064 // scanner.encapsedStringStack.pop();
3070 private void encaps_var_offset() {
3075 case TokenNameSTRING :
3078 case TokenNameIntegerLiteral :
3081 case TokenNameVariable :
3084 case TokenNameIdentifier :
3088 throwSyntaxError("Variable or String token expected.");
3092 private void internal_functions_in_yacc() {
3094 case TokenNameisset :
3095 // T_ISSET '(' isset_variables ')'
3097 if (token != TokenNameLPAREN) {
3098 throwSyntaxError("'(' expected after keyword 'isset'");
3102 if (token != TokenNameRPAREN) {
3103 throwSyntaxError("')' expected after keyword 'isset'");
3107 case TokenNameempty :
3108 // T_EMPTY '(' variable ')'
3110 if (token != TokenNameLPAREN) {
3111 throwSyntaxError("'(' expected after keyword 'empty'");
3115 if (token != TokenNameRPAREN) {
3116 throwSyntaxError("')' expected after keyword 'empty'");
3120 case TokenNameinclude :
3125 case TokenNameinclude_once :
3126 // T_INCLUDE_ONCE expr
3130 case TokenNameeval :
3131 // T_EVAL '(' expr ')'
3133 if (token != TokenNameLPAREN) {
3134 throwSyntaxError("'(' expected after keyword 'eval'");
3138 if (token != TokenNameRPAREN) {
3139 throwSyntaxError("')' expected after keyword 'eval'");
3143 case TokenNamerequire :
3148 case TokenNamerequire_once :
3149 // T_REQUIRE_ONCE expr
3155 private void isset_variables() {
3157 // | isset_variables ','
3158 if (token == TokenNameRPAREN) {
3159 throwSyntaxError("Variable expected after keyword 'isset'");
3163 if (token == TokenNameCOMMA) {
3170 private boolean common_scalar() {
3174 // | T_CONSTANT_ENCAPSED_STRING
3181 case TokenNameIntegerLiteral :
3184 case TokenNameDoubleLiteral :
3187 case TokenNameStringLiteral :
3190 case TokenNameStringConstant :
3193 case TokenNameStringInterpolated :
3196 case TokenNameFILE :
3199 case TokenNameLINE :
3202 case TokenNameCLASS_C :
3205 case TokenNameMETHOD_C :
3208 case TokenNameFUNC_C :
3214 private void scalar() {
3217 //| T_STRING_VARNAME
3220 //| '"' encaps_list '"'
3221 //| '\'' encaps_list '\''
3222 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3223 throwSyntaxError("Not yet implemented (scalar).");
3225 private void static_scalar() {
3226 // static_scalar: /* compile-time evaluated scalars */
3229 // | '+' static_scalar
3230 // | '-' static_scalar
3231 // | T_ARRAY '(' static_array_pair_list ')'
3232 // | static_class_constant
3233 if (common_scalar()) {
3237 case TokenNameIdentifier :
3239 // static_class_constant:
3240 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3241 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3243 if (token == TokenNameIdentifier) {
3246 throwSyntaxError("Identifier expected after '::' operator.");
3250 case TokenNameEncapsedString0 :
3252 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3253 while (scanner.currentCharacter != '`') {
3254 if (scanner.currentCharacter == '\\') {
3255 scanner.currentPosition++;
3257 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3260 } catch (IndexOutOfBoundsException e) {
3261 throwSyntaxError("'`' expected at end of static string.");
3264 case TokenNameEncapsedString1 :
3266 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3267 while (scanner.currentCharacter != '\'') {
3268 if (scanner.currentCharacter == '\\') {
3269 scanner.currentPosition++;
3271 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3274 } catch (IndexOutOfBoundsException e) {
3275 throwSyntaxError("'\'' expected at end of static string.");
3278 case TokenNameEncapsedString2 :
3280 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3281 while (scanner.currentCharacter != '"') {
3282 if (scanner.currentCharacter == '\\') {
3283 scanner.currentPosition++;
3285 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3288 } catch (IndexOutOfBoundsException e) {
3289 throwSyntaxError("'\"' expected at end of static string.");
3292 case TokenNamePLUS :
3296 case TokenNameMINUS :
3300 case TokenNamearray :
3302 if (token != TokenNameLPAREN) {
3303 throwSyntaxError("'(' expected after keyword 'array'");
3306 if (token == TokenNameRPAREN) {
3310 non_empty_static_array_pair_list();
3311 if (token != TokenNameRPAREN) {
3312 throwSyntaxError("')' expected after keyword 'array'");
3316 // case TokenNamenull :
3319 // case TokenNamefalse :
3322 // case TokenNametrue :
3326 throwSyntaxError("Static scalar/constant expected.");
3329 private void non_empty_static_array_pair_list() {
3330 // non_empty_static_array_pair_list:
3331 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3333 //| non_empty_static_array_pair_list ',' static_scalar
3334 //| static_scalar T_DOUBLE_ARROW static_scalar
3338 if (token == TokenNameEQUAL_GREATER) {
3342 if (token != TokenNameCOMMA) {
3346 if (token == TokenNameRPAREN) {
3351 public void reportSyntaxError() { //int act, int currentKind, int
3353 /* remember current scanner position */
3354 int startPos = scanner.startPosition;
3355 int currentPos = scanner.currentPosition;
3356 // String[] expectings;
3357 // String tokenName = name[symbol_index[currentKind]];
3358 //fetch all "accurate" possible terminals that could recover the error
3359 // int start, end = start = asi(stack[stateStackTop]);
3360 // while (asr[end] != 0)
3362 // int length = end - start;
3363 // expectings = new String[length];
3364 // if (length != 0) {
3365 // char[] indexes = new char[length];
3366 // System.arraycopy(asr, start, indexes, 0, length);
3367 // for (int i = 0; i < length; i++) {
3368 // expectings[i] = name[symbol_index[indexes[i]]];
3371 //if the pb is an EOF, try to tell the user that they are some
3372 // if (tokenName.equals(UNEXPECTED_EOF)) {
3373 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3374 // char[] tokenSource;
3376 // tokenSource = this.scanner.getCurrentTokenSource();
3377 // } catch (Exception e) {
3378 // tokenSource = new char[] {};
3380 // problemReporter().parseError(
3381 // this.scanner.startPosition,
3382 // this.scanner.currentPosition - 1,
3387 // } else { //the next test is HEAVILY grammar DEPENDENT.
3388 // if ((length == 14)
3389 // && (expectings[0] == "=") //$NON-NLS-1$
3390 // && (expectings[1] == "*=") //$NON-NLS-1$
3391 // && (expressionPtr > -1)) {
3392 // switch(currentKind) {
3393 // case TokenNameSEMICOLON:
3394 // case TokenNamePLUS:
3395 // case TokenNameMINUS:
3396 // case TokenNameDIVIDE:
3397 // case TokenNameREMAINDER:
3398 // case TokenNameMULTIPLY:
3399 // case TokenNameLEFT_SHIFT:
3400 // case TokenNameRIGHT_SHIFT:
3401 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3402 // case TokenNameLESS:
3403 // case TokenNameGREATER:
3404 // case TokenNameLESS_EQUAL:
3405 // case TokenNameGREATER_EQUAL:
3406 // case TokenNameEQUAL_EQUAL:
3407 // case TokenNameNOT_EQUAL:
3408 // case TokenNameXOR:
3409 // case TokenNameAND:
3410 // case TokenNameOR:
3411 // case TokenNameOR_OR:
3412 // case TokenNameAND_AND:
3413 // // the ; is not the expected token ==> it ends a statement when an
3414 // expression is not ended
3415 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3417 // case TokenNameRBRACE :
3418 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3421 // char[] tokenSource;
3423 // tokenSource = this.scanner.getCurrentTokenSource();
3424 // } catch (Exception e) {
3425 // tokenSource = new char[] {};
3427 // problemReporter().parseError(
3428 // this.scanner.startPosition,
3429 // this.scanner.currentPosition - 1,
3433 // this.checkAndReportBracketAnomalies(problemReporter());
3438 tokenSource = this.scanner.getCurrentTokenSource();
3439 } catch (Exception e) {
3440 tokenSource = new char[]{};
3442 // problemReporter().parseError(
3443 // this.scanner.startPosition,
3444 // this.scanner.currentPosition - 1,
3448 this.checkAndReportBracketAnomalies(problemReporter());
3451 /* reset scanner where it was */
3452 scanner.startPosition = startPos;
3453 scanner.currentPosition = currentPos;
3455 public static final int RoundBracket = 0;
3456 public static final int SquareBracket = 1;
3457 public static final int CurlyBracket = 2;
3458 public static final int BracketKinds = 3;
3459 protected int[] nestedMethod; //the ptr is nestedType
3460 protected int nestedType, dimensions;
3462 final static int AstStackIncrement = 100;
3463 protected int astPtr;
3464 protected AstNode[] astStack = new AstNode[AstStackIncrement];
3465 protected int astLengthPtr;
3466 protected int[] astLengthStack;
3467 AstNode[] noAstNodes = new AstNode[AstStackIncrement];
3468 public CompilationUnitDeclaration compilationUnit; /*
3469 * the result from parse()
3471 protected ReferenceContext referenceContext;
3472 protected ProblemReporter problemReporter;
3473 protected CompilerOptions options;
3474 // protected CompilationResult compilationResult;
3476 * Returns this parser's problem reporter initialized with its reference
3477 * context. Also it is assumed that a problem is going to be reported, so
3478 * initializes the compilation result's line positions.
3480 public ProblemReporter problemReporter() {
3481 if (scanner.recordLineSeparator) {
3482 compilationUnit.compilationResult.lineSeparatorPositions = scanner
3485 problemReporter.referenceContext = referenceContext;
3486 return problemReporter;
3489 * Reconsider the entire source looking for inconsistencies in {} () []
3491 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
3492 scanner.wasAcr = false;
3493 boolean anomaliesDetected = false;
3495 char[] source = scanner.source;
3496 int[] leftCount = {0, 0, 0};
3497 int[] rightCount = {0, 0, 0};
3498 int[] depths = {0, 0, 0};
3499 int[][] leftPositions = new int[][]{new int[10], new int[10], new int[10]};
3500 int[][] leftDepths = new int[][]{new int[10], new int[10], new int[10]};
3501 int[][] rightPositions = new int[][]{new int[10], new int[10],
3503 int[][] rightDepths = new int[][]{new int[10], new int[10], new int[10]};
3504 scanner.currentPosition = scanner.initialPosition; //starting
3506 // (first-zero-based
3508 while (scanner.currentPosition < scanner.eofPosition) { //loop for
3513 // ---------Consume white space and handles
3514 // startPosition---------
3515 boolean isWhiteSpace;
3517 scanner.startPosition = scanner.currentPosition;
3518 // if (((scanner.currentCharacter =
3519 // source[scanner.currentPosition++]) == '\\') &&
3520 // (source[scanner.currentPosition] == 'u')) {
3521 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
3523 if (scanner.recordLineSeparator
3524 && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3525 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3526 // only record line positions we have not
3528 scanner.pushLineSeparator();
3531 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
3533 } while (isWhiteSpace
3534 && (scanner.currentPosition < scanner.eofPosition));
3535 // -------consume token until } is found---------
3536 switch (scanner.currentCharacter) {
3539 int index = leftCount[CurlyBracket]++;
3540 if (index == leftPositions[CurlyBracket].length) {
3541 System.arraycopy(leftPositions[CurlyBracket], 0,
3542 (leftPositions[CurlyBracket] = new int[index * 2]), 0,
3545 .arraycopy(leftDepths[CurlyBracket], 0,
3546 (leftDepths[CurlyBracket] = new int[index * 2]), 0,
3549 leftPositions[CurlyBracket][index] = scanner.startPosition;
3550 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
3555 int index = rightCount[CurlyBracket]++;
3556 if (index == rightPositions[CurlyBracket].length) {
3557 System.arraycopy(rightPositions[CurlyBracket], 0,
3558 (rightPositions[CurlyBracket] = new int[index * 2]), 0,
3560 System.arraycopy(rightDepths[CurlyBracket], 0,
3561 (rightDepths[CurlyBracket] = new int[index * 2]), 0,
3564 rightPositions[CurlyBracket][index] = scanner.startPosition;
3565 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
3570 int index = leftCount[RoundBracket]++;
3571 if (index == leftPositions[RoundBracket].length) {
3572 System.arraycopy(leftPositions[RoundBracket], 0,
3573 (leftPositions[RoundBracket] = new int[index * 2]), 0,
3576 .arraycopy(leftDepths[RoundBracket], 0,
3577 (leftDepths[RoundBracket] = new int[index * 2]), 0,
3580 leftPositions[RoundBracket][index] = scanner.startPosition;
3581 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
3586 int index = rightCount[RoundBracket]++;
3587 if (index == rightPositions[RoundBracket].length) {
3588 System.arraycopy(rightPositions[RoundBracket], 0,
3589 (rightPositions[RoundBracket] = new int[index * 2]), 0,
3591 System.arraycopy(rightDepths[RoundBracket], 0,
3592 (rightDepths[RoundBracket] = new int[index * 2]), 0,
3595 rightPositions[RoundBracket][index] = scanner.startPosition;
3596 rightDepths[RoundBracket][index] = --depths[RoundBracket];
3601 int index = leftCount[SquareBracket]++;
3602 if (index == leftPositions[SquareBracket].length) {
3603 System.arraycopy(leftPositions[SquareBracket], 0,
3604 (leftPositions[SquareBracket] = new int[index * 2]), 0,
3606 System.arraycopy(leftDepths[SquareBracket], 0,
3607 (leftDepths[SquareBracket] = new int[index * 2]), 0,
3610 leftPositions[SquareBracket][index] = scanner.startPosition;
3611 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
3616 int index = rightCount[SquareBracket]++;
3617 if (index == rightPositions[SquareBracket].length) {
3618 System.arraycopy(rightPositions[SquareBracket], 0,
3619 (rightPositions[SquareBracket] = new int[index * 2]), 0,
3621 System.arraycopy(rightDepths[SquareBracket], 0,
3622 (rightDepths[SquareBracket] = new int[index * 2]), 0,
3625 rightPositions[SquareBracket][index] = scanner.startPosition;
3626 rightDepths[SquareBracket][index] = --depths[SquareBracket];
3631 if (scanner.getNextChar('\\')) {
3632 scanner.scanEscapeCharacter();
3633 } else { // consume next character
3634 scanner.unicodeAsBackSlash = false;
3635 // if (((scanner.currentCharacter =
3636 // source[scanner.currentPosition++]) ==
3638 // (source[scanner.currentPosition] ==
3640 // scanner.getNextUnicodeChar();
3642 if (scanner.withoutUnicodePtr != 0) {
3643 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3647 scanner.getNextChar('\'');
3651 // consume next character
3652 scanner.unicodeAsBackSlash = false;
3653 // if (((scanner.currentCharacter =
3654 // source[scanner.currentPosition++]) == '\\') &&
3655 // (source[scanner.currentPosition] == 'u')) {
3656 // scanner.getNextUnicodeChar();
3658 if (scanner.withoutUnicodePtr != 0) {
3659 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3662 while (scanner.currentCharacter != '"') {
3663 if (scanner.currentCharacter == '\r') {
3664 if (source[scanner.currentPosition] == '\n')
3665 scanner.currentPosition++;
3666 break; // the string cannot go further that
3669 if (scanner.currentCharacter == '\n') {
3670 break; // the string cannot go further that
3673 if (scanner.currentCharacter == '\\') {
3674 scanner.scanEscapeCharacter();
3676 // consume next character
3677 scanner.unicodeAsBackSlash = false;
3678 // if (((scanner.currentCharacter =
3679 // source[scanner.currentPosition++]) == '\\')
3680 // && (source[scanner.currentPosition] == 'u'))
3682 // scanner.getNextUnicodeChar();
3684 if (scanner.withoutUnicodePtr != 0) {
3685 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3693 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
3696 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3697 && (source[scanner.currentPosition] == 'u')) {
3698 //-------------unicode traitement
3700 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3701 scanner.currentPosition++;
3702 while (source[scanner.currentPosition] == 'u') {
3703 scanner.currentPosition++;
3706 .getNumericValue(source[scanner.currentPosition++])) > 15
3709 .getNumericValue(source[scanner.currentPosition++])) > 15
3712 .getNumericValue(source[scanner.currentPosition++])) > 15
3715 .getNumericValue(source[scanner.currentPosition++])) > 15
3716 || c4 < 0) { //error don't
3719 scanner.currentCharacter = 'A';
3720 } //something different from \n and \r
3722 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3725 while (scanner.currentCharacter != '\r'
3726 && scanner.currentCharacter != '\n') {
3728 scanner.startPosition = scanner.currentPosition;
3729 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3730 && (source[scanner.currentPosition] == 'u')) {
3731 //-------------unicode traitement
3733 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3734 scanner.currentPosition++;
3735 while (source[scanner.currentPosition] == 'u') {
3736 scanner.currentPosition++;
3739 .getNumericValue(source[scanner.currentPosition++])) > 15
3742 .getNumericValue(source[scanner.currentPosition++])) > 15
3745 .getNumericValue(source[scanner.currentPosition++])) > 15
3748 .getNumericValue(source[scanner.currentPosition++])) > 15
3749 || c4 < 0) { //error don't
3752 scanner.currentCharacter = 'A';
3753 } //something different from \n
3756 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3760 if (scanner.recordLineSeparator
3761 && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3762 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3763 // only record line positions we
3764 // have not recorded yet
3765 scanner.pushLineSeparator();
3766 if (this.scanner.taskTags != null) {
3767 this.scanner.checkTaskTag(this.scanner
3768 .getCurrentTokenStartPosition(), this.scanner
3769 .getCurrentTokenEndPosition());
3775 if (test > 0) { //traditional and annotation
3777 boolean star = false;
3778 // consume next character
3779 scanner.unicodeAsBackSlash = false;
3780 // if (((scanner.currentCharacter =
3781 // source[scanner.currentPosition++]) ==
3783 // (source[scanner.currentPosition] ==
3785 // scanner.getNextUnicodeChar();
3787 if (scanner.withoutUnicodePtr != 0) {
3788 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3791 if (scanner.currentCharacter == '*') {
3795 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3796 && (source[scanner.currentPosition] == 'u')) {
3797 //-------------unicode traitement
3799 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3800 scanner.currentPosition++;
3801 while (source[scanner.currentPosition] == 'u') {
3802 scanner.currentPosition++;
3805 .getNumericValue(source[scanner.currentPosition++])) > 15
3808 .getNumericValue(source[scanner.currentPosition++])) > 15
3811 .getNumericValue(source[scanner.currentPosition++])) > 15
3814 .getNumericValue(source[scanner.currentPosition++])) > 15
3815 || c4 < 0) { //error don't
3818 scanner.currentCharacter = 'A';
3819 } //something different from * and /
3821 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3824 //loop until end of comment */
3825 while ((scanner.currentCharacter != '/') || (!star)) {
3826 star = scanner.currentCharacter == '*';
3828 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3829 && (source[scanner.currentPosition] == 'u')) {
3830 //-------------unicode traitement
3832 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3833 scanner.currentPosition++;
3834 while (source[scanner.currentPosition] == 'u') {
3835 scanner.currentPosition++;
3838 .getNumericValue(source[scanner.currentPosition++])) > 15
3841 .getNumericValue(source[scanner.currentPosition++])) > 15
3844 .getNumericValue(source[scanner.currentPosition++])) > 15
3847 .getNumericValue(source[scanner.currentPosition++])) > 15
3848 || c4 < 0) { //error don't
3851 scanner.currentCharacter = 'A';
3852 } //something different from * and
3855 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3859 if (this.scanner.taskTags != null) {
3860 this.scanner.checkTaskTag(this.scanner
3861 .getCurrentTokenStartPosition(), this.scanner
3862 .getCurrentTokenEndPosition());
3869 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
3870 scanner.scanIdentifierOrKeyword(false);
3873 if (Character.isDigit(scanner.currentCharacter)) {
3874 scanner.scanNumber(false);
3878 //-----------------end switch while
3879 // try--------------------
3880 } catch (IndexOutOfBoundsException e) {
3881 break; // read until EOF
3882 } catch (InvalidInputException e) {
3883 return false; // no clue
3886 if (scanner.recordLineSeparator) {
3887 // compilationUnit.compilationResult.lineSeparatorPositions =
3888 // scanner.getLineEnds();
3890 // check placement anomalies against other kinds of brackets
3891 for (int kind = 0; kind < BracketKinds; kind++) {
3892 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
3893 int start = leftPositions[kind][leftIndex]; // deepest
3895 // find matching closing bracket
3896 int depth = leftDepths[kind][leftIndex];
3898 for (int i = 0; i < rightCount[kind]; i++) {
3899 int pos = rightPositions[kind][i];
3900 // want matching bracket further in source with same
3902 if ((pos > start) && (depth == rightDepths[kind][i])) {
3907 if (end < 0) { // did not find a good closing match
3908 problemReporter.unmatchedBracket(start, referenceContext,
3909 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,
3928 compilationUnit.compilationResult); //bracket
3934 // too many opening brackets ?
3935 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
3936 anomaliesDetected = true;
3937 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind]
3938 - i - 1], referenceContext, compilationUnit.compilationResult);
3940 // too many closing brackets ?
3941 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
3942 anomaliesDetected = true;
3943 problemReporter.unmatchedBracket(rightPositions[kind][i],
3944 referenceContext, compilationUnit.compilationResult);
3946 if (anomaliesDetected)
3949 return anomaliesDetected;
3950 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
3951 return anomaliesDetected;
3952 } catch (NullPointerException e) { // jdk1.2.2 jit bug
3953 return anomaliesDetected;
3956 protected void pushOnAstLengthStack(int pos) {
3958 astLengthStack[++astLengthPtr] = pos;
3959 } catch (IndexOutOfBoundsException e) {
3960 int oldStackLength = astLengthStack.length;
3961 int[] oldPos = astLengthStack;
3962 astLengthStack = new int[oldStackLength + StackIncrement];
3963 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
3964 astLengthStack[astLengthPtr] = pos;
3967 protected void pushOnAstStack(AstNode node) {
3969 * add a new obj on top of the ast stack
3972 astStack[++astPtr] = node;
3973 } catch (IndexOutOfBoundsException e) {
3974 int oldStackLength = astStack.length;
3975 AstNode[] oldStack = astStack;
3976 astStack = new AstNode[oldStackLength + AstStackIncrement];
3977 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
3978 astPtr = oldStackLength;
3979 astStack[astPtr] = node;
3982 astLengthStack[++astLengthPtr] = 1;
3983 } catch (IndexOutOfBoundsException e) {
3984 int oldStackLength = astLengthStack.length;
3985 int[] oldPos = astLengthStack;
3986 astLengthStack = new int[oldStackLength + AstStackIncrement];
3987 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
3988 astLengthStack[astLengthPtr] = 1;