/******************************************************************************
** Copyright (C) 2001, University of Alabama in Huntsville. All rights 
** reserved.
**
** File   : CGIFParser.cpp
**
** Author : Saranyu Tantipongsakul
**
** Description:
**    This file provides the implementation for CCGIFParser class.
**
** History:
** 01-Dec-01 Saranyu Tantipongsakul
**     File Created.  This class uses CGIFSyntaxAnalyzer and 
**     CGIFLexicalAnalyzer classes.
** 02-Dec-01 Satish Hota
**     Implemented Generate method.
******************************************************************************/

#include "CGIFParser.h"
#include "CCGIFGenerator.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCGIFParser::CCGIFParser()
{

}

CCGIFParser::~CCGIFParser()
{

}

bool CCGIFParser::Parse(std::string strFileName, ACCGFactory *pFactory, CKnowledgeBase **ppKnowledgebase)
{
	try
	{
		CCGIFLexicalAnalyzer oTokenizer;

		// Read CGIF file
		oTokenizer.readCGIF(strFileName);

		// Convert Tokens to TokenList
		oTokenizer.convertTokens();

		CCGIFSyntaxAnalyzer oElement(&oTokenizer);

		// Install everything
		*ppKnowledgebase = oElement.install(pFactory);
	}
	catch(...)
	{
		return false;
	}
	return true;
}

bool CCGIFParser::Generate(std::string strFileName, CKnowledgeBase *pKnowledgeBase)
{
	CGIFGenerator oGenerator;

	return oGenerator.CCGIFParserGenerate(strFileName, pKnowledgeBase);
}
