Lexer is ready just added some test files t#09
This commit is contained in:
4
Makefile
4
Makefile
@ -28,6 +28,8 @@ test:
|
||||
./$(EXE) ./tests/test_otherpunc.alpha
|
||||
./$(EXE) ./tests/test_simpleIntTest.alpha
|
||||
./$(EXE) ./tests/test_simpleLiterals.alpha
|
||||
./$(EXE) ./tests/test_real_alpha_file.alpha
|
||||
./$(EXE) ./tests/test_real_alpha_2.alpha
|
||||
./$(EXE) -tok ./tests/test_comments.alpha
|
||||
./$(EXE) -tok ./tests/test_generalTokenTest.alpha
|
||||
./$(EXE) -tok ./tests/test_keywords.alpha
|
||||
@ -35,6 +37,8 @@ test:
|
||||
./$(EXE) -tok ./tests/test_otherpunc.alpha
|
||||
./$(EXE) -tok ./tests/test_simpleIntTest.alpha
|
||||
./$(EXE) -tok ./tests/test_simpleLiterals.alpha
|
||||
./$(EXE) -tok ./tests/test_real_alpha_file.alpha
|
||||
./$(EXE) -tok ./tests/test_real_alpha_2.alpha
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f lex.yy.c
|
||||
|
13
runner.c
13
runner.c
@ -7,7 +7,7 @@ int main(int argc, char *argv[]) {
|
||||
FILE *output;
|
||||
|
||||
if (argc == 1 || argc > 3 || (argc == 2 && is_alpha_file(argv[1], strlen(argv[1])) != 0)) {
|
||||
fprintf(stderr, "invalid input with 1, >3, or non .alpha arg \n");
|
||||
fprintf(stderr, "invalid input with 1, >3, or non .alpha arg \n");
|
||||
return -1; //no alpha file or too many args
|
||||
} else if (argc == 2) {
|
||||
arg = NO_ARG; //no argument but valid input
|
||||
@ -15,7 +15,7 @@ int main(int argc, char *argv[]) {
|
||||
} else {
|
||||
check_input = is_tok(argc, argv);
|
||||
if (strcmp(CHECK_OTHER, check_input) == 0 || strcmp(INVALID_ARG, check_input) == 0) {
|
||||
fprintf(stderr, "check_other or invalid_arg \n");
|
||||
fprintf(stderr, "check_other or invalid_arg \n");
|
||||
return -1; //invalid argument (need to update as we add more valid arguments)
|
||||
}
|
||||
output = fopen(check_input, "w");
|
||||
@ -65,16 +65,17 @@ char *is_tok(int argc, char *argv[]) {
|
||||
|
||||
// Calculate lengths
|
||||
int basename_len = strlen(basename);
|
||||
char* FILE_tok = calloc(basename_len - ALPHA_OFFSET + TOK_LEN + 1, sizeof(char));
|
||||
|
||||
char* FILE_tok = calloc(basename_len - ALPHA_OFFSET + TOK_LEN + 2, sizeof(char));
|
||||
|
||||
// Copy filename and add .tok extension
|
||||
strncpy(FILE_tok, basename, basename_len - ALPHA_OFFSET);
|
||||
//fprintf(stderr, "hello");
|
||||
strcat(FILE_tok, ".tok");
|
||||
|
||||
|
||||
return FILE_tok;
|
||||
}
|
||||
return CHECK_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
int is_alpha_file(char *file, int file_len) {
|
||||
if (strcmp(".alpha", file + sizeof(char) * (file_len - ALPHA_OFFSET)) != 0) {
|
||||
|
26
tests/test_real_alpha_2.alpha
Normal file
26
tests/test_real_alpha_2.alpha
Normal file
@ -0,0 +1,26 @@
|
||||
(* Type definitions *)
|
||||
type string: 1 -> character
|
||||
type int2int: integer -> integer
|
||||
type string2int: string -> integer
|
||||
(* Function prototypes
|
||||
They use the above type definitions
|
||||
*)
|
||||
function square : int2int
|
||||
function entry : string2int
|
||||
(* Function definition
|
||||
Functions must be declared before they are defined
|
||||
*)
|
||||
square(x) := {
|
||||
return x * x;
|
||||
}
|
||||
(* Function definition
|
||||
entry is the first function called
|
||||
*)
|
||||
entry(arg) := {
|
||||
input = 7;
|
||||
expected = 49;
|
||||
actual := square(input);
|
||||
rseult := expected = actual;
|
||||
return 0;
|
||||
[ integer: input; integer: expected; integer: actual; boolean: result; string: input ]
|
||||
}
|
28
tests/test_real_alpha_file.alpha
Normal file
28
tests/test_real_alpha_file.alpha
Normal file
@ -0,0 +1,28 @@
|
||||
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); (* see types.alpha – reserve returns a value of type address,
|
||||
which can be assigned to array and record variables
|
||||
*)
|
||||
w.x := 5;
|
||||
w.y := 7;
|
||||
result := bar1(w); (* pass w (a rec type value) to bar1 *)
|
||||
result := bar2(5,7); (* implicitly build a rec type value, assign 5 and 7 to fields x and y, but call them r and s *)
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user