Exemplo n.º 1
0
 public void Visit(ExprUnaryNode node)
 {
     foreach (var subnode in node)
     {
         Visit((dynamic)subnode);
     }
 }
Exemplo n.º 2
0
        public Node ExprUnary()
        {
            var top  = new ExprUnaryNode();
            var temp = top;

            if (firstOfExprUnary.Contains(CurrentToken))
            {
                while (firstOfExprUnary.Contains(CurrentToken))
                {
                    switch (CurrentToken)
                    {
                    case TokenCategory.PLUS:
                        temp.AnchorToken = Expect(TokenCategory.PLUS);
                        break;

                    case TokenCategory.NEG:
                        temp.AnchorToken = Expect(TokenCategory.NEG);
                        break;

                    case TokenCategory.NOT:
                        temp.AnchorToken = Expect(TokenCategory.NOT);
                        break;

                    default:
                        throw new SyntaxError(firstOfExprUnary, tokenStream.Current);
                    }
                    if (!firstOfExprUnary.Contains(CurrentToken))
                    {
                        temp.Add(ExprPrimary());
                    }
                    else
                    {
                        var newNode = new ExprUnaryNode();
                        temp.Add(newNode);
                        temp = newNode;
                    }
                }
            }
            else
            {
                return(ExprPrimary());
            }
            return(top);
        }