DE-labtory / koa

The koa is a high-level language that has more expressions than the bitcoin script and is simpler and easy to analyze
Apache License 2.0
74 stars 18 forks source link

[parser] check symbol table when parsing assignment statement #259

Closed zeroFruit closed 5 years ago

zeroFruit commented 5 years ago

Detail

// parseAssignStatement parse assign statements which assign values
// to its identifier. e.g. int a = 1
func parseAssignStatement(buf TokenBuffer) (*ast.AssignStatement, error) {
    stmt := &ast.AssignStatement{}

    token := buf.Read()

    ds := datastructureMap[token.Type]
    stmt.Type = ds

    token = buf.Read()
    if token.Type != Ident {
        return nil, ExpectError{
            token,
            Ident,
        }
    }

    // TODO: check whether variable name exist
    // TODO: if not, add symbol to the scope