Combined binaries (parser + alpha)
This commit is contained in:
6
Makefile
6
Makefile
@ -26,11 +26,8 @@ tmp/runner.o: src/runner.c src/runner.h tmp/flex.h
|
|||||||
tmp/symbol_table.o: src/symbol_table.c src/symbol_table.h
|
tmp/symbol_table.o: src/symbol_table.c src/symbol_table.h
|
||||||
$(CC) $(CFLAGS) -o tmp/symbol_table.o -c src/symbol_table.c
|
$(CC) $(CFLAGS) -o tmp/symbol_table.o -c src/symbol_table.c
|
||||||
|
|
||||||
parser : clean tmp/lex.yy.c tmp/grammar.tab.c
|
|
||||||
$(CC) -o parser tmp/lex.yy.c tmp/grammar.tab.c
|
|
||||||
|
|
||||||
runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o
|
runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o
|
||||||
$(CC) $(CFLAGS) -o $(EXE) tmp/runner.o tmp/lex.yy.c tmp/symbol_table.o
|
$(CC) $(CFLAGS) -o $(EXE) tmp/runner.o tmp/grammar.tab.c tmp/lex.yy.c
|
||||||
|
|
||||||
debug: CFLAGS += -DDEBUG=1
|
debug: CFLAGS += -DDEBUG=1
|
||||||
debug: clean compiler
|
debug: clean compiler
|
||||||
@ -46,6 +43,7 @@ test-s2:
|
|||||||
chmod +x ./check.sh
|
chmod +x ./check.sh
|
||||||
$(foreach test, $(TESTS-S2), ./$(EXE) -tok $(test);)
|
$(foreach test, $(TESTS-S2), ./$(EXE) -tok $(test);)
|
||||||
./check.sh
|
./check.sh
|
||||||
|
$(foreach test, $(TESTS-S2), ./$(EXE) $(test);)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
|
@ -253,10 +253,10 @@ types:
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
void yyerror(const char *err) {
|
void yyerror(const char *err) {
|
||||||
// fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number);
|
fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
/* int main() {
|
||||||
//char *str = strdup("taco");
|
//char *str = strdup("taco");
|
||||||
//cur_value = NULL;
|
//cur_value = NULL;
|
||||||
//cur_type = NULL;
|
//cur_type = NULL;
|
||||||
@ -276,4 +276,4 @@ int main() {
|
|||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} */
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
%{
|
%{
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "grammar.tab.h"
|
#include "../tmp/grammar.tab.h"
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#endif
|
#endif
|
||||||
@ -76,7 +76,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
|||||||
"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}}
|
"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}}
|
||||||
"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}}
|
"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}}
|
||||||
|
|
||||||
{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {/*yylval.words = strdup(yytext);*/ return ID;}}
|
{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}}
|
||||||
|
|
||||||
\n {line_number++; column_number = 1;}
|
\n {line_number++; column_number = 1;}
|
||||||
\t {column_number++;}
|
\t {column_number++;}
|
||||||
|
31
src/runner.c
31
src/runner.c
@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
fprintf(
|
fprintf(stderr, INVALID);
|
||||||
stderr, INVALID);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,16 +59,21 @@ int check_flag(char *arg, char *alpha) {
|
|||||||
|
|
||||||
int run(FILE *alpha) {
|
int run(FILE *alpha) {
|
||||||
int token;
|
int token;
|
||||||
// check that file exists
|
curr = CreateScope(NULL, 1, 1);
|
||||||
|
|
||||||
|
// If file is not found
|
||||||
if (alpha == NULL) {
|
if (alpha == NULL) {
|
||||||
fprintf(stderr, "INPUT FILE NOT FOUND\n");
|
fprintf(stderr, "INPUT FILE NOT FOUND\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
yyin = alpha;
|
yyin = alpha;
|
||||||
|
|
||||||
|
// TOK FLAG
|
||||||
|
if (tok_flag != NULL) {
|
||||||
while (0 != (token = yylex())) {
|
while (0 != (token = yylex())) {
|
||||||
if (tok_flag != NULL) {
|
if (tok_flag != NULL) {
|
||||||
fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, token,
|
fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number,
|
||||||
yytext);
|
token, yytext);
|
||||||
}
|
}
|
||||||
if (token == COMMENT) {
|
if (token == COMMENT) {
|
||||||
for (int i = 0; i < yyleng; i++) {
|
for (int i = 0; i < yyleng; i++) {
|
||||||
@ -86,24 +90,31 @@ int run(FILE *alpha) {
|
|||||||
"On line number %d and column number %d we have an invalid "
|
"On line number %d and column number %d we have an invalid "
|
||||||
"character:%s\n",
|
"character:%s\n",
|
||||||
line_number, column_number, yytext);
|
line_number, column_number, yytext);
|
||||||
// return -1;
|
|
||||||
}
|
}
|
||||||
column_number += yyleng;
|
column_number += yyleng;
|
||||||
}
|
}
|
||||||
|
fclose(tok_flag);
|
||||||
|
|
||||||
|
if (yyin != NULL) {
|
||||||
|
fclose(yyin);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (st_flag != NULL) {
|
if (st_flag != NULL) {
|
||||||
// output symbol table, file pointer is
|
// output symbol table, file pointer is
|
||||||
// print_symbol_table(top,st_flag);
|
// print_symbol_table(top,st_flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
yyparse();
|
||||||
|
FILE *f = fdopen(1, "w");
|
||||||
|
print_symbol_table(getAncestor(curr), f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
if (yyin != NULL) {
|
if (yyin != NULL) {
|
||||||
fclose(yyin);
|
fclose(yyin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok_flag != NULL) {
|
|
||||||
fclose(tok_flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
#include "../tmp/flex.h"
|
#include "../tmp/flex.h"
|
||||||
#include "symbol_table.h"
|
#include "symbol_table.h"
|
||||||
#include "typedefs.h"
|
//#include "typedefs.h"
|
||||||
|
#include "../tmp/grammar.tab.h"
|
||||||
|
|
||||||
extern int line_number, column_number;
|
extern int line_number, column_number;
|
||||||
extern char *yytext;
|
extern char *yytext;
|
||||||
|
Reference in New Issue
Block a user