2024-10-05 18:58:49 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
type StmtVisitor interface {
|
|
|
|
visitVarStmt(v *VarStmt)
|
2024-10-05 23:27:00 +03:00
|
|
|
visitExprStmt(es *ExprStmt)
|
|
|
|
visitPrintStmt(p *PrintStmt)
|
|
|
|
visitBlockStmt(b *BlockStmt)
|
2024-10-05 18:58:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Stmt interface {
|
|
|
|
stmt()
|
|
|
|
accept(v StmtVisitor)
|
|
|
|
}
|
|
|
|
|
|
|
|
type PrintStmt struct {
|
|
|
|
val Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
type ExprStmt struct {
|
|
|
|
expr Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
type VarStmt struct {
|
|
|
|
name Token
|
|
|
|
initializer Expr
|
|
|
|
}
|
|
|
|
|
2024-10-05 23:27:00 +03:00
|
|
|
type BlockStmt struct {
|
|
|
|
stmts []Stmt
|
|
|
|
}
|
|
|
|
|
2024-10-05 18:58:49 +03:00
|
|
|
func (vs *VarStmt) stmt() {}
|
2024-10-05 23:27:00 +03:00
|
|
|
func (es *ExprStmt) stmt() {}
|
|
|
|
func (p *PrintStmt) stmt() {}
|
|
|
|
func (b *BlockStmt) stmt() {}
|
2024-10-05 18:58:49 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2024-10-05 23:27:00 +03:00
|
|
|
|
|
|
|
func (b *BlockStmt) accept(v StmtVisitor) {
|
|
|
|
v.visitBlockStmt(b)
|
|
|
|
}
|