X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.java b/net.sourceforge.phpeclipse/src/test/PHPParser.java index c20eb33..9012909 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.java @@ -8,79 +8,159 @@ import org.eclipse.ui.texteditor.MarkerUtilities; import org.eclipse.jface.preference.IPreferenceStore; import java.util.Hashtable; +import java.util.ArrayList; import java.io.StringReader; +import java.io.*; import java.text.MessageFormat; import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpdt.internal.compiler.ast.*; +import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; -import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren; -import net.sourceforge.phpdt.internal.compiler.parser.PHPFunctionDeclaration; -import net.sourceforge.phpdt.internal.compiler.parser.PHPClassDeclaration; -import net.sourceforge.phpdt.internal.compiler.parser.PHPVarDeclaration; -import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration; +import net.sourceforge.phpdt.internal.corext.Assert; /** * A new php parser. - * This php parser is inspired by the Java 1.2 grammar example + * This php parser is inspired by the Java 1.2 grammar example * given with JavaCC. You can get JavaCC at http://www.webgain.com * You can test the parser with the PHPParserTestCase2.java * @author Matthieu Casanova */ -public class PHPParser extends PHPParserSuperclass implements PHPParserConstants { +public final class PHPParser extends PHPParserSuperclass implements PHPParserConstants { - private static IFile fileToParse; +//todo : fix the variables names bug +//todo : handle tilde operator - /** The current segment */ - private static PHPSegmentWithChildren currentSegment; + + /** The current segment. */ + private static OutlineableWithChildren currentSegment; private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$ private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ - PHPOutlineInfo outlineInfo; + static PHPOutlineInfo outlineInfo; + + /** The error level of the current ParseException. */ private static int errorLevel = ERROR; + /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */ private static String errorMessage; - public PHPParser() { + private static int errorStart = -1; + private static int errorEnd = -1; + private static PHPDocument phpDocument; + + private static final String SYNTAX_ERROR_CHAR = "syntax error"; + /** + * The point where html starts. + * It will be used by the token manager to create HTMLCode objects + */ + public static int htmlStart; + + //ast stack + private final static int AstStackIncrement = 100; + /** The stack of node. */ + private static AstNode[] nodes; + /** The cursor in expression stack. */ + private static int nodePtr; + + public static final boolean PARSER_DEBUG = false; + + public final void setFileToParse(final IFile fileToParse) { + PHPParser.fileToParse = fileToParse; } - public void setFileToParse(IFile fileToParse) { - this.fileToParse = fileToParse; + public PHPParser() { } - public PHPParser(IFile fileToParse) { + public PHPParser(final IFile fileToParse) { this(new StringReader("")); - this.fileToParse = fileToParse; + PHPParser.fileToParse = fileToParse; } - public void phpParserTester(String strEval) throws CoreException, ParseException { - PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING); - StringReader stream = new StringReader(strEval); + public static final void phpParserTester(final String strEval) throws ParseException { + final StringReader stream = new StringReader(strEval); if (jj_input_stream == null) { jj_input_stream = new SimpleCharStream(stream, 1, 1); } ReInit(new StringReader(strEval)); + init(); + phpDocument = new PHPDocument(null,"_root".toCharArray()); + currentSegment = phpDocument; + outlineInfo = new PHPOutlineInfo(null, currentSegment); + PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING); phpTest(); } - public void htmlParserTester(String strEval) throws CoreException, ParseException { - StringReader stream = new StringReader(strEval); + public static final void htmlParserTester(final File fileName) throws FileNotFoundException, ParseException { + final Reader stream = new FileReader(fileName); + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } + ReInit(stream); + init(); + phpDocument = new PHPDocument(null,"_root".toCharArray()); + currentSegment = phpDocument; + outlineInfo = new PHPOutlineInfo(null, currentSegment); + phpFile(); + } + + public static final void htmlParserTester(final String strEval) throws ParseException { + final StringReader stream = new StringReader(strEval); if (jj_input_stream == null) { jj_input_stream = new SimpleCharStream(stream, 1, 1); } ReInit(stream); + init(); + phpDocument = new PHPDocument(null,"_root".toCharArray()); + currentSegment = phpDocument; + outlineInfo = new PHPOutlineInfo(null, currentSegment); phpFile(); } - public PHPOutlineInfo parseInfo(Object parent, String s) { - outlineInfo = new PHPOutlineInfo(parent); - currentSegment = outlineInfo.getDeclarations(); - StringReader stream = new StringReader(s); + /** + * Reinitialize the parser. + */ + private static final void init() { + nodes = new AstNode[AstStackIncrement]; + nodePtr = -1; + htmlStart = 0; + } + + /** + * Add an php node on the stack. + * @param node the node that will be added to the stack + */ + private static final void pushOnAstNodes(final AstNode node) { + try { + nodes[++nodePtr] = node; + } catch (IndexOutOfBoundsException e) { + final int oldStackLength = nodes.length; + final AstNode[] oldStack = nodes; + nodes = new AstNode[oldStackLength + AstStackIncrement]; + System.arraycopy(oldStack, 0, nodes, 0, oldStackLength); + nodePtr = oldStackLength; + nodes[nodePtr] = node; + } + } + + public final PHPOutlineInfo parseInfo(final Object parent, final String s) { + phpDocument = new PHPDocument(parent,"_root".toCharArray()); + currentSegment = phpDocument; + outlineInfo = new PHPOutlineInfo(parent, currentSegment); + final StringReader stream = new StringReader(s); if (jj_input_stream == null) { jj_input_stream = new SimpleCharStream(stream, 1, 1); } ReInit(stream); + init(); try { parse(); + phpDocument.nodes = new AstNode[nodes.length]; + System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length); + if (PHPeclipsePlugin.DEBUG) { + PHPeclipsePlugin.log(1,phpDocument.toString()); + } } catch (ParseException e) { processParseException(e); } @@ -88,6 +168,19 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants } /** + * This function will throw the exception if we are in debug mode + * and process it if we are in production mode. + * this should be fast since the PARSER_DEBUG is static final so the difference will be at compile time + * @param e the exception + * @throws ParseException the thrown exception + */ + private static void processParseExceptionDebug(final ParseException e) throws ParseException { + if (PARSER_DEBUG) { + throw e; + } + processParseException(e); + } + /** * This method will process the parse exception. * If the error message is null, the parse exception wasn't catched and a trace is written in the log * @param e the ParseException @@ -96,55 +189,53 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants if (errorMessage == null) { PHPeclipsePlugin.log(e); errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it"; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; } setMarker(e); errorMessage = null; + // if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e); } /** - * Create marker for the parse error + * Create marker for the parse error. + * @param e the ParseException */ - private static void setMarker(ParseException e) { + private static void setMarker(final ParseException e) { try { - setMarker(fileToParse, errorMessage, jj_input_stream.tokenBegin,jj_input_stream.tokenBegin+e.currentToken.image.length(), errorLevel); + if (errorStart == -1) { + setMarker(fileToParse, + errorMessage, + e.currentToken.sourceStart, + e.currentToken.sourceEnd, + errorLevel, + "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+":"+e.currentToken.sourceEnd); + } else { + setMarker(fileToParse, + errorMessage, + errorStart, + errorEnd, + errorLevel, + "Line " + e.currentToken.beginLine+", "+errorStart+":"+errorEnd); + errorStart = -1; + errorEnd = -1; + } } catch (CoreException e2) { PHPeclipsePlugin.log(e2); } } - /** - * Create markers according to the external parser output - */ - private static void createMarkers(String output, IFile file) throws CoreException { - // delete all markers - file.deleteMarkers(IMarker.PROBLEM, false, 0); - - int indx = 0; - int brIndx = 0; - boolean flag = true; - while ((brIndx = output.indexOf("
", indx)) != -1) { - // newer php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 6; - flag = false; - } - if (flag) { - while ((brIndx = output.indexOf("
", indx)) != -1) { - // older php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 4; - } - } - } - - private static void scanLine(String output, IFile file, int indx, int brIndx) throws CoreException { + private static void scanLine(final String output, + final IFile file, + final int indx, + final int brIndx) throws CoreException { String current; - StringBuffer lineNumberBuffer = new StringBuffer(10); + final StringBuffer lineNumberBuffer = new StringBuffer(10); char ch; current = output.substring(indx, brIndx); if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) { - int onLine = current.indexOf("on line "); + final int onLine = current.indexOf("on line "); if (onLine != -1) { lineNumberBuffer.delete(0, lineNumberBuffer.length()); for (int i = onLine; i < current.length(); i++) { @@ -154,9 +245,9 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants } } - int lineNumber = Integer.parseInt(lineNumberBuffer.toString()); + final int lineNumber = Integer.parseInt(lineNumberBuffer.toString()); - Hashtable attributes = new Hashtable(); + final Hashtable attributes = new Hashtable(); current = current.replaceAll("\n", ""); current = current.replaceAll("", ""); @@ -175,8 +266,13 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants } } - public void parse(String s) throws CoreException { - ReInit(new StringReader(s)); + public final void parse(final String s) { + final StringReader stream = new StringReader(s); + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } + ReInit(stream); + init(); try { parse(); } catch (ParseException e) { @@ -188,15 +284,15 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants * Call the php parse command ( php -l -f <filename> ) * and create markers according to the external parser output */ - public static void phpExternalParse(IFile file) { - IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); - String filename = file.getLocation().toString(); + public static void phpExternalParse(final IFile file) { + final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + final String filename = file.getLocation().toString(); - String[] arguments = { filename }; - MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); - String command = form.format(arguments); + final String[] arguments = { filename }; + final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); + final String command = form.format(arguments); - String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: "); + final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: "); try { // parse the buffer to find the errors and warnings @@ -206,38 +302,256 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants } } - public void parse() throws ParseException { + /** + * Put a new html block in the stack. + */ + public static final void createNewHTMLCode() { + final int currentPosition = token.sourceStart; + if (currentPosition == htmlStart || + currentPosition < htmlStart || + currentPosition > SimpleCharStream.currentBuffer.length()) { + return; + } + final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart, + currentPosition).toCharArray(); + pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition)); + } + + /** Create a new task. */ + public static final void createNewTask(final int todoStart) { + final String todo = SimpleCharStream.currentBuffer.substring(todoStart, + SimpleCharStream.currentBuffer.indexOf("\n", + todoStart)-1); + if (!PARSER_DEBUG) { + try { + setMarker(fileToParse, + todo, + SimpleCharStream.getBeginLine(), + TASK, + "Line "+SimpleCharStream.getBeginLine()); + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + } + } + } + + private static final void parse() throws ParseException { phpFile(); } -/***************************************** - * THE JAVA LANGUAGE GRAMMAR STARTS HERE * - *****************************************/ + static final public void todo() throws ParseException { + Token todoToken; + todoToken = jj_consume_token(23); + createNewTask(todoToken.sourceStart); + } -/* - * Program structuring syntax follows. - */ static final public void phpTest() throws ParseException { Php(); jj_consume_token(0); } static final public void phpFile() throws ParseException { - label_1: - while (true) { + try { + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PHPSTARTSHORT: + case PHPSTARTLONG: + case PHPECHOSTART: + case PHPEND: + case CLASS: + case FUNCTION: + case IF: + case ARRAY: + case BREAK: + case LIST: + case PRINT: + case ECHO: + case INCLUDE: + case REQUIRE: + case INCLUDE_ONCE: + case REQUIRE_ONCE: + case GLOBAL: + case DEFINE: + case STATIC: + case CONTINUE: + case DO: + case FOR: + case NEW: + case NULL: + case RETURN: + case SWITCH: + case TRUE: + case FALSE: + case WHILE: + case FOREACH: + case AT: + case BANG: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: + case PLUS: + case MINUS: + case BIT_AND: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case SEMICOLON: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + PhpBlock(); + } + PHPParser.createNewHTMLCode(); + } catch (TokenMgrError e) { + PHPeclipsePlugin.log(e); + errorStart = SimpleCharStream.beginOffset; + errorEnd = SimpleCharStream.endOffset; + errorMessage = e.getMessage(); + errorLevel = ERROR; + {if (true) throw generateParseException();} + } + } + +/** + * A php block is a + * or + * or + */ + static final public void PhpBlock() throws ParseException { + final PHPEchoBlock phpEchoBlock; + final Token token,phpEnd; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PHPECHOSTART: + phpEchoBlock = phpEchoBlock(); + pushOnAstNodes(phpEchoBlock); + break; + case PHPSTARTSHORT: + case PHPSTARTLONG: + case PHPEND: + case CLASS: + case FUNCTION: + case IF: + case ARRAY: + case BREAK: + case LIST: + case PRINT: + case ECHO: + case INCLUDE: + case REQUIRE: + case INCLUDE_ONCE: + case REQUIRE_ONCE: + case GLOBAL: + case DEFINE: + case STATIC: + case CONTINUE: + case DO: + case FOR: + case NEW: + case NULL: + case RETURN: + case SWITCH: + case TRUE: + case FALSE: + case WHILE: + case FOREACH: + case AT: + case BANG: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: + case PLUS: + case MINUS: + case BIT_AND: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case SEMICOLON: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case PHPSTART: - ; + case PHPSTARTSHORT: + case PHPSTARTLONG: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PHPSTARTLONG: + jj_consume_token(PHPSTARTLONG); + break; + case PHPSTARTSHORT: + token = jj_consume_token(PHPSTARTSHORT); + try { + setMarker(fileToParse, + "You should use '' expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseExceptionDebug(e); + } + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); } - jj_consume_token(0); + } + + static final public PHPEchoBlock phpEchoBlock() throws ParseException { + final Expression expr; + final PHPEchoBlock echoBlock; + final Token token, token2; + token = jj_consume_token(PHPECHOSTART); + PHPParser.createNewHTMLCode(); + expr = Expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case SEMICOLON: + jj_consume_token(SEMICOLON); + break; + default: + jj_la1[4] = jj_gen; + ; + } + token2 = jj_consume_token(PHPEND); + htmlStart = token2.sourceEnd; + + echoBlock = new PHPEchoBlock(expr,token.sourceStart,token2.sourceEnd); + pushOnAstNodes(echoBlock); + {if (true) return echoBlock;} + throw new Error("Missing return statement in function"); } static final public void Php() throws ParseException { @@ -248,6 +562,8 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants case FUNCTION: case IF: case ARRAY: + case BREAK: + case LIST: case PRINT: case ECHO: case INCLUDE: @@ -255,73 +571,124 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants case INCLUDE_ONCE: case REQUIRE_ONCE: case GLOBAL: + case DEFINE: case STATIC: - case BREAK: case CONTINUE: case DO: - case FALSE: case FOR: case NEW: case NULL: case RETURN: case SWITCH: case TRUE: + case FALSE: case WHILE: + case FOREACH: + case AT: + case BANG: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: + case PLUS: + case MINUS: + case BIT_AND: case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: case IDENTIFIER: case LPAREN: case LBRACE: case SEMICOLON: - case AT: - case DOLLAR: - case BANG: - case INCR: - case DECR: - case PLUS: - case MINUS: - case BIT_AND: - case DOLLAR_ID: ; break; default: - jj_la1[1] = jj_gen; + jj_la1[5] = jj_gen; break label_2; } BlockStatement(); } } - static final public void ClassDeclaration() throws ParseException { - PHPClassDeclaration classDeclaration; - Token className; - int pos = jj_input_stream.bufpos; - jj_consume_token(CLASS); - className = jj_consume_token(IDENTIFIER); + static final public ClassDeclaration ClassDeclaration() throws ParseException { + final ClassDeclaration classDeclaration; + Token className = null; + final Token superclassName, token, extendsToken; + String classNameImage = SYNTAX_ERROR_CHAR; + String superclassNameImage = null; + final int classEnd; + token = jj_consume_token(CLASS); + try { + className = jj_consume_token(IDENTIFIER); + classNameImage = className.image; + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected"; + errorLevel = ERROR; + errorStart = token.sourceEnd+1; + errorEnd = token.sourceEnd+1; + processParseExceptionDebug(e); + } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case EXTENDS: - jj_consume_token(EXTENDS); - jj_consume_token(IDENTIFIER); + extendsToken = jj_consume_token(EXTENDS); + try { + superclassName = jj_consume_token(IDENTIFIER); + superclassNameImage = superclassName.image; + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected"; + errorLevel = ERROR; + errorStart = extendsToken.sourceEnd+1; + errorEnd = extendsToken.sourceEnd+1; + processParseExceptionDebug(e); + superclassNameImage = SYNTAX_ERROR_CHAR; + } break; default: - jj_la1[2] = jj_gen; + jj_la1[6] = jj_gen; ; } - classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos); - currentSegment.add(classDeclaration); - currentSegment = classDeclaration; - ClassBody(); - currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); + int start, end; + if (className == null) { + start = token.sourceStart; + end = token.sourceEnd; + } else { + start = className.sourceStart; + end = className.sourceEnd; + } + if (superclassNameImage == null) { + + classDeclaration = new ClassDeclaration(currentSegment, + classNameImage, + start, + end); + } else { + classDeclaration = new ClassDeclaration(currentSegment, + classNameImage, + superclassNameImage, + start, + end); + } + currentSegment.add(classDeclaration); + currentSegment = classDeclaration; + classEnd = ClassBody(classDeclaration); + currentSegment = (OutlineableWithChildren) currentSegment.getParent(); + classDeclaration.sourceEnd = classEnd; + pushOnAstNodes(classDeclaration); + {if (true) return classDeclaration;} + throw new Error("Missing return statement in function"); } - static final public void ClassBody() throws ParseException { + static final public int ClassBody(final ClassDeclaration classDeclaration) throws ParseException { +Token token; try { jj_consume_token(LBRACE); } catch (ParseException e) { - errorMessage = "'{' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected"; errorLevel = ERROR; - {if (true) throw e;} + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseExceptionDebug(e); } label_3: while (true) { @@ -331,40 +698,64 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants ; break; default: - jj_la1[3] = jj_gen; + jj_la1[7] = jj_gen; break label_3; } - ClassBodyDeclaration(); + ClassBodyDeclaration(classDeclaration); } try { - jj_consume_token(RBRACE); + token = jj_consume_token(RBRACE); + {if (true) return token.sourceEnd;} } catch (ParseException e) { - errorMessage = "'var', 'function' or '}' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected"; errorLevel = ERROR; - {if (true) throw e;} + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseExceptionDebug(e); + {if (true) return PHPParser.token.sourceEnd;} } + throw new Error("Missing return statement in function"); } - static final public void ClassBodyDeclaration() throws ParseException { +/** + * A class can contain only methods and fields. + */ + static final public void ClassBodyDeclaration(final ClassDeclaration classDeclaration) throws ParseException { + final MethodDeclaration method; + final FieldDeclaration field; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case FUNCTION: - MethodDeclaration(); + method = MethodDeclaration(); + method.analyzeCode(); + classDeclaration.addMethod(method); break; case VAR: - FieldDeclaration(); + field = FieldDeclaration(); + classDeclaration.addField(field); break; default: - jj_la1[4] = jj_gen; + jj_la1[8] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } - static final public void FieldDeclaration() throws ParseException { - PHPVarDeclaration variableDeclaration; - jj_consume_token(VAR); - variableDeclaration = VariableDeclarator(); - currentSegment.add(variableDeclaration); +/** + * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;. + * it is only used by ClassBodyDeclaration() + */ + static final public FieldDeclaration FieldDeclaration() throws ParseException { + VariableDeclaration variableDeclaration; + final VariableDeclaration[] list; + final ArrayList arrayList = new ArrayList(); + final Token token; + Token token2 = null; + int pos; + token = jj_consume_token(VAR); + variableDeclaration = VariableDeclaratorNoSuffix(); + arrayList.add(variableDeclaration); + outlineInfo.addVariable(variableDeclaration.name()); + pos = variableDeclaration.sourceEnd; label_4: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -372,55 +763,144 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants ; break; default: - jj_la1[5] = jj_gen; + jj_la1[9] = jj_gen; break label_4; } jj_consume_token(COMMA); - variableDeclaration = VariableDeclarator(); - currentSegment.add(variableDeclaration); + variableDeclaration = VariableDeclaratorNoSuffix(); + arrayList.add(variableDeclaration); + outlineInfo.addVariable(variableDeclaration.name()); + pos = variableDeclaration.sourceEnd; } try { - jj_consume_token(SEMICOLON); + token2 = jj_consume_token(SEMICOLON); } catch (ParseException e) { - errorMessage = "';' expected after variable declaration"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration"; errorLevel = ERROR; - {if (true) throw e;} - } + errorStart = pos+1; + errorEnd = pos+1; + processParseExceptionDebug(e); + } + list = new VariableDeclaration[arrayList.size()]; + arrayList.toArray(list); + int end; + if (token2 == null) { + end = list[list.length-1].sourceEnd; + } else { + end = token2.sourceEnd; + } + {if (true) return new FieldDeclaration(list, + token.sourceStart, + end, + currentSegment);} + throw new Error("Missing return statement in function"); } - static final public PHPVarDeclaration VariableDeclarator() throws ParseException { - String varName; - String varValue = null; - int pos = jj_input_stream.bufpos; - varName = VariableDeclaratorId(); +/** + * a strict variable declarator : there cannot be a suffix here. + * It will be used by fields and formal parameters + */ + static final public VariableDeclaration VariableDeclaratorNoSuffix() throws ParseException { + final Token token, lbrace,rbrace; + Expression expr, initializer = null; + Token assignToken; + Variable variable; + jj_consume_token(DOLLAR); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + token = jj_consume_token(IDENTIFIER); + variable = new Variable(token.image,token.sourceStart,token.sourceEnd); + break; + case LBRACE: + lbrace = jj_consume_token(LBRACE); + expr = Expression(); + rbrace = jj_consume_token(RBRACE); + variable = new Variable(expr,lbrace.sourceStart,rbrace.sourceEnd); + break; + default: + jj_la1[10] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ASSIGN: - jj_consume_token(ASSIGN); + assignToken = jj_consume_token(ASSIGN); try { - varValue = VariableInitializer(); + initializer = VariableInitializer(); } catch (ParseException e) { errorMessage = "Literal expression expected in variable initializer"; errorLevel = ERROR; - {if (true) throw e;} + errorStart = assignToken.sourceEnd +1; + errorEnd = assignToken.sourceEnd +1; + processParseExceptionDebug(e); } break; default: - jj_la1[6] = jj_gen; + jj_la1[11] = jj_gen; ; } - if (varValue == null) { - {if (true) return new PHPVarDeclaration(currentSegment,varName,pos);} + if (initializer == null) { + {if (true) return new VariableDeclaration(currentSegment, + variable, + variable.sourceStart, + variable.sourceEnd);} + } + {if (true) return new VariableDeclaration(currentSegment, + variable, + initializer, + VariableDeclaration.EQUAL, + variable.sourceStart);} + throw new Error("Missing return statement in function"); + } + +/** + * this will be used by static statement + */ + static final public VariableDeclaration VariableDeclarator() throws ParseException { + final AbstractVariable variable; + Expression initializer = null; + final Token token; + variable = VariableDeclaratorId(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ASSIGN: + token = jj_consume_token(ASSIGN); + try { + initializer = VariableInitializer(); + } catch (ParseException e) { + errorMessage = "Literal expression expected in variable initializer"; + errorLevel = ERROR; + errorStart = token.sourceEnd+1; + errorEnd = token.sourceEnd+1; + processParseExceptionDebug(e); + } + break; + default: + jj_la1[12] = jj_gen; + ; } - {if (true) return new PHPVarDeclaration(currentSegment,varName,pos,varValue);} + if (initializer == null) { + {if (true) return new VariableDeclaration(currentSegment, + variable, + variable.sourceStart, + variable.sourceEnd);} + } + {if (true) return new VariableDeclaration(currentSegment, + variable, + initializer, + VariableDeclaration.EQUAL, + variable.sourceStart);} throw new Error("Missing return statement in function"); } - static final public String VariableDeclaratorId() throws ParseException { - String expr; - StringBuffer buff = new StringBuffer(); +/** + * A Variable name. + * @return the variable name (with suffix) + */ + static final public AbstractVariable VariableDeclaratorId() throws ParseException { + final Variable var; + AbstractVariable expression = null; try { - expr = Variable(); - buff.append(expr); + var = Variable(); label_5: while (true) { if (jj_2_1(2)) { @@ -428,180 +908,174 @@ public class PHPParser extends PHPParserSuperclass implements PHPParserConstants } else { break label_5; } - expr = VariableSuffix(); - buff.append(expr); + expression = VariableSuffix(var); } - {if (true) return buff.toString();} + if (expression == null) { + {if (true) return var;} + } + {if (true) return expression;} } catch (ParseException e) { errorMessage = "'$' expected for variable identifier"; errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; {if (true) throw e;} } throw new Error("Missing return statement in function"); } - static final public String Variable() throws ParseException { - String expr = null; - Token token; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case DOLLAR_ID: - token = jj_consume_token(DOLLAR_ID); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACE: - jj_consume_token(LBRACE); - expr = Expression(); - jj_consume_token(RBRACE); - break; - default: - jj_la1[7] = jj_gen; - ; - } - if (expr == null) { - {if (true) return token.image;} - } - {if (true) return token + "{" + expr + "}";} - break; - case DOLLAR: - jj_consume_token(DOLLAR); - expr = VariableName(); - {if (true) return "$" + expr;} - break; - default: - jj_la1[8] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + static final public Variable Variable() throws ParseException { + Variable variable = null; + final Token token; + token = jj_consume_token(DOLLAR); + variable = Var(); + {if (true) return variable;} throw new Error("Missing return statement in function"); } - static final public String VariableName() throws ParseException { -String expr = null; -Token token; + static final public Variable Var() throws ParseException { + Variable variable = null; + final Token token,token2; + ConstantIdentifier constant; + Expression expression; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case DOLLAR: + token = jj_consume_token(DOLLAR); + variable = Var(); + {if (true) return new Variable(variable,variable.sourceStart,variable.sourceEnd);} + break; case LBRACE: - jj_consume_token(LBRACE); - expr = Expression(); - jj_consume_token(RBRACE); - {if (true) return "{"+expr+"}";} + token = jj_consume_token(LBRACE); + expression = Expression(); + token2 = jj_consume_token(RBRACE); + {if (true) return new Variable(expression, + token.sourceStart, + token2.sourceEnd);} break; case IDENTIFIER: token = jj_consume_token(IDENTIFIER); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LBRACE: - jj_consume_token(LBRACE); - expr = Expression(); - jj_consume_token(RBRACE); - break; - default: - jj_la1[9] = jj_gen; - ; - } - if (expr == null) { - {if (true) return token.image;} - } - {if (true) return token + "{" + expr + "}";} - break; - case DOLLAR: - jj_consume_token(DOLLAR); - expr = VariableName(); - {if (true) return "$" + expr;} - break; - case DOLLAR_ID: - token = jj_consume_token(DOLLAR_ID); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - case LBRACE: - case DOLLAR: - case DOLLAR_ID: - expr = VariableName(); - break; - default: - jj_la1[10] = jj_gen; - ; - } - if (expr == null) { - {if (true) return token.image;} - } - {if (true) return token.image + expr;} + {if (true) return new Variable(token.image,token.sourceStart,token.sourceEnd);} break; default: - jj_la1[11] = jj_gen; + jj_la1[13] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String VariableInitializer() throws ParseException { - String expr; + static final public Expression VariableInitializer() throws ParseException { + final Expression expr; + final Token token, token2; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case FALSE: case NULL: case TRUE: + case FALSE: case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case STRING_LITERAL: + case DOUBLEQUOTE: expr = Literal(); {if (true) return expr;} break; + case MINUS: + token2 = jj_consume_token(MINUS); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + token = jj_consume_token(INTEGER_LITERAL); + break; + case FLOATING_POINT_LITERAL: + token = jj_consume_token(FLOATING_POINT_LITERAL); + break; + default: + jj_la1[14] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + {if (true) return new PrefixedUnaryExpression(new NumberLiteral(token), + OperatorIds.MINUS, + token2.sourceStart);} + break; + case PLUS: + token2 = jj_consume_token(PLUS); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + token = jj_consume_token(INTEGER_LITERAL); + break; + case FLOATING_POINT_LITERAL: + token = jj_consume_token(FLOATING_POINT_LITERAL); + break; + default: + jj_la1[15] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + {if (true) return new PrefixedUnaryExpression(new NumberLiteral(token), + OperatorIds.PLUS, + token2.sourceStart);} + break; case ARRAY: expr = ArrayDeclarator(); {if (true) return expr;} break; + case IDENTIFIER: + token = jj_consume_token(IDENTIFIER); + {if (true) return new ConstantIdentifier(token);} + break; default: - jj_la1[12] = jj_gen; + jj_la1[16] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String ArrayVariable() throws ParseException { -String expr; -StringBuffer buff = new StringBuffer(); + static final public ArrayVariableDeclaration ArrayVariable() throws ParseException { +final Expression expr,expr2; expr = Expression(); - buff.append(expr); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ARRAYASSIGN: jj_consume_token(ARRAYASSIGN); - expr = Expression(); - buff.append("=>").append(expr); + expr2 = Expression(); + {if (true) return new ArrayVariableDeclaration(expr,expr2);} break; default: - jj_la1[13] = jj_gen; + jj_la1[17] = jj_gen; ; } - {if (true) return buff.toString();} + {if (true) return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());} throw new Error("Missing return statement in function"); } - static final public String ArrayInitializer() throws ParseException { -String expr = null; -StringBuffer buff = new StringBuffer("("); + static final public ArrayVariableDeclaration[] ArrayInitializer() throws ParseException { + ArrayVariableDeclaration expr; + final ArrayList list = new ArrayList(); jj_consume_token(LPAREN); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ARRAY: + case LIST: case PRINT: - case FALSE: case NEW: case NULL: case TRUE: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: + case FALSE: case AT: - case DOLLAR: case BANG: - case INCR: - case DECR: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: case PLUS: case MINUS: case BIT_AND: - case DOLLAR_ID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: expr = ArrayVariable(); - buff.append(expr); + list.add(expr); label_6: while (true) { if (jj_2_2(2)) { @@ -611,67 +1085,138 @@ StringBuffer buff = new StringBuffer("("); } jj_consume_token(COMMA); expr = ArrayVariable(); - buff.append(",").append(expr); + list.add(expr); } break; default: - jj_la1[14] = jj_gen; + jj_la1[18] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + jj_consume_token(COMMA); + list.add(null); + break; + default: + jj_la1[19] = jj_gen; ; } jj_consume_token(RPAREN); - buff.append(")"); - {if (true) return buff.toString();} + final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()]; + list.toArray(vars); + {if (true) return vars;} throw new Error("Missing return statement in function"); } - static final public void MethodDeclaration() throws ParseException { - PHPFunctionDeclaration functionDeclaration; - jj_consume_token(FUNCTION); - functionDeclaration = MethodDeclarator(); - currentSegment.add(functionDeclaration); - currentSegment = functionDeclaration; - Block(); - currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); +/** + * A Method Declaration. + * function MetodDeclarator() Block() + */ + static final public MethodDeclaration MethodDeclaration() throws ParseException { + final MethodDeclaration functionDeclaration; + final Block block; + final OutlineableWithChildren seg = currentSegment; + final Token token; + token = jj_consume_token(FUNCTION); + try { + functionDeclaration = MethodDeclarator(token.sourceStart); + outlineInfo.addVariable(functionDeclaration.name); + } catch (ParseException e) { + if (errorMessage != null) {if (true) throw e;} + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + {if (true) throw e;} + } + currentSegment = functionDeclaration; + block = Block(); + functionDeclaration.statements = block.statements; + currentSegment = seg; + {if (true) return functionDeclaration;} + throw new Error("Missing return statement in function"); } - static final public PHPFunctionDeclaration MethodDeclarator() throws ParseException { - Token identifier; - StringBuffer methodDeclaration = new StringBuffer(); - String formalParameters; - int pos = jj_input_stream.bufpos; +/** + * A MethodDeclarator. + * [&] IDENTIFIER(parameters ...). + * @return a function description for the outline + */ + static final public MethodDeclaration MethodDeclarator(final int start) throws ParseException { + Token identifier = null; + Token reference = null; + final Hashtable formalParameters = new Hashtable(); + String identifierChar = SYNTAX_ERROR_CHAR; + int end = start; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BIT_AND: - jj_consume_token(BIT_AND); - methodDeclaration.append("&"); + reference = jj_consume_token(BIT_AND); + end = reference.sourceEnd; break; default: - jj_la1[15] = jj_gen; + jj_la1[20] = jj_gen; ; } - identifier = jj_consume_token(IDENTIFIER); - methodDeclaration.append(identifier); - formalParameters = FormalParameters(); - methodDeclaration.append(formalParameters); - {if (true) return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);} + try { + identifier = jj_consume_token(IDENTIFIER); + identifierChar = identifier.image; + end = identifier.sourceEnd; + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected"; + errorLevel = ERROR; + errorStart = e.currentToken.sourceEnd; + errorEnd = e.currentToken.next.sourceStart; + processParseExceptionDebug(e); + } + end = FormalParameters(formalParameters); + int nameStart, nameEnd; + if (identifier == null) { + if (reference == null) { + nameStart = start + 9; + nameEnd = start + 10; + } else { + nameStart = reference.sourceEnd + 1; + nameEnd = reference.sourceEnd + 2; + } + } else { + nameStart = identifier.sourceStart; + nameEnd = identifier.sourceEnd; + } + {if (true) return new MethodDeclaration(currentSegment, + identifierChar, + formalParameters, + reference != null, + nameStart, + nameEnd, + start, + end);} throw new Error("Missing return statement in function"); } - static final public String FormalParameters() throws ParseException { - String expr; - final StringBuffer buff = new StringBuffer("("); +/** + * FormalParameters follows method identifier. + * (FormalParameter()) + */ + static final public int FormalParameters(final Hashtable parameters) throws ParseException { + VariableDeclaration var; + final Token token; + Token tok = PHPParser.token; + int end = tok.sourceEnd; try { - jj_consume_token(LPAREN); + tok = jj_consume_token(LPAREN); + end = tok.sourceEnd; } catch (ParseException e) { - errorMessage = "Formal parameter expected after function identifier"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier"; errorLevel = ERROR; - jj_consume_token(token.kind); + errorStart = e.currentToken.next.sourceStart; + errorEnd = e.currentToken.next.sourceEnd; + processParseExceptionDebug(e); } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case DOLLAR: case BIT_AND: - case DOLLAR_ID: - expr = FormalParameter(); - buff.append(expr); + case DOLLAR: + var = FormalParameter(); + parameters.put(var.name(),var);end = var.sourceEnd; label_7: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -679,118 +1224,127 @@ StringBuffer buff = new StringBuffer("("); ; break; default: - jj_la1[16] = jj_gen; + jj_la1[21] = jj_gen; break label_7; } jj_consume_token(COMMA); - expr = FormalParameter(); - buff.append(",").append(expr); + var = FormalParameter(); + parameters.put(var.name(),var);end = var.sourceEnd; } break; default: - jj_la1[17] = jj_gen; + jj_la1[22] = jj_gen; ; } try { - jj_consume_token(RPAREN); + token = jj_consume_token(RPAREN); + end = token.sourceEnd; } catch (ParseException e) { errorMessage = "')' expected"; errorLevel = ERROR; - {if (true) throw e;} + errorStart = e.currentToken.next.sourceStart; + errorEnd = e.currentToken.next.sourceEnd; + processParseExceptionDebug(e); } - buff.append(")"); - {if (true) return buff.toString();} + {if (true) return end;} throw new Error("Missing return statement in function"); } - static final public String FormalParameter() throws ParseException { - PHPVarDeclaration variableDeclaration; - StringBuffer buff = new StringBuffer(); +/** + * A formal parameter. + * $varname[=value] (,$varname[=value]) + */ + static final public VariableDeclaration FormalParameter() throws ParseException { + final VariableDeclaration variableDeclaration; + Token token = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BIT_AND: - jj_consume_token(BIT_AND); - buff.append("&"); + token = jj_consume_token(BIT_AND); break; default: - jj_la1[18] = jj_gen; + jj_la1[23] = jj_gen; ; } - variableDeclaration = VariableDeclarator(); - buff.append(variableDeclaration.toString()); - {if (true) return buff.toString();} + variableDeclaration = VariableDeclaratorNoSuffix(); + if (token != null) { + variableDeclaration.setReference(true); + } + {if (true) return variableDeclaration;} throw new Error("Missing return statement in function"); } - static final public String Type() throws ParseException { + static final public ConstantIdentifier Type() throws ParseException { + final Token token; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: - jj_consume_token(STRING); - {if (true) return "string";} + token = jj_consume_token(STRING); + {if (true) return new ConstantIdentifier(token);} break; case BOOL: - jj_consume_token(BOOL); - {if (true) return "bool";} + token = jj_consume_token(BOOL); + {if (true) return new ConstantIdentifier(token);} break; case BOOLEAN: - jj_consume_token(BOOLEAN); - {if (true) return "boolean";} + token = jj_consume_token(BOOLEAN); + {if (true) return new ConstantIdentifier(token);} break; case REAL: - jj_consume_token(REAL); - {if (true) return "real";} + token = jj_consume_token(REAL); + {if (true) return new ConstantIdentifier(token);} break; case DOUBLE: - jj_consume_token(DOUBLE); - {if (true) return "double";} + token = jj_consume_token(DOUBLE); + {if (true) return new ConstantIdentifier(token);} break; case FLOAT: - jj_consume_token(FLOAT); - {if (true) return "float";} + token = jj_consume_token(FLOAT); + {if (true) return new ConstantIdentifier(token);} break; case INT: - jj_consume_token(INT); - {if (true) return "int";} + token = jj_consume_token(INT); + {if (true) return new ConstantIdentifier(token);} break; case INTEGER: - jj_consume_token(INTEGER); - {if (true) return "integer";} + token = jj_consume_token(INTEGER); + {if (true) return new ConstantIdentifier(token);} + break; + case OBJECT: + token = jj_consume_token(OBJECT); + {if (true) return new ConstantIdentifier(token);} break; default: - jj_la1[19] = jj_gen; + jj_la1[24] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String Expression() throws ParseException { - String expr; - String assignOperator = null; - String expr2 = null; + static final public Expression Expression() throws ParseException { + final Expression expr; + Expression initializer = null; + int assignOperator = -1; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case PRINT: - expr = PrintExpression(); - {if (true) return expr;} - break; case ARRAY: - case FALSE: case NEW: case NULL: case TRUE: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: + case FALSE: case AT: - case DOLLAR: case BANG: - case INCR: - case DECR: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: case PLUS: case MINUS: case BIT_AND: - case DOLLAR_ID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: expr = ConditionalExpression(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ASSIGN: @@ -803,102 +1357,168 @@ StringBuffer buff = new StringBuffer("("); case XORASSIGN: case DOTASSIGN: case REMASSIGN: + case TILDEEQUAL: case LSHIFTASSIGN: case RSIGNEDSHIFTASSIGN: - case RUNSIGNEDSHIFTASSIGN: assignOperator = AssignmentOperator(); try { - expr2 = Expression(); + initializer = Expression(); } catch (ParseException e) { - errorMessage = "expression expected"; + if (errorMessage != null) { + {if (true) throw e;} + } + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; errorLevel = ERROR; - {if (true) throw generateParseException();} + errorEnd = SimpleCharStream.getPosition(); + {if (true) throw e;} } break; default: - jj_la1[20] = jj_gen; + jj_la1[25] = jj_gen; ; } - if (expr2 == null) { - {if (true) return expr;} - } else { - {if (true) return expr + assignOperator + expr2;} + if (assignOperator != -1) {// todo : change this, very very bad :( + if (expr instanceof AbstractVariable) { + {if (true) return new VariableDeclaration(currentSegment, + (AbstractVariable) expr, + initializer, + expr.sourceStart, + initializer.sourceEnd);} + } + String varName = expr.toStringExpression().substring(1); + {if (true) return new VariableDeclaration(currentSegment, + new Variable(varName, + expr.sourceStart, + expr.sourceEnd), + expr.sourceStart, + initializer.sourceEnd);} } + {if (true) return expr;} + break; + case LIST: + case PRINT: + expr = ExpressionWBang(); + {if (true) return expr;} break; default: - jj_la1[21] = jj_gen; + jj_la1[26] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String AssignmentOperator() throws ParseException { + static final public Expression ExpressionWBang() throws ParseException { + final Expression expr; + final Token token; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BANG: + token = jj_consume_token(BANG); + expr = ExpressionWBang(); + {if (true) return new PrefixedUnaryExpression(expr,OperatorIds.NOT,token.sourceStart);} + break; + case LIST: + case PRINT: + expr = ExpressionNoBang(); + {if (true) return expr;} + break; + default: + jj_la1[27] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); + } + + static final public Expression ExpressionNoBang() throws ParseException { + Expression expr; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LIST: + expr = ListExpression(); + {if (true) return expr;} + break; + case PRINT: + expr = PrintExpression(); + {if (true) return expr;} + break; + default: + jj_la1[28] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); + } + +/** + * Any assignement operator. + * @return the assignement operator id + */ + static final public int AssignmentOperator() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ASSIGN: jj_consume_token(ASSIGN); - {if (true) return "=";} + {if (true) return VariableDeclaration.EQUAL;} break; case STARASSIGN: jj_consume_token(STARASSIGN); - {if (true) return "*=";} + {if (true) return VariableDeclaration.STAR_EQUAL;} break; case SLASHASSIGN: jj_consume_token(SLASHASSIGN); - {if (true) return "/=";} + {if (true) return VariableDeclaration.SLASH_EQUAL;} break; case REMASSIGN: jj_consume_token(REMASSIGN); - {if (true) return "%=";} + {if (true) return VariableDeclaration.REM_EQUAL;} break; case PLUSASSIGN: jj_consume_token(PLUSASSIGN); - {if (true) return "+=";} + {if (true) return VariableDeclaration.PLUS_EQUAL;} break; case MINUSASSIGN: jj_consume_token(MINUSASSIGN); - {if (true) return "-=";} + {if (true) return VariableDeclaration.MINUS_EQUAL;} break; case LSHIFTASSIGN: jj_consume_token(LSHIFTASSIGN); - {if (true) return "<<=";} + {if (true) return VariableDeclaration.LSHIFT_EQUAL;} break; case RSIGNEDSHIFTASSIGN: jj_consume_token(RSIGNEDSHIFTASSIGN); - {if (true) return ">>=";} - break; - case RUNSIGNEDSHIFTASSIGN: - jj_consume_token(RUNSIGNEDSHIFTASSIGN); - {if (true) return ">>>=";} + {if (true) return VariableDeclaration.RSIGNEDSHIFT_EQUAL;} break; case ANDASSIGN: jj_consume_token(ANDASSIGN); - {if (true) return "&=";} + {if (true) return VariableDeclaration.AND_EQUAL;} break; case XORASSIGN: jj_consume_token(XORASSIGN); - {if (true) return "|=";} + {if (true) return VariableDeclaration.XOR_EQUAL;} break; case ORASSIGN: jj_consume_token(ORASSIGN); - {if (true) return "|=";} + {if (true) return VariableDeclaration.OR_EQUAL;} break; case DOTASSIGN: jj_consume_token(DOTASSIGN); - {if (true) return ".=";} + {if (true) return VariableDeclaration.DOT_EQUAL;} + break; + case TILDEEQUAL: + jj_consume_token(TILDEEQUAL); + {if (true) return VariableDeclaration.TILDE_EQUAL;} break; default: - jj_la1[22] = jj_gen; + jj_la1[29] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String ConditionalExpression() throws ParseException { - String expr; - String expr2 = null; - String expr3 = null; + static final public Expression ConditionalExpression() throws ParseException { + final Expression expr; + Expression expr2 = null; + Expression expr3 = null; expr = ConditionalOrExpression(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case HOOK: @@ -908,99 +1528,91 @@ StringBuffer buff = new StringBuffer("("); expr3 = ConditionalExpression(); break; default: - jj_la1[23] = jj_gen; + jj_la1[30] = jj_gen; ; } if (expr3 == null) { {if (true) return expr;} - } else { - {if (true) return expr + "?" + expr2 + ":" + expr3;} } + {if (true) return new ConditionalExpression(expr,expr2,expr3);} throw new Error("Missing return statement in function"); } - static final public String ConditionalOrExpression() throws ParseException { - String expr; - Token operator; - String expr2 = null; - StringBuffer buff = new StringBuffer(); + static final public Expression ConditionalOrExpression() throws ParseException { + Expression expr,expr2; + int operator; expr = ConditionalAndExpression(); - buff.append(expr); label_8: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case OR_OR: case _ORL: - case SC_OR: ; break; default: - jj_la1[24] = jj_gen; + jj_la1[31] = jj_gen; break label_8; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SC_OR: - operator = jj_consume_token(SC_OR); + case OR_OR: + jj_consume_token(OR_OR); + operator = OperatorIds.OR_OR; break; case _ORL: - operator = jj_consume_token(_ORL); + jj_consume_token(_ORL); + operator = OperatorIds.ORL; break; default: - jj_la1[25] = jj_gen; + jj_la1[32] = jj_gen; jj_consume_token(-1); throw new ParseException(); } expr2 = ConditionalAndExpression(); - buff.append(operator.image); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,operator); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String ConditionalAndExpression() throws ParseException { - String expr; - Token operator; - String expr2 = null; - StringBuffer buff = new StringBuffer(); + static final public Expression ConditionalAndExpression() throws ParseException { + Expression expr,expr2; + int operator; expr = ConcatExpression(); - buff.append(expr); label_9: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case AND_AND: case _ANDL: - case SC_AND: ; break; default: - jj_la1[26] = jj_gen; + jj_la1[33] = jj_gen; break label_9; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SC_AND: - operator = jj_consume_token(SC_AND); + case AND_AND: + jj_consume_token(AND_AND); + operator = OperatorIds.AND_AND; break; case _ANDL: - operator = jj_consume_token(_ANDL); + jj_consume_token(_ANDL); + operator = OperatorIds.ANDL; break; default: - jj_la1[27] = jj_gen; + jj_la1[34] = jj_gen; jj_consume_token(-1); throw new ParseException(); } expr2 = ConcatExpression(); - buff.append(operator.image); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,operator); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String ConcatExpression() throws ParseException { - String expr; - String expr2 = null; - StringBuffer buff = new StringBuffer(); + static final public Expression ConcatExpression() throws ParseException { + Expression expr,expr2; expr = InclusiveOrExpression(); - buff.append(expr); label_10: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1008,24 +1620,20 @@ StringBuffer buff = new StringBuffer("("); ; break; default: - jj_la1[28] = jj_gen; + jj_la1[35] = jj_gen; break label_10; } jj_consume_token(DOT); expr2 = InclusiveOrExpression(); - buff.append("."); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,OperatorIds.DOT); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String InclusiveOrExpression() throws ParseException { - String expr; - String expr2 = null; - StringBuffer buff = new StringBuffer(); + static final public Expression InclusiveOrExpression() throws ParseException { + Expression expr,expr2; expr = ExclusiveOrExpression(); - buff.append(expr); label_11: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1033,24 +1641,20 @@ StringBuffer buff = new StringBuffer("("); ; break; default: - jj_la1[29] = jj_gen; + jj_la1[36] = jj_gen; break label_11; } jj_consume_token(BIT_OR); expr2 = ExclusiveOrExpression(); - buff.append("|"); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,OperatorIds.OR); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String ExclusiveOrExpression() throws ParseException { - String expr; - String expr2 = null; - StringBuffer buff = new StringBuffer(); + static final public Expression ExclusiveOrExpression() throws ParseException { + Expression expr,expr2; expr = AndExpression(); - buff.append(expr); label_12: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1058,24 +1662,20 @@ StringBuffer buff = new StringBuffer("("); ; break; default: - jj_la1[30] = jj_gen; + jj_la1[37] = jj_gen; break label_12; } jj_consume_token(XOR); expr2 = AndExpression(); - buff.append("^"); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,OperatorIds.XOR); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String AndExpression() throws ParseException { - String expr; - String expr2 = null; - StringBuffer buff = new StringBuffer(); + static final public Expression AndExpression() throws ParseException { + Expression expr,expr2; expr = EqualityExpression(); - buff.append(expr); label_13: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1083,63 +1683,85 @@ StringBuffer buff = new StringBuffer("("); ; break; default: - jj_la1[31] = jj_gen; + jj_la1[38] = jj_gen; break label_13; } jj_consume_token(BIT_AND); expr2 = EqualityExpression(); - buff.append("&"); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,OperatorIds.AND); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String EqualityExpression() throws ParseException { - String expr; - Token operator; - String expr2; - StringBuffer buff = new StringBuffer(); + static final public Expression EqualityExpression() throws ParseException { + Expression expr,expr2; + int operator; + Token token; expr = RelationalExpression(); - buff.append(expr); label_14: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EQ: - case NE: + case EQUAL_EQUAL: + case NOT_EQUAL: + case DIF: + case BANGDOUBLEEQUAL: + case TRIPLEEQUAL: ; break; default: - jj_la1[32] = jj_gen; + jj_la1[39] = jj_gen; break label_14; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EQ: - operator = jj_consume_token(EQ); + case EQUAL_EQUAL: + token = jj_consume_token(EQUAL_EQUAL); + operator = OperatorIds.EQUAL_EQUAL; + break; + case DIF: + token = jj_consume_token(DIF); + operator = OperatorIds.DIF; break; - case NE: - operator = jj_consume_token(NE); + case NOT_EQUAL: + token = jj_consume_token(NOT_EQUAL); + operator = OperatorIds.DIF; + break; + case BANGDOUBLEEQUAL: + token = jj_consume_token(BANGDOUBLEEQUAL); + operator = OperatorIds.BANG_EQUAL_EQUAL; + break; + case TRIPLEEQUAL: + token = jj_consume_token(TRIPLEEQUAL); + operator = OperatorIds.EQUAL_EQUAL_EQUAL; break; default: - jj_la1[33] = jj_gen; + jj_la1[40] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - expr2 = RelationalExpression(); - buff.append(operator.image); - buff.append(expr2); + try { + expr2 = RelationalExpression(); + } catch (ParseException e) { + if (errorMessage != null) { + {if (true) throw e;} } - {if (true) return buff.toString();} + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; + errorLevel = ERROR; + errorStart = token.sourceEnd +1; + errorEnd = token.sourceEnd +1; + expr2 = new ConstantIdentifier(SYNTAX_ERROR_CHAR,token.sourceEnd +1,token.sourceEnd +1); + processParseExceptionDebug(e); + } + expr = new BinaryExpression(expr,expr2,operator); + } + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String RelationalExpression() throws ParseException { - String expr; - Token operator; - String expr2; - StringBuffer buff = new StringBuffer(); + static final public Expression RelationalExpression() throws ParseException { + Expression expr,expr2; + int operator; expr = ShiftExpression(); - buff.append(expr); label_15: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1150,42 +1772,42 @@ StringBuffer buff = new StringBuffer("("); ; break; default: - jj_la1[34] = jj_gen; + jj_la1[41] = jj_gen; break label_15; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LT: - operator = jj_consume_token(LT); + jj_consume_token(LT); + operator = OperatorIds.LESS; break; case GT: - operator = jj_consume_token(GT); + jj_consume_token(GT); + operator = OperatorIds.GREATER; break; case LE: - operator = jj_consume_token(LE); + jj_consume_token(LE); + operator = OperatorIds.LESS_EQUAL; break; case GE: - operator = jj_consume_token(GE); + jj_consume_token(GE); + operator = OperatorIds.GREATER_EQUAL; break; default: - jj_la1[35] = jj_gen; + jj_la1[42] = jj_gen; jj_consume_token(-1); throw new ParseException(); } expr2 = ShiftExpression(); - buff.append(operator.image); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,operator); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String ShiftExpression() throws ParseException { - String expr; - Token operator; - String expr2; - StringBuffer buff = new StringBuffer(); + static final public Expression ShiftExpression() throws ParseException { + Expression expr,expr2; + int operator; expr = AdditiveExpression(); - buff.append(expr); label_16: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1195,39 +1817,38 @@ StringBuffer buff = new StringBuffer("("); ; break; default: - jj_la1[36] = jj_gen; + jj_la1[43] = jj_gen; break label_16; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LSHIFT: - operator = jj_consume_token(LSHIFT); + jj_consume_token(LSHIFT); + operator = OperatorIds.LEFT_SHIFT; break; case RSIGNEDSHIFT: - operator = jj_consume_token(RSIGNEDSHIFT); + jj_consume_token(RSIGNEDSHIFT); + operator = OperatorIds.RIGHT_SHIFT; break; case RUNSIGNEDSHIFT: - operator = jj_consume_token(RUNSIGNEDSHIFT); + jj_consume_token(RUNSIGNEDSHIFT); + operator = OperatorIds.UNSIGNED_RIGHT_SHIFT; break; default: - jj_la1[37] = jj_gen; + jj_la1[44] = jj_gen; jj_consume_token(-1); throw new ParseException(); } expr2 = AdditiveExpression(); - buff.append(operator.image); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,operator); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String AdditiveExpression() throws ParseException { - String expr; - Token operator; - String expr2; - StringBuffer buff = new StringBuffer(); + static final public Expression AdditiveExpression() throws ParseException { + Expression expr,expr2; + int operator; expr = MultiplicativeExpression(); - buff.append(expr); label_17: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1236,556 +1857,932 @@ StringBuffer buff = new StringBuffer("("); ; break; default: - jj_la1[38] = jj_gen; + jj_la1[45] = jj_gen; break label_17; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case PLUS: - operator = jj_consume_token(PLUS); + jj_consume_token(PLUS); + operator = OperatorIds.PLUS; break; case MINUS: - operator = jj_consume_token(MINUS); + jj_consume_token(MINUS); + operator = OperatorIds.MINUS; break; default: - jj_la1[39] = jj_gen; + jj_la1[46] = jj_gen; jj_consume_token(-1); throw new ParseException(); } expr2 = MultiplicativeExpression(); - buff.append(operator.image); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,operator); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String MultiplicativeExpression() throws ParseException { - String expr, expr2; - Token operator; - final StringBuffer buff = new StringBuffer(); - expr = UnaryExpression(); - buff.append(expr); + static final public Expression MultiplicativeExpression() throws ParseException { + Expression expr,expr2; + int operator; + try { + expr = UnaryExpression(); + } catch (ParseException e) { + if (errorMessage != null) {if (true) throw e;} + errorMessage = "unexpected token '"+e.currentToken.next.image+"'"; + errorLevel = ERROR; + errorStart = PHPParser.token.sourceStart; + errorEnd = PHPParser.token.sourceEnd; + {if (true) throw e;} + } label_18: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STAR: case SLASH: - case REM: + case REMAINDER: ; break; default: - jj_la1[40] = jj_gen; + jj_la1[47] = jj_gen; break label_18; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STAR: - operator = jj_consume_token(STAR); + jj_consume_token(STAR); + operator = OperatorIds.MULTIPLY; break; case SLASH: - operator = jj_consume_token(SLASH); + jj_consume_token(SLASH); + operator = OperatorIds.DIVIDE; break; - case REM: - operator = jj_consume_token(REM); + case REMAINDER: + jj_consume_token(REMAINDER); + operator = OperatorIds.REMAINDER; break; default: - jj_la1[41] = jj_gen; + jj_la1[48] = jj_gen; jj_consume_token(-1); throw new ParseException(); } expr2 = UnaryExpression(); - buff.append(operator.image); - buff.append(expr2); + expr = new BinaryExpression(expr,expr2,operator); } - {if (true) return buff.toString();} + {if (true) return expr;} throw new Error("Missing return statement in function"); } - static final public String UnaryExpression() throws ParseException { - String expr; - Token token; +/** + * An unary expression starting with @, & or nothing + */ + static final public Expression UnaryExpression() throws ParseException { + final Expression expr; + /* expr = UnaryExpressionNoPrefix() //why did I had that ? + {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);} + | */ + expr = AtNotTildeUnaryExpression(); + {if (true) return expr;} + throw new Error("Missing return statement in function"); + } + + static final public Expression AtNotTildeUnaryExpression() throws ParseException { + final Expression expr; + final Token token; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AT: - jj_consume_token(AT); - expr = UnaryExpression(); - {if (true) return "@" + expr;} + token = jj_consume_token(AT); + expr = AtNotTildeUnaryExpression(); + {if (true) return new PrefixedUnaryExpression(expr,OperatorIds.AT,token.sourceStart);} + break; + case TILDE: + token = jj_consume_token(TILDE); + expr = AtNotTildeUnaryExpression(); + {if (true) return new PrefixedUnaryExpression(expr,OperatorIds.TWIDDLE,token.sourceStart);} break; + case BANG: + token = jj_consume_token(BANG); + expr = AtNotUnaryExpression(); + {if (true) return new PrefixedUnaryExpression(expr,OperatorIds.NOT,token.sourceStart);} + break; + case ARRAY: + case NEW: + case NULL: + case TRUE: + case FALSE: + case PLUS_PLUS: + case MINUS_MINUS: case PLUS: case MINUS: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case PLUS: - token = jj_consume_token(PLUS); - break; - case MINUS: - token = jj_consume_token(MINUS); - break; - default: - jj_la1[42] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - expr = UnaryExpression(); - {if (true) return token.image + expr;} - break; - case INCR: - expr = PreIncrementExpression(); + case BIT_AND: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + expr = UnaryExpressionNoPrefix(); {if (true) return expr;} break; - case DECR: - expr = PreDecrementExpression(); - {if (true) return expr;} + default: + jj_la1[49] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); + } + +/** + * An expression prefixed (or not) by one or more @ and !. + * @return the expression + */ + static final public Expression AtNotUnaryExpression() throws ParseException { + final Expression expr; + final Token token; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case AT: + token = jj_consume_token(AT); + expr = AtNotUnaryExpression(); + {if (true) return new PrefixedUnaryExpression(expr,OperatorIds.AT,token.sourceStart);} + break; + case BANG: + token = jj_consume_token(BANG); + expr = AtNotUnaryExpression(); + {if (true) return new PrefixedUnaryExpression(expr,OperatorIds.NOT,token.sourceStart);} break; case ARRAY: - case FALSE: case NEW: case NULL: case TRUE: + case FALSE: + case PLUS_PLUS: + case MINUS_MINUS: + case PLUS: + case MINUS: + case BIT_AND: case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: case IDENTIFIER: case LPAREN: - case DOLLAR: - case BANG: - case BIT_AND: - case DOLLAR_ID: - expr = UnaryExpressionNotPlusMinus(); + expr = UnaryExpressionNoPrefix(); {if (true) return expr;} break; default: - jj_la1[43] = jj_gen; + jj_la1[50] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String PreIncrementExpression() throws ParseException { -String expr; - jj_consume_token(INCR); - expr = PrimaryExpression(); - {if (true) return "++"+expr;} + static final public Expression UnaryExpressionNoPrefix() throws ParseException { + final Expression expr; + final Token token; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PLUS: + token = jj_consume_token(PLUS); + expr = AtNotTildeUnaryExpression(); + {if (true) return new PrefixedUnaryExpression(expr, + OperatorIds.PLUS, + token.sourceStart);} + break; + case MINUS: + token = jj_consume_token(MINUS); + expr = AtNotTildeUnaryExpression(); + {if (true) return new PrefixedUnaryExpression(expr, + OperatorIds.MINUS, + token.sourceStart);} + break; + case PLUS_PLUS: + case MINUS_MINUS: + expr = PreIncDecExpression(); + {if (true) return expr;} + break; + case ARRAY: + case NEW: + case NULL: + case TRUE: + case FALSE: + case BIT_AND: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + expr = UnaryExpressionNotPlusMinus(); + {if (true) return expr;} + break; + default: + jj_la1[51] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } throw new Error("Missing return statement in function"); } - static final public String PreDecrementExpression() throws ParseException { -String expr; - jj_consume_token(DECR); + static final public Expression PreIncDecExpression() throws ParseException { +final Expression expr; +final int operator; +final Token token; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PLUS_PLUS: + token = jj_consume_token(PLUS_PLUS); + operator = OperatorIds.PLUS_PLUS; + break; + case MINUS_MINUS: + token = jj_consume_token(MINUS_MINUS); + operator = OperatorIds.MINUS_MINUS; + break; + default: + jj_la1[52] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } expr = PrimaryExpression(); - {if (true) return "--"+expr;} + {if (true) return new PrefixedUnaryExpression(expr,operator,token.sourceStart);} throw new Error("Missing return statement in function"); } - static final public String UnaryExpressionNotPlusMinus() throws ParseException { - String expr; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BANG: - jj_consume_token(BANG); - expr = UnaryExpression(); - {if (true) return "!" + expr;} - break; - default: - jj_la1[44] = jj_gen; - if (jj_2_3(2147483647)) { - expr = CastExpression(); - {if (true) return expr;} - } else { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ARRAY: - case NEW: - case IDENTIFIER: - case DOLLAR: - case BIT_AND: - case DOLLAR_ID: - expr = PostfixExpression(); - {if (true) return expr;} - break; - case FALSE: - case NULL: - case TRUE: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case STRING_LITERAL: - expr = Literal(); - {if (true) return expr;} - break; - case LPAREN: - jj_consume_token(LPAREN); - expr = Expression(); + static final public Expression UnaryExpressionNotPlusMinus() throws ParseException { + final Expression expr; + if (jj_2_3(2147483647)) { + expr = CastExpression(); + {if (true) return expr;} + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ARRAY: + case NEW: + case BIT_AND: + case DOLLAR: + case IDENTIFIER: + expr = PostfixExpression(); + {if (true) return expr;} + break; + case NULL: + case TRUE: + case FALSE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + expr = Literal(); + {if (true) return expr;} + break; + case LPAREN: + jj_consume_token(LPAREN); + expr = Expression(); + try { jj_consume_token(RPAREN); - {if (true) return "("+expr+")";} - break; - default: - jj_la1[45] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); + } catch (ParseException e) { + errorMessage = "')' expected"; + errorLevel = ERROR; + errorStart = expr.sourceEnd +1; + errorEnd = expr.sourceEnd +1; + processParseExceptionDebug(e); } + {if (true) return expr;} + break; + default: + jj_la1[53] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); } } throw new Error("Missing return statement in function"); } - static final public String CastExpression() throws ParseException { -String type; -String expr; - jj_consume_token(LPAREN); - type = Type(); + static final public CastExpression CastExpression() throws ParseException { +final ConstantIdentifier type; +final Expression expr; +final Token token,token1; + token1 = jj_consume_token(LPAREN); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + case OBJECT: + case BOOL: + case BOOLEAN: + case REAL: + case DOUBLE: + case FLOAT: + case INT: + case INTEGER: + type = Type(); + break; + case ARRAY: + token = jj_consume_token(ARRAY); + type = new ConstantIdentifier(token); + break; + default: + jj_la1[54] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } jj_consume_token(RPAREN); expr = UnaryExpression(); - {if (true) return "(" + type + ")" + expr;} + {if (true) return new CastExpression(type,expr,token1.sourceStart,expr.sourceEnd);} throw new Error("Missing return statement in function"); } - static final public String PostfixExpression() throws ParseException { - String expr; - Token operator = null; + static final public Expression PostfixExpression() throws ParseException { + final Expression expr; + int operator = -1; + Token token = null; expr = PrimaryExpression(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case INCR: - case DECR: + case PLUS_PLUS: + case MINUS_MINUS: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case INCR: - operator = jj_consume_token(INCR); + case PLUS_PLUS: + token = jj_consume_token(PLUS_PLUS); + operator = OperatorIds.PLUS_PLUS; break; - case DECR: - operator = jj_consume_token(DECR); + case MINUS_MINUS: + token = jj_consume_token(MINUS_MINUS); + operator = OperatorIds.MINUS_MINUS; break; default: - jj_la1[46] = jj_gen; + jj_la1[55] = jj_gen; jj_consume_token(-1); throw new ParseException(); } break; default: - jj_la1[47] = jj_gen; + jj_la1[56] = jj_gen; ; } - if (operator == null) { + if (operator == -1) { {if (true) return expr;} } - {if (true) return expr + operator.image;} + {if (true) return new PostfixedUnaryExpression(expr,operator,token.sourceEnd);} throw new Error("Missing return statement in function"); } - static final public String PrimaryExpression() throws ParseException { - Token identifier; - String expr; - final StringBuffer buff = new StringBuffer(); - if (jj_2_4(2)) { + static final public Expression PrimaryExpression() throws ParseException { + Expression expr; + Token token = null; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case NEW: + case BIT_AND: + case DOLLAR: + case IDENTIFIER: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BIT_AND: + token = jj_consume_token(BIT_AND); + break; + default: + jj_la1[57] = jj_gen; + ; + } + expr = refPrimaryExpression(token); + {if (true) return expr;} + break; + case ARRAY: + expr = ArrayDeclarator(); + {if (true) return expr;} + break; + default: + jj_la1[58] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); + } + + static final public Expression refPrimaryExpression(final Token reference) throws ParseException { + Expression expr; + Expression expr2 = null; + final Token identifier; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: identifier = jj_consume_token(IDENTIFIER); - jj_consume_token(STATICCLASSACCESS); - expr = ClassIdentifier(); - buff.append(identifier.image).append("::").append(expr); + expr = new ConstantIdentifier(identifier); label_19: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CLASSACCESS: - case LPAREN: - case LBRACKET: + case STATICCLASSACCESS: ; break; default: - jj_la1[48] = jj_gen; + jj_la1[59] = jj_gen; break label_19; } - expr = PrimarySuffix(); - buff.append(expr); + jj_consume_token(STATICCLASSACCESS); + expr2 = ClassIdentifier(); + expr = new ClassAccess(expr, + expr2, + ClassAccess.STATIC); } - {if (true) return buff.toString();} - } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case NEW: - case IDENTIFIER: - case DOLLAR: - case BIT_AND: - case DOLLAR_ID: - expr = PrimaryPrefix(); - buff.append(expr); - label_20: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case CLASSACCESS: - case LPAREN: - case LBRACKET: - ; - break; - default: - jj_la1[49] = jj_gen; - break label_20; - } - expr = PrimarySuffix(); - buff.append(expr); - } - {if (true) return buff.toString();} - break; - case ARRAY: - expr = ArrayDeclarator(); - {if (true) return "array" + expr;} + case LPAREN: + expr2 = Arguments(expr); break; default: - jj_la1[50] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); + jj_la1[60] = jj_gen; + ; + } + if (expr2 == null) { + if (reference != null) { + ParseException e = generateParseException(); + errorMessage = "you cannot use a constant by reference"; + errorLevel = ERROR; + errorStart = reference.sourceStart; + errorEnd = reference.sourceEnd; + processParseExceptionDebug(e); } + {if (true) return expr;} } - throw new Error("Missing return statement in function"); - } - - static final public String ArrayDeclarator() throws ParseException { - String expr; - jj_consume_token(ARRAY); - expr = ArrayInitializer(); - {if (true) return "array" + expr;} - throw new Error("Missing return statement in function"); - } - - static final public String PrimaryPrefix() throws ParseException { - String expr; - Token token = null; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - token = jj_consume_token(IDENTIFIER); - {if (true) return token.image;} + {if (true) return expr2;} break; - case NEW: - case BIT_AND: + case DOLLAR: + expr = VariableDeclaratorId(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BIT_AND: - token = jj_consume_token(BIT_AND); + case LPAREN: + expr = Arguments(expr); break; default: - jj_la1[51] = jj_gen; + jj_la1[61] = jj_gen; ; } - jj_consume_token(NEW); + {if (true) return expr;} + break; + case NEW: + token = jj_consume_token(NEW); expr = ClassIdentifier(); - if (token == null) { - {if (true) return "new " + expr;} + int start; + if (reference == null) { + start = token.sourceStart; + } else { + start = reference.sourceStart; } - {if (true) return "new &" + expr;} - break; - case DOLLAR: - case DOLLAR_ID: - expr = VariableDeclaratorId(); + expr = new ClassInstantiation(expr, + reference != null, + start); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LPAREN: + expr = Arguments(expr); + break; + default: + jj_la1[62] = jj_gen; + ; + } {if (true) return expr;} break; default: - jj_la1[52] = jj_gen; + jj_la1[63] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String ClassIdentifier() throws ParseException { - String expr; - Token token; +/** + * An array declarator. + * array(vars) + * @return an array + */ + static final public ArrayInitializer ArrayDeclarator() throws ParseException { + final ArrayVariableDeclaration[] vars; + final Token token; + token = jj_consume_token(ARRAY); + vars = ArrayInitializer(); + {if (true) return new ArrayInitializer(vars, + token.sourceStart, + PHPParser.token.sourceEnd);} + throw new Error("Missing return statement in function"); + } + + static final public Expression ClassIdentifier() throws ParseException { + final Expression expr; + final Token token; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IDENTIFIER: token = jj_consume_token(IDENTIFIER); - {if (true) return token.image;} + {if (true) return new ConstantIdentifier(token);} + break; + case STRING: + case OBJECT: + case BOOL: + case BOOLEAN: + case REAL: + case DOUBLE: + case FLOAT: + case INT: + case INTEGER: + expr = Type(); + {if (true) return expr;} break; case DOLLAR: - case DOLLAR_ID: expr = VariableDeclaratorId(); - {if (true) return expr;} - break; - default: - jj_la1[53] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - throw new Error("Missing return statement in function"); - } - - static final public String PrimarySuffix() throws ParseException { - String expr; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case LPAREN: - expr = Arguments(); - {if (true) return expr;} - break; - case CLASSACCESS: - case LBRACKET: - expr = VariableSuffix(); - {if (true) return expr;} + {if (true) return expr;} break; default: - jj_la1[54] = jj_gen; + jj_la1[64] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String VariableSuffix() throws ParseException { - String expr = null; +/** + * Used by Variabledeclaratorid and primarysuffix + */ + static final public AbstractVariable VariableSuffix(final AbstractVariable prefix) throws ParseException { + Expression expression = null; + final Token classAccessToken,lbrace,rbrace; + Token token; + int pos; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case CLASSACCESS: - jj_consume_token(CLASSACCESS); - expr = VariableName(); - {if (true) return "->" + expr;} + classAccessToken = jj_consume_token(CLASSACCESS); + try { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACE: + lbrace = jj_consume_token(LBRACE); + expression = Expression(); + rbrace = jj_consume_token(RBRACE); + expression = new Variable(expression, + lbrace.sourceStart, + rbrace.sourceEnd); + break; + case IDENTIFIER: + token = jj_consume_token(IDENTIFIER); + expression = new ConstantIdentifier(token.image,token.sourceStart,token.sourceEnd); + break; + case DOLLAR: + expression = Variable(); + break; + default: + jj_la1[65] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected"; + errorLevel = ERROR; + errorStart = classAccessToken.sourceEnd +1; + errorEnd = classAccessToken.sourceEnd +1; + processParseExceptionDebug(e); + } + {if (true) return new ClassAccess(prefix, + expression, + ClassAccess.NORMAL);} break; case LBRACKET: - jj_consume_token(LBRACKET); + token = jj_consume_token(LBRACKET); + pos = token.sourceEnd+1; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ARRAY: + case LIST: case PRINT: - case FALSE: case NEW: case NULL: case TRUE: + case FALSE: + case STRING: + case OBJECT: + case BOOL: + case BOOLEAN: + case REAL: + case DOUBLE: + case FLOAT: + case INT: + case INTEGER: + case AT: + case BANG: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: + case PLUS: + case MINUS: + case BIT_AND: case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: case IDENTIFIER: case LPAREN: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ARRAY: + case LIST: + case PRINT: + case NEW: + case NULL: + case TRUE: + case FALSE: + case AT: + case BANG: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: + case PLUS: + case MINUS: + case BIT_AND: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + expression = Expression(); + pos = expression.sourceEnd+1; + break; + case STRING: + case OBJECT: + case BOOL: + case BOOLEAN: + case REAL: + case DOUBLE: + case FLOAT: + case INT: + case INTEGER: + expression = Type(); + pos = expression.sourceEnd+1; + break; + default: + jj_la1[66] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[67] = jj_gen; + ; + } + try { + token = jj_consume_token(RBRACKET); + pos = token.sourceEnd; + } catch (ParseException e) { + errorMessage = "']' expected"; + errorLevel = ERROR; + errorStart = pos; + errorEnd = pos; + processParseExceptionDebug(e); + } + {if (true) return new ArrayDeclarator(prefix,expression,pos);} + break; + case LBRACE: + token = jj_consume_token(LBRACE); + pos = token.sourceEnd+1; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ARRAY: + case LIST: + case PRINT: + case NEW: + case NULL: + case TRUE: + case FALSE: + case STRING: + case OBJECT: + case BOOL: + case BOOLEAN: + case REAL: + case DOUBLE: + case FLOAT: + case INT: + case INTEGER: case AT: - case DOLLAR: case BANG: - case INCR: - case DECR: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: case PLUS: case MINUS: case BIT_AND: - case DOLLAR_ID: - expr = Expression(); + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ARRAY: + case LIST: + case PRINT: + case NEW: + case NULL: + case TRUE: + case FALSE: + case AT: + case BANG: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: + case PLUS: + case MINUS: + case BIT_AND: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + expression = Expression(); + pos = expression.sourceEnd+1; + break; + case STRING: + case OBJECT: + case BOOL: + case BOOLEAN: + case REAL: + case DOUBLE: + case FLOAT: + case INT: + case INTEGER: + expression = Type(); + pos = expression.sourceEnd+1; + break; + default: + jj_la1[68] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } break; default: - jj_la1[55] = jj_gen; + jj_la1[69] = jj_gen; ; } try { - jj_consume_token(RBRACKET); + token = jj_consume_token(RBRACE); + pos = token.sourceEnd; } catch (ParseException e) { errorMessage = "']' expected"; errorLevel = ERROR; - {if (true) throw generateParseException();} + errorStart = pos; + errorEnd = pos; + processParseExceptionDebug(e); } - if(expr == null) { - {if (true) return "[]";} - } - {if (true) return "[" + expr + "]";} + {if (true) return new ArrayDeclarator(prefix,expression,pos);} break; default: - jj_la1[56] = jj_gen; + jj_la1[70] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String Literal() throws ParseException { - String expr; - Token token; + static final public Literal Literal() throws ParseException { + final Token token; + StringLiteral literal; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case INTEGER_LITERAL: token = jj_consume_token(INTEGER_LITERAL); - {if (true) return token.image;} + {if (true) return new NumberLiteral(token);} break; case FLOATING_POINT_LITERAL: token = jj_consume_token(FLOATING_POINT_LITERAL); - {if (true) return token.image;} + {if (true) return new NumberLiteral(token);} break; case STRING_LITERAL: - try { - token = jj_consume_token(STRING_LITERAL); - {if (true) return token.image;} - } catch (TokenMgrError e) { - errorMessage = "unterminated string"; - errorLevel = ERROR; - {if (true) throw generateParseException();} - } + token = jj_consume_token(STRING_LITERAL); + {if (true) return new StringLiteral(token);} break; - case FALSE: case TRUE: - expr = BooleanLiteral(); - {if (true) return expr;} + token = jj_consume_token(TRUE); + {if (true) return new TrueLiteral(token);} break; - case NULL: - expr = NullLiteral(); - {if (true) return expr;} + case FALSE: + token = jj_consume_token(FALSE); + {if (true) return new FalseLiteral(token);} break; - default: - jj_la1[57] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - throw new Error("Missing return statement in function"); - } - - static final public String BooleanLiteral() throws ParseException { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TRUE: - jj_consume_token(TRUE); - {if (true) return "true";} + case NULL: + token = jj_consume_token(NULL); + {if (true) return new NullLiteral(token);} break; - case FALSE: - jj_consume_token(FALSE); - {if (true) return "false";} + case DOUBLEQUOTE: + literal = evaluableString(); + {if (true) return literal;} break; default: - jj_la1[58] = jj_gen; + jj_la1[71] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } - static final public String NullLiteral() throws ParseException { - jj_consume_token(NULL); - {if (true) return "null";} + static final public StringLiteral evaluableString() throws ParseException { + ArrayList list = new ArrayList(); + Token start,end; + Token token,lbrace,rbrace; + AbstractVariable var; + Expression expr; + start = jj_consume_token(DOUBLEQUOTE); + label_20: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case DOLLARS: + ; + break; + default: + jj_la1[72] = jj_gen; + break label_20; + } + jj_consume_token(DOLLARS); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + token = jj_consume_token(IDENTIFIER); + list.add(new Variable(token.image, + token.sourceStart, + token.sourceEnd)); + break; + case LBRACE1: + lbrace = jj_consume_token(LBRACE1); + token = jj_consume_token(ID); + list.add(new Variable(token.image, + token.sourceStart, + token.sourceEnd)); + rbrace = jj_consume_token(RBRACE1); + break; + default: + jj_la1[73] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + end = jj_consume_token(DOUBLEQUOTE2); + AbstractVariable[] vars = new AbstractVariable[list.size()]; + list.toArray(vars); + {if (true) return new StringLiteral(SimpleCharStream.currentBuffer.substring(start.sourceEnd,end.sourceStart), + start.sourceStart, + end.sourceEnd, + vars);} throw new Error("Missing return statement in function"); } - static final public String Arguments() throws ParseException { -String expr = null; - jj_consume_token(LPAREN); + static final public FunctionCall Arguments(final Expression func) throws ParseException { +Expression[] args = null; +final Token token,lparen; + lparen = jj_consume_token(LPAREN); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ARRAY: + case LIST: case PRINT: - case FALSE: case NEW: case NULL: case TRUE: - case INTEGER_LITERAL: - case FLOATING_POINT_LITERAL: - case STRING_LITERAL: - case IDENTIFIER: - case LPAREN: + case FALSE: case AT: - case DOLLAR: case BANG: - case INCR: - case DECR: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: case PLUS: case MINUS: case BIT_AND: - case DOLLAR_ID: - expr = ArgumentList(); + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + args = ArgumentList(); break; default: - jj_la1[59] = jj_gen; + jj_la1[74] = jj_gen; ; } try { - jj_consume_token(RPAREN); + token = jj_consume_token(RPAREN); + {if (true) return new FunctionCall(func,args,token.sourceEnd);} } catch (ParseException e) { - errorMessage = "')' expected to close the argument list"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list"; errorLevel = ERROR; - {if (true) throw e;} + if (args == null) { + errorStart = lparen.sourceEnd+1; + errorEnd = lparen.sourceEnd+2; + } else { + errorStart = args[args.length-1].sourceEnd+1; + errorEnd = args[args.length-1].sourceEnd+2; } - if (expr == null) { - {if (true) return "()";} - } - {if (true) return "(" + expr + ")";} + processParseExceptionDebug(e); + } + int sourceEnd = (args == null && args.length != 0) ? lparen.sourceEnd+1 : args[args.length-1].sourceEnd; + {if (true) return new FunctionCall(func,args,sourceEnd);} throw new Error("Missing return statement in function"); } - static final public String ArgumentList() throws ParseException { -String expr; -StringBuffer buff = new StringBuffer(); - expr = Expression(); - buff.append(expr); +/** + * An argument list is a list of arguments separated by comma : + * argumentDeclaration() (, argumentDeclaration)* + * @return an array of arguments + */ + static final public Expression[] ArgumentList() throws ParseException { +Expression arg; +final ArrayList list = new ArrayList(); +int pos; +Token token; + arg = Expression(); + list.add(arg);pos = arg.sourceEnd; label_21: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1793,100 +2790,88 @@ StringBuffer buff = new StringBuffer(); ; break; default: - jj_la1[60] = jj_gen; + jj_la1[75] = jj_gen; break label_21; } - jj_consume_token(COMMA); + token = jj_consume_token(COMMA); + pos = token.sourceEnd; try { - expr = Expression(); + arg = Expression(); + list.add(arg); + pos = arg.sourceEnd; } catch (ParseException e) { - errorMessage = "expression expected after a comma in argument list"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list"; errorLevel = ERROR; - {if (true) throw e;} + errorStart = pos+1; + errorEnd = pos+1; + processParseException(e); } - buff.append(",").append("expr"); } - {if (true) return buff.toString();} + final Expression[] arguments = new Expression[list.size()]; + list.toArray(arguments); + {if (true) return arguments;} throw new Error("Missing return statement in function"); } -/* - * Statement syntax follows. +/** + * A Statement without break. + * @return a statement */ - static final public void Statement() throws ParseException { - if (jj_2_5(2)) { - Expression(); - try { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); - break; - case 127: - jj_consume_token(127); - break; - default: - jj_la1[61] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } catch (ParseException e) { - errorMessage = "';' expected"; - errorLevel = ERROR; - {if (true) throw e;} - } - } else if (jj_2_6(2)) { - LabeledStatement(); + static final public Statement StatementNoBreak() throws ParseException { + final Statement statement; + Token token = null; + if (jj_2_4(2)) { + statement = expressionStatement(); + {if (true) return statement;} } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + statement = LabeledStatement(); + {if (true) return statement;} + break; case LBRACE: - Block(); + statement = Block(); + {if (true) return statement;} break; case SEMICOLON: - EmptyStatement(); - break; - case ARRAY: - case NEW: - case IDENTIFIER: - case DOLLAR: - case INCR: - case DECR: - case BIT_AND: - case DOLLAR_ID: - StatementExpression(); - try { - jj_consume_token(SEMICOLON); - } catch (ParseException e) { - errorMessage = "';' expected after expression"; - errorLevel = ERROR; - {if (true) throw e;} - } + statement = EmptyStatement(); + {if (true) return statement;} break; case SWITCH: - SwitchStatement(); + statement = SwitchStatement(); + {if (true) return statement;} break; case IF: - IfStatement(); + statement = IfStatement(); + {if (true) return statement;} break; case WHILE: - WhileStatement(); + statement = WhileStatement(); + {if (true) return statement;} break; case DO: - DoStatement(); + statement = DoStatement(); + {if (true) return statement;} break; case FOR: - ForStatement(); + statement = ForStatement(); + {if (true) return statement;} break; - case BREAK: - BreakStatement(); + case FOREACH: + statement = ForeachStatement(); + {if (true) return statement;} break; case CONTINUE: - ContinueStatement(); + statement = ContinueStatement(); + {if (true) return statement;} break; case RETURN: - ReturnStatement(); + statement = ReturnStatement(); + {if (true) return statement;} break; case ECHO: - EchoStatement(); + statement = EchoStatement(); + {if (true) return statement;} break; case INCLUDE: case REQUIRE: @@ -1895,180 +2880,350 @@ StringBuffer buff = new StringBuffer(); case AT: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AT: - jj_consume_token(AT); + token = jj_consume_token(AT); break; default: - jj_la1[62] = jj_gen; + jj_la1[76] = jj_gen; ; } - IncludeStatement(); + statement = IncludeStatement(); + if (token != null) { + ((InclusionStatement)statement).silent = true; + statement.sourceStart = token.sourceStart; + } + {if (true) return statement;} break; case STATIC: - StaticStatement(); + statement = StaticStatement(); + {if (true) return statement;} break; case GLOBAL: - GlobalStatement(); + statement = GlobalStatement(); + {if (true) return statement;} + break; + case DEFINE: + statement = defineStatement(); + currentSegment.add((Outlineable)statement);{if (true) return statement;} break; default: - jj_la1[63] = jj_gen; + jj_la1[77] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } + throw new Error("Missing return statement in function"); } - static final public void IncludeStatement() throws ParseException { - String expr; - int pos = jj_input_stream.bufpos; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case REQUIRE: - jj_consume_token(REQUIRE); - expr = Expression(); - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr)); - try { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); - break; - case 127: - jj_consume_token(127); - break; - default: - jj_la1[64] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } catch (ParseException e) { - errorMessage = "';' expected"; +/** + * A statement expression. + * expression ; + * @return an expression + */ + static final public Statement expressionStatement() throws ParseException { + final Statement statement; + final Token token; + statement = Expression(); + try { + token = jj_consume_token(SEMICOLON); + statement.sourceEnd = token.sourceEnd; + } catch (ParseException e) { + if (e.currentToken.next.kind != PHPParserConstants.PHPEND) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected"; + errorLevel = ERROR; + errorStart = statement.sourceEnd+1; + errorEnd = statement.sourceEnd+1; + processParseExceptionDebug(e); + } + } + {if (true) return statement;} + throw new Error("Missing return statement in function"); + } + + static final public Define defineStatement() throws ParseException { + Expression defineName,defineValue; + final Token defineToken; + Token token; + int pos; + defineToken = jj_consume_token(DEFINE); + pos = defineToken.sourceEnd+1; + try { + token = jj_consume_token(LPAREN); + pos = token.sourceEnd+1; + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected"; errorLevel = ERROR; - {if (true) throw e;} - } - break; - case REQUIRE_ONCE: - jj_consume_token(REQUIRE_ONCE); - expr = Expression(); - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr)); - try { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); - break; - case 127: - jj_consume_token(127); - break; - default: - jj_la1[65] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } catch (ParseException e) { - errorMessage = "';' expected"; + errorStart = pos; + errorEnd = pos; + processParseExceptionDebug(e); + } + try { + defineName = Expression(); + pos = defineName.sourceEnd+1; + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; errorLevel = ERROR; - {if (true) throw e;} - } - break; - case INCLUDE: - jj_consume_token(INCLUDE); - expr = Expression(); - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr)); - try { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); - break; - case 127: - jj_consume_token(127); - break; - default: - jj_la1[66] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } catch (ParseException e) { - errorMessage = "';' expected"; + errorStart = pos; + errorEnd = pos; + processParseExceptionDebug(e); + defineName = new StringLiteral(SYNTAX_ERROR_CHAR,pos,pos); + } + try { + token = jj_consume_token(COMMA); + pos = defineName.sourceEnd+1; + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected"; errorLevel = ERROR; - {if (true) throw e;} - } - break; - case INCLUDE_ONCE: - jj_consume_token(INCLUDE_ONCE); - expr = Expression(); - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr)); - try { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); - break; - case 127: - jj_consume_token(127); - break; - default: - jj_la1[67] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } catch (ParseException e) { - errorMessage = "';' expected"; + errorStart = pos; + errorEnd = pos; + processParseExceptionDebug(e); + } + try { + defineValue = Expression(); + pos = defineValue.sourceEnd+1; + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; errorLevel = ERROR; - {if (true) throw e;} - } + errorStart = pos; + errorEnd = pos; + processParseExceptionDebug(e); + defineValue = new StringLiteral(SYNTAX_ERROR_CHAR,pos,pos); + } + try { + token = jj_consume_token(RPAREN); + pos = token.sourceEnd+1; + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected"; + errorLevel = ERROR; + errorStart = pos; + errorEnd = pos; + processParseExceptionDebug(e); + } + {if (true) return new Define(currentSegment, + defineName, + defineValue, + defineToken.sourceStart, + pos);} + throw new Error("Missing return statement in function"); + } + +/** + * A Normal statement. + */ + static final public Statement Statement() throws ParseException { + final Statement statement; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IF: + case ARRAY: + case LIST: + case PRINT: + case ECHO: + case INCLUDE: + case REQUIRE: + case INCLUDE_ONCE: + case REQUIRE_ONCE: + case GLOBAL: + case DEFINE: + case STATIC: + case CONTINUE: + case DO: + case FOR: + case NEW: + case NULL: + case RETURN: + case SWITCH: + case TRUE: + case FALSE: + case WHILE: + case FOREACH: + case AT: + case BANG: + case TILDE: + case PLUS_PLUS: + case MINUS_MINUS: + case PLUS: + case MINUS: + case BIT_AND: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case DOUBLEQUOTE: + case DOLLAR: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case SEMICOLON: + statement = StatementNoBreak(); + {if (true) return statement;} + break; + case BREAK: + statement = BreakStatement(); + {if (true) return statement;} break; default: - jj_la1[68] = jj_gen; + jj_la1[78] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - } - - static final public String PrintExpression() throws ParseException { - StringBuffer buff = new StringBuffer("print "); - String expr; - jj_consume_token(PRINT); - expr = Expression(); - buff.append(expr); - {if (true) return buff.toString();} throw new Error("Missing return statement in function"); } - static final public void EchoStatement() throws ParseException { - jj_consume_token(ECHO); - Expression(); +/** + * An html block inside a php syntax. + */ + static final public HTMLBlock htmlBlock() throws ParseException { + final int startIndex = nodePtr; + final AstNode[] blockNodes; + final int nbNodes; + final Token phpEnd; + phpEnd = jj_consume_token(PHPEND); + htmlStart = phpEnd.sourceEnd; label_22: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case COMMA: + case PHPECHOSTART: ; break; default: - jj_la1[69] = jj_gen; + jj_la1[79] = jj_gen; break label_22; } - jj_consume_token(COMMA); - Expression(); + phpEchoBlock(); } try { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMICOLON: - jj_consume_token(SEMICOLON); + case PHPSTARTLONG: + jj_consume_token(PHPSTARTLONG); break; - case 127: - jj_consume_token(127); + case PHPSTARTSHORT: + jj_consume_token(PHPSTARTSHORT); break; default: - jj_la1[70] = jj_gen; + jj_la1[80] = jj_gen; jj_consume_token(-1); throw new ParseException(); } + PHPParser.createNewHTMLCode(); } catch (ParseException e) { - errorMessage = "';' expected after 'echo' statement"; + errorMessage = "unexpected end of file , '= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 98; i++) { + for (int i = 0; i < 128; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1< jj_gen) { @@ -4573,8 +7548,6 @@ StringBuffer buff = new StringBuffer(); case 2: jj_3_3(); break; case 3: jj_3_4(); break; case 4: jj_3_5(); break; - case 5: jj_3_6(); break; - case 6: jj_3_7(); break; } } p = p.next;