[06 - Top Down Parser] Fix "program*" in TestXminTopDownParser.class
This commit is contained in:
Binary file not shown.
@@ -65,23 +65,12 @@ public class XParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Tree parseStatList() {
|
private Tree parseStatList() {
|
||||||
// int oldPosition = in.getPosition();
|
|
||||||
Tree tree = new Tree(new Token(Token.STATLIST));
|
Tree tree = new Tree(new Token(Token.STATLIST));
|
||||||
Tree stat;
|
Tree stat;
|
||||||
|
|
||||||
while ((stat = parseStatWithSemicolon()) != null) {
|
while ((stat = parseStatWithSemicolon()) != null) {
|
||||||
tree.addLastChild(stat);
|
tree.addLastChild(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ((block = parseBlock()) != null) {
|
|
||||||
// tree.addFirstChild(new Tree(new Token(Token.STATWITHSEMI)));
|
|
||||||
// tree.addFirstChild(block);
|
|
||||||
// tree.addLastChild(new Tree(new Token(Token.SEMICOLON)));
|
|
||||||
//
|
|
||||||
// return tree;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// in.setPosition(oldPosition);
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +117,59 @@ public class XParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Tree parseCondStat() {
|
private Tree parseCondStat() {
|
||||||
|
int oldPosition = in.getPosition();
|
||||||
|
Tree tree = new Tree(new Token(Token.CONDSTAT));
|
||||||
|
Tree ifKey, cond, then, stat1, elseKey, stat2;
|
||||||
|
|
||||||
|
if ((ifKey = parseToken(Token.IF)) != null
|
||||||
|
&& (cond = parseCond()) != null
|
||||||
|
&& (then = parseToken(Token.THEN)) != null
|
||||||
|
&& (stat1 = parseStat()) != null
|
||||||
|
&& (elseKey = parseToken(Token.ELSE)) != null
|
||||||
|
&& (stat2 = parseStat()) != null) {
|
||||||
|
|
||||||
|
tree.addLastChild(ifKey);
|
||||||
|
tree.addLastChild(cond);
|
||||||
|
tree.addLastChild(then);
|
||||||
|
tree.addLastChild(stat1);
|
||||||
|
tree.addLastChild(elseKey);
|
||||||
|
tree.addLastChild(stat2);
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
in.setPosition(oldPosition);
|
||||||
|
|
||||||
|
if (((ifKey = parseToken(Token.IF)) != null)
|
||||||
|
&& (cond = parseCond()) != null
|
||||||
|
&& (then = parseToken(Token.THEN)) != null
|
||||||
|
&& (stat1 = parseStat()) != null) {
|
||||||
|
tree.addLastChild(ifKey);
|
||||||
|
tree.addLastChild(cond);
|
||||||
|
tree.addLastChild(then);
|
||||||
|
tree.addLastChild(stat1);
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
in.setPosition(oldPosition);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Tree parseCond() {
|
||||||
|
int oldPosition = in.getPosition();
|
||||||
|
Tree tree = new Tree(new Token(Token.COND));
|
||||||
|
Tree a, operator, b;
|
||||||
|
|
||||||
|
if ((a = parseNumExpr()) != null
|
||||||
|
&& ((operator = parseToken(Token.EQUALS)) != null
|
||||||
|
|| (operator = parseToken(Token.LESS)) != null
|
||||||
|
|| (operator = parseToken(Token.MORE)) != null)
|
||||||
|
&& (b = parseNumExpr()) != null) {
|
||||||
|
tree.addLastChild(a);
|
||||||
|
tree.addLastChild(operator);
|
||||||
|
tree.addLastChild(b);
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
in.setPosition(oldPosition);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user