Compare commits
1 Commits
or-skip-ri
...
times-init
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d64e597414 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ out/
|
|||||||
*.zip
|
*.zip
|
||||||
prg/**/*.ast
|
prg/**/*.ast
|
||||||
prg/**/*.out
|
prg/**/*.out
|
||||||
|
prg/**/*.pins25
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fun putstr(s)
|
|
||||||
|
|
||||||
fun f1() =
|
|
||||||
putstr("funkcija 1\n\00"),
|
|
||||||
0
|
|
||||||
|
|
||||||
fun f2() =
|
|
||||||
putstr("funkcija 2\n\00"),
|
|
||||||
0
|
|
||||||
|
|
||||||
fun main() =
|
|
||||||
f1() || f2()
|
|
||||||
@@ -69,6 +69,10 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
|
|||||||
* Kljucna beseda {@code in}.
|
* Kljucna beseda {@code in}.
|
||||||
*/
|
*/
|
||||||
IN,
|
IN,
|
||||||
|
/**
|
||||||
|
* Kljucna beseda {@code times}.
|
||||||
|
*/
|
||||||
|
TIMES,
|
||||||
/**
|
/**
|
||||||
* Kljucna beseda {@code end}.
|
* Kljucna beseda {@code end}.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -227,10 +227,13 @@ public class CodeGen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PDM.CodeInstr> visit(AST.BinExpr binExpr, Mem.Frame frame) {
|
public List<PDM.CodeInstr> visit(AST.BinExpr binExpr, Mem.Frame frame) {
|
||||||
Report.Location loc = attrAST.attrLoc.get(binExpr).location();
|
Report.Locatable loc = attrAST.attrLoc.get(binExpr);
|
||||||
|
|
||||||
List<PDM.CodeInstr> code = new ArrayList<>();
|
List<PDM.CodeInstr> code = new ArrayList<>();
|
||||||
|
|
||||||
|
code.addAll(binExpr.fstExpr.accept(this, frame));
|
||||||
|
code.addAll(binExpr.sndExpr.accept(this, frame));
|
||||||
|
|
||||||
PDM.OPER.Oper oper = switch (binExpr.oper) {
|
PDM.OPER.Oper oper = switch (binExpr.oper) {
|
||||||
case OR -> PDM.OPER.Oper.OR;
|
case OR -> PDM.OPER.Oper.OR;
|
||||||
case AND -> PDM.OPER.Oper.AND;
|
case AND -> PDM.OPER.Oper.AND;
|
||||||
@@ -247,34 +250,7 @@ public class CodeGen {
|
|||||||
case MOD -> PDM.OPER.Oper.MOD;
|
case MOD -> PDM.OPER.Oper.MOD;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (oper == PDM.OPER.Oper.OR) {
|
code.add(new PDM.OPER(oper, loc));
|
||||||
String locStr = loc.begLine() + ":" + loc.begColumn();
|
|
||||||
String rightLabel = "$or:right" + locStr;
|
|
||||||
String skipLabel = "$or:skip@" + locStr;
|
|
||||||
String endLabel = "$or:end@" + locStr;
|
|
||||||
|
|
||||||
code.addAll(binExpr.fstExpr.accept(this, frame));
|
|
||||||
code.add(new PDM.NAME(skipLabel, loc));
|
|
||||||
code.add(new PDM.NAME(rightLabel, loc));
|
|
||||||
code.add(new PDM.CJMP(loc));
|
|
||||||
|
|
||||||
code.add(new PDM.LABEL(rightLabel, loc));
|
|
||||||
code.add(new PDM.PUSH(0, loc));
|
|
||||||
code.addAll(binExpr.sndExpr.accept(this, frame));
|
|
||||||
code.add(new PDM.OPER(oper, loc));
|
|
||||||
code.add(new PDM.NAME(endLabel, loc));
|
|
||||||
code.add(new PDM.UJMP(loc));
|
|
||||||
|
|
||||||
code.add(new PDM.LABEL(skipLabel, loc));
|
|
||||||
code.add(new PDM.PUSH(1, loc));
|
|
||||||
|
|
||||||
code.add(new PDM.LABEL(endLabel, loc));
|
|
||||||
} else {
|
|
||||||
code.addAll(binExpr.fstExpr.accept(this, frame));
|
|
||||||
code.addAll(binExpr.sndExpr.accept(this, frame));
|
|
||||||
|
|
||||||
code.add(new PDM.OPER(oper, loc));
|
|
||||||
}
|
|
||||||
|
|
||||||
attrAST.attrCode.put(binExpr, code);
|
attrAST.attrCode.put(binExpr, code);
|
||||||
return code;
|
return code;
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ public class LexAn implements AutoCloseable {
|
|||||||
case "let" -> Token.Symbol.LET;
|
case "let" -> Token.Symbol.LET;
|
||||||
case "in" -> Token.Symbol.IN;
|
case "in" -> Token.Symbol.IN;
|
||||||
case "end" -> Token.Symbol.END;
|
case "end" -> Token.Symbol.END;
|
||||||
|
case "times" -> Token.Symbol.TIMES;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,9 +360,9 @@ public class SynAn implements AutoCloseable {
|
|||||||
|
|
||||||
private AST.AtomExpr parseIntegerConstantMultiplier() {
|
private AST.AtomExpr parseIntegerConstantMultiplier() {
|
||||||
Token token = lexAn.peekToken();
|
Token token = lexAn.peekToken();
|
||||||
if (token.symbol() == Token.Symbol.MUL) {
|
if (token.symbol() == Token.Symbol.TIMES) {
|
||||||
// intconstmult -> MUL const
|
// intconstmult -> TIMES const
|
||||||
check(Token.Symbol.MUL);
|
check(Token.Symbol.TIMES);
|
||||||
return parseConstant();
|
return parseConstant();
|
||||||
}
|
}
|
||||||
// intconstmult -> ε
|
// intconstmult -> ε
|
||||||
|
|||||||
Reference in New Issue
Block a user