Esempio n. 1
0
 public string VisitVariableAssign(VariableAssign variableAssign)
 {
     throw new NotImplementedException();
 }
Esempio n. 2
0
        /// <summary>
        /// Parses the tokens provided by a lexer
        /// </summary>
        /// <param name="lexer"></param>
        private void ParseInstructions(Lexer lexer)
        {
            IFormatInstructions instruction;

            // iterate over every token
            while (lexer.MoveNext())
            {
                Token currToken = lexer.CurrrentToken;

                // found a comment line
                if (currToken.Type == TokenType.LINE_COMMENT)
                {
                    // ignore every token in that line
                    while (lexer.CurrrentToken.Type != TokenType.NEW_LINE)
                    {
                        lexer.MoveNext();
                    }

                    // now CurrentToken is a new Line
                }
                // found and origin
                else if (currToken.Type == TokenType.ORIGIN)
                {
                    lexer.MoveNext();

                    // get the next token (address) associated with the ORG
                    Token address = lexer.CurrrentToken;

                    AddInstruction(new OriginCmd(currToken, address));
                }
                // found an operator
                else if (OperatorsInfo.IsOperator(currToken.Value))
                {
                    // make instruction
                    MakeInstruction(lexer);
                }
                // found variable assign without name
                else if (currToken.Type == TokenType.VARIABLE_ASSIGN)
                {
                    List <Token> variableList = new List <Token>();

                    // move lexer to first param
                    lexer.MoveNext();

                    // add params to list
                    while (lexer.CurrrentToken.Type != TokenType.NEW_LINE)
                    {
                        variableList.Add(lexer.CurrrentToken);
                        lexer.MoveNext();
                    }

                    // add instruction to list
                    AddInstruction(new VariableAssign(currToken, null, variableList.ToArray()));

                    variableList.Clear();
                }
                // found constant assignment
                else if (currToken.Type == TokenType.CONSTANT_ASSIGN)
                {
                    // move to name
                    lexer.MoveNext();
                    Token name = lexer.CurrrentToken;

                    // move to value
                    lexer.MoveNext();
                    Token value = lexer.CurrrentToken;

                    AddInstruction(new ConstantAssign(currToken, name, value));
                }
                // found a possible label, variable name for db, or possible typo in an operator
                else if (currToken.Type == TokenType.IDENTIFIER)
                {
                    // found db after identifier.
                    if (lexer.PeekNext().Type == TokenType.VARIABLE_ASSIGN)
                    {
                        List <Token> paramList = new List <Token>();

                        // move lexer to db keyword
                        lexer.MoveNext();

                        Token dbKeyword = lexer.CurrrentToken;

                        // move lexer to first param
                        lexer.MoveNext();

                        // add params to list
                        while (lexer.CurrrentToken.Type != TokenType.NEW_LINE)
                        {
                            paramList.Add(lexer.CurrrentToken);

                            // iterate
                            lexer.MoveNext();
                        }

                        instruction = new VariableAssign(dbKeyword, currToken, paramList.ToArray());

                        AddInstruction(instruction);
                    }
                    // found a colon after identifier this means it is a label
                    else if (lexer.PeekNext().Type == TokenType.COLON)
                    {
                        Token labelName = lexer.CurrrentToken;

                        // start label block
                        // add current label to the instruction list
                        AddInstruction(new Label(labelName));
                    }
                    else
                    {
                        List <Token> paramList = new List <Token>();

                        Token invalidInstruction = lexer.CurrrentToken;

                        lexer.MoveNext();

                        // add params to list
                        while (lexer.CurrrentToken.Type != TokenType.NEW_LINE)
                        {
                            paramList.Add(lexer.CurrrentToken);
                            lexer.MoveNext();
                        }

                        AddInstruction(new InvalidInstruction(invalidInstruction, paramList.ToArray()));
                    }
                }
            }
        }