-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpc.c
More file actions
40 lines (31 loc) · 1.17 KB
/
mpc.c
File metadata and controls
40 lines (31 loc) · 1.17 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
***************************************************************************
* Mini Pascal Compiler *
* AUTHORS: Charles Randolph, Joe Jones. *
* SNUMBERS: s2897318, s2990652. *
***************************************************************************
*/
#define USAGE "./mpc <InputFile> <OutputFile>\n"
#define MAXLINE 1000
char line[MAXLINE];
int main (int argc, const char *argv[]) {
/* Verify correct number of arguments are provided. */
if (argc != 3) {
fprintf(stderr, USAGE);
return EXIT_FAILURE;
}
/* Perform Semantic Analysis: Remove the "-c" flag to disable color */
sprintf(line, "./frontend/a.out -c < %s", argv[1]);
int verifiedSemantics = system(line);
/* If successful, generate IR code. */
if (verifiedSemantics == EXIT_SUCCESS) {
sprintf(line, "./backend/a.out %s < %s", argv[2], argv[1]);
system(line);
} else {
fprintf(stderr, "mpc: Compilation failed at semantic stage!\n");
}
return 0;
}