Added LoxPrintMultiple version
This commit is contained in:
parent
a21c16d7e5
commit
b0d934707b
4 changed files with 23 additions and 7 deletions
2
dub.sdl
2
dub.sdl
|
|
@ -8,7 +8,7 @@ dependency "taggedalgebraic" version="~>0.11.23"
|
|||
targetType "executable"
|
||||
buildRequirements "requireBoundsCheck" "requireContracts"
|
||||
|
||||
versions "LoxConcatNonStrings" "LoxExtraNativeFuncs"
|
||||
versions "LoxConcatNonStrings" "LoxExtraNativeFuncs" "LoxPrintMultiple"
|
||||
|
||||
configuration "jlox" {
|
||||
sourcePaths "src/jlox" "src/common"
|
||||
|
|
|
|||
|
|
@ -116,8 +116,12 @@ class Interpreter : Stmt.Visitor!void, Expr.Visitor!TValue {
|
|||
execute(stmt.elseBranch);
|
||||
}
|
||||
void visit(Stmt.Print stmt){
|
||||
TValue value = evaluate(stmt.expression);
|
||||
writeln(tvalueToString(value));
|
||||
version(LoxPrintMultiple){
|
||||
writeln(stmt.expressions.map!(x => evaluate(x)).map!tvalueToString.join("\t"));
|
||||
} else {
|
||||
TValue value = evaluate(stmt.expression);
|
||||
writeln(tvalueToString(value));
|
||||
}
|
||||
}
|
||||
void visit(Stmt.Return stmt){
|
||||
TValue value = stmt.value !is null ? evaluate(stmt.value) : TValue.nil(tvalueNil);
|
||||
|
|
|
|||
|
|
@ -81,9 +81,18 @@ class Parser{
|
|||
}
|
||||
|
||||
private Stmt printStatement(){
|
||||
Expr value = expression();
|
||||
consume(TokenType.SEMICOLON, "Expect ';' after value.");
|
||||
return new Stmt.Print(value);
|
||||
version(LoxPrintMultiple){
|
||||
Expr[] values;
|
||||
do {
|
||||
values ~= expression();
|
||||
} while(match(TokenType.COMMA));
|
||||
consume(TokenType.SEMICOLON, "Expect ';' after values.");
|
||||
return new Stmt.Print(values);
|
||||
} else {
|
||||
Expr value = expression();
|
||||
consume(TokenType.SEMICOLON, "Expect ';' after value.");
|
||||
return new Stmt.Print(value);
|
||||
}
|
||||
}
|
||||
private Stmt returnStatement(){
|
||||
Token keyword = previous();
|
||||
|
|
|
|||
|
|
@ -50,7 +50,10 @@ abstract class Stmt{
|
|||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class Print : typeof(this){
|
||||
Expr expression;
|
||||
version(LoxPrintMultiple)
|
||||
Expr[] expressions;
|
||||
else
|
||||
Expr expression;
|
||||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class Return : typeof(this){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue