public Node ExprRel()
        {
            //‹expr-add› (‹op-rel› ‹expr-add›)*
            var n1 = ExprAdd();

            while (firstOfExprRel.Contains(CurrentToken))
            {
                var n2 = new ExprRel();
                switch (CurrentToken)
                {
                case TokenCategory.LESS:
                    n2.AnchorToken = Expect(TokenCategory.LESS);
                    break;

                case TokenCategory.LESSEQUAL:
                    n2.AnchorToken = Expect(TokenCategory.LESSEQUAL);
                    break;

                case TokenCategory.GREATER:
                    n2.AnchorToken = Expect(TokenCategory.GREATER);
                    break;

                case TokenCategory.GREATEREQUAL:
                    n2.AnchorToken = Expect(TokenCategory.GREATEREQUAL);
                    break;

                default:
                    throw new SyntaxError(firstOfExprRel, tokenStream.Current);
                }
                n2.Add(n1);
                n2.Add(ExprAdd());
                n1 = n2;
            }
            return(n1);
        }
Beispiel #2
0
        public string Visit(ExprRel node)
        {
            var lbl = GenerateLabel();

            if (node.AnchorToken.Category == TokenCategory.GREATER)
            {
                return
                    (Line(Indent() + "ldc.i4.0")
                     + VisitChildren(node)
                     + Line(Indent() + "ble '" + lbl + "'")
                     + Line(Indent() + "pop")
                     + Line(Indent() + "ldc.i4 42")
                     + Line(Indent() + lbl + ":"));
            }
            if (node.AnchorToken.Category == TokenCategory.LESSEQUAL)
            {
                return
                    (Line(Indent() + "ldc.i4 42")
                     + VisitChildren(node)
                     + Line(Indent() + "ble '" + lbl + "'")
                     + Line(Indent() + "pop")
                     + Line(Indent() + "ldc.i4.0")
                     + Line(Indent() + lbl + ":"));
            }
            if (node.AnchorToken.Category == TokenCategory.GREATEREQUAL)
            {
                return
                    (Line(Indent() + "ldc.i4 42")
                     + VisitChildren(node)
                     + Line(Indent() + "bge '" + lbl + "'")
                     + Line(Indent() + "pop")
                     + Line(Indent() + "ldc.i4.0")
                     + Line(Indent() + lbl + ":"));
            }
            if (node.AnchorToken.Category == TokenCategory.LESS)
            {
                return
                    (Line(Indent() + "ldc.i4.0")
                     + VisitChildren(node)
                     + Line(Indent() + "bge '" + lbl + "'")
                     + Line(Indent() + "pop")
                     + Line(Indent() + "ldc.i4 42")
                     + Line(Indent() + lbl + ":"));
            }
            return(node.ToString() + "\n" + VisitChildren(node));
        }
 public void Visit(ExprRel node)
 {
     VisitChildren(node);
 }