예제 #1
0
 public Node UnaryExpression()
 {
     if (CurrentToken == TokenCategory.NOT)
     {
         var result = new Not()
         {
             AnchorToken = Expect(TokenCategory.NOT)
         };
         result.Add(UnaryExpression());
         return(result);
     }
     else if (CurrentToken == TokenCategory.NEG)
     {
         var result = new Neg()
         {
             AnchorToken = Expect(TokenCategory.NEG)
         };
         result.Add(UnaryExpression());
         return(result);
     }
     else
     {
         return(SimpleExpression());
     }
 }
예제 #2
0
        public Node SimpleExpr()
        {
            switch (Current)
            {
            case TokenCategory.PAR_OPEN:
                Expect(TokenCategory.PAR_OPEN);
                var n = Expr();
                Expect(TokenCategory.PAR_CLOSE);
                return(n);

            case TokenCategory.NOT:
                var node1 = new Not()
                {
                    AnchorToken = Expect(TokenCategory.NOT)
                };
                node1.Add(SimpleExpr());
                return(node1);

            case TokenCategory.LITERAL_0:
                return(new Literal_0()
                {
                    AnchorToken = Expect(TokenCategory.LITERAL_0)
                });

            case TokenCategory.LITERAL_1:
                return(new Literal_1()
                {
                    AnchorToken = Expect(TokenCategory.LITERAL_1)
                });

            default:
                throw new SyntaxError();
            }
        }
예제 #3
0
        //expr-unary>//
        public Node ExprUnary()
        {
            var xprUn = new Node();

            if (firstofUnary.Contains(CurrentToken))
            {
                while (firstofUnary.Contains(CurrentToken))
                {
                    switch (CurrentToken)
                    {
                    case TokenCategory.NOT:
                        xprUn = new Not()
                        {
                            AnchorToken = Expect(TokenCategory.NOT)
                        };
                        break;

                    default:
                        throw new SyntaxError(firstofUnary,
                                              tokenStream.Current);
                    }
                    xprUn.Add(ExprUnary());
                }
            }
            else
            {
                xprUn = ExprPrimary();
            }
            return(xprUn);
        }
예제 #4
0
 public Node UnaryExpression()
 {
     if (CurrentToken == TokenCategory.NOT)
     {
         var result = new Not()
         {
             AnchorToken = Expect(TokenCategory.NOT)
         };
         result.Add(UnaryExpression());
         return(result);
     }
     else if (CurrentToken == TokenCategory.MINUS)
     {
         var result = new Negative()
         {
             AnchorToken = Expect(TokenCategory.MINUS)
         };
         result.Add(UnaryExpression());
         return(result);
     }
     else if (firstOfSimpleExpression.Contains(CurrentToken))
     {
         return(SimpleExpression());
     }
     else
     {
         throw new SyntaxError(firstOfUnaryExpression, tokenStream.Current);
     }
 }