glox/expr.go

99 lines
1.6 KiB
Go
Raw Normal View History

2024-10-05 18:58:49 +03:00
package main
type ExprVisitor interface {
visitUnary(u *Unary) any
visitBinary(b *Binary) any
visitLiteral(l *Literal) any
visitGrouping(g *Grouping) any
visitVariable(v *Variable) any
2024-10-06 16:30:57 +03:00
visitLogicalOr(l *LogicalOr) any
2024-10-05 18:58:49 +03:00
visitAssignment(a *Assign) any
2024-10-06 16:30:57 +03:00
visitLogicalAnd(l *LogicalAnd) any
2024-10-05 18:58:49 +03:00
}
type Expr interface {
expr()
accept(v ExprVisitor) any
}
type Unary struct {
op Token
right Expr
}
type Binary struct {
left Expr
op Token
right Expr
}
type Literal struct {
value any
}
type Grouping struct {
expression Expr
}
type Variable struct {
name Token
}
type Assign struct {
variable Token
value Expr
}
2024-10-06 16:30:57 +03:00
type LogicalOr struct {
left Expr
or Token
right Expr
}
type LogicalAnd struct {
left Expr
and Token
right Expr
}
func (u *Unary) expr() {}
func (a *Assign) expr() {}
func (b *Binary) expr() {}
func (l *Literal) expr() {}
func (g *Grouping) expr() {}
func (v *Variable) expr() {}
func (l *LogicalOr) expr() {}
func (l *LogicalAnd) expr() {}
2024-10-05 18:58:49 +03:00
func (u *Unary) accept(v ExprVisitor) any {
return v.visitUnary(u)
}
func (b *Binary) accept(v ExprVisitor) any {
return v.visitBinary(b)
}
func (l *Literal) accept(v ExprVisitor) any {
return v.visitLiteral(l)
}
func (g *Grouping) accept(v ExprVisitor) any {
return v.visitGrouping(g)
}
func (va *Variable) accept(v ExprVisitor) any {
return v.visitVariable(va)
}
func (a *Assign) accept(v ExprVisitor) any {
return v.visitAssignment(a)
}
2024-10-06 16:30:57 +03:00
func (l *LogicalOr) accept(v ExprVisitor) any {
return v.visitLogicalOr(l)
}
func (l *LogicalAnd) accept(v ExprVisitor) any {
return v.visitLogicalAnd(l)
}