// lex_main.cpp
// Glenn G. Chappell
// VERSION 3a
// 9 Feb 2009
//
// For CS 331 Spring 2009
// Sample main program for class Lex

#include "lex.h"  // for class Lex
#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;
using std::cin;


// printTokenType
// Print string representation of Lex::Token value
// Pre: None.
// Post:
//     String representation of tok (length == 10, padded on right with blanks)
//      has been output to os, or indication of bad value if tok is illegal.
void printTokenType(std::ostream & os,
                    Lex::Token tok)
{
    switch (tok)
    {
    case Lex::NONE:
        os << "NONE      ";
        break;
    case Lex::IDENTIFIER:
        os << "IDENTIFIER";
        break;
    case Lex::OPERATOR:
        os << "OPERATOR  ";
        break;
    case Lex::NUMBER:
        os << "NUMBER    ";
        break;
    case Lex::ILLEGAL:
        os << "ILLEGAL   ";
        break;
    default:
        os << "** BAD! **";
        break;
    }
}


// main
// Use class Lex to analyze a "program",
//  and print the lexemes, one on each line.
int main()
{
    // input is "program"
    string input = "int main(int argc,char**argv){\n";
    input += "int ii=42;// The ANSWER\ndouble dogCat_4=-.34;//???\n";
    input += "dogCat_4=sin(int(--ii*-3));return 0;}//THE END";

    // Print input in raw form
    cout << "\"Program\" to analyze:" << endl << endl;
    cout << input << endl << endl;

    // Analyze input & print lexemes
    Lex x(input);
    while (!x.done())
    {
        Lex::Lexeme result = x.next();
        cout << "Lexeme: ";
        printTokenType(cout, result.first);
        cout << " " << result.second << endl;
    }
    cout << endl;

    cout << "Press ENTER to quit ";
    while (cin.get() != '\n') ;

    return 0;

}
