Testing update with check.sh
This commit is contained in:
28
Makefile
28
Makefile
@ -5,7 +5,10 @@ EXE := alpha
|
|||||||
CFLAGS :=
|
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
|
tmp/grammar.tab.c: src/grammar.y
|
||||||
mkdir -p tmp
|
mkdir -p tmp
|
||||||
@ -35,25 +38,14 @@ debug: clean compiler
|
|||||||
test: test-s1 test-s2
|
test: test-s1 test-s2
|
||||||
|
|
||||||
test-s1:
|
test-s1:
|
||||||
./$(EXE) -tok ./tests/sprint1/test_comment_fix1.alpha
|
chmod +x ./check.sh
|
||||||
./$(EXE) -tok ./tests/sprint1/test_comment_fix2.alpha
|
$(foreach test, $(TESTS-S1), ./$(EXE) -tok $(test);)
|
||||||
./$(EXE) -tok ./tests/sprint1/test_comment_issues.alpha
|
./check.sh
|
||||||
./$(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
|
|
||||||
|
|
||||||
test-s2:
|
test-s2:
|
||||||
./$(EXE) -tok ./tests/sprint2/alpha/test_library.alpha
|
chmod +x ./check.sh
|
||||||
./$(EXE) -tok ./tests/sprint2/alpha/test_one_line.alpha
|
$(foreach test, $(TESTS-S2), ./$(EXE) -tok $(test);)
|
||||||
./$(EXE) -tok ./tests/sprint2/alpha/test_simple.alpha
|
./check.sh
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
|
27
check.sh
Executable file
27
check.sh
Executable 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
|
@ -1,5 +1,5 @@
|
|||||||
/* Syntax Analyzer with Bison (3.8.1) */
|
/* Syntax Analyzer with Bison (3.8.1) */
|
||||||
/* (referenced Bison manual for file boilerplate [3.1]) */
|
/* The Translators - Spring 2025 */
|
||||||
|
|
||||||
// Prologue
|
// Prologue
|
||||||
%{
|
%{
|
||||||
|
@ -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 noyywrap
|
||||||
%option header-file="flex.h"
|
%option header-file="flex.h"
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
//#include "typedefs.h"
|
|
||||||
#include "grammar.tab.h"
|
#include "grammar.tab.h"
|
||||||
int line_number = 1, column_number = 1;
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int line_number = 1, column_number = 1;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
STARCOM [^\*]|\*+[^\)\*]+
|
STARCOM [^\*]|\*+[^\)\*]+
|
||||||
|
32
src/runner.c
32
src/runner.c
@ -1,37 +1,32 @@
|
|||||||
// #include "symbol_table.h"
|
/* Runner File - Compiles alpha Compiler */
|
||||||
|
/* The Translators - Spring 2025 */
|
||||||
|
|
||||||
#include "runner.h"
|
#include "runner.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr,
|
stderr, INVALID);
|
||||||
"INVALID INPUT: Include a .alpha file or use -help for more inputs \n");
|
|
||||||
return -1;
|
return -1;
|
||||||
} else if (argc == 2) {
|
}
|
||||||
// can be either -help or .alpha file
|
|
||||||
|
else if (argc == 2) {
|
||||||
if (is_help(argv[1])) {
|
if (is_help(argv[1])) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (is_alpha_file(argv[1], strlen(argv[1])) == 0) {
|
} else if (is_alpha_file(argv[1], strlen(argv[1])) == 0) {
|
||||||
// run flex for now
|
no_flag = SET_FLAG;
|
||||||
no_flag = SET_FLAG; // no argument but valid input
|
|
||||||
alpha_file = fopen(argv[1], "r");
|
alpha_file = fopen(argv[1], "r");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
fprintf(stderr, INVALID);
|
||||||
"INVALID INPUT: Include a .alpha file or use -help for more "
|
|
||||||
"inputs\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
// last input must be .alpha
|
|
||||||
|
else {
|
||||||
if (is_alpha_file(argv[argc - 1], strlen(argv[argc - 1])) != 0) {
|
if (is_alpha_file(argv[argc - 1], strlen(argv[argc - 1])) != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, INVALID);
|
||||||
"INVALID INPUT: Include a .alpha file at end of input or use "
|
|
||||||
"-help for more inputs \n");
|
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} 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++) {
|
for (int i = 1; i < argc - 1; i++) {
|
||||||
if (check_flag(argv[i], argv[argc - 1]) != 0) {
|
if (check_flag(argv[i], argv[argc - 1]) != 0) {
|
||||||
fprintf(stderr, "INVALID FLAG(S): Use -help to view valid inputs \n");
|
fprintf(stderr, "INVALID FLAG(S): Use -help to view valid inputs \n");
|
||||||
@ -117,6 +112,7 @@ bool is_help(char *input) {
|
|||||||
printf("%s", HELP);
|
printf("%s", HELP);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* Runner File - Compiles alpha Compiler */
|
||||||
|
/* The Translators - Spring 2025 */
|
||||||
|
|
||||||
#define ALPHA_OFFSET 6
|
#define ALPHA_OFFSET 6
|
||||||
#define TOK_LEN 3
|
#define TOK_LEN 3
|
||||||
#define ST_LEN 2
|
#define ST_LEN 2
|
||||||
@ -7,8 +10,9 @@
|
|||||||
"number for each of the tokens to the .tok file\n-st output the symbol " \
|
"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 " \
|
"table for the program to the .st file\n-help print this message and exit " \
|
||||||
"the alpha compiler\n"
|
"the alpha compiler\n"
|
||||||
// use to set flags for arg types
|
#define SET_FLAG 1 // Used to set flags for arg types
|
||||||
#define SET_FLAG 1
|
#define INVALID \
|
||||||
|
"INVALID INPUT: Include a .alpha file or use -help for more inputs \n"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
1
tests/sprint1/expected/sp1_comment_fix1.expected
Normal file
1
tests/sprint1/expected/sp1_comment_fix1.expected
Normal file
@ -0,0 +1 @@
|
|||||||
|
daskmskdfm
|
30
tests/sprint2/test/sp2_library.alpha
Normal file
30
tests/sprint2/test/sp2_library.alpha
Normal 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
|
1
tests/sprint2/test/sp2_one_line.alpha
Normal file
1
tests/sprint2/test/sp2_one_line.alpha
Normal 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; }
|
4
tests/sprint2/test/sp2_simple.alpha
Normal file
4
tests/sprint2/test/sp2_simple.alpha
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include "library.alpha"
|
||||||
|
entry(arg) := {
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user