예제 #1
0
        public IProgram Program()
        {
            Declarations globals = new Declarations();
            Functions    funcs   = new Functions();

            globals.PutAll(Declarations(funcs));
            return(new IProgram(globals, funcs));
        }
예제 #2
0
 public Function(Type t, string i, Declarations p, Declarations l, Block b)
 {
     this._type   = t;
     this._id     = i;
     this._param  = p;
     this._locals = l;
     this._body   = b;
 }
예제 #3
0
        public static State initialState(Declarations d)
        {
            State state = new State();

            foreach (Declaration decl in d.values())
            {
                state.put(decl.variable(), Value.mkValue(decl.type()));
            }
            return(state);
        }
예제 #4
0
        public static TypeMap Typing(Declarations d)
        {
            TypeMap map = new TypeMap();

            foreach (Declaration di in d.Values)
            {
                map.Add(di.variable(), di.type());
            }
            return(map);
        }
예제 #5
0
        public static State InitialState(Declarations d)
        {
            State state = new State();

            foreach (Declaration decl in d.Values)
            {
                state.Add(decl.variable(), Value.MkValue(decl.type()));
            }
            return(state);
        }
예제 #6
0
        private Declarations Declarations(Functions functions)
        {
            Declarations ds = new Declarations();

            while (IsType())
            {
                Declaration(ds, functions);
            }

            return(ds);
        }
예제 #7
0
        private void Function(Functions functions, Type t, Variable v)
        {
            currentFunction = v;
            Match(Token.Type.LeftParen);
            Declarations param = Parameters();

            Match(Token.Type.RightParen);
            Match(Token.Type.LeftBrace);
            Declarations locals = Declarations(functions);
            Block        body   = Statements();

            Match(Token.Type.RightBrace);

            functions.Add(v.ToString(), new Function(t, v.ToString(), param, locals, body));
        }
예제 #8
0
        private Declarations Parameters()
        {
            Declarations decs = new Declarations();

            while (currentToken.GetType() != Token.Type.RightParen)
            {
                Type     t = GetType();
                Variable v = new Variable(currentToken.GetValue());
                Match(Token.Type.Identifier);
                decs.Add(v.ToString(), new Declaration(v, t));
                if (currentToken.GetType() == Token.Type.Comma)
                {
                    Match(Token.Type.Comma);
                }
            }

            return(decs);
        }
예제 #9
0
        private void Declaration(Declarations ds, Functions functions)
        {
            Type Type = GetType();

            while (currentToken.GetType() != Token.Type.Eof)
            {
                Variable v = new Variable(currentToken.GetValue());
                Match(Token.Type.Identifier);
                if (currentToken.GetType() == Token.Type.LeftParen)
                {
                    Function(functions, Type, v);
                    if (IsType())
                    {
                        Type = GetType();
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    ds.Add(v.ToString(), new Declaration(v, Type));
                    if (currentToken.GetType() == Token.Type.Comma)
                    {
                        Match(Token.Type.Comma);
                    }
                    else if (currentToken.GetType() == Token.Type.Semicolon)
                    {
                        Match(Token.Type.Semicolon);
                        if (IsType())
                        {
                            Type = GetType();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
예제 #10
0
 public IProgram(Declarations globals, Functions _functions)
 {
     this.globals    = globals;
     this._functions = _functions;
 }