Merge branch '29-remove-print-statement' into 'master'

delete print statement

Closes #29

See merge request mkais001/klang!16
This commit is contained in:
Dennis Kaiser
2020-03-09 14:23:07 +01:00
8 changed files with 1 additions and 63 deletions

View File

@@ -28,8 +28,7 @@ braced_block
// Only the first child of a rule alternative will be visited!
// i.e. SCOL won't be visited, but thats unneccesary anyway
statement
: print
| if_statement
: if_statement
| variable_declaration SCOL
| variable_assignment SCOL
| return_statement
@@ -38,10 +37,6 @@ statement
| forLoop
;
print
: PRINT expression SCOL
;
if_statement
: IF OPAR cond = expression CPAR then = braced_block (ELSE (alt = braced_block | elif = if_statement) )?
;
@@ -123,7 +118,6 @@ forLoop
step = variable_assignment CPAR braced_block
;
PRINT: 'print';
IF: 'if';
ELSE: 'else';
FUNC: 'function';

View File

@@ -102,18 +102,6 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
return result;
}
@Override
public Node visitPrint(KlangParser.PrintContext ctx) {
ctx.start.getLine();
ctx.start.getCharPositionInLine();
Node expression = this.visit(ctx.expression());
PrintStatement result = new PrintStatement((Expression) expression);
result.type = null;
result.line = ctx.start.getLine();
result.col = ctx.start.getCharPositionInLine();
return result;
}
@Override
public Node visitIf_statement(KlangParser.If_statementContext ctx) {
Node condition = this.visit(ctx.cond);

View File

@@ -1,17 +0,0 @@
package de.hsrm.compiler.Klang.nodes.statements;
import de.hsrm.compiler.Klang.nodes.expressions.Expression;
import de.hsrm.compiler.Klang.visitors.Visitor;
public class PrintStatement extends Statement {
public Expression expression;
public PrintStatement(Expression expression) {
this.expression = expression;
}
@Override
public <R> R welcome(Visitor<R> v) {
return v.visit(this);
}
}

View File

@@ -385,13 +385,6 @@ public class EvalVisitor implements Visitor<Value> {
return result;
}
@Override
public Value visit(PrintStatement e) {
Value value = e.expression.welcome(this);
System.out.println(value.asObject());
return null;
}
@Override
public Value visit(VariableDeclaration e) {
Value initialValue = null;

View File

@@ -556,11 +556,6 @@ public class GenASM implements Visitor<Void> {
return null;
}
@Override
public Void visit(PrintStatement e) {
throw new RuntimeException("Das machen wir mal nicht, ne?!");
}
@Override
public Void visit(VariableDeclaration e) {
// If there is an initialization present,

View File

@@ -179,12 +179,6 @@ class GetVars implements Visitor<Void> {
return null;
}
@Override
public Void visit(PrintStatement e) {
e.expression.welcome(this);
return null;
}
@Override
public Void visit(VariableDeclaration e) {
vars.add(e.name);

View File

@@ -276,14 +276,6 @@ public class PrettyPrintVisitor implements Visitor<Void> {
return null;
}
@Override
public Void visit(PrintStatement e) {
ex.write("print ");
e.expression.welcome(this);
ex.write(";");
return null;
}
@Override
public Void visit(VariableDeclaration e) {
ex.write("let " + e.name + ": " + e.type.getName());

View File

@@ -32,7 +32,6 @@ public interface Visitor<R> {
R visit(WhileLoop e);
R visit(DoWhileLoop e);
R visit(ForLoop e);
R visit(PrintStatement e);
R visit(VariableDeclaration e);
R visit(VariableAssignment e);
R visit(ReturnStatement e);