Resolved issue of including path to .alpha file and tested with multiple directories

This commit is contained in:
Annie
2025-02-13 01:44:19 -05:00
parent e91eb1815b
commit 228f66a385
3 changed files with 54 additions and 6 deletions

View File

@ -21,17 +21,12 @@ int main(int argc, char *argv[]) {
arg = TOK_ARG; //it is a -tok arg with a valid alpha file at argv[2] arg = TOK_ARG; //it is a -tok arg with a valid alpha file at argv[2]
yyin = fopen(argv[2], "r"); yyin = fopen(argv[2], "r");
} }
token = yylex(); while (0 != (token = yylex())) {
fprintf(stderr, "made it here");
while (token != 0) {
if (arg == TOK_ARG) { if (arg == TOK_ARG) {
fprintf(output, "%d %d %3d \"%s\"\n", line_number, column_number, token, yytext); fprintf(output, "%d %d %3d \"%s\"\n", line_number, column_number, token, yytext);
} }
token = yylex();
fprintf(stderr, "made it past yylex");
} }
fprintf(stderr, "returned 0\n");
return 0; return 0;
} }
@ -43,6 +38,19 @@ char *is_tok(int argc, char *argv[]) {
if (is_alpha_file(input_prog, file_len) != 0) { if (is_alpha_file(input_prog, file_len) != 0) {
return INVALID_ARG; return INVALID_ARG;
} }
int ignore_path = 0;
int count_since_slash = 0;
for (int i = 0; i < file_len; i++) {
count_since_slash++;
if (input_prog[i] == '/') {
ignore_path += count_since_slash;
count_since_slash = 0;
}
}
file_len -= ignore_path;
input_prog += ignore_path;
char* FILE_tok = calloc(sizeof(char), file_len - ALPHA_OFFSET + TOK_LEN); char* FILE_tok = calloc(sizeof(char), file_len - ALPHA_OFFSET + TOK_LEN);
strncpy(FILE_tok, input_prog, file_len - ALPHA_OFFSET); //copy name of prog before .alpha strncpy(FILE_tok, input_prog, file_len - ALPHA_OFFSET); //copy name of prog before .alpha
strcpy(FILE_tok + sizeof(char) * (file_len - ALPHA_OFFSET), ".tok"); //add .tok to end of file name strcpy(FILE_tok + sizeof(char) * (file_len - ALPHA_OFFSET), ".tok"); //add .tok to end of file name

View File

@ -0,0 +1,23 @@
This is a test
9combined 7okens
12345
893247892
combined'DueToUnknownChar _validtoken __validtoken1 _valid_token2 validToken3_
true false
null while !wrong if when
else type function
return external as
string _NOte_that_was_not_reserved
([)]{}:;,->"\
+-*/%
<=
:=
"This is not a valid
String"
"This is a valid String"
!|
..
(* this is a comment *)
(*Not a comment
$^&
>

View File

@ -0,0 +1,17 @@
+
-
*
/
\
%
<
>
=
:=
=:
:
=
!
&
|
.