/*	Compiler implementation file
	by Jason Plumb */

#include <stdio.h>
#include <conio.h>
#include <memory.h>
#include "defines.h"
#include "helper_func.h"
#include "lex.h"
#include "syntax.h"
#include "comp.h"

/* Globally defined symbols */
extern TOKEN SymTable[SYM_TABLE_SIZE];	//The symbol table
extern int iCurrLine;					//Indicates the current line
extern int iException;					//The number of overall errors...

//Main program
int main(int argc, char *argv[]){

	if((argc==1) || ((argc > 1) && (
		(!ccstrncmp(argv[1], "-h", 2)) || (!ccstrncmp(argv[1], "--h", 3))))){

		showUsage();		//Tell em how to use the darn thing
		return -1;
	}//if

	printf("\n");

	initLex(argv[1]);		//Init lex functions

	bool b = sf_program();
	if(!iException){
		printf("Valid program! Congrats\n");
	}
	else{
		printf("\n-------------------------\nTotal Errors Detected: %d\n", iException);
	}
	/*
	int iIndex = 1;
	TOKEN t;
	while(iIndex != ERR_EOF){

		iIndex = getNT();
		if(iIndex > 0){
			memcpy(&t, &SymTable[iIndex], sizeof(TOKEN));
			printf("Line %0.2d: [%0.3d] %s\n", iCurrLine, iIndex, t.lexemeID);
		}
		else{
			if(iIndex != ERR_EOF)
				printf("Line %0.2d: *** ERROR * Invalid lexical element\n", iCurrLine);
		}//else
	}//while
*/
	printf("\n");//All done");

	return 0;
}//main

//Shows how to use the main program
void showUsage(){
	printf("\nUsage:  comp.exe <filename>\n\n");
}//showUsage function