Пример #1
0
        public string Visit(NExprRel nExprRel)
        {
            string retVal = "";

            if (nExprRel.children.Count == 2)
            {
                string pushTrueValue  = GenerateLabel();
                string pushFalseValue = GenerateLabel();
                string exitExpression = GenerateLabel();
                if (nExprRel.AnchorToken.Lexeme == "<")
                {
                    retVal += Visit((dynamic)nExprRel[0]);
                    retVal += Visit((dynamic)nExprRel[1]);
                    retVal += "\t\tclt\n";
                    retVal += "\t\tbrtrue " + pushTrueValue + "\n";
                    retVal += "\t\tbr " + pushFalseValue + "\n";
                }
                else if (nExprRel.AnchorToken.Lexeme == "<=")
                {
                    retVal += Visit((dynamic)nExprRel[0]);
                    retVal += Visit((dynamic)nExprRel[1]);
                    retVal += "\t\tcgt\n";
                    retVal += "\t\tldc.i4.0\n";
                    retVal += "\t\tceq\n";
                    retVal += "\t\tbrtrue " + pushTrueValue + "\n";
                    retVal += "\t\tbr " + pushFalseValue + "\n";
                }
                else if (nExprRel.AnchorToken.Lexeme == ">")
                {
                    retVal += Visit((dynamic)nExprRel[0]);
                    retVal += Visit((dynamic)nExprRel[1]);
                    retVal += "\t\tcgt\n";
                    retVal += "\t\tbrtrue " + pushTrueValue + "\n";
                    retVal += "\t\tbr " + pushFalseValue + "\n";
                }
                else if (nExprRel.AnchorToken.Lexeme == ">=")
                {
                    retVal += Visit((dynamic)nExprRel[0]);
                    retVal += Visit((dynamic)nExprRel[1]);
                    retVal += "\t\tclt\n";
                    retVal += "\t\tldc.i4.0\n";
                    retVal += "\t\tceq\n";
                    retVal += "\t\tbrtrue " + pushTrueValue + "\n";
                    retVal += "\t\tbr " + pushFalseValue + "\n";
                }
                retVal += pushTrueValue + ":\n";
                retVal += "\t\tldc.i8 1\n";
                retVal += "\t\tbr " + exitExpression + "\n";
                retVal += pushFalseValue + ":\n";
                retVal += "\t\tldc.i8 0\n";
                retVal += exitExpression + ":\n";
            }
            else
            {
                retVal += Visit((dynamic)nExprRel[0]);
            }
            return(retVal);
        }
Пример #2
0
        // Returns NExprRel or any of subproduction nodes
        public Node ExprRel()
        {
            Node resultingNode = ExprBitOr();

            while (CurrentToken == TokenCategory.LESS_THAN || CurrentToken == TokenCategory.LESS_OR_EQUAL_THAN || CurrentToken == TokenCategory.GREATER_THAN || CurrentToken == TokenCategory.GREATER_OR_EQUAL_THAN)
            {
                NExprRel tmp = new NExprRel();
                tmp.Add(resultingNode);
                resultingNode = tmp;
                switch (CurrentToken)
                {
                case TokenCategory.LESS_THAN: {
                    resultingNode.AnchorToken = Expect(TokenCategory.LESS_THAN);
                    resultingNode.Add(ExprBitOr());
                    break;
                }

                case TokenCategory.LESS_OR_EQUAL_THAN: {
                    resultingNode.AnchorToken = Expect(TokenCategory.LESS_OR_EQUAL_THAN);
                    resultingNode.Add(ExprBitOr());
                    break;
                }

                case TokenCategory.GREATER_THAN: {
                    resultingNode.AnchorToken = Expect(TokenCategory.GREATER_THAN);
                    resultingNode.Add(ExprBitOr());
                    break;
                }

                case TokenCategory.GREATER_OR_EQUAL_THAN: {
                    resultingNode.AnchorToken = Expect(TokenCategory.GREATER_OR_EQUAL_THAN);
                    resultingNode.Add(ExprBitOr());
                    break;
                }
                }
            }
            return(resultingNode);
        }
Пример #3
0
//------------------------------------------------------------
        public void Visit(NExprRel node)
        {
            Console.WriteLine($"+++++++++++++++ NExprRel ++++++++++++++++");

            //VisitChildren(node);
        }
 public void Visit(NExprRel nExprRel)
 {
     GenericChildVisitor(nExprRel);
 }