Académique Documents
Professionnel Documents
Culture Documents
h"
retval = fileread(&grammarArray,grammarFile,&count);
if(retval)
{
printf("\n%s:%d Error reading from file %s.",__FILE__,__LINE__,g
rammarFile);
printf("\nWill exit.");
exit(EXIT_FAILURE);
}
printf("\n%d bytes read from file %s",count,grammarFile);
printf("\nFile contents are:\n");
printRaw(grammarArray,count);
printf("\n");
tokenSet = preProcess(&grammarArray,count);
assert(tokenSet != NULL);
assert(grammarArray != NULL);
grammarTable = makeGrammarTable(grammarArray,&error,&number_of_variables
);
if(error == 1)
{
printf("\n%s:%d Function makeGrammarTable() returned 1",__FILE_
_,__LINE__);
printf("\nWill exit now.\n");
free(grammarArray);
free(grammarTable);
exit(EXIT_FAILURE);
}
printf("\n\n\n%s ",grammarTable[i]->head);
if(grammarTable[i]->nullable == true)
{
printf("%-s"," NULLABLE = true;");
}
else
{
printf("%-s"," NULLABLE = false;");
}
sprintf(tmp," %s %d; FOLLOW = %s","Number of productions",gramm
arTable[i]->prodcount,grammarTable[i]->follow);
printf("%-s",tmp);
printf("\n|");
for(j=0;j<grammarTable[i]->prodcount;j++)
{
printf("\n|\n|");
printf("-> %-20s",grammarTable[i]->productions[j]);
printf(" FIRST = %-20s",grammarTable[i]->first[j]);
}
}
/* Generate Parse Table */
retval = genParseTable(&parseTable,grammarTable,number_of_variables,toke
nSet);
if(retval )
{
printf("\n%s:%d Error: Function genParseTable() returned 1\n",_
_FILE__,__LINE__);
//exit(EXIT_FAILURE);
}
/* Print parse table */
printf("\n\n************************************** PARSE TABLE *********
*********************************\n");
printf("%10s","");
for(i=0;i<parseTable.termcount;i++)
{
printf(" %10s ",parseTable.terminals[i]);
}
printf("\n\n");
for(j=0 ; j<parseTable.varcount ; j++)
{
printf("%10s",parseTable.variables[j]);
for(k=0;k<parseTable.termcount;k++)
{
printf(" %10s ",parseTable.actions[j][k]);
}
printf("\n");
}
if(retval)
{
system("rm parsetable.txt");
exit(EXIT_FAILURE);
}
/* Write parse table to file */
retval = save(parseTable);
if(retval )
{
printf("\n%s:%d save() returned 1.\n Parse table could not be w
ritten to parsetable.txt",__FILE__,__LINE__);
}
printf("\n\nExiting..");
printf("\nHAPPY HAPPY JOY JOY\n");
return 0;
}