X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FParser.java;h=f594eeea2f4c2359a189215d900da838b99e87a8;hb=2a94571c07db6db966f6bfa32583a72287f4db29;hp=73b359039559579841f96eac693790319761c093;hpb=bf615a8d1871c2f8a9bf0044297ff253600862e3;p=org.ibex.core.git
diff --git a/src/org/xwt/js/Parser.java b/src/org/xwt/js/Parser.java
index 73b3590..f594eee 100644
--- a/src/org/xwt/js/Parser.java
+++ b/src/org/xwt/js/Parser.java
@@ -10,11 +10,7 @@ class Parser extends Lexer implements ByteCodes {
// Constructors //////////////////////////////////////////////////////
- public Parser(Reader r, String sourceName, int line) throws IOException {
- super(r);
- this.sourceName = sourceName;
- this.line = line;
- }
+ public Parser(Reader r, String sourceName, int line) throws IOException { super(r, sourceName, line); }
/** for debugging */
public static void main(String[] s) throws Exception {
@@ -65,7 +61,7 @@ class Parser extends Lexer implements ByteCodes {
/** gets a token and throws an exception if it is not code */
public void consume(int code) throws IOException {
if (getToken() != code)
- throw new ParserException("expected " + codeToString[code] + ", got " + (op == -1 ? "EOL" : codeToString[op]));
+ throw new ParserException("expected " + codeToString[code] + ", got " + (op == -1 ? "EOF" : codeToString[op]));
}
/** append the largest expression beginning with prefix containing no operators of precedence below minPrecedence */
@@ -81,9 +77,6 @@ class Parser extends Lexer implements ByteCodes {
int tok = getToken();
int curLine = line;
if (tok == -1) return;
- if (minPrecedence > 0 && precedence[tok] != 0)
- if (precedence[tok] < minPrecedence || (precedence[tok] == minPrecedence && !isRightAssociative[tok]))
- { pushBackToken(); return; }
ByteCodeBlock b = appendTo;
@@ -111,7 +104,8 @@ class Parser extends Lexer implements ByteCodes {
}
case SUB: {
consume(NUMBER);
- continueExpr(b.add(ByteCodeBlock.LITERAL, new Double(number.doubleValue() * -1)), minPrecedence);
+ b.add(ByteCodeBlock.LITERAL, new Double(number.doubleValue() * -1));
+ continueExpr(b, minPrecedence);
return;
}
case LP: {
@@ -135,8 +129,7 @@ class Parser extends Lexer implements ByteCodes {
}
case LC: {
b.add(OBJECT, null);
- if (peekToken() == RC) { consume(RC); continueExpr(b, minPrecedence); return; }
- while(true) {
+ if (peekToken() != RC) while(true) {
if (peekToken() != NAME && peekToken() != STRING) throw new Error("expected NAME or STRING");
getToken();
b.add(LITERAL, string);
@@ -144,10 +137,13 @@ class Parser extends Lexer implements ByteCodes {
startExpr(b);
b.add(PUT);
b.add(POP);
- if (peekToken() == RC) { consume(RC); continueExpr(b, minPrecedence); return; }
+ if (peekToken() == RC) break;
consume(COMMA);
- if (peekToken() == RC) { consume(RC); continueExpr(b, minPrecedence); return; }
+ if (peekToken() == RC) break;
}
+ consume(RC);
+ continueExpr(b, minPrecedence);
+ return;
}
case NAME: {
String name = string;
@@ -262,8 +258,8 @@ class Parser extends Lexer implements ByteCodes {
// invocation
int i = 0;
while(peekToken() != RP) {
- startExpr(b);
i++;
+ startExpr(b);
if (peekToken() == RP) break;
consume(COMMA);
}
@@ -534,7 +530,8 @@ class Parser extends Lexer implements ByteCodes {
consume(LP);
tok = getToken();
- if (tok == VAR) tok = getToken();
+ boolean hadVar = false;
+ if (tok == VAR) { hadVar = true; tok = getToken(); }
String varName = string;
boolean forIn = peekToken() == IN;
pushBackToken(tok, varName);
@@ -564,14 +561,13 @@ class Parser extends Lexer implements ByteCodes {
break;
} else {
+ if (hadVar) pushBackToken(VAR, null);
ByteCodeBlock b2 = newbb(curLine);
b.add(SCOPE, b2);
b.add(POP);
int size = b2.size();
- startExpr(b2);
- if (b2.size() - size > 0) b2.add(POP);
- consume(SEMI);
+ parseStatement(false, b2);
ByteCodeBlock e2 = startExpr();
consume(SEMI);
if (e2 == null) e2 = newbb(curLine).add(b.LITERAL, null);
@@ -591,7 +587,7 @@ class Parser extends Lexer implements ByteCodes {
b3.add(JT, new Integer(2));
b3.add(BREAK);
parseStatement(false, b3);
- b3.add(BREAK);
+ b3.add(CONTINUE);
break;
}
}