Testing suite updated

This commit is contained in:
Scarlett
2025-03-26 12:45:05 -04:00
parent 0c8c3e30f3
commit 5aefd319ae
20 changed files with 573 additions and 172 deletions

View File

@ -41,9 +41,8 @@ test-s1:
test-s2: test-s2:
chmod +x ./check.sh chmod +x ./check.sh
$(foreach test, $(TESTS-S2), ./$(EXE) -tok $(test);) $(foreach test, $(TESTS-S2), ./$(EXE) -st $(test);)
./check.sh ./check.sh
$(foreach test, $(TESTS-S2), ./$(EXE) $(test);)
clean: clean:
rm -f *.o rm -f *.o

View File

@ -5,6 +5,11 @@
# The Translators - Spring 2025 # # The Translators - Spring 2025 #
TOK_DIR="out" TOK_DIR="out"
RED='\033[0;31m'
GREEN='\033[0;32m'
WHITE='\033[0m'
PURPLE='\033[0;35m'
ORANGE='\033[0;33m'
if [[ ! -d "$TOK_DIR" ]]; then if [[ ! -d "$TOK_DIR" ]]; then
echo "Directory $TOK_DIR does not exist." echo "Directory $TOK_DIR does not exist."
@ -19,9 +24,15 @@ for file in "$TOK_DIR"/*; do
exp="./tests/sprint$num/expected/$filename.expected" exp="./tests/sprint$num/expected/$filename.expected"
if [[ -f "$exp" ]]; then if [[ -f "$exp" ]]; then
echo -e "--------------------------------------------" diff -q "$file" "$exp" > /dev/null
echo -e "Checking $file...\n" if [[ $? -eq 0 ]]; then
echo -e "${GREEN}[✔] ${PURPLE}$filename ${WHITE}passed."
else
echo -e "\n${RED}[✘] ${PURPLE}$file ${WHITE}failed with an unexpected value..."
diff --color=always "$file" "$exp" diff --color=always "$file" "$exp"
echo -e "--------------------------------------------\n" echo -e ""
fi
else
echo -e "${ORANGE}[-] ${PURPLE}$filename ${WHITE}does not have an expected value."
fi fi
done done

View File

@ -131,8 +131,13 @@ int run(FILE *alpha) {
} }
if (st_flag != NULL) { if (st_flag != NULL) {
// output symbol table, file pointer is yyparse();
// print_symbol_table(top,st_flag); print_symbol_table(getAncestor(cur), st_flag);
fclose(st_flag);
if (yyin != NULL) {
fclose(yyin);
}
return 0;
} }
yyparse(); yyparse();

View File

@ -1 +1 @@
daskmskdfm 1 1 700 "(***)"

View File

@ -0,0 +1,3 @@
1 1 700 "(*(**)"
1 7 603 "*"
1 8 502 ")"

View File

@ -0,0 +1,22 @@
1 1 700 "(*(**)"
1 7 603 "*"
1 8 502 ")"
2 1 700 "(***)"
3 1 700 "(******)"
3 9 700 "(*\kpp*********)"
4 1 501 "("
4 2 700 "(*((*)"
4 8 502 ")"
5 1 700 "(***)"
5 6 700 "(*)
(* *)"
7 1 700 "(***)"
7 6 502 ")"
7 7 502 ")"
7 8 502 ")"
7 9 502 ")"
7 10 502 ")"
7 11 502 ")"
7 12 603 "*"
7 13 700 "(*))))))))*)"
7 25 502 ")"

View File

@ -0,0 +1,9 @@
1 1 700 "(* hello *)"
2 1 700 "(* hello *)"
3 1 700 "(* I'd think this is a legal "string" that contains several \n \t
escaped characters, isn't it? *)"
5 1 700 "(* \ *)"
6 1 700 "(* *)"
7 1 700 "(*{COMMENT}+ *)"
8 1 700 "(* * *)"
9 1 700 "(* (hello) *)"

View File

@ -0,0 +1,68 @@
1 1 101 "This"
1 6 101 "is"
1 9 101 "a"
1 11 101 "test"
2 1 301 "9"
2 2 101 "combined"
2 11 301 "7"
2 12 101 "okens"
3 1 301 "12345"
4 1 301 "893247892"
5 1 101 "combined"
5 10 101 "DueToUnknownChar"
5 27 101 "_validtoken"
5 39 101 "__validtoken1"
5 53 101 "_valid_token2"
5 67 101 "validToken3_"
6 1 305 "true"
6 6 306 "false"
7 1 302 "null"
7 6 401 "while"
7 12 609 "!"
7 13 101 "wrong"
7 19 402 "if"
7 22 101 "when"
8 1 404 "else"
8 6 405 "type"
8 11 406 "function"
9 1 407 "return"
9 9 408 "external"
9 25 409 "as"
10 1 101 "string"
10 8 101 "_NOte_that_was_not_reserved"
11 1 501 "("
11 2 503 "["
11 3 502 ")"
11 4 504 "]"
11 5 505 "{"
11 6 506 "}"
11 7 508 ":"
11 8 507 ";"
11 9 509 ","
11 10 510 "->"
12 1 601 "+"
12 2 602 "-"
12 3 603 "*"
12 4 604 "/"
12 5 605 "%"
13 1 606 "<"
13 2 607 "="
14 1 608 ":="
15 2 101 "This"
15 7 101 "is"
15 10 101 "not"
15 14 101 "a"
15 16 101 "valid"
16 1 101 "String"
17 1 304 ""This is a valid String""
18 1 609 "!"
18 2 611 "|"
19 1 612 "."
19 2 612 "."
20 1 700 "(* this is a comment *)"
21 1 501 "("
21 2 603 "*"
21 3 101 "Not"
21 7 101 "a"
21 9 101 "comment"
22 3 610 "&"

View File

@ -0,0 +1,29 @@
1 1 401 "while"
2 1 101 "While"
3 1 101 "whiLe"
4 1 402 "if"
5 1 101 "IF"
6 1 101 "If"
7 1 101 "iF"
8 1 403 "then"
9 1 101 "Then"
10 1 101 "theN"
11 1 404 "else"
12 1 101 "eLse"
13 1 101 "elSe"
14 1 101 "Else"
15 1 405 "type"
16 1 101 "Type"
17 1 101 "tyPe"
18 1 406 "function"
19 1 101 "Function"
20 1 101 "functioN"
21 1 407 "return"
22 1 101 "Return"
23 1 101 "returN"
24 1 408 "external"
25 1 101 "External"
26 1 101 "exteRnal"
27 1 409 "as"
28 1 101 "As"
29 1 101 "aS"

View File

@ -0,0 +1,22 @@
1 1 601 "+"
2 1 602 "-"
3 1 603 "*"
4 1 604 "/"
6 1 605 "%"
7 1 606 "<"
9 1 607 "="
10 1 608 ":="
11 1 607 "="
11 2 508 ":"
12 1 508 ":"
13 1 607 "="
14 1 609 "!"
15 1 610 "&"
16 1 611 "|"
17 1 612 "."
18 1 101 "relEASE"
19 1 614 "release"
20 1 101 "RELEASE"
21 1 613 "reserve"
22 1 101 "RESERVE"
23 1 101 "reSERVe"

View File

@ -0,0 +1,7 @@
1 1 507 ";"
2 1 508 ":"
3 1 509 ","
4 1 510 "->"
5 1 510 "->"
6 1 602 "-"
6 2 510 "->"

View File

@ -0,0 +1,59 @@
1 1 502 ")"
2 1 101 "a"
2 2 502 ")"
3 1 502 ")"
3 2 101 "a"
4 1 502 ")"
4 2 603 "*"
5 1 603 "*"
5 2 502 ")"
7 1 700 "(* jellsls
well this seems to work
*)"
13 1 501 "("
14 1 101 "a"
14 2 501 "("
15 1 501 "("
15 2 101 "a"
16 1 501 "("
16 2 603 "*"
17 1 603 "*"
17 2 501 "("
20 1 505 "{"
21 1 101 "a"
21 2 505 "{"
22 1 505 "{"
22 2 101 "a"
23 1 505 "{"
23 2 603 "*"
24 1 603 "*"
24 2 505 "{"
25 1 506 "}"
26 1 101 "a"
26 2 506 "}"
27 1 506 "}"
27 2 101 "a"
28 1 506 "}"
28 2 603 "*"
29 1 603 "*"
29 2 506 "}"
33 1 503 "["
34 1 101 "a"
34 2 503 "["
35 1 503 "["
35 2 101 "a"
36 1 503 "["
36 2 603 "*"
37 1 603 "*"
37 2 503 "["
38 1 504 "]"
39 1 101 "a"
39 2 504 "]"
40 1 504 "]"
40 2 101 "a"
41 1 504 "]"
41 2 603 "*"
42 1 603 "*"
42 2 504 "]"

View File

@ -0,0 +1,145 @@
1 1 405 "type"
1 6 101 "rec"
1 9 508 ":"
1 11 503 "["
1 12 201 "integer"
1 19 508 ":"
1 21 101 "x"
1 22 507 ";"
1 24 201 "integer"
1 31 508 ":"
1 33 101 "y"
1 34 504 "]"
2 1 405 "type"
2 6 101 "T1"
2 8 508 ":"
2 10 201 "integer"
2 18 510 "->"
2 21 201 "integer"
3 1 405 "type"
3 6 101 "T2"
3 8 508 ":"
3 10 101 "rec"
3 14 510 "->"
3 17 201 "integer"
4 1 406 "function"
4 10 101 "foo"
4 14 508 ":"
4 16 101 "T1"
5 1 406 "function"
5 10 101 "bar1"
5 15 508 ":"
5 17 101 "T2"
6 1 406 "function"
6 10 101 "bar2"
6 15 508 ":"
6 17 101 "T2"
7 1 101 "foo"
7 4 501 "("
7 5 101 "x"
7 6 502 ")"
7 8 608 ":="
7 11 505 "{"
8 2 407 "return"
8 9 101 "x"
8 11 603 "*"
8 13 101 "x"
8 14 507 ";"
9 9 506 "}"
10 1 101 "bar1"
10 5 501 "("
10 6 101 "a"
10 7 502 ")"
10 9 608 ":="
10 12 505 "{"
11 9 407 "return"
11 16 101 "a"
11 17 612 "."
11 18 101 "x"
11 20 603 "*"
11 22 101 "a"
11 23 612 "."
11 24 101 "y"
11 25 507 ";"
12 9 506 "}"
13 1 101 "bar2"
13 6 409 "as"
13 9 501 "("
13 10 101 "r"
13 11 509 ","
13 12 101 "s"
13 13 502 ")"
13 15 608 ":="
13 18 505 "{"
14 9 407 "return"
14 16 101 "r"
14 18 603 "*"
14 20 101 "s"
14 21 507 ";"
15 9 506 "}"
16 1 101 "entry"
16 6 501 "("
16 7 101 "arg"
16 10 502 ")"
16 12 608 ":="
16 15 505 "{"
17 9 503 "["
17 11 201 "integer"
17 18 508 ":"
17 20 101 "result"
17 27 507 ";"
17 29 101 "rec"
17 32 508 ":"
17 34 101 "w"
17 35 504 "]"
18 9 101 "result"
18 16 608 ":="
18 19 101 "foo"
18 22 501 "("
18 23 301 "5"
18 24 502 ")"
18 25 507 ";"
19 9 101 "w"
19 11 608 ":="
19 14 613 "reserve"
19 21 501 "("
19 22 101 "w"
19 23 502 ")"
19 24 507 ";"
19 26 700 "(* see types.alpha reserve returns a value of type address,
which can be assigned to array and record variables
*)"
22 9 101 "w"
22 10 612 "."
22 11 101 "x"
22 13 608 ":="
22 16 301 "5"
22 17 507 ";"
23 9 101 "w"
23 10 612 "."
23 11 101 "y"
23 13 608 ":="
23 16 301 "7"
23 17 507 ";"
24 9 101 "result"
24 16 608 ":="
24 19 101 "bar1"
24 23 501 "("
24 24 101 "w"
24 25 502 ")"
24 26 507 ";"
24 28 700 "(* pass w (a rec type value) to bar1 *)"
25 9 101 "result"
25 16 608 ":="
25 19 101 "bar2"
25 23 501 "("
25 24 301 "5"
25 25 509 ","
25 26 301 "7"
25 27 502 ")"
25 28 507 ";"
25 30 700 "(* implicitly build a rec type value, assign 5 and 7 to fields x and y, but call them r and s *)"
27 9 407 "return"
27 16 301 "0"
27 17 507 ";"
28 1 506 "}"

View File

@ -0,0 +1,100 @@
1 1 700 "(* Type definitions *)"
2 1 405 "type"
2 6 101 "string"
2 12 508 ":"
2 14 301 "1"
2 16 510 "->"
2 19 204 "character"
3 1 405 "type"
3 6 101 "int2int"
3 13 508 ":"
3 15 201 "integer"
3 23 510 "->"
3 26 201 "integer"
4 1 405 "type"
4 6 101 "string2int"
4 16 508 ":"
4 18 101 "string"
4 25 510 "->"
4 28 201 "integer"
5 1 700 "(* Function prototypes
They use the above type definitions
*)"
8 1 406 "function"
8 10 101 "square"
8 17 508 ":"
8 19 101 "int2int"
9 1 406 "function"
9 10 101 "entry"
9 16 508 ":"
9 18 101 "string2int"
10 1 700 "(* Function definition
Functions must be declared before they are defined
*)"
13 1 101 "square"
13 7 501 "("
13 8 101 "x"
13 9 502 ")"
13 11 608 ":="
13 14 505 "{"
14 1 407 "return"
14 8 101 "x"
14 10 603 "*"
14 12 101 "x"
14 13 507 ";"
15 1 506 "}"
16 1 700 "(* Function definition
entry is the first function called
*)"
19 1 101 "entry"
19 6 501 "("
19 7 101 "arg"
19 10 502 ")"
19 12 608 ":="
19 15 505 "{"
20 1 101 "input"
20 7 607 "="
20 9 301 "7"
20 10 507 ";"
21 1 101 "expected"
21 10 607 "="
21 12 301 "49"
21 14 507 ";"
22 1 101 "actual"
22 8 608 ":="
22 11 101 "square"
22 17 501 "("
22 18 101 "input"
22 23 502 ")"
22 24 507 ";"
23 1 101 "rseult"
23 8 608 ":="
23 11 101 "expected"
23 20 607 "="
23 22 101 "actual"
23 28 507 ";"
24 1 407 "return"
24 8 301 "0"
24 9 507 ";"
25 1 503 "["
25 3 201 "integer"
25 10 508 ":"
25 12 101 "input"
25 17 507 ";"
25 19 201 "integer"
25 26 508 ":"
25 28 101 "expected"
25 36 507 ";"
25 38 201 "integer"
25 45 508 ":"
25 47 101 "actual"
25 53 507 ";"
25 55 101 "boolean"
25 62 508 ":"
25 64 101 "result"
25 70 507 ";"
25 72 101 "string"
25 78 508 ":"
25 80 101 "input"
25 86 504 "]"
26 1 506 "}"

View File

@ -0,0 +1,8 @@
1 1 301 "45"
2 1 301 "123"
3 1 301 "8392"
4 1 301 "40"
4 4 301 "40"
5 2 301 "200"
5 6 301 "50"
5 9 301 "21783"

View File

@ -0,0 +1,64 @@
1 1 304 ""this is a string""
1 20 301 "721398"
1 27 303 "'g'"
1 32 604 "/"
1 33 101 "n"
1 36 700 "(* should print 3 tokens before this *)"
4 1 301 "12893"
4 8 101 "this"
4 13 101 "is"
4 16 101 "not"
4 20 101 "a"
4 22 101 "string"
4 29 700 "(*one valid token before this*)"
5 1 700 "(* spacey comment here
over multiple lines
will it work? *)"
7 18 306 "false"
11 1 306 "false"
12 1 700 "(**)"
14 1 101 "nullfalse"
15 2 101 "nulltrue"
16 1 302 "null"
17 1 303 "'7'"
18 1 305 "true"
19 2 301 "189"
20 1 303 "'\t'"
21 1 303 "'"'"
22 1 303 "'/'"
23 1 303 "'\n'"
24 1 303 "'\''"
25 1 303 "'\t'"
26 1 303 "'\\'"
27 1 303 "'n'"
29 2 101 "fdsf"
30 1 700 "(*/jnewjno2893u86^ Lots of random characters /n /t '") *)"
35 1 304 ""STRINGwithnotSPaces""
36 1 303 "' '"
38 1 304 ""J""
39 1 304 """"
40 1 304 "" ""
42 1 304 ""{SCHAR}""
43 1 304 ""SCHAR""
44 1 304 ""[SCHAR]""
45 1 304 ""FINAL: I'd think this is a legal \"string\" that contains \n \t several escaped characters, isn't it?""
46 2 101 "I"
46 4 101 "d"
46 6 101 "think"
46 12 101 "this"
46 17 101 "is"
46 20 101 "a"
46 22 101 "legal"
46 30 101 "string"
46 39 101 "that"
46 44 101 "contains"
46 53 101 "several"
46 63 101 "n"
46 66 101 "t"
46 68 101 "escaped"
46 76 101 "characters"
46 86 509 ","
46 88 101 "isn"
46 92 101 "t"
46 94 101 "it"
47 1 101 "nullLike"

View File

@ -0,0 +1,13 @@
1 1 101 "valid1"
2 1 101 "Valid2"
3 1 101 "_valid3"
4 1 101 "_valid_name_4"
5 1 101 "VALID"
6 1 301 "0"
6 2 101 "Invalid"
7 1 301 "1"
7 2 101 "invalid"
8 2 101 "invalid"
9 1 101 "invalid"
9 8 607 "="
10 1 101 "String"

View File

@ -1,48 +0,0 @@
/* Function type. */
typedef double (func_t) (double);
/* Data type for links in the chain of symbols. */
struct symrec
{
char *name; /* name of symbol */
int type; /* type of symbol: either VAR or FUN */
union
{
double var; /* value of a VAR */
func_t *fun; /* value of a FUN */
} value;
struct symrec *next; /* link field */
};
typedef struct symrec symrec;
/* The symbol table: a chain of 'struct symrec'. */
extern symrec *sym_table;
symrec *putsym (char const *name, int sym_type);
symrec *getsym (char const *name);
struct init
{
char const *name;
func_t *fun;
};
struct init const funs[] =
{
{ "atan", atan },
{ "cos", cos },
{ "exp", exp },
{ "ln", log },
{ "sin", sin },
{ "sqrt", sqrt },
{ 0, 0 },
};
/* The symbol table: a chain of 'struct symrec'. */
symrec *sym_table;
/* Put functions in table. */
static void
init_table (void)
{
for (int i = 0; funs[i].name; i++)
{
symrec *ptr = putsym (funs[i].name, FUN);
ptr->value.fun = funs[i].fun;
}
}

View File

@ -1,74 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include "symbol_table.h"
int main(void){
char *prim = strdup("primitive");
char *inte = strdup("integer");
SymbolTable * parant = CreateScope(NULL, 1,1);
char *boole = strdup("Boolean");
char *chare = strdup("character");
char *str = strdup("string");
char *arg = strdup("arg");
char *one_to_char = strdup("1 -> character");
char *int_to_int = strdup("integer -> integer");
char *int2int = strdup("int2int");
char *str_to_int = strdup("string -> integer");
char *str2int = strdup("string2int");
char *square = strdup("square");
char *string2int = strdup("string2int");
char *entry = strdup("entry");
char *x = strdup("x");
char *input = strdup("input");
char *expected = strdup("expected");
char *actual = strdup("actual");
char *$_und_type = strdup("$_undefined_type");
char *result = strdup("result");
char *BOO = strdup("BOO");
char *YAZOO = strdup("YAZOO");
CreateEntry(parant, prim, boole);
CreateEntry(parant, prim, chare);
CreateEntry(parant, prim, inte);
CreateEntry(parant, one_to_char, str);
CreateEntry(parant, int_to_int, int2int);
CreateEntry(parant, str_to_int, str2int);
CreateEntry(parant, int2int, square);
CreateEntry(parant, string2int, entry);
SymbolTable * child = CreateScope(parant, 14,14);
CreateEntry(child, inte, x);
SymbolTable * second = CreateScope(parant, 21,15);
CreateEntry(second, str, arg);
CreateEntry(second, inte, input);
CreateEntry(second, inte, expected);
CreateEntry(second, inte, actual);
CreateEntry(second, $_und_type, result);
SymbolTable * third = CreateScope(second, 33,44);
CreateEntry(third, BOO, arg);
CreateEntry(third, YAZOO, input);
TableNode *ret = table_lookup(third, "arg");
printf("%s == %s\n", ret->theName, "arg");
ret = table_lookup(third, "hello");
printf("This should be nil %p != %s\n", ret, "BOO");
ret = look_up(second, "input");
printf("%s == %s\n", ret->theName, "input");
ret = look_up(second, "square");
printf("%s == %s\n", ret->theName, "square");
ret = look_up(second, "spuare");
printf("This should be nil %p == %s\n", ret, "square");
print_symbol_table(parant, stderr);
free(inte);
free(boole);
free(prim);
free(str);
free(chare);
free(arg);
return 0;
}

View File

@ -1,41 +0,0 @@
%{
#include <stdio.h> /* For printf, etc. */
#include <math.h> /* For pow, used in the grammar. */
#include "calc.h" /* Contains definition of 'symrec'. */
int yylex (void);
void yyerror (char const *);
%}
%define api.value.type union /* Generate YYSTYPE from these types: */
%token <double> NUM /* Double precision number. */
%token <symrec*> VAR FUN /* Symbol table pointer: variable/function. */
%nterm <double> exp
%precedence '='
%left '-' '+'
%left '*' '/'
%precedence NEG /* negation--unary minus */
%right '^' /* exponentiation */
%% /* The grammar follows. */
input:
%empty
| input line
;
line:
'\n'
| exp '\n' { printf ("%.10g\n", $1); }
| error '\n' { yyerrok; }
;
exp:
NUM
| VAR { $$ = $1->value.var; }
| VAR '=' exp { $$ = $3; $1->value.var = $3; }
| FUN '(' exp ')' { $$ = $1->value.fun ($3); }
| exp '+' exp { $$ = $1 + $3; }
| exp '-' exp { $$ = $1 - $3; }
| exp '*' exp { $$ = $1 * $3; }
| exp '/' exp { $$ = $1 / $3; }
| '-' exp %prec NEG { $$ = -$2; }
| exp '^' exp { $$ = pow ($1, $3); }
| '(' exp ')' { $$ = $2; }
;
/* End of grammar. */
%%