72 lines
1.1 KiB
Go
72 lines
1.1 KiB
Go
package main
|
|
|
|
type StmtVisitor interface {
|
|
visitIfStmt(i *IfStmt)
|
|
visitVarStmt(v *VarStmt)
|
|
visitExprStmt(es *ExprStmt)
|
|
visitPrintStmt(p *PrintStmt)
|
|
visitBlockStmt(b *BlockStmt)
|
|
visitEnvStmt(e *EnvStmt)
|
|
}
|
|
|
|
type Stmt interface {
|
|
stmt()
|
|
accept(v StmtVisitor)
|
|
}
|
|
|
|
type PrintStmt struct {
|
|
val Expr
|
|
}
|
|
|
|
type ExprStmt struct {
|
|
expr Expr
|
|
}
|
|
|
|
type VarStmt struct {
|
|
name Token
|
|
initializer Expr
|
|
}
|
|
|
|
type BlockStmt struct {
|
|
stmts []Stmt
|
|
}
|
|
|
|
type EnvStmt struct{}
|
|
|
|
type IfStmt struct {
|
|
name Token
|
|
expr Expr
|
|
then Stmt
|
|
or Stmt
|
|
}
|
|
|
|
func (i *IfStmt) stmt() {}
|
|
func (vs *VarStmt) stmt() {}
|
|
func (es *ExprStmt) stmt() {}
|
|
func (p *PrintStmt) stmt() {}
|
|
func (b *BlockStmt) stmt() {}
|
|
func (e *EnvStmt) stmt() {}
|
|
|
|
func (p *PrintStmt) accept(v StmtVisitor) {
|
|
v.visitPrintStmt(p)
|
|
}
|
|
|
|
func (se *ExprStmt) accept(v StmtVisitor) {
|
|
v.visitExprStmt(se)
|
|
}
|
|
|
|
func (vs *VarStmt) accept(v StmtVisitor) {
|
|
v.visitVarStmt(vs)
|
|
}
|
|
|
|
func (b *BlockStmt) accept(v StmtVisitor) {
|
|
v.visitBlockStmt(b)
|
|
}
|
|
|
|
func (i *IfStmt) accept(v StmtVisitor) {
|
|
v.visitIfStmt(i)
|
|
}
|
|
|
|
func (e *EnvStmt) accept(v StmtVisitor) {
|
|
v.visitEnvStmt(e)
|
|
}
|