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;
41 import net.sourceforge.phpdt.internal.compiler.parser.PHPVarDeclaration;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
51 public class PHPParser extends PHPParserSuperclass {
53 private static IFile fileToParse;
55 /** The current segment */
56 private static PHPSegmentWithChildren currentSegment;
58 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
59 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
60 PHPOutlineInfo outlineInfo;
61 private static int errorLevel = ERROR;
62 private static String errorMessage;
67 public void setFileToParse(IFile fileToParse) {
68 this.fileToParse = fileToParse;
71 public PHPParser(IFile fileToParse) {
72 this(new StringReader(""));
73 this.fileToParse = fileToParse;
76 public void phpParserTester(String strEval) throws CoreException, ParseException {
77 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
78 StringReader stream = new StringReader(strEval);
79 if (jj_input_stream == null) {
80 jj_input_stream = new SimpleCharStream(stream, 1, 1);
82 ReInit(new StringReader(strEval));
86 public void htmlParserTester(String strEval) throws CoreException, ParseException {
87 StringReader stream = new StringReader(strEval);
88 if (jj_input_stream == null) {
89 jj_input_stream = new SimpleCharStream(stream, 1, 1);
95 public PHPOutlineInfo parseInfo(Object parent, String s) {
96 outlineInfo = new PHPOutlineInfo(parent);
97 currentSegment = outlineInfo.getDeclarations();
98 StringReader stream = new StringReader(s);
99 if (jj_input_stream == null) {
100 jj_input_stream = new SimpleCharStream(stream, 1, 1);
105 } catch (ParseException e) {
106 processParseException(e);
112 * This method will process the parse exception.
113 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
114 * @param e the ParseException
116 private static void processParseException(final ParseException e) {
117 if (errorMessage == null) {
118 PHPeclipsePlugin.log(e);
119 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
126 * Create marker for the parse error
128 private static void setMarker(ParseException e) {
130 setMarker(fileToParse,
132 jj_input_stream.tokenBegin,
133 jj_input_stream.tokenBegin + e.currentToken.image.length(),
135 "Line " + e.currentToken.beginLine);
136 } catch (CoreException e2) {
137 PHPeclipsePlugin.log(e2);
142 * Create markers according to the external parser output
144 private static void createMarkers(String output, IFile file) throws CoreException {
145 // delete all markers
146 file.deleteMarkers(IMarker.PROBLEM, false, 0);
151 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
152 // newer php error output (tested with 4.2.3)
153 scanLine(output, file, indx, brIndx);
158 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
159 // older php error output (tested with 4.2.3)
160 scanLine(output, file, indx, brIndx);
166 private static void scanLine(String output, IFile file, int indx, int brIndx) throws CoreException {
168 StringBuffer lineNumberBuffer = new StringBuffer(10);
170 current = output.substring(indx, brIndx);
172 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
173 int onLine = current.indexOf("on line <b>");
175 lineNumberBuffer.delete(0, lineNumberBuffer.length());
176 for (int i = onLine; i < current.length(); i++) {
177 ch = current.charAt(i);
178 if ('0' <= ch && '9' >= ch) {
179 lineNumberBuffer.append(ch);
183 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
185 Hashtable attributes = new Hashtable();
187 current = current.replaceAll("\n", "");
188 current = current.replaceAll("<b>", "");
189 current = current.replaceAll("</b>", "");
190 MarkerUtilities.setMessage(attributes, current);
192 if (current.indexOf(PARSE_ERROR_STRING) != -1)
193 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
194 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
195 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
197 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
198 MarkerUtilities.setLineNumber(attributes, lineNumber);
199 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
204 public void parse(String s) throws CoreException {
205 ReInit(new StringReader(s));
208 } catch (ParseException e) {
209 processParseException(e);
214 * Call the php parse command ( php -l -f <filename> )
215 * and create markers according to the external parser output
217 public static void phpExternalParse(IFile file) {
218 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
219 String filename = file.getLocation().toString();
221 String[] arguments = { filename };
222 MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
223 String command = form.format(arguments);
225 String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
228 // parse the buffer to find the errors and warnings
229 createMarkers(parserResult, file);
230 } catch (CoreException e) {
231 PHPeclipsePlugin.log(e);
235 public void parse() throws ParseException {
240 PARSER_END(PHPParser)
244 <PHPSTART : "<?php" | "<?"> : PHPPARSING
249 <PHPEND :"?>"> : DEFAULT
273 "//" : IN_SINGLE_LINE_COMMENT
275 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
277 "/*" : IN_MULTI_LINE_COMMENT
280 <IN_SINGLE_LINE_COMMENT>
283 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" | "?>" > : PHPPARSING
289 <FORMAL_COMMENT: "*/" > : PHPPARSING
292 <IN_MULTI_LINE_COMMENT>
295 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
298 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
308 | <FUNCTION : "function">
311 | <ELSEIF : "elseif">
316 /* LANGUAGE CONSTRUCT */
321 | <INCLUDE : "include">
322 | <REQUIRE : "require">
323 | <INCLUDE_ONCE : "include_once">
324 | <REQUIRE_ONCE : "require_once">
325 | <GLOBAL : "global">
326 | <STATIC : "static">
327 | <CLASSACCESS: "->">
328 | <STATICCLASSACCESS: "::">
329 | <ARRAYASSIGN: "=>">
332 /* RESERVED WORDS AND LITERALS */
339 | < CONTINUE: "continue" >
340 | < _DEFAULT: "default" >
342 | < EXTENDS: "extends" >
348 | < RETURN: "return" >
350 | < SWITCH: "switch" >
354 | < ENDWHILE : "endwhile" >
362 | <OBJECT : "object">
364 | <BOOLEAN : "boolean">
366 | <DOUBLE : "double">
369 | <INTEGER : "integer">
383 <DECIMAL_LITERAL> (["l","L"])?
384 | <HEX_LITERAL> (["l","L"])?
385 | <OCTAL_LITERAL> (["l","L"])?
388 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
390 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
392 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
394 < FLOATING_POINT_LITERAL:
395 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
396 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
397 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
398 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
401 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
403 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
438 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
441 ["a"-"z"] | ["A"-"Z"]
449 "_" | ["\u007f"-"\u00ff"]
497 | <RSIGNEDSHIFT: ">>" >
498 | <RUNSIGNEDSHIFT: ">>>" >
499 | <PLUSASSIGN: "+=" >
500 | <MINUSASSIGN: "-=" >
501 | <STARASSIGN: "*=" >
502 | <SLASHASSIGN: "/=" >
508 | <LSHIFTASSIGN: "<<=" >
509 | <RSIGNEDSHIFTASSIGN: ">>=" >
510 | <BANGDOUBLEEQUAL: "!==" >
511 | <TRIPLEEQUAL: "===" >
512 | <TILDEEQUAL: "~=" >
517 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
520 /*****************************************
521 * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
522 *****************************************/
525 * Program structuring syntax follows.
539 (<PHPSTART> Php() <PHPEND>)*
541 } catch (TokenMgrError e) {
542 errorMessage = e.getMessage();
544 throw generateParseException();
554 void ClassDeclaration() :
556 PHPClassDeclaration classDeclaration;
558 int pos = jj_input_stream.bufpos;
561 <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
563 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
564 currentSegment.add(classDeclaration);
565 currentSegment = classDeclaration;
569 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
578 } catch (ParseException e) {
579 errorMessage = "'{' expected";
583 ( ClassBodyDeclaration() )*
586 } catch (ParseException e) {
587 errorMessage = "'var', 'function' or '}' expected";
593 void ClassBodyDeclaration() :
601 void FieldDeclaration() :
603 PHPVarDeclaration variableDeclaration;
606 <VAR> variableDeclaration = VariableDeclarator()
607 {currentSegment.add(variableDeclaration);}
609 variableDeclaration = VariableDeclarator()
610 {currentSegment.add(variableDeclaration);}
614 } catch (ParseException e) {
615 errorMessage = "';' expected after variable declaration";
621 PHPVarDeclaration VariableDeclarator() :
624 String varValue = null;
625 int pos = jj_input_stream.bufpos;
628 varName = VariableDeclaratorId()
632 varValue = VariableInitializer()
633 } catch (ParseException e) {
634 errorMessage = "Literal expression expected in variable initializer";
640 if (varValue == null) {
641 return new PHPVarDeclaration(currentSegment,varName,pos);
643 return new PHPVarDeclaration(currentSegment,varName,pos,varValue);
647 String VariableDeclaratorId() :
650 StringBuffer buff = new StringBuffer();
656 ( LOOKAHEAD(2) expr = VariableSuffix()
659 {return buff.toString();}
660 } catch (ParseException e) {
661 errorMessage = "'$' expected for variable identifier";
673 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
678 return token + "{" + expr + "}";
681 <DOLLAR> expr = VariableName()
685 String VariableName():
691 <LBRACE> expr = Expression() <RBRACE>
692 {return "{"+expr+"}";}
694 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
699 return token + "{" + expr + "}";
702 <DOLLAR> expr = VariableName()
705 token = <DOLLAR_ID> [expr = VariableName()]
710 return token.image + expr;
714 String VariableInitializer() :
723 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
724 {return "-" + token.image;}
726 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
727 {return "+" + token.image;}
729 expr = ArrayDeclarator()
733 {return token.image;}
736 String ArrayVariable() :
739 StringBuffer buff = new StringBuffer();
744 [<ARRAYASSIGN> expr = Expression()
745 {buff.append("=>").append(expr);}]
746 {return buff.toString();}
749 String ArrayInitializer() :
752 StringBuffer buff = new StringBuffer("(");
755 <LPAREN> [ expr = ArrayVariable()
757 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
758 {buff.append(",").append(expr);}
763 return buff.toString();
767 void MethodDeclaration() :
769 PHPFunctionDeclaration functionDeclaration;
772 <FUNCTION> functionDeclaration = MethodDeclarator()
774 currentSegment.add(functionDeclaration);
775 currentSegment = functionDeclaration;
779 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
783 PHPFunctionDeclaration MethodDeclarator() :
786 StringBuffer methodDeclaration = new StringBuffer();
787 String formalParameters;
788 int pos = jj_input_stream.bufpos;
791 [ <BIT_AND> {methodDeclaration.append("&");} ]
792 identifier = <IDENTIFIER>
793 {methodDeclaration.append(identifier);}
794 formalParameters = FormalParameters()
796 methodDeclaration.append(formalParameters);
797 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
801 String FormalParameters() :
804 final StringBuffer buff = new StringBuffer("(");
809 } catch (ParseException e) {
810 errorMessage = "Formal parameter expected after function identifier";
812 jj_consume_token(token.kind);
814 [ expr = FormalParameter()
817 <COMMA> expr = FormalParameter()
818 {buff.append(",").append(expr);}
823 } catch (ParseException e) {
824 errorMessage = "')' expected";
830 return buff.toString();
834 String FormalParameter() :
836 PHPVarDeclaration variableDeclaration;
837 StringBuffer buff = new StringBuffer();
840 [<BIT_AND> {buff.append("&");}] variableDeclaration = VariableDeclarator()
842 buff.append(variableDeclaration.toString());
843 return buff.toString();
875 String Expression() :
878 String assignOperator = null;
882 expr = PrintExpression()
885 expr = ConditionalExpression()
887 assignOperator = AssignmentOperator()
890 } catch (ParseException e) {
891 errorMessage = "expression expected";
900 return expr + assignOperator + expr2;
905 String AssignmentOperator() :
922 | <RSIGNEDSHIFTASSIGN>
936 String ConditionalExpression() :
943 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
948 return expr + "?" + expr2 + ":" + expr3;
953 String ConditionalOrExpression() :
958 StringBuffer buff = new StringBuffer();
961 expr = ConditionalAndExpression()
966 (operator = <SC_OR> | operator = <_ORL>) expr2 = ConditionalAndExpression()
968 buff.append(operator.image);
973 return buff.toString();
977 String ConditionalAndExpression() :
982 StringBuffer buff = new StringBuffer();
985 expr = ConcatExpression()
990 (operator = <SC_AND> | operator = <_ANDL>) expr2 = ConcatExpression()
992 buff.append(operator.image);
997 return buff.toString();
1001 String ConcatExpression() :
1004 String expr2 = null;
1005 StringBuffer buff = new StringBuffer();
1008 expr = InclusiveOrExpression()
1013 <DOT> expr2 = InclusiveOrExpression()
1020 return buff.toString();
1024 String InclusiveOrExpression() :
1027 String expr2 = null;
1028 StringBuffer buff = new StringBuffer();
1031 expr = ExclusiveOrExpression()
1036 <BIT_OR> expr2 = ExclusiveOrExpression()
1043 return buff.toString();
1047 String ExclusiveOrExpression() :
1050 String expr2 = null;
1051 StringBuffer buff = new StringBuffer();
1054 expr = AndExpression()
1059 <XOR> expr2 = AndExpression()
1066 return buff.toString();
1070 String AndExpression() :
1073 String expr2 = null;
1074 StringBuffer buff = new StringBuffer();
1077 expr = EqualityExpression()
1082 <BIT_AND> expr2 = EqualityExpression()
1089 return buff.toString();
1093 String EqualityExpression() :
1098 StringBuffer buff = new StringBuffer();
1101 expr = RelationalExpression()
1102 {buff.append(expr);}
1106 | operator = <BANGDOUBLEEQUAL>
1107 | operator = <TRIPLEEQUAL>
1109 expr2 = RelationalExpression()
1111 buff.append(operator.image);
1115 {return buff.toString();}
1118 String RelationalExpression() :
1123 StringBuffer buff = new StringBuffer();
1126 expr = ShiftExpression()
1127 {buff.append(expr);}
1129 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr2 = ShiftExpression()
1131 buff.append(operator.image);
1135 {return buff.toString();}
1138 String ShiftExpression() :
1143 StringBuffer buff = new StringBuffer();
1146 expr = AdditiveExpression()
1147 {buff.append(expr);}
1149 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr2 = AdditiveExpression()
1151 buff.append(operator.image);
1155 {return buff.toString();}
1158 String AdditiveExpression() :
1163 StringBuffer buff = new StringBuffer();
1166 expr = MultiplicativeExpression()
1167 {buff.append(expr);}
1169 ( operator = <PLUS> | operator = <MINUS> ) expr2 = MultiplicativeExpression()
1171 buff.append(operator.image);
1175 {return buff.toString();}
1178 String MultiplicativeExpression() :
1182 final StringBuffer buff = new StringBuffer();}
1184 expr = UnaryExpression()
1185 {buff.append(expr);}
1187 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr2 = UnaryExpression()
1189 buff.append(operator.image);
1193 {return buff.toString();}
1197 * An unary expression starting with @, & or nothing
1199 String UnaryExpression() :
1203 final StringBuffer buff = new StringBuffer();
1206 token = <BIT_AND> expr = UnaryExpressionNoPrefix()
1208 if (token == null) {
1211 return token.image + expr;
1214 (<AT> {buff.append("@");})* expr = UnaryExpressionNoPrefix()
1215 {return buff.append(expr).toString();}
1218 String UnaryExpressionNoPrefix() :
1224 ( token = <PLUS> | token = <MINUS> ) expr = UnaryExpression()
1226 return token.image + expr;
1229 expr = PreIncrementExpression()
1232 expr = PreDecrementExpression()
1235 expr = UnaryExpressionNotPlusMinus()
1240 String PreIncrementExpression() :
1245 <INCR> expr = PrimaryExpression()
1249 String PreDecrementExpression() :
1254 <DECR> expr = PrimaryExpression()
1258 String UnaryExpressionNotPlusMinus() :
1263 <BANG> expr = UnaryExpression()
1264 {return "!" + expr;}
1266 LOOKAHEAD( <LPAREN> Type() <RPAREN> )
1267 expr = CastExpression()
1270 expr = PostfixExpression()
1276 <LPAREN> expr = Expression()<RPAREN>
1277 {return "("+expr+")";}
1280 String CastExpression() :
1286 <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
1287 {return "(" + type + ")" + expr;}
1290 String PostfixExpression() :
1293 Token operator = null;
1296 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1298 if (operator == null) {
1301 return expr + operator.image;
1305 String PrimaryExpression() :
1309 final StringBuffer buff = new StringBuffer();
1313 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1314 {buff.append(identifier.image).append("::").append(expr);}
1316 expr = PrimarySuffix()
1317 {buff.append(expr);}
1319 {return buff.toString();}
1321 expr = PrimaryPrefix() {buff.append(expr);}
1322 ( expr = PrimarySuffix() {buff.append(expr);} )*
1323 {return buff.toString();}
1325 expr = ArrayDeclarator()
1326 {return "array" + expr;}
1329 String ArrayDeclarator() :
1334 <ARRAY> expr = ArrayInitializer()
1335 {return "array" + expr;}
1338 String PrimaryPrefix() :
1344 token = <IDENTIFIER>
1345 {return token.image;}
1347 <NEW> expr = ClassIdentifier()
1349 return "new " + expr;
1352 expr = VariableDeclaratorId()
1356 String ClassIdentifier():
1362 token = <IDENTIFIER>
1363 {return token.image;}
1365 expr = VariableDeclaratorId()
1369 String PrimarySuffix() :
1377 expr = VariableSuffix()
1381 String VariableSuffix() :
1386 <CLASSACCESS> expr = VariableName()
1387 {return "->" + expr;}
1389 <LBRACKET> [ expr = Expression() ]
1392 } catch (ParseException e) {
1393 errorMessage = "']' expected";
1401 return "[" + expr + "]";
1411 token = <INTEGER_LITERAL>
1412 {return token.image;}
1414 token = <FLOATING_POINT_LITERAL>
1415 {return token.image;}
1417 token = <STRING_LITERAL>
1418 {return token.image;}
1420 expr = BooleanLiteral()
1423 expr = NullLiteral()
1427 String BooleanLiteral() :
1437 String NullLiteral() :
1444 String Arguments() :
1449 <LPAREN> [ expr = ArgumentList() ]
1452 } catch (ParseException e) {
1453 errorMessage = "')' expected to close the argument list";
1461 return "(" + expr + ")";
1465 String ArgumentList() :
1468 StringBuffer buff = new StringBuffer();
1472 {buff.append(expr);}
1476 } catch (ParseException e) {
1477 errorMessage = "expression expected after a comma in argument list";
1482 buff.append(",").append("expr");
1485 {return buff.toString();}
1489 * Statement syntax follows.
1498 (<SEMICOLON> | "?>")
1499 } catch (ParseException e) {
1500 errorMessage = "';' expected";
1512 StatementExpression()
1515 } catch (ParseException e) {
1516 errorMessage = "';' expected after expression";
1539 [<AT>] IncludeStatement()
1546 void IncludeStatement() :
1549 int pos = jj_input_stream.bufpos;
1554 {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));}
1556 (<SEMICOLON> | "?>")
1557 } catch (ParseException e) {
1558 errorMessage = "';' expected";
1565 {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));}
1567 (<SEMICOLON> | "?>")
1568 } catch (ParseException e) {
1569 errorMessage = "';' expected";
1576 {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));}
1578 (<SEMICOLON> | "?>")
1579 } catch (ParseException e) {
1580 errorMessage = "';' expected";
1587 {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));}
1589 (<SEMICOLON> | "?>")
1590 } catch (ParseException e) {
1591 errorMessage = "';' expected";
1597 String PrintExpression() :
1599 StringBuffer buff = new StringBuffer("print ");
1603 <PRINT> expr = Expression()
1606 return buff.toString();
1610 void EchoStatement() :
1613 <ECHO> Expression() (<COMMA> Expression())*
1615 (<SEMICOLON> | "?>")
1616 } catch (ParseException e) {
1617 errorMessage = "';' expected after 'echo' statement";
1623 void GlobalStatement() :
1626 <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())*
1628 (<SEMICOLON> | "?>")
1629 } catch (ParseException e) {
1630 errorMessage = "';' expected";
1636 void StaticStatement() :
1639 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
1641 (<SEMICOLON> | "?>")
1642 } catch (ParseException e) {
1643 errorMessage = "';' expected";
1649 void LabeledStatement() :
1652 <IDENTIFIER> <COLON> Statement()
1660 } catch (ParseException e) {
1661 errorMessage = "'{' expected";
1665 ( BlockStatement() )*
1669 void BlockStatement() :
1679 void LocalVariableDeclaration() :
1682 VariableDeclarator() ( <COMMA> VariableDeclarator() )*
1685 void EmptyStatement() :
1691 void StatementExpression() :
1694 PreIncrementExpression()
1696 PreDecrementExpression()
1704 AssignmentOperator() Expression()
1708 void SwitchStatement() :
1711 <SWITCH> <LPAREN> Expression() <RPAREN> <LBRACE>
1712 ( SwitchLabel() ( BlockStatement() )* )*
1716 void SwitchLabel() :
1719 <CASE> Expression() <COLON>
1724 void IfStatement() :
1726 * The disambiguating algorithm of JavaCC automatically binds dangling
1727 * else's to the innermost if statement. The LOOKAHEAD specification
1728 * is to tell JavaCC that we know what we are doing.
1732 <IF> Condition("if") Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
1735 void Condition(String keyword) :
1740 } catch (ParseException e) {
1741 errorMessage = "'(' expected after " + keyword + " keyword";
1748 } catch (ParseException e) {
1749 errorMessage = "')' expected after " + keyword + " keyword";
1755 void ElseIfStatement() :
1758 <ELSEIF> Condition("elseif") Statement()
1761 void WhileStatement() :
1764 <WHILE> Condition("while") WhileStatement0()
1767 void WhileStatement0() :
1770 <COLON> (Statement())* <ENDWHILE>
1772 (<SEMICOLON> | "?>")
1773 } catch (ParseException e) {
1774 errorMessage = "';' expected";
1782 void DoStatement() :
1785 <DO> Statement() <WHILE> Condition("while")
1787 (<SEMICOLON> | "?>")
1788 } catch (ParseException e) {
1789 errorMessage = "';' expected";
1795 void ForStatement() :
1798 <FOR> <LPAREN> [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ ForUpdate() ] <RPAREN> Statement()
1804 LOOKAHEAD(LocalVariableDeclaration())
1805 LocalVariableDeclaration()
1807 StatementExpressionList()
1810 void StatementExpressionList() :
1813 StatementExpression() ( <COMMA> StatementExpression() )*
1819 StatementExpressionList()
1822 void BreakStatement() :
1825 <BREAK> [ <IDENTIFIER> ] <SEMICOLON>
1828 void ContinueStatement() :
1831 <CONTINUE> [ <IDENTIFIER> ] <SEMICOLON>
1834 void ReturnStatement() :
1837 <RETURN> [ Expression() ] <SEMICOLON>