Classes 12
This commit is contained in:
parent
52a7b73a9e
commit
d8ac625429
18 changed files with 417 additions and 186 deletions
|
|
@ -4,8 +4,6 @@ import std.conv;
|
|||
import std.stdio;
|
||||
import std.meta : AliasSeq;
|
||||
|
||||
import taggedalgebraic;
|
||||
|
||||
import jlox.token;
|
||||
import jlox.tokentype;
|
||||
import common.util;
|
||||
|
|
@ -15,13 +13,16 @@ abstract class Expr{
|
|||
R visit(Assign expr);
|
||||
R visit(Binary expr);
|
||||
R visit(Call expr);
|
||||
R visit(Get expr);
|
||||
R visit(Grouping expr);
|
||||
R visit(Literal expr);
|
||||
R visit(Logical expr);
|
||||
R visit(Set expr);
|
||||
R visit(This expr);
|
||||
R visit(Unary expr);
|
||||
R visit(Variable expr);
|
||||
}
|
||||
private alias rTypes = AliasSeq!(string, TValue, void);
|
||||
private alias rTypes = AliasSeq!(string, LoxValue, void);
|
||||
static foreach(T; rTypes)
|
||||
abstract T accept(Visitor!T visitor);
|
||||
private template defCtorAndAccept(){
|
||||
|
|
@ -47,12 +48,17 @@ abstract class Expr{
|
|||
Expr[] arguments;
|
||||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class Get : typeof(this){
|
||||
Expr object;
|
||||
Token name;
|
||||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class Grouping : typeof(this){
|
||||
Expr expression;
|
||||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class Literal : typeof(this){
|
||||
TValue value;
|
||||
LoxValue value;
|
||||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class Logical : typeof(this){
|
||||
|
|
@ -61,6 +67,16 @@ abstract class Expr{
|
|||
Expr right;
|
||||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class Set : typeof(this){
|
||||
Expr object;
|
||||
Token name;
|
||||
Expr value;
|
||||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class This : typeof(this){
|
||||
Token keyword;
|
||||
mixin defCtorAndAccept;
|
||||
}
|
||||
static class Unary : typeof(this){
|
||||
Token operator;
|
||||
Expr right;
|
||||
|
|
@ -72,31 +88,3 @@ abstract class Expr{
|
|||
}
|
||||
}
|
||||
|
||||
/* class AstPrinter : Expr.Visitor!string{ */
|
||||
/* string print(Expr expr){ */
|
||||
/* return expr.accept(this); */
|
||||
/* } */
|
||||
/* string parenthesize(Args...)(string name, Args args){ */
|
||||
/* string s = "(" ~ name; */
|
||||
/* static foreach(expr; args){ */
|
||||
/* s ~= " "; */
|
||||
/* s ~= expr.accept(this); */
|
||||
/* } */
|
||||
/* return s ~ ")"; */
|
||||
/* } */
|
||||
/* string visit(Expr.Binary expr){ */
|
||||
/* return parenthesize(expr.operator.lexeme, expr.left, expr.right); */
|
||||
/* } */
|
||||
/* string visit(Expr.Grouping expr){ */
|
||||
/* return parenthesize("group", expr.expression); */
|
||||
/* } */
|
||||
/* string visit(Expr.Literal expr){ */
|
||||
/* if(expr.value.isNil) */
|
||||
/* return "nil"; */
|
||||
/* return expr.value.to!string; */
|
||||
/* } */
|
||||
/* string visit(Expr.Unary expr){ */
|
||||
/* return parenthesize(expr.operator.lexeme, expr.right); */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue