//
// g1main.cc
// ---------
// Testmodul for dragon
//
// by Bjoern Lemke, (C)opyright 2003 by Bjoern Lemke
//


#include <lfc/Chain.h>

#if defined(SAMPLE_G1)
#include "G1.h"
#elif defined(SAMPLE_G2)
#include "G2.h"
#elif defined(SAMPLE_G3)
#include "G3.h"
#endif

#include <lfc/Exception.h>

#if defined(SAMPLE_G1)
class GxMain  : public G1 {
#elif defined(SAMPLE_G2)
class GxMain  : public G2 {
#elif defined(SAMPLE_G3)
class GxMain  : public G3 {
#endif
    
public:

#if defined(SAMPLE_G1)
    GxMain(char *pC) : G1()  {
#elif defined(SAMPLE_G2)
    GxMain(char *pC) : G2()  {
#elif defined(SAMPLE_G3)
    GxMain(char *pC) : G3()  {
#endif
   
	cout << "setting up " << pC << endl;
	_pC = pC;
	_i = 0;
    }

    char nextChar() {
	if (_pC[_i])
	{
	    if ( _pC[_i] == '\'')
	    {
		// setReserved(RES1);

		_i++;		
		while ( _pC[_i] != '\'')
		{
		    cout << "Storing: " << _pC[_i] << endl; 
		    _i++;
		}
		_i++;
		return 0;
		
	    }
	    _i++;
	    return (_pC[_i-1]);
	}
	return 0;
    }

    void backChar() {
        _i--;
	return;
    }

    void A1() {
	cout << "A1 called" << endl;
	cout << "TokenList is " << endl;
	
	ListT<Chain> tlist =  getTokenList();
	Chain* pS = tlist.First();
	while (pS)
	{
	    cout << *pS << endl;
	    pS = tlist.Next();
	}

    }

    void A2() {
	cout << "A2 called" << endl;

	cout << "TokenList is " << endl;
	
	ListT<Chain> tlist =  getTokenList();
	Chain* pS = tlist.First();
	while (pS)
	{
	    cout << *pS << endl;
	    pS = tlist.Next();
	}


    }
    void A3() {
	cout << "A3 called" << endl;

	cout << "TokenList is " << endl;
	
	ListT<Chain> tlist =  getTokenList();
	Chain* pS = tlist.First();
	while (pS)
	{
	    cout << *pS << endl;
	    pS = tlist.Next();
	}

    }

    void A4() {
	cout << "A4 called" << endl;

	cout << "TokenList is " << endl;
	
	ListT<Chain> tlist =  getTokenList();
	Chain* pS = tlist.First();
	while (pS)
	{
	    cout << *pS << endl;
	    pS = tlist.Next();
	}

    }


    void A5() {
	cout << "A5 called" << endl;

	cout << "TokenList is " << endl;
	
	ListT<Chain> tlist =  getTokenList();
	Chain* pS = tlist.First();
	while (pS)
	{
	    cout << *pS << endl;
	    pS = tlist.Next();
	}

    }


private:

    int _i;
    char *_pC;

  
};

int main(int argc, char** argv)
{
    GxMain g(argv[1]);

    cout << "parsing" << endl;


    try {

	g.parse();

	cout << "Parse OK" << endl;

    }
    catch (Exception e)
    {
	e.print();
	exit(1);
    }

    exit(0);

    
}



