1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

rename compiler2.parser to v.parser etc

This commit is contained in:
Alexander Medvednikov 2019-12-27 05:43:17 +01:00
parent 98b81252b7
commit 14e9c3c7bb
12 changed files with 47 additions and 27 deletions

View File

@ -4,7 +4,7 @@
module ast module ast
import ( import (
compiler2.token v.token
) )

View File

@ -2,7 +2,7 @@ module cgen
import ( import (
strings strings
compiler2.ast v.ast
) )
struct Gen { struct Gen {
@ -10,13 +10,13 @@ struct Gen {
} }
pub fn gen(program ast.Program) { pub fn gen(program ast.Program) string {
mut g := Gen{out:strings.new_builder(100)} mut g := Gen{out:strings.new_builder(100)}
for expr in program.exprs { for expr in program.exprs {
g.expr(expr) g.expr(expr)
g.writeln('') g.writeln('')
} }
println(g.out.str()) return (g.out.str())
} }
pub fn (g &Gen) save() { pub fn (g &Gen) save() {

View File

@ -4,10 +4,10 @@
module parser module parser
import ( import (
compiler2.scanner v.scanner
compiler2.ast v.ast
compiler2.token v.token
compiler2.table v.table
) )
struct Parser { struct Parser {

View File

@ -1,9 +1,9 @@
module parser module parser
import ( import (
compiler2.ast v.ast
compiler2.cgen v.cgen
compiler2.table v.table
) )
@ -55,25 +55,45 @@ fn test_cgen2() {
fn test_cgen() { fn test_cgen() {
//if true { return } //if true { return }
s := [ input := [
'2 + 3',
'2+2*4',
//'(2+2)*4',
'x := 10', 'x := 10',
//'x := 10' 'a := 12',
]
output := [
'2 + 3',
'2 + 2 * 4',
//'(2 + 2) * 4',
'int x = 10;',
'int a = 12;',
] ]
//expr := parse_expr('3 + 7 * 2') //expr := parse_expr('3 + 7 * 2')
//expr2 := parse_stmt('a := 3 + "f"') //expr2 := parse_stmt('a := 3 + "f"')
mut e := []ast.Expr mut e := []ast.Expr
table := &table.Table{} table := &table.Table{}
for ss in s { for s in input {
//expr2 := parse_expr('x := 10') e << parse_expr(s, table)
//program := ast.Program{
e << parse_expr(ss, table)
//exprs: [
//expr2,
//parse_expr('2 * 2'),
//]
} }
program := ast.Program{exprs:e} program := ast.Program{exprs:e}
cgen.gen(program) res := cgen.gen(program)
println('========')
println(res)
println('========')
lines := res.split_into_lines()
mut i := 0
for line in lines {
if line == '' {
continue
}
println('"$line" "${output[i]}"')
assert line == output[i]
i++
if i >= output.len {
break
}
}
//cgen.save() //cgen.save()
} }

View File

@ -5,7 +5,7 @@ module scanner
import ( import (
os os
compiler2.token v.token
// strings // strings
) )

View File

@ -4,7 +4,7 @@
module scanner module scanner
import ( import (
compiler2.token v.token
) )
fn test_scan() { fn test_scan() {