-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
124 lines (100 loc) · 2.65 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* GROUP 48:
PUNEET ANAND 2016B4A70487P
MAYANK JASORIA 2016B1A70703P
SHUBHAM TIWARI 2016B4A70935P
VIBHAV OSWAL 2016B4A70594P */
#include "lexer.h"
#include "lexerDef.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "data_structures/stack.h"
void printList1(List ll) {
Node* curr = ll->head;
while(curr != NULL) {
printf("[ %d ] --> ", *((int*)(curr->data)));
curr = curr->next;
}
printf("NULL\n");
}
void printListReverse(List ll) {
Node* curr = ll->end;
printf("NULL");
while(curr != NULL) {
printf(" <-- [%d]", *((int*)curr->data));
curr = curr->prev;
}
printf("\n");
}
int main() {
lexerinit();
FILE * fp = fopen("prog.eg", "r");
int i = 1;
token * tok;
while(1) {
tok = getNextToken(fp);
if(tok -> id == 57)
break;
else {
printf("Token Sequence: %d Token id:%d Token Lexeme: %s %d\n", i + 1, tok -> id, tok -> lex, tok -> line_num);
i++;
}
}
// if(fp == NULL) {
// printf("Error opening file\n");
// return 0;
// }
// while(endofLexer == 0) {
// fp = getStream(fp);
// }
// int i;
// printf("%d\n", line_num);
// for(i = 0; i < ntokens; i++)
// printf("Token Sequence: %d Token id:%d Token Lexeme: %s %d\n", i + 1, tokenStream[i] -> id, tokenStream[i] -> lex, tokenStream[i] -> line_num);
printf("Total number of token generated: %d\n", ntokens);
// removeComments("prog.eg", "clean.eg");
// Testing Linked List
// List ll = getList();
// srand(time(0));
// for(int i = 0, j = 0; i < 10; i++, j = j^1) {
// int *ins = malloc(sizeof(int));
// *ins = rand();
// printf("Inserted %d\n", *ins);
// ll = insertToList(ll, ins, j);
// }
// printListReverse(ll);
// // delete third element
// ll = deleteByNode(ll, ll->head->next->next);
// while (ll->head) {
// ll = deleteByNode(ll, ll->head);
// printListReverse(ll);
// }
// printListReverse(ll);
// // delete head
// ll = deleteByNode(ll, ll->head);
// printListReverse(ll);
// // delete tail
// ll = deleteByNode(ll, ll->end);
// printListReverse(ll);
// testing stack
// Stack st = getStack();
// srand(time(0));
// for(int i = 0; i < 10; i++) {
// int* val = (int*) malloc(sizeof(int));
// *val = rand();
// printf("pushed %d\n", *val);
// push(st, val);
// }
// // popping 3 elements
// for(int i = 0; i < 3; i++) {
// printf("popped :%d\n", *((int*)top(st)));
// st = pop(st);
// }
// printf("Top: %d\n", *((int*)top(st)));
// popMany(st, 4);
// printf("new Top: %d\n", *((int*)top(st)));
// popMany(st, 39);
}