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; }
int parseOnlySourceCode(Parser* p, Lexer lex) { int result = parseInputSourceCode(p, lex); if (result) { printf("\n\nThe input is syntactically correct. :)\n\n"); return PARSED_SUCCESSFULLY; } else { printf("\n\nThe input is NOT syntactically correct. :(\n\n"); return PARSING_FAILED; } }