Пример #1
0
        private StatementNode ParseStatement(Token initialToken)
        {
            if (initialToken.TokenType == Tokens.EndOfLine)
                return null;

            if (initialToken.TokenType == Tokens.Identifier)
            {
                StatementNode statement = new StatementNode();
                var instructionTokens = new List<Token>();

                Token t = _lex.GetNextToken();

                if (t.TokenType == Tokens.Colon)
                {
                    statement.Label = initialToken.SourceText;                    

                    t = _lex.GetNextToken();                    
                }
                else
                {
                    instructionTokens.Add(initialToken);
                }
               
                while (t.TokenType != Tokens.EndOfLine)
                {
                    instructionTokens.Add(t);
                    t = _lex.GetNextToken();
                }

                ParseInstruction(statement, instructionTokens);
                return statement;
            }

            throw new UnexprectedTokenException(String.Format("Unexprected token: {0}", initialToken));
        }
Пример #2
0
        private ParameterNode ParseParemeter(Token token)
        {
            if (token.TokenType == Tokens.Identifier)
                return new ParameterNode() { Identifier = token.SourceText };

            if (token.TokenType == Tokens.Number)
            {
                Int32 numberLength = 0;

                if (token.SourceText.Length == 3 || (token.SourceText.StartsWith("0") && token.SourceText.Length == 4))
                    numberLength = 8;
                else if (token.SourceText.Length == 3 || (token.SourceText.StartsWith("0") && token.SourceText.Length == 4))
                    numberLength = 16;
                else
                    throw new ApplicationException(String.Format("Invalid length for literal number: {0}", token.SourceText));

                return new ParameterNode() { Number = GetNumber(token.SourceText), NumberSize = numberLength };
            }

            throw new UnexprectedTokenException(String.Format("Unexprected token: {0}", token));
        }