You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
820 B
Go
49 lines
820 B
Go
package ast
|
|
|
|
import "golox/token"
|
|
|
|
type StmtVisitor[T any] interface {
|
|
VisitErrorStmt(es *ErrorStmt) T
|
|
VisitExpressionStmt(es *ExpressionStmt) T
|
|
VisitPrintStmt(ps *PrintStmt) T
|
|
VisitVarStmt(vs *VarStmt) T
|
|
}
|
|
|
|
type Stmt interface {
|
|
Accept(visitor StmtVisitor[any]) any
|
|
}
|
|
|
|
type ErrorStmt struct {
|
|
Value string
|
|
}
|
|
|
|
func (es *ErrorStmt) Accept(v StmtVisitor[any]) any {
|
|
return v.VisitErrorStmt(es)
|
|
}
|
|
|
|
type ExpressionStmt struct {
|
|
Expression Expr
|
|
}
|
|
|
|
func (es *ExpressionStmt) Accept(v StmtVisitor[any]) any {
|
|
return v.VisitExpressionStmt(es)
|
|
}
|
|
|
|
type PrintStmt struct {
|
|
Expression Expr
|
|
}
|
|
|
|
func (ps *PrintStmt) Accept(v StmtVisitor[any]) any {
|
|
return v.VisitPrintStmt(ps)
|
|
}
|
|
|
|
type VarStmt struct {
|
|
Name token.Token
|
|
Initializer Expr
|
|
}
|
|
|
|
func (vs *VarStmt) Accept(v StmtVisitor[any]) any {
|
|
return v.VisitVarStmt(vs)
|
|
}
|
|
|