Package org.yinwang.yin.ast

Source Code of org.yinwang.yin.ast.Name

package org.yinwang.yin.ast;


import org.yinwang.yin.Scope;
import org.yinwang.yin.Util;
import org.yinwang.yin.value.Value;

public class Name extends Node {
    public String id;


    public Name(String id, String file, int start, int end, int line, int col) {
        super(file, start, end, line, col);
        this.id = id;
    }


    /**
     * Generate a name without location info
     */
    public static Name genName(String id) {
        return new Name(id, null, 0, 0, 0, 0);
    }


    public Value interp(Scope s) {
        return s.lookup(id);
    }


    @Override
    public Value typecheck(Scope s) {
        Value v = s.lookup(id);
        if (v != null) {
            return v;
        } else {
            Util.abort(this, "unbound variable: " + id);
            return Value.VOID;
        }
    }


    public String toString() {
        return id;
    }
}
TOP

Related Classes of org.yinwang.yin.ast.Name

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.