final static int TT_DOTASSIGN = 48;
final static int TT_SET = 49;
-
+ final static int TT_REF = 50;
final static int TT_FOREACH = 51;
+ final static int TT_AMPERSAND = 52;
+ final static int TT_DOLLARLISTOPEN = 53;
final static int TT_ARGOPEN = 128;
final static int TT_ARGCLOSE = 129;
final static int TT_LISTOPEN = 130;
*@param sess Description of Parameter
*@see
*/
- public PHPParser(String s, int rowCount) {
+ public PHPParser() {
if (keywordMap == null) {
keywordMap = new HashMap();
for (int i = 0; i < PHP_KEYWORS.length; i++) {
keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
}
}
- this.str = s;
+ this.str = "";
this.token = TT_EOF;
this.chIndx = 0;
- this.rowCount = rowCount;
+ this.rowCount = 1;
this.columnCount = 0;
getNextToken();
break;
}
}
- throw new SyntaxError(rowCount, chIndx - columnCount, str.substring(columnCount + 1, eol), error);
+ throw new SyntaxError(rowCount, chIndx - columnCount + 1, str.substring(columnCount, eol), error);
}
/**
chIndx++;
// multi line comment:
while (str.length() > chIndx) {
- if (str.charAt(chIndx) == '*' &&
- (str.length() > (chIndx+1) ) &&
- str.charAt(chIndx+1) == '/') {
+ if (str.charAt(chIndx) == '*' && (str.length() > (chIndx + 1)) && str.charAt(chIndx + 1) == '/') {
chIndx += 2;
break;
}
}
}
}
- if (str.length() > chIndx) {
- chIndx++;
- }
+ // if (str.length() > chIndx) {
+ // chIndx++;
+ // }
token = TT_INTERPOLATED_STRING;
return;
} else if (ch == '\'') {
}
}
}
- if (str.length() > chIndx) {
- chIndx++;
- }
+ // if (str.length() > chIndx) {
+ // chIndx++;
+ // }
token = TT_STRING_CONSTANT;
return;
}
break;
}
+ if (str.charAt(chIndx) == '>') {
+ chIndx++;
+ token = TT_REF;
+
+ break;
+ }
}
break;
case '|' :
if (str.length() > chIndx) {
- if (str.charAt(chIndx++) == '|') {
+ if (str.charAt(chIndx) == '|') {
+ chIndx++;
token = TT_OR;
break;
break;
case '&' :
if (str.length() > chIndx) {
- if (str.charAt(chIndx++) == '&') {
+ if (str.charAt(chIndx) == '&') {
+ chIndx++;
token = TT_AND;
break;
+ } else {
+ token = TT_AMPERSAND;
+
+ break;
}
}
void getIdentifier() {
StringBuffer ident = new StringBuffer();
- ident.append(ch);
ident.append(ch);
if (ch == '$') {
getChar();
}
identifier = ident.toString();
+ chIndx--;
- Integer i = (Integer) keywordMap.get(identifier);
+ Integer i = (Integer) keywordMap.get(identifier.toLowerCase());
if (i != null) {
token = i.intValue();
}
}
}
}
-
- // token = TT_INT_NUMBER;
+ chIndx--;
try {
if (dFlag != ' ') {
}
}
- public void start() throws SyntaxError {
+ public void start(String s, int rowCount) throws SyntaxError {
+ // start up
+ this.str = s;
+ this.token = TT_EOF;
+ this.chIndx = 0;
+ this.rowCount = rowCount;
+ this.columnCount = 0;
+ getNextToken();
+
statementList();
if (token != TT_EOF) {
if (token == TT_ARGCLOSE) {
throwSyntaxError("too many closing ']'; end-of-file not reached");
}
+ if (token == TT_ARGOPEN) {
+ throwSyntaxError("read character '('; end-of-file not reached");
+ }
+ if (token == TT_LISTOPEN) {
+ throwSyntaxError("read character '{'; end-of-file not reached");
+ }
+ if (token == TT_PARTOPEN) {
+ throwSyntaxError("read character '['; end-of-file not reached");
+ }
+
throwSyntaxError("end-of-file not reached");
}
}
public void statementList() {
- statement();
+ do {
+ statement();
+ if ((token == TT_LISTCLOSE)
+ || (token == TT_elseif)
+ || (token == TT_endif)
+ || (token == TT_endfor)
+ || (token == TT_endforeach)
+ || (token == TT_endwhile)
+ || (token == TT_endswitch)
+ || (token == TT_EOF)) {
+ return;
+ }
+ } while (true);
}
public void statement() {
- while (token != TT_UNDEFINED) {
+ while (token != TT_UNDEFINED && token != TT_EOF) {
if (token > TT_KEYWORD) {
if (token == TT_case) {
getNextToken();
return;
} else if (token == TT_require || token == TT_require_once) {
getNextToken();
- constant();
+ //constant();
+ expression();
if (token == TT_SEMICOLON) {
getNextToken();
} else {
}
- } else {
- if (token == TT_LISTOPEN) {
- getNextToken();
+ } else if (token == TT_LISTOPEN) {
+ // compundStatement
+ getNextToken();
+ if (token != TT_LISTCLOSE) {
statementList();
- if (token == TT_LISTCLOSE) {
- getNextToken();
- } else {
- throwSyntaxError("'}' expected.");
- }
}
- }
- expression();
- if (token == TT_SEMICOLON) {
- getNextToken();
+ if (token == TT_LISTCLOSE) {
+ getNextToken();
+ } else {
+ throwSyntaxError("'}' expected.");
+ }
} else {
- throwSyntaxError("';' expected after expression.");
+ if (token != TT_SEMICOLON) {
+ expression();
+ }
+ if (token == TT_SEMICOLON) {
+ getNextToken();
+ } else {
+ throwSyntaxError("';' expected after expression.");
+ }
}
}
}
public void inclusionStatement() {
}
- public void compoundStatement() {
- }
+ // public void compoundStatement() {
+ // }
public void selectionStatement() {
}
}
public void ifStatement() {
+ // statement [else-statement]
+ statement();
+ if (token == TT_else) {
+ getNextToken();
+ statement();
+ }
}
public void switchStatement() {
}
public void postfixExpression() {
+ switch (token) {
+ case TT_ARGOPEN :
+ getNextToken();
+ expression();
+ if (token != TT_ARGCLOSE) {
+ throwSyntaxError(") expected in postfix-expression.");
+ }
+ getNextToken();
+ break;
+ case TT_DOUBLE_NUMBER :
+ getNextToken();
+ break;
+ case TT_INT_NUMBER :
+ getNextToken();
+ break;
+ case TT_VARIABLE :
+ getNextToken();
+ break;
+ case TT_IDENTIFIER :
+ getNextToken();
+ if (token == TT_ARGOPEN) {
+ getNextToken();
+ if (token != TT_ARGCLOSE) {
+ expressionList();
+ if (token != TT_ARGCLOSE) {
+ throwSyntaxError(") expected after identifier in postfix-expression.");
+ }
+ }
+ getNextToken();
+ }
+ break;
+ }
+ boolean while_flag = true;
+ do {
+ switch (token) {
+ case TT_PARTOPEN :
+ getNextToken();
+ expression();
+ if (token != TT_PARTCLOSE) {
+ throwSyntaxError("] expected in postfix-expression.");
+ }
+ getNextToken();
+ break;
+ case TT_REF :
+ switch (token) {
+ case TT_VARIABLE :
+ getNextToken();
+ break;
+ case TT_IDENTIFIER :
+ getNextToken();
+ break;
+ case TT_LISTOPEN :
+ getNextToken();
+ expression();
+ if (token != TT_LISTCLOSE) {
+ throwSyntaxError("] expected in postfix-expression.");
+ }
+ getNextToken();
+ break;
+ default :
+ throwSyntaxError("Syntax error after '->' token.");
+ }
+ case TT_INCREMENT :
+ getNextToken();
+ break;
+ case TT_DECREMENT :
+ getNextToken();
+ break;
+ default :
+ while_flag = false;
+ }
+ } while (while_flag);
}
public void variableList() {
public void constant() {
}
+
}
\ No newline at end of file