예제 #1
0
        public Transformation(string expression, string filter, string result)
        {
            ExpressionText = expression;
            FilterText     = filter;
            ResultText     = result;

            TokenizedExpression = Tokenizer.Parse(ExpressionText);
            TokenizedFilter     = Tokenizer.Parse(FilterText);
            TokenizedResult     = Tokenizer.Parse(ResultText);

            InstructionTree       = InstructionParser.Parse(TokenizedExpression);
            ResultInstructionTree = ResultParser.Parse(TokenizedResult);
            Filters = FilterParser.ParseAll(TokenizedFilter);

            LabelSet = new LabelSet(InstructionTree);
            LabelSet.AddUse(ResultInstructionTree);
        }
예제 #2
0
        private static (InstructionNode node, int end, int nodeNbr) ParseInstructionNode(List <Token> tokens, int start, int nodeNbr)
        {
            var node = new InstructionNode()
            {
                NodeNbr = nodeNbr
            };
            var length = tokens.Count;

            for (int index = start; index < length; index++)
            {
                var token = tokens[index];

                if (token.TokenType == TokenType.OpenParens)
                {
                    if (node.InstructionName == null)
                    {
                        index++;
                        node.InstructionName = tokens[index].Value;
                    }
                    else
                    {
                        var childNode = ParseInstructionNode(tokens, index, nodeNbr + 1);

                        index   = childNode.end;
                        nodeNbr = childNode.nodeNbr;

                        node.Operands.Add(new Operand(childNode.node, node.Operands.Count));
                    }
                }
                else if (token.TokenType == TokenType.CloseParens)
                {
                    return(node, index, nodeNbr);
                }
                else if (token.TokenType == TokenType.Word)
                {
                    node.Operands.Add(new Operand(new Token(TokenType.Label, token.Position, token.Value), node.Operands.Count));
                }
                else if (token.TokenType == TokenType.IntegerConstant)
                {
                    node.Operands.Add(new Operand(token, node.Operands.Count));
                }
                else if (token.TokenType == TokenType.DoubleConstant)
                {
                    node.Operands.Add(new Operand(token, node.Operands.Count));
                }
                else if (token.TokenType == TokenType.FloatConstant)
                {
                    node.Operands.Add(new Operand(token, node.Operands.Count));
                }
                else if (token.TokenType == TokenType.Underscore)
                {
                    node.Operands.Add(new Operand(token, node.Operands.Count));
                }
                else if (token.TokenType == TokenType.OpenCurly)
                {
                    index++;                     // skip to next token, which should be label
                    node.Conditions = InstructionParser.ParseConditions(tokens, ref index);
                    node.Condition  = node.Conditions[0];
                }
                else
                {
                    throw new Exception($"parsing error {token}");
                }
            }

            throw new Exception($"parsing error incomplete");
        }