Merge pull request #42 from UB-CSE443/Sprint3-TC_Flag-t#NoTask

Sprint3 tc flag t#no task
This commit is contained in:
Annie Slenker
2025-04-04 18:49:54 -04:00
committed by GitHub
4 changed files with 43 additions and 23 deletions

View File

@ -37,7 +37,7 @@ debug: clean compiler
test:
chmod +x ./check.sh
chmod +x ./test.sh
$(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) -debug || true);)
$(foreach test, $(TESTS-S1), (./$(EXE) -tok -debug $(test) || true);)
./test.sh sp2
./test.sh sp3
./test.sh sp4
@ -46,7 +46,7 @@ test:
test-s1:
chmod +x ./check.sh
chmod +x ./test.sh
$(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) -debug || true);)
$(foreach test, $(TESTS-S1), (./$(EXE) -tok -debug $(test) || true);)
./check.sh sp1
test-s2:

View File

@ -6,10 +6,10 @@
int main(int argc, char *argv[]) {
// if last argument is debug then set to true and ignore it for the rest
// of this file
if (argc > 1 && strcmp(argv[argc - 1], "-debug") == 0) {
DEBUG = true;
argc--;
}
//if (argc > 1 && strcmp(argv[argc - 1], "-debug") == 0) {
// DEBUG = true;
// argc--;
// }
if (argc == 1) {
fprintf(stderr, INVALID);
@ -61,6 +61,14 @@ int check_flag(char *arg, char *alpha) {
}
fprintf(stderr, "FLAGS REPEAT\n");
return -1;
} else if (strcmp("-tc", arg) == 0) {
if (tc_flag == NULL) {
return new_file(arg, alpha);
}
} else if (strcmp("-debug", arg) == 0) {
DEBUG = true;
return 0;
} else {
fprintf(stderr, "INVALID FLAG: Use -help for valid inputs\n");
return -1;
@ -151,6 +159,10 @@ int run(FILE *alpha) {
return 0;
}
if (tc_flag != NULL) {
//SCARLETT NEEDS TO ADD THIS FUNCTIONALITY
}
yyparse();
FILE *f = fdopen(1, "w");
@ -194,6 +206,8 @@ int new_file(char *arg, char *alpha) {
type_len = TOK_LEN;
} else if (strcmp(arg, "-st") == 0) {
type_len = ST_LEN;
} else if (strcmp(arg, "-tc") == 0){
type_len = TC_LEN;
}else {
fprintf(stderr,
"INVALID FLAG: Use -help to view valid inputs\n");
@ -214,6 +228,9 @@ int new_file(char *arg, char *alpha) {
tok_flag = fopen(file_name, "w");
} else if (strcmp(arg, "-st") == 0) {
st_flag = fopen(file_name, "w");
} else if (strcmp(arg, "-tc") == 0) {
tc_flag = fopen(file_name, "w");
}
return 0;
}

View File

@ -4,6 +4,7 @@
#define ALPHA_OFFSET 6
#define TOK_LEN 3
#define ST_LEN 2
#define TC_LEN 2
#define HELP \
"HELP:\nHow to run the alpha compiler:\n./alpha [options] " \
"program\nValid " \
@ -13,7 +14,8 @@
"symbol " \
"table for the program to the .st file\n-help print this message " \
"and exit " \
"the alpha compiler\n"
"the alpha compiler\n-debug print debugging messages in grammar rules \n"
#define SET_FLAG 1 // Used to set flags for arg types
#define INVALID \
"INVALID INPUT: Include a .alpha file or use -help for more inputs \n"
@ -39,6 +41,7 @@ SymbolTable *cur;
FILE *alpha_file;
FILE *tok_flag = NULL;
FILE *st_flag = NULL;
FILE *tc_flag = NULL;
bool DEBUG = false;
int no_flag = 0;
int arg;

18
test.sh
View File

@ -48,7 +48,7 @@ if [ $# -eq 0 ]; then
if [ -f "$file" ]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" -debug
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
@ -60,7 +60,7 @@ if [ $# -eq 0 ]; then
if [ -f "$file" ]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" -debug
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
@ -72,7 +72,7 @@ if [ $# -eq 0 ]; then
if [ -f "$file" ]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" -debug
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
@ -84,7 +84,7 @@ if [ $# -eq 0 ]; then
if [ -f "$file" ]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" -debug
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n${WHITE}"
switchfunc
fi
@ -106,7 +106,7 @@ else
if [ -f "$1" ]; then
filename=$(basename -- "$1")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$1" -debug
./alpha -st -debug "$1"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}"
exit 1
else
@ -121,7 +121,7 @@ else
if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" -debug
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
@ -132,7 +132,7 @@ else
if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" -debug
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
@ -143,7 +143,7 @@ else
if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" -debug
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
@ -154,7 +154,7 @@ else
if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" -debug
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi