-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompilers.c
More file actions
200 lines (184 loc) · 7.4 KB
/
Copy pathCompilers.c
File metadata and controls
200 lines (184 loc) · 7.4 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
************************************************************
* COMPILERS COURSE - Algonquin College
* Code version: Fall, 2025
* Author: Alex Vu and Yassine Amraoui
* Professors: Paulo Sousa
************************************************************
"\t=-------------------------------------------------------------------=\n",
"\t| COMPILERS - ALGONQUIN COLLEGE (S25) |\n",
"\t=-------------------------------------------------------------------=\n",
"\t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n",
"\t @@ @@ \n",
"\t @@ %&@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@ \n",
"\t @@ @%% (@@@@@@@@@ @ @ @@ \n",
"\t @@ @& @ @ @ @ @ @@ \n",
"\t @@ @ @ % / / @@@@@@ @ @@ \n",
"\t @@ & @ @ @@ @ @@ \n",
"\t @@ @/ @*@ @ @ @ @ @@ \n",
"\t @@ @@@@ @@ @ @ @ @@ \n",
"\t @@ /@@ @@@ @ @ @@ \n",
"\t @@ @ / / @@ @ @ @@ \n",
"\t @@ @ @@ /@/ @@@ @ @ @@ \n",
"\t @@ @@@@@@@@@@@@@@@ @ @@ \n",
"\t @@ @@ \n",
"\t @@ S T R U C T U R A L @@ \n",
"\t @@ By Alex Vu and Yassine Amraoui @@ \n",
"\t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n",
"\t \n",
"\t[COMPILER SCRIPT ..................................................]\n",*/
/*
************************************************************
* File name: compilers.c
* Compiler: MS Visual Studio 2022
* Course: CST 8152 � Compilers, Lab Section: [011, 012]
* Assignment: A12, A22, A32.
* Date: sEP 01 2025
* Professor: Paulo Sousa
* Purpose: This file is the main program of Compilers Project
* Function list: main().
************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#ifndef COMPILERS_H_
#include "Compilers.h"
#endif
#ifndef ENABLE_PARSER
#define ENABLE_PARSER 1
#endif
/*
* ............................................................................
* ADVICE 1:
* Please check the "TODO" labels to develop your activity.
*
* ADVICE 2: This file must be updated according to each assignment
* (see the progression: reader > scanner > parser).
* ............................................................................
*/
/*
***********************************************************
* Function name: main
* Purpose: Main function
* Author: Paulo Sousa
* History/Versions: Ver F25
* Called functions: mainReader(), mainScanner(), mainParser()
* Parameters: Command line arguments - argc, argv
* Return value: Status
* Algorithm: -
*************************************************************
*/
struct_int main(struct_int argc, struct_strg* argv) {
struct_int i;
printLogo();
if (DEBUG) {
for (i = 0; i < argc; ++i)
printf("argv[%d] = %s\n", i, argv[i]);
}
if (argc < 2) {
printf("%s%c%s%c%s%c%s%c%s%c%s", "OPTIONS:\n* [",
PGM_CDR, "] - Coder\n* [",
PGM_RDR, "] - Reader\n* [",
PGM_SCN, "] - Scanner\n* [",
PGM_PSR, "] - Parser\n* [",
PGM_WRT, "] - Writer\n");
return EXIT_FAILURE;
}
struct_char option = argv[1][0];
switch (option) {
case PGM_CDR:
printf("%s%c%s", "\n[Option '", PGM_CDR, "': Starting CODER .....]\n\n");
main1Coder(argc, argv);
break;
case PGM_RDR:
printf("%s%c%s", "\n[Option '", PGM_RDR, "': Starting READER .....]\n\n");
main2Reader(argc, argv);
break;
case PGM_SCN:
printf("%s%c%s", "\n[Option '", PGM_SCN, "': Starting SCANNER .....]\n\n");
main3Scanner(argc, argv);
break;
#if ENABLE_PARSER
case PGM_PSR:
printf("%s%c%s", "\n[Option '", PGM_PSR, "': Starting PARSER .....]\n\n");
main4Parser(argc, argv);
break;
#else
case PGM_PSR:
printf("%s%c%s", "\n[Option '", PGM_PSR, "': Parser not included in this build .....]\n\n");
break;
#endif
case PGM_WRT:
printf("%s%c%s", "\n[Option '", PGM_WRT, "': Starting WRITER .....]\n\n");
main5Writer(argc, argv);
break;
default:
printf("%s%c%s%c%s%c%s%c%s%c%s", "OPTIONS:\n* [",
PGM_CDR, "] - Coder\n* [",
PGM_RDR, "] - Reader\n* [",
PGM_SCN, "] - Scanner\n* [",
PGM_PSR, "] - Parser\n* [",
PGM_WRT, "] - Writer\n");
break;
}
return EXIT_SUCCESS;
}
/*
***********************************************************
* Function name: printLogo
* Purpose: Print Logo
* Author: Paulo Sousa
* History/Versions: Ver F25
* Called functions: -
* Parameters: -
* Return value: (Null)
* Algorithm: -
*************************************************************
*/
struct_void printLogo() {
printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
"\t=-------------------------------------------------------------------=\n",
"\t| COMPILERS - ALGONQUIN COLLEGE (S25) |\n",
"\t=-------------------------------------------------------------------=\n",
"\t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n",
"\t @@ @@ \n",
"\t @@ %&@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@ \n",
"\t @@ @%% (@@@@@@@@@ @ @ @@ \n",
"\t @@ @& @ @ @ @ @ @@ \n",
"\t @@ @ @ % / / @@@@@@ @ @@ \n",
"\t @@ & @ @ @@ @ @@ \n",
"\t @@ @/ @*@ @ @ @ @ @@ \n",
"\t @@ @@@@ @@ @ @ @ @@ \n",
"\t @@ /@@ @@@ @ @ @@ \n",
"\t @@ @ / / @@ @ @ @@ \n",
"\t @@ @ @@ /@/ @@@ @ @ @@ \n",
"\t @@ @@@@@@@@@@@@@@@ @ @@ \n",
"\t @@ @@ \n",
"\t @@ S T R U C T U R A L @@ \n",
"\t @@ By Alex Vu & Yassine Amraoui @@ \n",
"\t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n",
"\t \n",
"\t[COMPILER SCRIPT ..................................................]\n"
);
}
/*
************************************************************
* Error printing function with variable number of arguments
* Params: Variable arguments, using formats from C language.
* - Internal vars use list of arguments and types from stdarg.h
* - NOTE: The format is using signature from C Language
************************************************************
*/
struct_void errorPrint(struct_strg fmt, ...) {
/* Initialize variable list */
va_list ap;
va_start(ap, fmt);
(struct_void)vfprintf(stderr, fmt, ap);
va_end(ap);
/* Move to new line */
if (strchr(fmt, '\n') == NULL)
fprintf(stderr, "\n");
}