-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.c
65 lines (58 loc) · 1.91 KB
/
driver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include "lexerDef.h"
#include "lexer.h"
#include "parserDef.h"
#include "parser.h"
/**
* @author Nihav Jain
* @desc driver.c - driver program for the lexer and parser
* @cmd ./driver.exe <input_program.txt>
*/
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;
}