Beispiel #1
0
        public _64TassToken(_64TassTokenType tokenType, int tokenStartPosition, string tokenValue)
        {
            Contract.Requires(tokenStartPosition >= 0);

            this.tokenType          = tokenType;
            this.tokenValue         = tokenValue;
            this.tokenStartPosition = tokenStartPosition;
        }
        public _64TassToken(_64TassTokenType tokenType, int tokenStartPosition, string tokenValue)
        {
            Contract.Requires(tokenStartPosition >= 0);

            this.tokenType = tokenType;
            this.tokenValue = tokenValue;
            this.tokenStartPosition = tokenStartPosition;
        }
Beispiel #3
0
        public IEnumerable <_64TassToken> Tokenize(string inputLine)
        {
            currentState        = State.BeforeInstruction;
            intructionTokenType = _64TassTokenType.DontKnow;

            var scanner = new _64TassScanner(inputLine);

            while (scanner.SkipWhitespace())
            {
                yield return(GetNextToken(scanner));
            }
        }
        public IEnumerable<_64TassToken> Tokenize(string inputLine)
        {
            currentState = State.BeforeInstruction;
            intructionTokenType = _64TassTokenType.DontKnow;

            var scanner = new _64TassScanner(inputLine);

            while (scanner.SkipWhitespace())
            {
                yield return GetNextToken(scanner);
            }
        }
Beispiel #5
0
        private _64TassTokenType GetTokenTypeForLexem(string lexem)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(lexem));

            if (lexem[0] == ';')
            {
                return(_64TassTokenType.Comment);
            }
            else if (lexem[0] == '\"' || lexem[0] == '\'')
            {
                return(_64TassTokenType.StringLiteral);
            }
            else if (lexem[0] == '$')
            {
                return(IsValidHexNumber(lexem) ?
                       _64TassTokenType.HexadecimalNumber :
                       _64TassTokenType.DontKnow);
            }
            else if (lexem[0] == '%')
            {
                return(IsValidBinNumber(lexem) ?
                       _64TassTokenType.BinaryNumber :
                       _64TassTokenType.DontKnow);
            }
            else if (char.IsDigit(lexem[0]))
            {
                return(IsValidDecNumber(lexem) ?
                       _64TassTokenType.DecimalNumber :
                       _64TassTokenType.DontKnow);
            }
            else if (lexem[0] == '.' && CompilerDirectives.Any(d => d == lexem))
            {
                return(_64TassTokenType.CompilerDirective);
            }
            else
            {
                if (lexem.Length == 1)
                {
                    _64TassTokenType tokenType;
                    if (tokenTypePerChar.TryGetValue(lexem[0], out tokenType))
                    {
                        if (currentState == State._6502InstructionArgument && tokenType == _64TassTokenType.Coma)
                        {
                            currentState = State.Index;
                        }

                        return(tokenType);
                    }
                    else if (currentState == State.Index && ((lexem[0] & 0xdf) == 'X' || (lexem[0] & 0xdf) == 'Y'))
                    {
                        Contract.Requires(this.intructionTokenType == _64TassTokenType._6502Instruction ||
                                          this.intructionTokenType == _64TassTokenType._6502IllegalInstruction);

                        return(this.intructionTokenType);
                    }
                }
                else if (lexem.Length == 3 && currentState == State.BeforeInstruction)
                {
                    if (_6502Instructions.Any(i => lexem.ToUpper() == i))
                    {
                        currentState = State._6502InstructionArgument;

                        return(intructionTokenType = _64TassTokenType._6502Instruction);
                    }
                    else if (Illegal6502Instructions.Any(i => lexem.ToUpper() == i))
                    {
                        currentState = State._6502InstructionArgument;

                        return(intructionTokenType = _64TassTokenType._6502IllegalInstruction);
                    }
                }

                return(_64TassTokenType.Label);
            }
        }
        private _64TassTokenType GetTokenTypeForLexem(string lexem)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(lexem));

            if (lexem[0] == ';')
            {
                return _64TassTokenType.Comment;
            }
            else if (lexem[0] == '\"' || lexem[0] == '\'')
            {
                return _64TassTokenType.StringLiteral;
            }
            else if (lexem[0] == '$')
            {
                return IsValidHexNumber(lexem) ?
                    _64TassTokenType.HexadecimalNumber :
                    _64TassTokenType.DontKnow;
            }
            else if (lexem[0] == '%')
            {
                return IsValidBinNumber(lexem) ?
                    _64TassTokenType.BinaryNumber :
                    _64TassTokenType.DontKnow;
            }
            else if (char.IsDigit(lexem[0]))
            {
                return IsValidDecNumber(lexem) ?
                        _64TassTokenType.DecimalNumber :
                        _64TassTokenType.DontKnow;
            }
            else if (lexem[0] == '.' && CompilerDirectives.Any(d => d == lexem))
            {
                return _64TassTokenType.CompilerDirective;
            }
            else
            {
                if (lexem.Length == 1)
                {
                    _64TassTokenType tokenType;
                    if (tokenTypePerChar.TryGetValue(lexem[0], out tokenType))
                    {
                        if (currentState == State._6502InstructionArgument && tokenType == _64TassTokenType.Coma)
                        {
                            currentState = State.Index;
                        }

                        return tokenType;
                    }
                    else if(currentState == State.Index && ((lexem[0] & 0xdf) == 'X' || (lexem[0] & 0xdf) == 'Y'))
                    {
                        Contract.Requires(this.intructionTokenType == _64TassTokenType._6502Instruction ||
                            this.intructionTokenType == _64TassTokenType._6502IllegalInstruction);

                        return this.intructionTokenType;
                    }
                }
                else if (lexem.Length == 3 && currentState == State.BeforeInstruction)
                {
                    if (_6502Instructions.Any(i => lexem.ToUpper() == i))
                    {
                        currentState = State._6502InstructionArgument;

                        return intructionTokenType = _64TassTokenType._6502Instruction;
                    }
                    else if (Illegal6502Instructions.Any(i => lexem.ToUpper() == i))
                    {
                        currentState = State._6502InstructionArgument;

                        return intructionTokenType = _64TassTokenType._6502IllegalInstruction;
                    }
                }

                return _64TassTokenType.Label;
            }
        }