Package litil.ast

Examples of litil.ast.Type


    }

    private List<Type> types() {
        List<Type> res = new ArrayList<Type>();
        Type t = type();
        res.add(t);
        while (found(Token.Type.NEWLINE)) {
            res.add(type());
        }
        return res;
View Full Code Here


            if (found(Token.Type.SYM, ")")) {
                return Type.UNIT;
            }
            depth++;

            Type res = type(1);
            depth--;
            expect(Token.Type.SYM, ")");
            return res;
        } else {
            throw new IllegalArgumentException("Invalid symbol found " + tk);
View Full Code Here

    public Type type(int rbp) {
        dbg("type " + rbp);
        Token tk = lexer.pop();
        dbg("pop0 " + tk);
        depth++;
        Type left = nud(tk);
        depth--;
        while (dbg(rbp, lexer.peek(1)) && rbp < lbp(lexer.peek(1))) {
            tk = lexer.pop();
            dbg("pop " + tk);
            depth++;
View Full Code Here

    }

    private List<Type> types() {
        List<Type> res = new ArrayList<Type>();
        Type t = type();
        res.add(t);
        System.err.println(t);
        while (found(Token.Type.NEWLINE)) {
            t = type();
            res.add(t);
            System.err.println(t + "::" + t.getClass());
        }

        return res;
    }
View Full Code Here

    private Type type(Map<String, Type.Variable> mappings) {
        return funcType(mappings);
    }

    private Type funcType(Map<String, Type.Variable> mappings) {
        Type arg = prodType(mappings);
        if (found(Token.Type.SYM, "->")) {
            Type res = funcType(mappings);
            return Type.Function(arg, res);
        }
        return arg;
    }
View Full Code Here

    }

    private Type atomType(Map<String, Type.Variable> mappings) {
        if (found(Token.Type.SYM, "(")) {
            Type res = type(mappings);
            expect(Token.Type.SYM, ")");
            return res;
        } else if (found(Token.Type.SYM, "[")) {
            Type res = type(mappings);
            expect(Token.Type.SYM, "]");
            return Type.List(res);
        } else if (found(Token.Type.NAME)) {
            String name = token.text;
            if (Character.isLowerCase(name.charAt(0))) {
View Full Code Here

    public void define(String name, Type type) {
        scope.put(name, type);
    }

    public Type get(String name) {
        Type res = scope.get(name);
        if (res == null && parent != null) {
            res = parent.get(name);
        }
        return res;
    }
View Full Code Here

        res.define("int2str", Type.Function(Type.INT, Type.STR));
        res.define("print", Type.Function(Type.STR, Type.UNIT));
        res.define("error", Type.Function(Type.STR, new Type.Variable()));

        Type.Variable b = new Type.Variable();
        Type listType = Type.List(b);
        List<DataDecl.TypeConstructor> listConstructors = new ArrayList<DataDecl.TypeConstructor>();
        List<Type> listVars = Arrays.<Type>asList(b);
        listConstructors.add(new DataDecl.TypeConstructor("Cons", Arrays.asList(b, listType)));
        listConstructors.add(new DataDecl.TypeConstructor("Nil"));
        DataDecl list = new DataDecl("List", listType, Arrays.asList(b), listConstructors);
View Full Code Here

TOP

Related Classes of litil.ast.Type

Copyright © 2018 www.massapicom. 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.