Tests for generation from AST
This commit is contained in:
parent
22d61691f1
commit
a2aad0e4b9
|
|
@ -39,10 +39,6 @@ type BinaryExpr struct {
|
|||
right Expr
|
||||
}
|
||||
|
||||
func (b BinaryExpr) Kind() string {
|
||||
return "BinaryExpr"
|
||||
}
|
||||
|
||||
type UnaryExpr struct {
|
||||
startToken Token
|
||||
expr Expr
|
||||
|
|
@ -70,6 +66,15 @@ type BlockExpr struct {
|
|||
expressions []Expr
|
||||
}
|
||||
|
||||
func (e Identifier) Kind() string { return "Identifier" }
|
||||
func (e AssignmentExpr) Kind() string { return "AssignmentExpr" }
|
||||
func (e BinaryExpr) Kind() string { return "BinaryExpr" }
|
||||
func (e UnaryExpr) Kind() string { return "UnaryExpr" }
|
||||
func (e IfExpr) Kind() string { return "IfExpr" }
|
||||
func (e ElseIfExpr) Kind() string { return "ElseIfExpr" }
|
||||
func (e ElseExpr) Kind() string { return "ElseExpr" }
|
||||
func (e BlockExpr) Kind() string { return "BlockExpr" }
|
||||
|
||||
const (
|
||||
EOF = "EOF"
|
||||
INDENT = "INDENT"
|
||||
|
|
@ -120,6 +125,18 @@ var textOperators = map[string]bool{
|
|||
"not": true,
|
||||
}
|
||||
|
||||
func generate(program []Expr) string {
|
||||
var output string
|
||||
|
||||
for i := 0; i < len(program); i++ {
|
||||
expr := program[i]
|
||||
|
||||
fmt.Println(expr)
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
func parse(tokens []Token) []Expr {
|
||||
var program []Expr
|
||||
|
||||
|
|
@ -186,9 +203,6 @@ func parse(tokens []Token) []Expr {
|
|||
condTokens := getCondition()
|
||||
blockTokens := getBlock()
|
||||
|
||||
fmt.Println("cond tokens: ", condTokens)
|
||||
fmt.Println("block tokens:", blockTokens)
|
||||
|
||||
addExpr(IfExpr{
|
||||
startToken: token,
|
||||
condition: parse(condTokens),
|
||||
|
|
@ -201,9 +215,6 @@ func parse(tokens []Token) []Expr {
|
|||
condTokens := getCondition()
|
||||
blockTokens := getBlock()
|
||||
|
||||
fmt.Println("cond tokens: ", condTokens)
|
||||
fmt.Println("block tokens:", blockTokens)
|
||||
|
||||
addExpr(ElseIfExpr{
|
||||
startToken: token,
|
||||
condition: parse(condTokens),
|
||||
|
|
@ -218,8 +229,6 @@ func parse(tokens []Token) []Expr {
|
|||
|
||||
blockTokens := getBlock()
|
||||
|
||||
fmt.Println("block tokens:", blockTokens)
|
||||
|
||||
addExpr(ElseExpr{
|
||||
startToken: token,
|
||||
block: BlockExpr{
|
||||
|
|
@ -460,9 +469,9 @@ func main() {
|
|||
fmt.Printf("%-15s │ %-22s │ %s\n", toPrint...)
|
||||
}
|
||||
|
||||
parse(tokens)
|
||||
program := parse(tokens)
|
||||
|
||||
// out := generate(tokens)
|
||||
out := generate(program)
|
||||
|
||||
// fmt.Println(out)
|
||||
fmt.Println(out)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue