v/vlib/compiler2/parser/parser_test.v

36 lines
459 B
V
Raw Normal View History

2019-12-22 02:34:37 +01:00
module parser
import compiler2.ast
fn test_parser() {
//expr := ast.IntegerExpr {val:10}
//expr := ast.BinaryExpr{}
expr := parse_expr('3 + 7')
walk(expr)
println('')
}
fn walk(node ast.Expr) {
//println('walk()')
match node {
ast.IntegerExpr {
print(it.val)
}
ast.BinaryExpr {
walk(it.left)
match it.op {
.plus {
print(' + ')
}
.minus {
print(' - ')
}
else {}
}
walk(it.right)
}
else {}
}
}