Beispiel #1
0
        Node expr()
        {
            switch (currToken.Type)
            {

                case TokenType.IDE:
                    return ide();

                case TokenType.LET:

                    Env savedEnv = top;
                    top = new Env(top);

                    Token letToken = match(currToken.Type);
                    IdeNode id = ide();
                    match(TokenType.EQUAL);
                    Node definition = expr();
                    top.Put(id.Token, definition.eval());

                    match(TokenType.IN);
                    Node body = expr();

                    LetNode let = new LetNode(letToken, id, definition, body, top);

                    top = savedEnv;

                    return let;

                case TokenType.AND:
                    Token andToken = match(currToken.Type);
                    match(TokenType.OPENB);

                    AndNode and = new AndNode(andToken);

                    while (currToken.Type != TokenType.CLOSEB)
                    {
                        and.addExpression(expr());

                        if (currToken.Type != TokenType.CLOSEB)
                            match(TokenType.COMMA);
                    }
                    match(TokenType.CLOSEB);
                    return and;

                case TokenType.BOOL:
                    return new Node(match(currToken.Type));

                default:
                    Error("Error: invalid token: " + currToken.Type.ToString());
                    return null;
            }
        }
Beispiel #2
0
 public IdeNode(Token t, Env e)
     : base(t, e)
 {
 }
Beispiel #3
0
 public LetNode(Token t, IdeNode ide, Node definition, Node body, Env e)
     : base(t, e)
 {
     this.ide = ide;
     this.definition = definition;
     this.body = body;
 }
Beispiel #4
0
 public Node(Token t, Env e = null)
 {
     this.token = t;
     this.env = e;
 }
Beispiel #5
0
 public Env(Env p = null)
 {
     table = new Hashtable();
     this.prev = p;
 }