コード例 #1
0
        private ExpressionParserOutput ParseStringExpression(string expression)
        {
            var sc = new StringExpressionParser {
                Variables = Variables
            };

            sc.Compile(expression, Output.StringCounter, Output.LoopCounter);

            Output.StringCounter = sc.Output.StringCounter;
            Output.LoopCounter   = sc.Output.LoopCounter;
            Output.InitCode      = Output.InitCode + sc.Output.InitCode;

            foreach (var f in sc.Output.Functions)
            {
                if (!Output.Functions.Contains(f))
                {
                    Output.Functions.Add(f);
                }
            }

            foreach (KeyValuePair <string, string> kvp in sc.Variables)
            {
                if (!Variables.ContainsKey(kvp.Key))
                {
                    Variables.Add(kvp.Key, kvp.Value);
                }
            }

            return(sc.Output);
        }
コード例 #2
0
        private ExpressionParserOutput ParseStringExpression(string expression)
        {
            var sc = new StringExpressionParser {
                Variables = Variables
            };

            sc.Compile(expression, Output.StringCounter, Output.LoopCounter);

            Output.StringCounter = sc.Output.StringCounter;
            Output.LoopCounter   = sc.Output.LoopCounter;
            Output.InitCode      = Output.InitCode + sc.Output.InitCode;

            foreach (var f in sc.Output.Functions)
            {
                AddFunction(f);
            }

            return(sc.Output);
        }
コード例 #3
0
        private void DoInstr(TokenParser parser)
        {
            SkipWhiteSpace(parser);

            string exp1 = GetNumericExpression(parser, false);

            SkipWhiteSpace(parser);
            // Should be a comma
            parser.GetToken();
            SkipWhiteSpace(parser);

            string exp2 = GetStringExpression(parser);

            SkipWhiteSpace(parser);
            // Should be a comma
            parser.GetToken();
            SkipWhiteSpace(parser);

            string exp3 = GetStringExpression(parser).Trim();

            //exp3 = exp3.Remove(exp3.Length - 1, 1);

            SkipWhiteSpace(parser);
            // Should be closing parenthesis
            parser.GetToken();
            SkipWhiteSpace(parser);

            StringExpressionParser sourceString = new StringExpressionParser {
                Variables = Variables
            };

            sourceString.Compile(exp2, Output.StringCounter, Output.LoopCounter);

            Output.StringCounter = sourceString.Output.StringCounter;
            Output.LoopCounter   = sourceString.Output.LoopCounter;
            Output.BoolCounter   = sourceString.Output.BoolCounter;
            Output.InitCode      = Output.InitCode + sourceString.Output.InitCode;

            foreach (Functions f in sourceString.Output.Functions)
            {
                if (!Output.Functions.Contains(f))
                {
                    Output.Functions.Add(f);
                }
            }

            string param2Code = sourceString.Output.Output;

            StringExpressionParser destString = new StringExpressionParser {
                Variables = Variables
            };

            destString.Compile(exp3, Output.StringCounter, Output.LoopCounter);

            Output.StringCounter = destString.Output.StringCounter;
            Output.LoopCounter   = destString.Output.LoopCounter;
            Output.BoolCounter   = destString.Output.BoolCounter;
            Output.InitCode      = Output.InitCode + destString.Output.InitCode;

            foreach (Functions f in destString.Output.Functions)
            {
                if (!Output.Functions.Contains(f))
                {
                    Output.Functions.Add(f);
                }
            }

            string param3Code = destString.Output.Output;

            NumericExpressionParser startIndex = new NumericExpressionParser {
                Variables = Variables
            };

            startIndex.Compile(exp1, Output.StringCounter, Output.LoopCounter);

            Output.StringCounter = startIndex.Output.StringCounter;
            Output.LoopCounter   = startIndex.Output.LoopCounter;
            Output.BoolCounter   = startIndex.Output.BoolCounter;
            Output.InitCode      = Output.InitCode + startIndex.Output.InitCode;

            Output.Output = Output.Output + startIndex.Output.Output;
            Output.Output = Output.Output + " push x" + Environment.NewLine;
            Output.Output = Output.Output + param2Code;
            Output.Output = Output.Output + " push x" + Environment.NewLine;
            Output.Output = Output.Output + param3Code;
            Output.Output = Output.Output + " call funcINSTR" + Environment.NewLine;
        }