Example #1
0
int main(int argc, char** argv)
{
	// details of implementation (as per the assignment requirements)
	printf("(a) Lexer implemented using TWIN BUFFER\n");
	printf("(b) FIRST set automated, hardcoded FOLLOW set taken as input from a text file\n");
	printf("(c) Both lexical and syntax analysis modules implemented\n");
	printf("(d) PARSE TABLE generated\n");
	printf("(e) STACK for syntax checking successfully implemented\n");
	printf("(f) Catches only one syntax error at a time.\n");
	printf("(g) PARSE TREE successfully generated\n");
	printf("(h) All 3 option in driver working\n");

	printf(" Press option for the defined task\n");
	printf("1 :  for  printing the token list (on the console) generated by the lexer. Each token appears in a new line alongwith the corresponding lexeme\n");
	printf("2 :  for parsing to verify the syntactic correctness of the input source code \n");
	printf("3 :  for creating the parse tree and printing it appropriately\n");
	
	int option;
	scanf("%d", &option);

	if(option == 1)
	{
		FILE *dfafp = fopen("dfa.txt", "r");
		TreeNode *dfa;
		dfa = (TreeNode *)createDFA(dfafp, dfa);
		FILE *fp = fopen(*++argv, "r");
		buffersize k = 1000;
		buffer b = createBuffer(k);
		tokenInfo info = getNextToken(fp, dfa, b, k);
		// print all tokens in the input program
		while(info.value != NULL)
		{
			printf("%s\t%s\n", info.tokenName, info.value);
			info = getNextToken(fp, dfa, b, k);
		}
	}
	else if(option == 2)
	{
		table t;
		parseTree parsetree = parseInputSourceCode(*++argv, t);	
	}
	else if(option == 3)
	{
		table t;
		parseTree parsetree = parseInputSourceCode(*++argv, t);
		printParseTree(parsetree, *++argv);
	}
	
	return 0;
}
Example #2
0
static PTBL_ParseTable generateParseTable() {
  int i;

  ATermList vertex; 

  PTBL_State state;
  PTBL_States statelist = PTBL_makeStatesEmpty();
  PTBL_Gotos gotos; 
  PTBL_Choices actions;

  
  calc_first_table();
  calc_follow_table();
  createDFA();

  for (i = PGEN_getNumberOfStates()-1; i >= 0; i--) {
    vertex = PGEN_getStateOfStateNumber(i);

    gotos = (PTBL_Gotos)PGEN_getGotosOfState(vertex);
    if (!gotos) {
      gotos = PTBL_makeGotosEmpty();
    } 
    else if (PGEN_getStatsFlag) {
      PGEN_STATS_increaseGotos(PTBL_getGotosLength(gotos));
    }

    actions = PGEN_getActionsOfState(vertex);
    if (!actions) {
      actions = PTBL_makeChoicesEmpty();
    }
    else if (PGEN_getStatsFlag) {
      PGEN_STATS_increaseActions(PTBL_getChoicesLength(actions));
    }

    state = PTBL_makeStateDefault(i, gotos, actions);
    statelist = PTBL_makeStatesMany(state, statelist);
  }

  if (PGEN_getStatsFlag) { PGEN_STATS_print(); }

  return PTBL_makeParseTableParseTable(PTBL_makeVersionDefault(), PGEN_getInitialStateNumber(), PGEN_getLabelSection(), statelist, PGEN_getPrioSection());
}
bool matchRegex(char *regex , char *str){
	return checkDFA(createDFA(regex),str);
}