public IProgram Program() { Declarations globals = new Declarations(); Functions funcs = new Functions(); globals.PutAll(Declarations(funcs)); return(new IProgram(globals, funcs)); }
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; }
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); }
public static TypeMap Typing(Declarations d) { TypeMap map = new TypeMap(); foreach (Declaration di in d.Values) { map.Add(di.variable(), di.type()); } return(map); }
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); }
private Declarations Declarations(Functions functions) { Declarations ds = new Declarations(); while (IsType()) { Declaration(ds, functions); } return(ds); }
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)); }
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); }
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; } } } } }
public IProgram(Declarations globals, Functions _functions) { this.globals = globals; this._functions = _functions; }