Testing update with check.sh

This commit is contained in:
Scarlett
2025-03-05 12:30:33 -05:00
parent c26253c20f
commit 4d674eb8b7
24 changed files with 101 additions and 44 deletions

View File

@ -3,9 +3,12 @@ FLEX := flex
LEX := src/lexicalStructure.lex
EXE := alpha
CFLAGS :=
YACC := bison
YACC := bison
compiler: runner
TESTS-S1 := $(wildcard tests/sprint1/test/*.alpha)
TESTS-S2 := $(wildcard tests/sprint2/test/*.alpha)
compiler: clean runner
tmp/grammar.tab.c: src/grammar.y
mkdir -p tmp
@ -35,25 +38,14 @@ debug: clean compiler
test: test-s1 test-s2
test-s1:
./$(EXE) -tok ./tests/sprint1/test_comment_fix1.alpha
./$(EXE) -tok ./tests/sprint1/test_comment_fix2.alpha
./$(EXE) -tok ./tests/sprint1/test_comment_issues.alpha
./$(EXE) -tok ./tests/sprint1/test_comments.alpha
./$(EXE) -tok ./tests/sprint1/test_general_token.alpha
./$(EXE) -tok ./tests/sprint1/test_keywords.alpha
./$(EXE) -tok ./tests/sprint1/test_operators.alpha
./$(EXE) -tok ./tests/sprint1/test_other_punc.alpha
./$(EXE) -tok ./tests/sprint1/test_punc_grouping.alpha
./$(EXE) -tok ./tests/sprint1/test_real_alpha_file1.alpha
./$(EXE) -tok ./tests/sprint1/test_real_alpha_file2.alpha
./$(EXE) -tok ./tests/sprint1/test_simple_int.alpha
./$(EXE) -tok ./tests/sprint1/test_simple_literals.alpha
./$(EXE) -tok ./tests/sprint1/test_variables.alpha
chmod +x ./check.sh
$(foreach test, $(TESTS-S1), ./$(EXE) -tok $(test);)
./check.sh
test-s2:
./$(EXE) -tok ./tests/sprint2/alpha/test_library.alpha
./$(EXE) -tok ./tests/sprint2/alpha/test_one_line.alpha
./$(EXE) -tok ./tests/sprint2/alpha/test_simple.alpha
chmod +x ./check.sh
$(foreach test, $(TESTS-S2), ./$(EXE) -tok $(test);)
./check.sh
clean:
rm -f *.o

27
check.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
# Diff-Check Tool #
# Checks if outputed TOK = exp #
# The Translators - Spring 2025 #
TOK_DIR="out"
if [[ ! -d "$TOK_DIR" ]]; then
echo "Directory $TOK_DIR does not exist."
exit 1
fi
echo -e "\n"
for file in "$TOK_DIR"/*; do
filename=$(basename -- "$file")
filename="${filename%.*}"
num=${filename:2:1}
exp="./tests/sprint$num/expected/$filename.expected"
if [[ -f "$exp" ]]; then
echo -e "--------------------------------------------"
echo -e "Checking $file...\n"
diff --color=always "$file" "$exp"
echo -e "--------------------------------------------\n"
fi
done

View File

@ -1,5 +1,5 @@
/* Syntax Analyzer with Bison (3.8.1) */
/* (referenced Bison manual for file boilerplate [3.1]) */
/* Syntax Analyzer with Bison (3.8.1) */
/* The Translators - Spring 2025 */
// Prologue
%{

View File

@ -1,15 +1,17 @@
/* Lexical Analyzer with Flex (1.6.0) */
/* Lexical Analyzer with Flex (1.6.0) */
/* The Translators - Spring 2025 */
%option noyywrap
%option header-file="flex.h"
%{
#include <stdbool.h>
//#include "typedefs.h"
#include "grammar.tab.h"
int line_number = 1, column_number = 1;
#ifndef DEBUG
#define DEBUG 0
#endif
int line_number = 1, column_number = 1;
%}
STARCOM [^\*]|\*+[^\)\*]+

View File

@ -1,37 +1,32 @@
// #include "symbol_table.h"
/* Runner File - Compiles alpha Compiler */
/* The Translators - Spring 2025 */
#include "runner.h"
int main(int argc, char *argv[]) {
if (argc == 1) {
fprintf(
stderr,
"INVALID INPUT: Include a .alpha file or use -help for more inputs \n");
stderr, INVALID);
return -1;
} else if (argc == 2) {
// can be either -help or .alpha file
}
else if (argc == 2) {
if (is_help(argv[1])) {
return 0;
} else if (is_alpha_file(argv[1], strlen(argv[1])) == 0) {
// run flex for now
no_flag = SET_FLAG; // no argument but valid input
no_flag = SET_FLAG;
alpha_file = fopen(argv[1], "r");
} else {
fprintf(stderr,
"INVALID INPUT: Include a .alpha file or use -help for more "
"inputs\n");
fprintf(stderr, INVALID);
return -1;
}
} else {
// last input must be .alpha
}
else {
if (is_alpha_file(argv[argc - 1], strlen(argv[argc - 1])) != 0) {
fprintf(stderr,
"INVALID INPUT: Include a .alpha file at end of input or use "
"-help for more inputs \n");
fprintf(stderr, INVALID);
return -1;
} else {
// now check that other args are valid (flags will not be null if flag is
// present)
for (int i = 1; i < argc - 1; i++) {
if (check_flag(argv[i], argv[argc - 1]) != 0) {
fprintf(stderr, "INVALID FLAG(S): Use -help to view valid inputs \n");
@ -117,6 +112,7 @@ bool is_help(char *input) {
printf("%s", HELP);
return true;
}
return false;
}

View File

@ -1,3 +1,6 @@
/* Runner File - Compiles alpha Compiler */
/* The Translators - Spring 2025 */
#define ALPHA_OFFSET 6
#define TOK_LEN 3
#define ST_LEN 2
@ -7,8 +10,9 @@
"number for each of the tokens to the .tok file\n-st output the symbol " \
"table for the program to the .st file\n-help print this message and exit " \
"the alpha compiler\n"
// use to set flags for arg types
#define SET_FLAG 1
#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"
#include <stdbool.h>
#include <stdio.h>

View File

@ -0,0 +1 @@
daskmskdfm

View File

@ -0,0 +1,30 @@
(* At compiler start-up your program should create symbol table entries for the four primitive types:
Boolean (1 byte)
character (1 byte)
integer (4 bytes)
address (8 bytes)
You should #include this file at the start of your alpha file.
Some useful types are defined below.
*)
type string: 1 -> character
type BooleanXBoolean: [Boolean: x, y]
type characterXcharacter: [character: x, y]
type integerXinteger: [integer: x, y]
type Boolean2Boolean: Boolean -> Boolean
type integer2integer: integer -> integer
type character2integer: character -> integer
type Boolean2integer: Boolean -> integer
type string2integer: string -> integer
type integerXinteger2integer: integerXinteger -> integer
type integerXinteger2Boolean: integerXinteger -> Boolean
type characterXcharacter2Boolean: characterXcharacter -> Boolean
type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean
type integer2address: integer -> address
type address2integer: address -> integer
external function printInteger: integer2integer
external function printCharacter: character2integer
external function printBoolean: Boolean2integer
external function reserve: integer2address
external function release: address2integer
function entry: string2integer

View File

@ -0,0 +1 @@
type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve(w); w.x := 5; w.y := 7; result := bar1(w); result := bar2(5,7); return 0; }

View File

@ -0,0 +1,4 @@
#include "library.alpha"
entry(arg) := {
return 0;
}