diff --git a/ÜB-Praxis-Abstiegsparser für X-Leer/bin/de/dhbw/compiler/xparser/XParser.class b/ÜB-Praxis-Abstiegsparser für X-Leer/bin/de/dhbw/compiler/xparser/XParser.class index 7c4511d..1ea3e36 100644 Binary files a/ÜB-Praxis-Abstiegsparser für X-Leer/bin/de/dhbw/compiler/xparser/XParser.class and b/ÜB-Praxis-Abstiegsparser für X-Leer/bin/de/dhbw/compiler/xparser/XParser.class differ diff --git a/ÜB-Praxis-Abstiegsparser für X-Leer/src/de/dhbw/compiler/xparser/XParser.java b/ÜB-Praxis-Abstiegsparser für X-Leer/src/de/dhbw/compiler/xparser/XParser.java index 9391790..0bb307c 100644 --- a/ÜB-Praxis-Abstiegsparser für X-Leer/src/de/dhbw/compiler/xparser/XParser.java +++ b/ÜB-Praxis-Abstiegsparser für X-Leer/src/de/dhbw/compiler/xparser/XParser.java @@ -65,23 +65,12 @@ public class XParser { } private Tree parseStatList() { - // int oldPosition = in.getPosition(); Tree tree = new Tree(new Token(Token.STATLIST)); Tree stat; while ((stat = parseStatWithSemicolon()) != null) { 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; } @@ -128,6 +117,59 @@ public class XParser { } 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; }