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"
|
targetType "executable"
|
||||||
buildRequirements "requireBoundsCheck" "requireContracts"
|
buildRequirements "requireBoundsCheck" "requireContracts"
|
||||||
|
|
||||||
versions "LoxConcatNonStrings" "LoxExtraNativeFuncs"
|
versions "LoxConcatNonStrings" "LoxExtraNativeFuncs" "LoxPrintMultiple"
|
||||||
|
|
||||||
configuration "jlox" {
|
configuration "jlox" {
|
||||||
sourcePaths "src/jlox" "src/common"
|
sourcePaths "src/jlox" "src/common"
|
||||||
|
|
|
||||||
|
|
@ -116,9 +116,13 @@ class Interpreter : Stmt.Visitor!void, Expr.Visitor!TValue {
|
||||||
execute(stmt.elseBranch);
|
execute(stmt.elseBranch);
|
||||||
}
|
}
|
||||||
void visit(Stmt.Print stmt){
|
void visit(Stmt.Print stmt){
|
||||||
|
version(LoxPrintMultiple){
|
||||||
|
writeln(stmt.expressions.map!(x => evaluate(x)).map!tvalueToString.join("\t"));
|
||||||
|
} else {
|
||||||
TValue value = evaluate(stmt.expression);
|
TValue value = evaluate(stmt.expression);
|
||||||
writeln(tvalueToString(value));
|
writeln(tvalueToString(value));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void visit(Stmt.Return stmt){
|
void visit(Stmt.Return stmt){
|
||||||
TValue value = stmt.value !is null ? evaluate(stmt.value) : TValue.nil(tvalueNil);
|
TValue value = stmt.value !is null ? evaluate(stmt.value) : TValue.nil(tvalueNil);
|
||||||
throw new Return(value);
|
throw new Return(value);
|
||||||
|
|
|
||||||
|
|
@ -81,10 +81,19 @@ class Parser{
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stmt printStatement(){
|
private Stmt printStatement(){
|
||||||
|
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();
|
Expr value = expression();
|
||||||
consume(TokenType.SEMICOLON, "Expect ';' after value.");
|
consume(TokenType.SEMICOLON, "Expect ';' after value.");
|
||||||
return new Stmt.Print(value);
|
return new Stmt.Print(value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private Stmt returnStatement(){
|
private Stmt returnStatement(){
|
||||||
Token keyword = previous();
|
Token keyword = previous();
|
||||||
Expr value;
|
Expr value;
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,9 @@ abstract class Stmt{
|
||||||
mixin defCtorAndAccept;
|
mixin defCtorAndAccept;
|
||||||
}
|
}
|
||||||
static class Print : typeof(this){
|
static class Print : typeof(this){
|
||||||
|
version(LoxPrintMultiple)
|
||||||
|
Expr[] expressions;
|
||||||
|
else
|
||||||
Expr expression;
|
Expr expression;
|
||||||
mixin defCtorAndAccept;
|
mixin defCtorAndAccept;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue