Example #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));
        }
Example #2
0
        private void ParseInstruction(StatementNode statement, IList<Token> instructionTokens)
        {
            if (instructionTokens[0].TokenType != Tokens.Identifier)
                throw new UnexprectedTokenException(String.Format("Unexprected token: {0}", instructionTokens[0]));

            statement.Mnemonic = instructionTokens[0].SourceText;

            instructionTokens.RemoveAt(0);

            if (instructionTokens.Count() > 0)
                ParseParameterList(statement, instructionTokens);
        }
Example #3
0
        private void ParseParameterList(StatementNode statement, IList<Token> parameterListTokens)
        {
            statement.Parameters.Add(ParseParemeter(parameterListTokens[0]));

            if (parameterListTokens.Count() > 1)
            {
                if (parameterListTokens[1].TokenType != Tokens.Comma)
                    throw new UnexprectedTokenException(String.Format("Unexprected token: {0}", parameterListTokens[1]));

                statement.Parameters.Add(ParseParemeter(parameterListTokens[2]));
            }

            if (parameterListTokens.Count() != 1 && parameterListTokens.Count() != 3)
                throw new ApplicationException("Unexpected parameter list.");
        }