Esempio n. 1
0
        object IVisitor <object> .visit(UnOpNode node)
        {
            Node child = node.getLeft();

            child.accept(this);
            return(null);
        }
        private Node factor()
        {
            Node node = null;

            switch (currentToken.type)
            {
            case "integer":
                node = new IntNode(currentToken);
                match(Token.INT);
                break;

            case "string":
                node = new StrNode(currentToken);
                match(Token.STRING);
                break;

            case "boolean":
                node = new BoolNode(currentToken);
                match(Token.BOOL);
                break;

            case "identifier":
                node = new IdNode(currentToken);
                match(Token.ID);
                break;

            case "lpar":
                nextToken();
                node = expr();
                match(Token.RPAR);
                break;

            case "negation":
                node = new UnOpNode(currentToken);
                match(Token.NEG);
                node.addChild(factor());
                break;

            default:
                new SyntaxError(currentToken, "Syntax Error: Expected integer, string, bool, identifier or (, got " + currentToken.value);
                break;
            }

            return(node);
        }
Esempio n. 3
0
        object IVisitor <object> .visit(UnOpNode node)
        {
            switch (node.value)
            {
            case "!":
                if (Convert.ToBoolean(evaluate(node.getLeft())))
                {
                    return(0);
                }
                else
                {
                    return(1);
                }

            default:
                break;
            }
            return(null);
        }
 object IVisitor <object> .visit(UnOpNode node)
 {
     return(null);
 }