/******************************************************************************
** Copyright (C) 2001, University of Alabama in Huntsville. All rights 
** reserved.
**
** File   : CGIFLexicalAnalyzer.h
**
** Author : Saranyu Tantipongsakul, Da Sun
**
** Description:
**    This file provides the interface for CCGIFLexicalAnalyzer class.
**
** History:
** 01-Dec-01 Saranyu Tantipongsakul, Da Sun
**     File Created.  Copied major portions from parser written in C by Da.
******************************************************************************/
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <fstream.h>
#include <iostream>
#include <string>
#include <vector>

#define IN_WHITE 0
#define IN_RTOKN 1   //regular token
#define IN_STOKN 2   //single character token

#define MAX_LINE_CHAR 2000  //the maximum number of characters per 
                            //line in CGIF file
#define TOKENSIZE    50
#define KINDSIZE     10
#define NAMESIZE     50
#define COMMENTSIZE 500

enum token_kind_type 
{
	     unknown,           // 0
		 identifier,        // 1
		 beginConcept,      // 2
		 endConcept,        // 3
         beginRelation,     // 4
		 endRelation,       // 5
		 beginComment,      // 6
		 endComment,        // 7
		 beginActor,        // 8
	     endActor,          // 9
		 beginSet,          //10
		 endSet,            //11
		 beginReferent,     //12
		 negation,          //13
		 listSeparator,     //14
	     defLabel,          //15
		 boundLabel,        //16
		 beginIndexical,    //17
		 beginQuantifier,   //18
		 beginStructure,    //19
	     disjunctSeparator, //20
		 conjunctSeparator, //21
		 whyExclamation,    //22
		 beginQuotedstr,    //23
	     endQuotedstr       //24
};

struct tokenType
{
	token_kind_type kind;
	std::string value;
};


typedef std::vector<tokenType> string_vector_type;


typedef struct simpleTokenType
{
	char value[TOKENSIZE];
	token_kind_type kind;
}simpletokenstruct;



class CCGIFLexicalAnalyzer
{
	public:
		CCGIFLexicalAnalyzer();
		~CCGIFLexicalAnalyzer();
		bool readCGIF(std::string sourcefile);
		bool convertTokens();
		bool printTokens(char *outputFile);


	public:
		simpleTokenType* simpleTokenList;
		int m_nNewTokenNumber;
		int seg[8]; //CGIF file have 4 partitions: typehierarchy, 
			        //relationhierarchy, catalog of individual, and 
				    //assertion. seg[8] will remember their start and end position 
					//for each segment

	private:
		int sindex(char ch,char *string);
		token_kind_type identifyTokenType(char ch);
		void getOneToken(tokenType *token, char *line, int *next, int *pstate);
		int tokenAnalyzer(string_vector_type &tmp_vect, char *line);

	private:
	    string_vector_type tokens;
		int tokenNumber;

};