projects
/
org.ibex.core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
2003/06/09 06:38:36
[org.ibex.core.git]
/
src
/
org
/
xwt
/
js
/
Parser.java
diff --git
a/src/org/xwt/js/Parser.java
b/src/org/xwt/js/Parser.java
index
73b3590
..
f594eee
100644
(file)
--- 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 //////////////////////////////////////////////////////
// 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 {
/** 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 <tt>code</tt> */
public void consume(int code) throws IOException {
if (getToken() != code)
/** gets a token and throws an exception if it is not <tt>code</tt> */
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 <tt>minPrecedence</tt> */
}
/** append the largest expression beginning with prefix containing no operators of precedence below <tt>minPrecedence</tt> */
@@
-81,9
+77,6
@@
class Parser extends Lexer implements ByteCodes {
int tok = getToken();
int curLine = line;
if (tok == -1) return;
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;
ByteCodeBlock b = appendTo;
@@
-111,7
+104,8
@@
class Parser extends Lexer implements ByteCodes {
}
case SUB: {
consume(NUMBER);
}
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: {
return;
}
case LP: {
@@
-135,8
+129,7
@@
class Parser extends Lexer implements ByteCodes {
}
case LC: {
b.add(OBJECT, null);
}
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);
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);
startExpr(b);
b.add(PUT);
b.add(POP);
- if (peekToken() == RC) { consume(RC); continueExpr(b, minPrecedence); return; }
+ if (peekToken() == RC) break;
consume(COMMA);
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;
}
case NAME: {
String name = string;
@@
-262,8
+258,8
@@
class Parser extends Lexer implements ByteCodes {
// invocation
int i = 0;
while(peekToken() != RP) {
// invocation
int i = 0;
while(peekToken() != RP) {
- startExpr(b);
i++;
i++;
+ startExpr(b);
if (peekToken() == RP) break;
consume(COMMA);
}
if (peekToken() == RP) break;
consume(COMMA);
}
@@
-534,7
+530,8
@@
class Parser extends Lexer implements ByteCodes {
consume(LP);
tok = getToken();
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);
String varName = string;
boolean forIn = peekToken() == IN;
pushBackToken(tok, varName);
@@
-564,14
+561,13
@@
class Parser extends Lexer implements ByteCodes {
break;
} else {
break;
} else {
+ if (hadVar) pushBackToken(VAR, null);
ByteCodeBlock b2 = newbb(curLine);
b.add(SCOPE, b2);
b.add(POP);
int size = b2.size();
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);
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(JT, new Integer(2));
b3.add(BREAK);
parseStatement(false, b3);
- b3.add(BREAK);
+ b3.add(CONTINUE);
break;
}
}
break;
}
}