Пример #1
0
 // Build a variable reference (the "v" in "v = 1"
 void BuildVariableReference(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
 {
     var e = new VariableReference(parentExpression, currentNode.FindToken().Convert());
     e.Name = currentNode.FindTokenAndGetText();
     e.ParentExpression = parentExpression;
     parentExpression.ChildExpressions.Add(e);
 }
Пример #2
0
        // Build a binary operator statement
        public static void BuildBinaryOperator(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            var op = new BinaryOperator(parentExpression, currentNode.FindToken().Convert());
            parentExpression.ChildExpressions.Add(op);

            // Determine which binary operator this is
            switch (currentNode.ChildNodes[1].Term.ToString())
            {
                case "*":
                    op.OperatorType = BinaryOperatorType.Multiply;
                    break;
                case "/":
                    op.OperatorType = BinaryOperatorType.Divide;
                    break;
                case "+":
                    op.OperatorType = BinaryOperatorType.Add;
                    break;
                case "-":
                    op.OperatorType = BinaryOperatorType.Subtract;
                    break;
                case "%":
                    op.OperatorType = BinaryOperatorType.Modulo;
                    break;
                case "<=":
                    op.OperatorType = BinaryOperatorType.LessOrEqual;
                    break;
                case "<":
                    op.OperatorType = BinaryOperatorType.Less;
                    break;
                case "==":
                    op.OperatorType = BinaryOperatorType.Equal;
                    break;
                case "!=":
                    op.OperatorType = BinaryOperatorType.NotEqual;
                    break;
                case ">=":
                    op.OperatorType = BinaryOperatorType.GreaterOrEqual;
                    break;
                case ">":
                    op.OperatorType = BinaryOperatorType.Greater;
                    break;
                case ">>":
                    op.OperatorType = BinaryOperatorType.BitwiseShiftRight;
                    break;
                case "<<":
                    op.OperatorType = BinaryOperatorType.BitwiseShiftLeft;
                    break;
                case "&&":
                    op.OperatorType = BinaryOperatorType.LogicalAnd;
                    break;
                case "||":
                    op.OperatorType = BinaryOperatorType.LogicalOr;
                    break;
                case "|":
                    op.OperatorType = BinaryOperatorType.BitwiseOr;
                    break;
                case "&":
                    op.OperatorType = BinaryOperatorType.BitwiseAnd;
                    break;
                case "^":
                    op.OperatorType = BinaryOperatorType.BitwiseXor;
                    break;
                case "as":
                    op.OperatorType = BinaryOperatorType.As;
                    break;
            }

            // Get the left operand
            parser.ConsumeParseTree(root, op, currentNode.ChildNodes[0]);

            // "as" operator is a type case and needs to be handled differently
            if(op.OperatorType == BinaryOperatorType.As)
            {
                var v = new VariableReference(op, null);
                v.Name = currentNode.ChildNodes[2].ChildNodes[0].FindTokenAndGetText();
                op.ChildExpressions.Add(v);
            }
            else
                parser.ConsumeParseTree(root, op, currentNode.ChildNodes[2]);
        }