-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.y
68 lines (53 loc) · 1.03 KB
/
parser.y
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
%{
#include <stdio.h>
#include <string.h>
#include "processor.h"
extern FILE* yyin;
void yyerror(char *);
int yylex(void);
extern void parseCfg(char*);
%}
%union {
char* hexStr;
}
%token <hexStr> HEXNUM
%token <int> NEWLINE
%token <int> END1
%type <int> number
%type <int> numbers
%start root
%%
root:
numbers { numofinstructions = memidx; goProcessor(); exit(0);}
;
numbers:
number {;}
|numbers number {;}
;
number:
HEXNUM { storeInMem($1, memidx); memidx++;}
;
%%
void yyerror(char* s){
fprintf(stderr, "Invalid Input.\n");
}
int main(int argc, char *argv[]) {
if (argc != 5){
printf("Invalid Command. Enter Proper Arguments\n");
exit(0);
}
initialiseCache();
// printf("Cache Initialised.\n");
parseCfg(strdup(argv[2]));
yyin=fopen(argv[1],"r");
if (yyin==NULL){
printf("File Not Found.\n");
exit(0);
}
image_file = (char*)malloc(sizeof(char)*1000);
output_file = (char*)malloc(sizeof(char)*1000);
strcpy(image_file, argv[3]);
strcpy(output_file, argv[4]);
yyparse();
return 0;
}