示例#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;
            }
        }