diff --git a/vlib/compiler2/ast/ast.v b/vlib/compiler2/ast/ast.v index c932ae44f2..605b56a34f 100644 --- a/vlib/compiler2/ast/ast.v +++ b/vlib/compiler2/ast/ast.v @@ -10,11 +10,11 @@ import ( struct Foo {} -pub type Expr = Foo | IfExpr | BinaryExpr | ScalarExpr | UnaryExpr | - StringLiteral | IntegerExpr +pub type Expr = Foo | IfExpr | BinaryExpr | UnaryExpr | + StringLiteral | IntegerLiteral pub type Stmt = Foo | VarDecl -pub struct IntegerExpr { +pub struct IntegerLiteral { pub: val int } @@ -66,16 +66,6 @@ pub: right Expr } -pub struct ScalarExpr { -pub: - token token.Token - // op BinaryOp - // op token.Token - typ token.Token - val string - left Expr -} - pub struct UnaryExpr { pub: // token token.Token @@ -102,9 +92,9 @@ pub fn (x Expr) str() string { BinaryExpr { return '(${it.left.str()}$it.op.str()${it.right.str()})' } - ScalarExpr { - return '${it.left.str()}$it.val' - } + //ScalarExpr { + //return '${it.left.str()}$it.val' + //} UnaryExpr { return '${it.left.str()}$it.op.str()' } diff --git a/vlib/compiler2/cgen/cgen.v b/vlib/compiler2/cgen/cgen.v index 4dcb11b946..a2ca782a39 100644 --- a/vlib/compiler2/cgen/cgen.v +++ b/vlib/compiler2/cgen/cgen.v @@ -44,15 +44,10 @@ const ( fn (g mut Gen) expr(node ast.Expr) Type { //println('cgen expr()') match node { - ast.IntegerExpr { + ast.IntegerLiteral { g.write(it.val.str()) return int_type } - ast.ScalarExpr { - g.expr(it.left) - g.write(' $it.val ') - - } ast.UnaryExpr { g.expr(it.left) g.write(' $it.op ') diff --git a/vlib/compiler2/parser/parser.v b/vlib/compiler2/parser/parser.v index 671fbd42a7..108ad64a74 100644 --- a/vlib/compiler2/parser/parser.v +++ b/vlib/compiler2/parser/parser.v @@ -64,10 +64,18 @@ pub fn (p mut Parser) expr(rbp int) ast.Expr { else { // TODO: fix bug. note odd conditon instead of else if (same below) if tok.is_scalar() { - node = ast.ScalarExpr{ - val: lit - typ: tok + if tok == .str { + node = ast.StringLiteral { + val: lit + } + } if tok == .number { + node = ast.IntegerLiteral { + val: lit.int() + } } + //else { + //verror('bad scalar token') + //} } if !tok.is_scalar() && tok.is_unary() { node = ast.UnaryExpr{ @@ -123,3 +131,8 @@ fn (p mut Parser) stmt() ast.Stmt { return ast.VarDecl{} } + +fn verror(s string) { + println(s) + exit(1) +} diff --git a/vlib/compiler2/parser/parser_test.v b/vlib/compiler2/parser/parser_test.v index aeecc58105..a8c028d922 100644 --- a/vlib/compiler2/parser/parser_test.v +++ b/vlib/compiler2/parser/parser_test.v @@ -40,7 +40,7 @@ fn test_parser() { fn test_cgen() { //expr := parse_expr('3 + 7 * 2') //expr2 := parse_stmt('a := 3 + "f"') - expr2 := parse_expr('2 +3 ')//"helo"') + expr2 := parse_expr('2 + "helo"') program := ast.Program{ exprs: [ expr2,