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;
}
}