glox/stmt.go

114 lines
1.8 KiB
Go
Raw Normal View History

2024-10-05 18:58:49 +03:00
package main
type StmtVisitor interface {
2024-10-06 16:30:57 +03:00
visitIfStmt(i *IfStmt)
2024-10-05 18:58:49 +03:00
visitVarStmt(v *VarStmt)
2024-10-09 23:36:18 +03:00
visitEnvStmt(e *EnvStmt)
visitFunStmt(f *FunStmt)
2024-10-05 23:27:00 +03:00
visitExprStmt(es *ExprStmt)
visitPrintStmt(p *PrintStmt)
visitBlockStmt(b *BlockStmt)
2024-10-07 21:06:23 +03:00
visitWhileStmt(w *WhileStmt)
2024-10-07 21:47:55 +03:00
visitBreakStmt(b *BreakStmt)
2024-10-11 17:01:12 +03:00
visitReturnStmt(r *ReturnStmt)
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-06 16:30:57 +03:00
type EnvStmt struct{}
type IfStmt struct {
name Token
2024-10-14 22:53:26 +03:00
cond Expr
2024-10-06 16:30:57 +03:00
then Stmt
or Stmt
}
2024-10-07 21:06:23 +03:00
type WhileStmt struct {
cond Expr
body Stmt
}
2024-10-07 21:47:55 +03:00
type BreakStmt struct{}
2024-10-09 23:36:18 +03:00
type FunStmt struct {
name Token
args []Token
2024-10-14 22:53:26 +03:00
body []Stmt
2024-10-09 23:36:18 +03:00
}
2024-10-11 17:01:12 +03:00
type ReturnStmt struct {
value Expr
}
func (i *IfStmt) stmt() {}
func (f *FunStmt) stmt() {}
func (e *EnvStmt) stmt() {}
func (vs *VarStmt) stmt() {}
func (es *ExprStmt) stmt() {}
func (p *PrintStmt) stmt() {}
func (b *BlockStmt) stmt() {}
func (w *WhileStmt) stmt() {}
func (b *BreakStmt) stmt() {}
func (r *ReturnStmt) 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)
}
2024-10-06 16:30:57 +03:00
func (i *IfStmt) accept(v StmtVisitor) {
v.visitIfStmt(i)
}
func (e *EnvStmt) accept(v StmtVisitor) {
v.visitEnvStmt(e)
}
2024-10-07 21:06:23 +03:00
func (w *WhileStmt) accept(v StmtVisitor) {
v.visitWhileStmt(w)
}
2024-10-07 21:47:55 +03:00
func (b *BreakStmt) accept(v StmtVisitor) {
v.visitBreakStmt(b)
}
2024-10-09 23:36:18 +03:00
func (f *FunStmt) accept(v StmtVisitor) {
v.visitFunStmt(f)
}
2024-10-11 17:01:12 +03:00
func (r *ReturnStmt) accept(v StmtVisitor) {
v.visitReturnStmt(r)
}