Skip to content

Instantly share code, notes, and snippets.

@Sleeplessy
Created April 9, 2017 16:12
Show Gist options
  • Select an option

  • Save Sleeplessy/e1d9ecc71e8e768805312f90d9295c0b to your computer and use it in GitHub Desktop.

Select an option

Save Sleeplessy/e1d9ecc71e8e768805312f90d9295c0b to your computer and use it in GitHub Desktop.
std::string Bit8RegTable[] =
{ /* "V1" to "VF" */
}
std::string InstructionTable[] =
{ /* like "ADD","MOV","SUB" */
}
std::vector < std::string > libc8Lexer(std::string ProgLine)
{
// lexer for an asm Line
std::vector < std::string > LexerOutput;
std::string Token;
std::stringstream LogStream;
std::string LogType("");
 for (auto CharInLine:ProgLine)
{
  if (CharInLine != ' ' && CharInLine != ',')
 Token += CharInLine;
   
else
{
if (std::find(InstructionTable.begin(), InstructionTable.end(), Token))
{
LogType = "Instruction";
}
else if (if (std::find(Bit8RegTable.begin(), Bit8RegTable.end(), Token))
{
LogType = "8 Bit Register";}
else
if (Token == "I")
{
LogType = "Address Register";}
else
{
LogType = "Var";}
/* else {   LogStream<<"Error token excepted.";
 throw  LEXER_ET; } */
if (!LogType.empty())
{
LogStream << LogType << " found: " << Token << std::endl;
 LexerOutput.push_back(Token);}
 }
 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment