public ParserType Visit(ParserPair pair)
        {
            var        leftType  = pair.Left.Accept(this);
            var        rightType = pair.Right.Accept(this);
            ParserType prodType  = new ParserProdType(leftType, rightType);

            pair.Type = prodType;
            return(prodType);
        }
Beispiel #2
0
        public Expression Visit(ParserUnaryOp op)
        {
            Expression     subExpr = op.Expr.Accept(this);
            ParserProdType type    = op.Expr.Type as ParserProdType;

            switch (op.OpType)
            {
            case ParserUnaryOpType.ProjL:
                if (type.Left is ParserNumType)
                {
                    return(new NumProjL(subExpr as AbstractPairExpression));
                }
                if (type.Left is ParserLogicType)
                {
                    return(new LogicProjL(subExpr as AbstractPairExpression));
                }
                if (type.Left is ParserProdType)
                {
                    return(new PairProjL(subExpr as AbstractPairExpression));
                }
                if (type.Left is ParserLambdaType)
                {
                    return(new LambdaProjL(subExpr as AbstractPairExpression));
                }
                break;

            case ParserUnaryOpType.ProjR:
                if (type.Right is ParserNumType)
                {
                    return(new NumProjR(subExpr as AbstractPairExpression));
                }
                if (type.Right is ParserLogicType)
                {
                    return(new LogicProjR(subExpr as AbstractPairExpression));
                }
                if (type.Right is ParserProdType)
                {
                    return(new PairProjR(subExpr as AbstractPairExpression));
                }
                if (type.Right is ParserLambdaType)
                {
                    return(new LambdaProjR(subExpr as AbstractPairExpression));
                }
                break;

            default:
                break;
            }

            throw new ArgumentException("Unknown unary operation");
        }