3 CHOICE_AMBIGUITY_CHECK = 2;
4 OTHER_AMBIGUITY_CHECK = 1;
7 DEBUG_LOOKAHEAD = false;
8 DEBUG_TOKEN_MANAGER = false;
9 OPTIMIZE_TOKEN_MANAGER = false;
10 ERROR_REPORTING = true;
11 JAVA_UNICODE_ESCAPE = false;
12 UNICODE_INPUT = false;
14 USER_TOKEN_MANAGER = false;
15 USER_CHAR_STREAM = false;
17 BUILD_TOKEN_MANAGER = true;
19 FORCE_LA_CHECK = false;
22 PARSER_BEGIN(PHPParser)
25 import org.eclipse.core.resources.IFile;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29 import org.eclipse.jface.preference.IPreferenceStore;
31 import java.util.Hashtable;
32 import java.io.StringReader;
33 import java.text.MessageFormat;
35 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
36 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
37 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
38 import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren;
39 import net.sourceforge.phpdt.internal.compiler.parser.PHPFunctionDeclaration;
40 import net.sourceforge.phpdt.internal.compiler.parser.PHPClassDeclaration;
44 * This php parser is inspired by the Java 1.2 grammar example
45 * given with JavaCC. You can get JavaCC at http://www.webgain.com
46 * You can test the parser with the PHPParserTestCase2.java
47 * @author Matthieu Casanova
49 public class PHPParser extends PHPParserSuperclass {
51 private static IFile fileToParse;
53 /** The current segment */
54 private static PHPSegmentWithChildren currentSegment;
56 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
57 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
58 public static final int ERROR = 2;
59 public static final int WARNING = 1;
60 public static final int INFO = 0;
61 PHPOutlineInfo outlineInfo;
62 private static int errorLevel = ERROR;
63 private static String errorMessage;
68 public void setFileToParse(IFile fileToParse) {
69 this.fileToParse = fileToParse;
72 public PHPParser(IFile fileToParse) {
73 this(new StringReader(""));
74 this.fileToParse = fileToParse;
77 public void phpParserTester(String strEval) throws CoreException, ParseException {
78 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
79 StringReader stream = new StringReader(strEval);
80 if (jj_input_stream == null) {
81 jj_input_stream = new SimpleCharStream(stream, 1, 1);
83 ReInit(new StringReader(strEval));
87 public void htmlParserTester(String strEval) throws CoreException, ParseException {
88 StringReader stream = new StringReader(strEval);
89 if (jj_input_stream == null) {
90 jj_input_stream = new SimpleCharStream(stream, 1, 1);
96 public PHPOutlineInfo parseInfo(Object parent, String s) {
97 outlineInfo = new PHPOutlineInfo(parent);
98 currentSegment = outlineInfo.getDeclarations();
99 StringReader stream = new StringReader(s);
100 if (jj_input_stream == null) {
101 jj_input_stream = new SimpleCharStream(stream, 1, 1);
106 } catch (ParseException e) {
107 if (errorMessage == null) {
108 PHPeclipsePlugin.log(e);
110 setMarker(errorMessage, e.currentToken.beginLine, errorLevel);
119 * Create marker for the parse error
121 private static void setMarker(String message, int lineNumber, int errorLevel) {
123 setMarker(fileToParse, message, lineNumber, errorLevel);
124 } catch (CoreException e) {
125 PHPeclipsePlugin.log(e);
129 public static void setMarker(IFile file, String message, int lineNumber, int errorLevel) throws CoreException {
131 Hashtable attributes = new Hashtable();
132 MarkerUtilities.setMessage(attributes, message);
133 switch (errorLevel) {
135 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
138 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
141 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
144 MarkerUtilities.setLineNumber(attributes, lineNumber);
145 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
150 * Create markers according to the external parser output
152 private static void createMarkers(String output, IFile file) throws CoreException {
153 // delete all markers
154 file.deleteMarkers(IMarker.PROBLEM, false, 0);
159 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
160 // newer php error output (tested with 4.2.3)
161 scanLine(output, file, indx, brIndx);
166 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
167 // older php error output (tested with 4.2.3)
168 scanLine(output, file, indx, brIndx);
174 private static void scanLine(String output, IFile file, int indx, int brIndx) throws CoreException {
176 StringBuffer lineNumberBuffer = new StringBuffer(10);
178 current = output.substring(indx, brIndx);
180 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
181 int onLine = current.indexOf("on line <b>");
183 lineNumberBuffer.delete(0, lineNumberBuffer.length());
184 for (int i = onLine; i < current.length(); i++) {
185 ch = current.charAt(i);
186 if ('0' <= ch && '9' >= ch) {
187 lineNumberBuffer.append(ch);
191 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
193 Hashtable attributes = new Hashtable();
195 current = current.replaceAll("\n", "");
196 current = current.replaceAll("<b>", "");
197 current = current.replaceAll("</b>", "");
198 MarkerUtilities.setMessage(attributes, current);
200 if (current.indexOf(PARSE_ERROR_STRING) != -1)
201 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
202 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
203 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
205 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
206 MarkerUtilities.setLineNumber(attributes, lineNumber);
207 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
212 public void parse(String s) throws CoreException {
213 ReInit(new StringReader(s));
216 } catch (ParseException e) {
217 if (errorMessage == null) {
218 PHPeclipsePlugin.log(e);
220 setMarker(errorMessage, e.currentToken.beginLine, errorLevel);
227 * Call the php parse command ( php -l -f <filename> )
228 * and create markers according to the external parser output
230 public static void phpExternalParse(IFile file) {
231 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
232 String filename = file.getLocation().toString();
234 String[] arguments = { filename };
235 MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
236 String command = form.format(arguments);
238 String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
241 // parse the buffer to find the errors and warnings
242 createMarkers(parserResult, file);
243 } catch (CoreException e) {
244 PHPeclipsePlugin.log(e);
248 public void parse() throws ParseException {
253 PARSER_END(PHPParser)
257 <PHPSTART : "<?php" | "<?"> : PHPPARSING
262 <PHPEND :"?>"> : DEFAULT
286 "//" : IN_SINGLE_LINE_COMMENT
288 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
290 "/*" : IN_MULTI_LINE_COMMENT
293 <IN_SINGLE_LINE_COMMENT>
296 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" | "?>" > : PHPPARSING
302 <FORMAL_COMMENT: "*/" > : PHPPARSING
305 <IN_MULTI_LINE_COMMENT>
308 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
311 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
321 | <FUNCTION : "function">
324 | <ELSEIF : "elseif">
329 /* LANGUAGE CONSTRUCT */
334 | <INCLUDE : "include">
335 | <REQUIRE : "require">
336 | <INCLUDE_ONCE : "include_once">
337 | <REQUIRE_ONCE : "require_once">
338 | <GLOBAL : "global">
339 | <STATIC : "static">
340 | <CLASSACCESS: "->">
341 | <STATICCLASSACCESS: "::">
342 | <ARRAYASSIGN: "=>">
345 /* RESERVED WORDS AND LITERALS */
352 | < CONTINUE: "continue" >
353 | < _DEFAULT: "default" >
355 | < EXTENDS: "extends" >
361 | < RETURN: "return" >
363 | < SWITCH: "switch" >
367 | < ENDWHILE : "endwhile" >
375 | <OBJECT : "object">
377 | <BOOLEAN : "boolean">
379 | <DOUBLE : "double">
382 | <INTEGER : "integer">
396 <DECIMAL_LITERAL> (["l","L"])?
397 | <HEX_LITERAL> (["l","L"])?
398 | <OCTAL_LITERAL> (["l","L"])?
401 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
403 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
405 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
407 < FLOATING_POINT_LITERAL:
408 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
409 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
410 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
411 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
414 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
416 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
441 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
444 ["a"-"z"] | ["A"-"Z"]
500 | < RSIGNEDSHIFT: ">>" >
501 | < RUNSIGNEDSHIFT: ">>>" >
502 | < PLUSASSIGN: "+=" >
503 | < MINUSASSIGN: "-=" >
504 | < STARASSIGN: "*=" >
505 | < SLASHASSIGN: "/=" >
506 | < ANDASSIGN: "&=" >
508 | < XORASSIGN: "^=" >
509 | < DOTASSIGN: ".=" >
510 | < REMASSIGN: "%=" >
511 | < LSHIFTASSIGN: "<<=" >
512 | < RSIGNEDSHIFTASSIGN: ">>=" >
513 | < RUNSIGNEDSHIFTASSIGN: ">>>=" >
518 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
521 /*****************************************
522 * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
523 *****************************************/
526 * Program structuring syntax follows.
539 (<PHPSTART> Php() <PHPEND>)*
549 void ClassDeclaration() :
551 PHPClassDeclaration classDeclaration;
553 int pos = jj_input_stream.bufpos;
556 <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
558 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
559 currentSegment.add(classDeclaration);
560 currentSegment = classDeclaration;
564 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
571 <LBRACE> ( ClassBodyDeclaration() )* <RBRACE>
574 void ClassBodyDeclaration() :
582 void FieldDeclaration() :
585 <VAR> VariableDeclarator() ( <COMMA> VariableDeclarator() )* <SEMICOLON>
588 String VariableDeclarator() :
591 StringBuffer buff = new StringBuffer();
594 expr = VariableDeclaratorId()
596 [ <ASSIGN> expr = VariableInitializer()
597 {buff.append("=").append(expr);}
599 {return buff.toString();}
602 String VariableDeclaratorId() :
605 StringBuffer buff = new StringBuffer();
610 ( LOOKAHEAD(2) expr = VariableSuffix()
613 {return buff.toString();}
622 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
627 return token + "{" + expr + "}";
630 <DOLLAR> expr = VariableName()
634 String VariableName():
640 <LBRACE> expr = Expression() <RBRACE>
641 {return "{"+expr+"}";}
643 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
648 return token + "{" + expr + "}";
650 <DOLLAR> expr = VariableName()
654 String VariableInitializer() :
663 String ArrayVariable() :
666 StringBuffer buff = new StringBuffer();
671 [<ARRAYASSIGN> expr = Expression()
672 {buff.append("=>").append(expr);}]
673 {return buff.toString();}
676 String ArrayInitializer() :
679 StringBuffer buff = new StringBuffer("(");
682 <LPAREN> [ expr = ArrayVariable()
684 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
685 {buff.append(",").append(expr);}
690 return buff.toString();
694 void MethodDeclaration() :
696 PHPFunctionDeclaration functionDeclaration;
699 <FUNCTION> functionDeclaration = MethodDeclarator()
701 currentSegment.add(functionDeclaration);
702 currentSegment = functionDeclaration;
704 ( Block() | <SEMICOLON> )
706 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
710 PHPFunctionDeclaration MethodDeclarator() :
713 StringBuffer methodDeclaration = new StringBuffer();
714 String formalParameters;
715 int pos = jj_input_stream.bufpos;
718 [ <BIT_AND> {methodDeclaration.append("&");}]
719 identifier = <IDENTIFIER> formalParameters = FormalParameters()
721 methodDeclaration.append(identifier).append(formalParameters);
722 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
726 String FormalParameters() :
729 StringBuffer buff = new StringBuffer("(");
732 <LPAREN> [ expr = FormalParameter() {buff.append(expr);}
733 ( <COMMA> expr = FormalParameter()
734 {buff.append(",").append(expr);}
738 return buff.toString();
742 String FormalParameter() :
745 StringBuffer buff = new StringBuffer();
748 [<BIT_AND> {buff.append("&");}] expr = VariableDeclarator()
751 return buff.toString();
783 String Expression() :
786 String assignOperator = null;
790 expr = PrintExpression()
793 expr = ConditionalExpression()
795 assignOperator = AssignmentOperator()
802 return expr + assignOperator + expr2;
807 String AssignmentOperator() :
809 Token assignOperator;
826 | <RSIGNEDSHIFTASSIGN>
828 | <RUNSIGNEDSHIFTASSIGN>
840 String ConditionalExpression() :
847 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
852 return expr + "?" + expr2 + ":" + expr3;
857 String ConditionalOrExpression() :
862 StringBuffer buff = new StringBuffer();
865 expr = ConditionalAndExpression()
870 (operator = <SC_OR> | operator = <_ORL>) expr2 = ConditionalAndExpression()
872 buff.append(operator.image);
877 return buff.toString();
881 String ConditionalAndExpression() :
886 StringBuffer buff = new StringBuffer();
889 expr = ConcatExpression()
894 (operator = <SC_AND> | operator = <_ANDL>) expr2 = ConcatExpression()
896 buff.append(operator.image);
901 return buff.toString();
905 String ConcatExpression() :
909 StringBuffer buff = new StringBuffer();
912 expr = InclusiveOrExpression()
917 <DOT> expr2 = InclusiveOrExpression()
924 return buff.toString();
928 String InclusiveOrExpression() :
932 StringBuffer buff = new StringBuffer();
935 expr = ExclusiveOrExpression()
940 <BIT_OR> expr2 = ExclusiveOrExpression()
947 return buff.toString();
951 String ExclusiveOrExpression() :
955 StringBuffer buff = new StringBuffer();
958 expr = AndExpression()
963 <XOR> expr2 = AndExpression()
970 return buff.toString();
974 String AndExpression() :
978 StringBuffer buff = new StringBuffer();
981 expr = EqualityExpression()
986 <BIT_AND> expr2 = EqualityExpression()
993 return buff.toString();
997 String EqualityExpression() :
1002 StringBuffer buff = new StringBuffer();
1005 expr = RelationalExpression()
1006 {buff.append(expr);}
1008 ( operator = <EQ> | operator = <NE> ) expr2 = RelationalExpression()
1010 buff.append(operator.image);
1014 {return buff.toString();}
1017 String RelationalExpression() :
1022 StringBuffer buff = new StringBuffer();
1025 expr = ShiftExpression()
1026 {buff.append(expr);}
1028 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr2 = ShiftExpression()
1030 buff.append(operator.image);
1034 {return buff.toString();}
1037 String ShiftExpression() :
1042 StringBuffer buff = new StringBuffer();
1045 expr = AdditiveExpression()
1046 {buff.append(expr);}
1048 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr2 = AdditiveExpression()
1050 buff.append(operator.image);
1054 {return buff.toString();}
1057 String AdditiveExpression() :
1062 StringBuffer buff = new StringBuffer();
1065 expr = MultiplicativeExpression()
1066 {buff.append(expr);}
1068 ( operator = <PLUS> | operator = <MINUS> ) expr2 = MultiplicativeExpression()
1070 buff.append(operator.image);
1074 {return buff.toString();}
1077 String MultiplicativeExpression() :
1082 StringBuffer buff = new StringBuffer();}
1084 expr = UnaryExpression()
1085 {buff.append(expr);}
1087 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr2 = UnaryExpression()
1089 buff.append(operator.image);
1093 {return buff.toString();}
1096 String UnaryExpression() :
1099 StringBuffer buff = new StringBuffer();
1102 <AT> expr = UnaryExpression()
1103 {return "@" + expr;}
1105 ( <PLUS> {buff.append("+");}| <MINUS> {buff.append("-");}) expr = UnaryExpression()
1108 return buff.toString();
1111 expr = PreIncrementExpression()
1114 expr = PreDecrementExpression()
1117 expr = UnaryExpressionNotPlusMinus()
1118 {return buff.toString();}
1121 String PreIncrementExpression() :
1126 <INCR> expr = PrimaryExpression()
1130 String PreDecrementExpression() :
1135 <DECR> expr = PrimaryExpression()
1139 String UnaryExpressionNotPlusMinus() :
1144 <BANG> expr = UnaryExpression()
1145 {return "!" + expr;}
1147 LOOKAHEAD( <LPAREN> Type() <RPAREN> )
1148 expr = CastExpression()
1151 expr = PostfixExpression()
1157 <LPAREN> expr = Expression()<RPAREN>
1158 {return "("+expr+")";}
1161 String CastExpression() :
1167 <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
1168 {return "(" + type + ")" + expr;}
1171 String PostfixExpression() :
1174 Token operator = null;
1177 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1179 if (operator == null) {
1182 return expr + operator.image;
1186 String PrimaryExpression() :
1190 StringBuffer buff = new StringBuffer();
1194 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1195 {buff.append(identifier.image).append("::").append(expr);}
1197 expr = PrimarySuffix()
1198 {buff.append(expr);}
1200 {return buff.toString();}
1202 expr = PrimaryPrefix()
1203 {buff.append(expr);}
1205 expr = PrimarySuffix()
1206 {buff.append(expr);}
1208 {return buff.toString();}
1210 <ARRAY> expr = ArrayInitializer()
1211 {return "array" + expr;}
1214 String PrimaryPrefix() :
1220 token = <IDENTIFIER>
1221 {return token.image;}
1223 [token = <BIT_AND>] <NEW> expr = ClassIdentifier()
1225 if (token == null) {
1226 return "new " + expr;
1228 return "new " + expr;
1231 expr = VariableDeclaratorId()
1235 String ClassIdentifier():
1241 token = <IDENTIFIER>
1242 {return token.image;}
1244 expr = VariableDeclaratorId()
1248 String PrimarySuffix() :
1256 expr = VariableSuffix()
1260 String VariableSuffix() :
1265 <CLASSACCESS> expr = VariableName()
1266 {return "->" + expr;}
1268 <LBRACKET> [ expr = Expression() ] <RBRACKET>
1273 return "[" + expr + "]";
1283 token = <INTEGER_LITERAL>
1284 {return token.image;}
1286 token = <FLOATING_POINT_LITERAL>
1287 {return token.image;}
1290 token = <STRING_LITERAL>
1291 {return token.image;}
1292 } catch (TokenMgrError e) {
1293 errorMessage = "unterminated string";
1295 throw generateParseException();
1298 expr = BooleanLiteral()
1301 expr = NullLiteral()
1305 String BooleanLiteral() :
1315 String NullLiteral() :
1322 String Arguments() :
1327 <LPAREN> [ expr = ArgumentList() ]
1330 } catch (ParseException e) {
1331 errorMessage = "')' expected to close the argument list";
1339 return "(" + expr + ")";
1343 String ArgumentList() :
1346 StringBuffer buff = new StringBuffer();
1350 {buff.append(expr);}
1354 } catch (ParseException e) {
1355 errorMessage = "expression expected after a comma in argument list";
1360 buff.append(",").append("expr");
1363 {return buff.toString();}
1367 * Statement syntax follows.
1374 Expression() (<SEMICOLON> | "?>")
1383 StatementExpression()
1386 } catch (ParseException e) {
1387 errorMessage = "';' expected after expression";
1417 void IncludeStatement() :
1420 <REQUIRE> Expression() (<SEMICOLON> | "?>")
1422 <REQUIRE_ONCE> Expression() (<SEMICOLON> | "?>")
1424 <INCLUDE> Expression() (<SEMICOLON> | "?>")
1426 <INCLUDE_ONCE> Expression() (<SEMICOLON> | "?>")
1429 String PrintExpression() :
1431 StringBuffer buff = new StringBuffer("print ");
1435 <PRINT> expr = Expression()
1438 return buff.toString();
1442 void EchoStatement() :
1445 <ECHO> Expression() (<COMMA> Expression())*
1447 (<SEMICOLON> | "?>")
1448 } catch (ParseException e) {
1449 errorMessage = "';' expected after 'echo' statement";
1455 void GlobalStatement() :
1458 <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())* (<SEMICOLON> | "?>")
1461 void StaticStatement() :
1464 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())* (<SEMICOLON> | "?>")
1467 void LabeledStatement() :
1470 <IDENTIFIER> <COLON> Statement()
1476 <LBRACE> ( BlockStatement() )* <RBRACE>
1479 void BlockStatement() :
1489 void LocalVariableDeclaration() :
1492 VariableDeclarator() ( <COMMA> VariableDeclarator() )*
1495 void EmptyStatement() :
1501 void StatementExpression() :
1503 * The last expansion of this production accepts more than the legal
1504 * Java expansions for StatementExpression. This expansion does not
1505 * use PostfixExpression for performance reasons.
1509 PreIncrementExpression()
1511 PreDecrementExpression()
1519 AssignmentOperator() Expression()
1523 void SwitchStatement() :
1526 <SWITCH> <LPAREN> Expression() <RPAREN> <LBRACE>
1527 ( SwitchLabel() ( BlockStatement() )* )*
1531 void SwitchLabel() :
1534 <CASE> Expression() <COLON>
1539 void IfStatement() :
1541 * The disambiguating algorithm of JavaCC automatically binds dangling
1542 * else's to the innermost if statement. The LOOKAHEAD specification
1543 * is to tell JavaCC that we know what we are doing.
1547 <IF> Condition("if") Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
1550 void Condition(String keyword) :
1555 } catch (ParseException e) {
1556 errorMessage = "'(' expected after " + keyword + " keyword";
1563 } catch (ParseException e) {
1564 errorMessage = "')' expected after " + keyword + " keyword";
1570 void ElseIfStatement() :
1573 <ELSEIF> Condition("elseif") Statement()
1576 void WhileStatement() :
1579 <WHILE> Condition("while") WhileStatement0()
1582 void WhileStatement0() :
1585 <COLON> (Statement())* <ENDWHILE> (<SEMICOLON> | "?>")
1590 void DoStatement() :
1593 <DO> Statement() <WHILE> Condition("while") (<SEMICOLON> | "?>")
1596 void ForStatement() :
1599 <FOR> <LPAREN> [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ ForUpdate() ] <RPAREN> Statement()
1605 LOOKAHEAD(LocalVariableDeclaration())
1606 LocalVariableDeclaration()
1608 StatementExpressionList()
1611 void StatementExpressionList() :
1614 StatementExpression() ( <COMMA> StatementExpression() )*
1620 StatementExpressionList()
1623 void BreakStatement() :
1626 <BREAK> [ <IDENTIFIER> ] <SEMICOLON>
1629 void ContinueStatement() :
1632 <CONTINUE> [ <IDENTIFIER> ] <SEMICOLON>
1635 void ReturnStatement() :
1638 <RETURN> [ Expression() ] <SEMICOLON>