Exemplo n.º 1
0
        /// <summary>
        /// Parses an expression operand into an IExpressionContainer
        /// </summary>
        /// <returns>The next token.</returns>
        /// <param name="token">Token.</param>
        /// <param name="parent">An IExpressionContainer.</param>
        private Token ParseOperand(Token token, IExpressionContainer parent)
        {
            // an operand can be an integer, string, boolean, variable or an expression
            // check the token's type to know what we're parsing
            switch (token.Type)
            {
            case TokenType.INT_VAL:
                ParseIntegerOperand(token, parent);
                break;

            case TokenType.STR_VAL:
                nodeBuilder.CreateStringValueNode(token, parent);
                break;

            case TokenType.BOOL_VAL:
                nodeBuilder.CreateBoolValueNode(token, parent);
                break;

            case TokenType.ID:
                nodeBuilder.CreateIdNode(token, parent);
                break;

            case TokenType.PARENTHESIS_LEFT:
                Token next = ParseExpression(scanner.getNextToken(token), parent);
                match(next, TokenType.PARENTHESIS_RIGHT);
                break;

            default:
                throw new UnexpectedTokenException(token, TokenType.UNDEFINED, ParserConstants.EXPECTATION_SET_EXPRESSION);
            }

            return(scanner.getNextToken(token));
        }
Exemplo n.º 2
0
        private static bool TryEvaluateExpression <T>(Activity <T> expression, LocationReferenceEnvironment locationReferenceEnvironment, ActivityContext context, out object result)
        {
            T local;

            if (!expression.TryGetValue(context, out local))
            {
                result = System.Activities.SR.DebugInfoTryGetValueFailed;
                return(false);
            }
            Activity rootActivity = local as Activity;

            context.Activity = rootActivity;
            if ((rootActivity != null) && !rootActivity.IsRuntimeReady)
            {
                WorkflowInspectionServices.CacheMetadata(rootActivity, locationReferenceEnvironment);
            }
            IExpressionContainer container = local as IExpressionContainer;

            if (container == null)
            {
                result = System.Activities.SR.DebugInfoNotAnIExpressionContainer;
                return(false);
            }
            Expression <Func <ActivityContext, object> > expression2 = container.Expression as Expression <Func <ActivityContext, object> >;

            if (expression2 == null)
            {
                result = System.Activities.SR.DebugInfoNoLambda;
                return(false);
            }
            result = expression2.Compile()(context);
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses the an expression into a node that implements IExpressionContainer interface.
        /// </summary>
        /// <returns>The next token.</returns>
        /// <param name="token">Token.</param>
        /// <param name="node">An IExpressionContainer.</param>
        private Token ParseExpression(Token token, IExpressionContainer node)
        {
            Token next;

            switch (token.Type)
            {
            case TokenType.INT_VAL:
            case TokenType.STR_VAL:
            case TokenType.BOOL_VAL:
            case TokenType.PARENTHESIS_LEFT:
            case TokenType.ID:
                // parse a binary operation
                BinOpNode binOp = nodeBuilder.CreateBinOpNode(node, token);
                // parse the first operand
                next = ParseOperand(token, binOp);
                // parse the rest of the operation
                return(ParseBinaryOp(next, binOp));

            case TokenType.UNARY_OP_LOG_NEG:
                // parse a unary operation
                UnOpNode unOp = nodeBuilder.CreateUnOpNode(node, token);
                // parse the operation, then the operand
                next = ParseUnaryOp(token, unOp);
                return(ParseOperand(next, unOp));

            default:
                throw new UnexpectedTokenException(token, TokenType.UNDEFINED, ParserConstants.EXPECTATION_SET_EXPRESSION);
            }
        }
Exemplo n.º 4
0
        public IExpressionNode CreateIdNode(Token t, IExpressionContainer parent)
        {
            VariableIdNode node = new VariableIdNode(t.Value, symbolTable, t);

            parent.AddExpression(node);

            return(node);
        }
Exemplo n.º 5
0
        public UnOpNode CreateUnOpNode(IExpressionContainer parent, Token t)
        {
            UnOpNode unOp = new UnOpNode(t);

            parent.AddExpression(unOp);

            return(unOp);
        }
Exemplo n.º 6
0
        public IExpressionNode CreateDefaultBoolValueNode(Token t, IExpressionContainer parent)
        {
            BoolValueNode node = new BoolValueNode(SemanticAnalysisConstants.DEFAULT_BOOL_VALUE, t);

            parent.AddExpression(node);

            return(node);
        }
Exemplo n.º 7
0
        public IExpressionNode CreateDefaultIntValueNode(Token t, IExpressionContainer parent)
        {
            IntValueNode node = new IntValueNode(SemanticAnalysisConstants.DEFAULT_INTEGER_VALUE, t);

            parent.AddExpression(node);

            return(node);
        }
Exemplo n.º 8
0
        public BinOpNode CreateBinOpNode(IExpressionContainer parent, Token t)
        {
            BinOpNode binOp = new BinOpNode(t);

            parent.AddExpression(binOp);

            return(binOp);
        }
Exemplo n.º 9
0
        public IExpressionNode CreateDefaultStringValueNode(Token t, IExpressionContainer parent)
        {
            StringValueNode node = new StringValueNode(SemanticAnalysisConstants.DEFAULT_STRING_VALUE, t);

            parent.AddExpression(node);

            return(node);
        }
Exemplo n.º 10
0
        public IExpressionNode CreateBoolValueNode(Token t, IExpressionContainer parent)
        {
            bool          value = StringUtils.parseToBoolean(t.Value);
            BoolValueNode node  = new BoolValueNode(value, t);

            parent.AddExpression(node);

            return(node);
        }
Exemplo n.º 11
0
        public IExpressionNode CreateStringValueNode(Token t, IExpressionContainer parent)
        {
            string          value = t.Value;
            StringValueNode node  = new StringValueNode(value, t);

            parent.AddExpression(node);

            return(node);
        }
Exemplo n.º 12
0
        public IExpressionNode CreateIntValueNode(Token t, IExpressionContainer parent)
        {
            int          value = StringUtils.parseToInt(t.Value);
            IntValueNode node  = new IntValueNode(value, t);

            parent.AddExpression(node);

            return(node);
        }
Exemplo n.º 13
0
        public BinOpNode CreateBinOpNode(IExpressionContainer parent, IExpressionNode leftHandSide, Token operation)
        {
            BinOpNode binOp = new BinOpNode(parent.Token);

            binOp.AddExpression(leftHandSide);
            binOp.Operation = operation.Type;
            parent.AddExpression(binOp);

            return(binOp);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Parses an integer operand into an IExpressionContainer
 /// </summary>
 /// <param name="token">Token.</param>
 /// <param name="parent">An IExpressionContainer.</param>
 private void ParseIntegerOperand(Token token, IExpressionContainer parent)
 {
     try {
         // try to create an IntValueNode for the value
         nodeBuilder.CreateIntValueNode(token, parent);
     } catch (OverflowException) {
         // In case the token's value is an integer that cannot be represented as a
         // signed 32-bit integer, an OverflowException is thrown.
         // In this case, the parses reports an IntegerOverflowError.
         notifyError(new IntegerOverflowError(token));
         nodeBuilder.CreateDefaultIntValueNode(token, parent);
     }
 }
Exemplo n.º 15
0
        public IExpressionNode CreateValueNode(Token t, IExpressionContainer node, TokenType valueType)
        {
            switch (valueType)
            {
            case TokenType.INT_VAL:
                return(CreateIntValueNode(t, node));

            case TokenType.STR_VAL:
                return(CreateStringValueNode(t, node));

            case TokenType.BOOL_VAL:
                return(CreateBoolValueNode(t, node));

            default:
                throw new ArgumentException();
            }
        }
Exemplo n.º 16
0
        public static string PrepareExpression(string withEmbedded, IExpressionContainer container, string idString, ParserValidationDelegate vd)
        {
            string checkExpression = withEmbedded;
            string retVal          = String.Empty;
            int    leftBrace       = 0;
            int    startPos        = 0;

            for (leftBrace = checkExpression.IndexOf("{", startPos); startPos >= 0; leftBrace = checkExpression.IndexOf("{", startPos))
            {
                if (leftBrace == -1)
                {
                    // No more strings to replace.
                    retVal += checkExpression.Substring(startPos, checkExpression.Length - startPos);
                    break;
                }
                else
                {
                    // Concatenate portion of string without embedded references.
                    retVal += checkExpression.Substring(startPos, leftBrace - startPos);
                }

                int rightBrace = checkExpression.IndexOf("}", leftBrace);
                if (rightBrace == -1)
                {
                    if (vd != null)
                    {
                        vd(ParserValidationArgs.NewError("The " + idString + " has a left brace({} with no corresonding right brace(}}"));
                    }
                    return("");
                }

                // Isolate the property reference and concatenate it's expansion.
                string expressionReference = checkExpression.Substring(leftBrace + 1, rightBrace - leftBrace - 1);
                retVal += container.GetExpressionSubstitution(expressionReference, idString, vd);

                // On to the next reference.
                startPos = rightBrace + 1;
            }

            return(retVal);
        }
        public MainWindow(
            ILanguageContainer languageContainer,
            IMathExpressionService mathService,
            IFileService fileService,
            IExpressionExtractor expressionExtractor,
            IExpressionContainer expressionContainer)
        {
            InitializeComponent();

            this.languageContainer   = languageContainer;
            this.mathService         = mathService;
            this.expressionExtractor = expressionExtractor;
            this.fileService         = fileService;
            this.expressionContainer = expressionContainer;

            this.checkedOperations = new HashSet <ExpressionOperation>();
            this.InitializeLanguages();
            this.CheckExpressionOperations();
            this.SetInitialData();
            this.InitializeExpressionTypes();
            this.ClearAlertBox();
        }
Exemplo n.º 18
0
 public static Expression ToLambda(this IExpressionContainer expressionContainer)
 {
     return(Expression.Lambda(expressionContainer.Expression));
 }
Exemplo n.º 19
0
 public ExpressionBuilder(IParser parser, IExpressionContainer expressionContainer)
 {
     _parser = parser;
     _expressionContainer = expressionContainer;
 }