Пример #1
0
 public void Visit(IntLiteralNode node)
 {
     Debug.Write(" " + node.Value + " ");
 }
Пример #2
0
        private Node LeafExpression()
        {
            Node result;

            switch (lex.Token)
            {
                case Token.Identifier:
                {
                    string identifier = lex.Lexeme;
                    lex.Next(false);
                    result = IdentifierRest(identifier, false);
                    break;
                }
                case Token.IntLiteral:
                {
                    int value = int.Parse(lex.Lexeme);
                    lex.Next(false);
                    result = new IntLiteralNode { Value = value };
                    break;
                }

                case Token.FloatLiteral:
                {
                    double value = double.Parse(lex.Lexeme);
                    lex.Next(false);
                    result = new FloatLiteralNode { Value = value };
                    break;
                }

                case Token.CharLiteral:
                {
                    char value = char.Parse(lex.Lexeme);
                    lex.Next(false);
                    result = new CharLiteralNode { Value = value };
                    break;
                }

                case Token.StringLiteral:
                {
                    string value = lex.Lexeme;
                    lex.Next(false);
                    result = new StringLiteralNode { Value = value };
                    break;
                }

                case Token.OpenParentheses:
                    lex.Next();
                    result = Expression();
                    if (lex.Token != Token.ClosedParentheses)
                    {
                        throw CreateErrorExpectedToken(Token.ClosedParentheses);
                    }
                    lex.Next();
                    break;

                default:
                    throw CreateErrorUnexpectedToken(lex.Token, lex.Lexeme);
            }

            return result;
        }
Пример #3
0
 public void Visit(IntLiteralNode node)
 {
     Debug.WriteLine("Visiting " + node.GetType().Name);
 }
Пример #4
0
 public void Visit(IntLiteralNode node)
 {
     valueStack.Push(node.Value);
 }