-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update main.c for manual testing feedback
- Loading branch information
Showing
5 changed files
with
105 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
#!/bin/bash | ||
|
||
if [[ $1 == 'test' ]]; then | ||
gcc -g ./test/*.c ./lexer/*.c ./parser/*.c -o croc | ||
echo 'built test.' | ||
gcc -g ./test/*.c ./lexer/*.c ./parser/*.c -o croc | ||
echo 'built test.' | ||
elif [[ $1 == 'debug' ]]; then | ||
gcc -g ./debug.c ./lexer/*.c ./parser/*.c -o croc | ||
echo 'built debug.' | ||
else | ||
gcc -g ./main.c ./lexer/*.c ./parser/*.c -o croc | ||
echo 'built main.' | ||
gcc -g ./main.c ./lexer/*.c ./parser/*.c -o croc | ||
echo 'built main.' | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "./lexer/lexer.h" | ||
#include "./lexer/printer.h" | ||
#include "./lexer/types.h" | ||
#include "./parser/parser.h" | ||
#include "./parser/syntax_error.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
// ANSI escape codes | ||
#define RESET "\033[0m" | ||
#define RED "\033[31m" | ||
#define GREEN "\033[32m" | ||
|
||
int main(int argc, char *argv[]) { | ||
/*if (argc != 2) {*/ | ||
/* fprintf(stderr, "Error. Usage: croc <code>\n");*/ | ||
/* return EXIT_FAILURE;*/ | ||
/*}*/ | ||
|
||
FILE *fd; | ||
int lineCount = 1; | ||
|
||
fd = fopen("./doc/examples/code.proc", "r"); | ||
if (fd == NULL) { | ||
fprintf(stderr, "Error opening file\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// lexing! | ||
while (true) { | ||
struct Token token = lexerGetNextChar(fd, &lineCount); | ||
if (token.category == END_OF_FILE) { | ||
fclose(fd); | ||
break; | ||
} | ||
// handle malformed manually to | ||
// keep the printing callback simple. | ||
if (token.category == MALFORMED_TOKEN) { | ||
fprintf(stderr, RED "ERROR: MALFORMED TOKEN %s ON LINE %d\n" RESET, token.lexeme, | ||
lineCount); | ||
exit(EXIT_FAILURE); | ||
} | ||
printToken(token); | ||
printf("\n"); | ||
} | ||
|
||
printf(GREEN "Lexing successful!" RESET "\n"); | ||
|
||
int *lc; | ||
int line = 1; | ||
lc = &line; | ||
|
||
fd = fopen("./doc/examples/code.proc", "r"); | ||
if (fd == NULL) { | ||
fprintf(stderr, "Error opening file\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// for integration tests, prog itself needs a previously initialized parser | ||
// with a token too | ||
struct Token token = lexerGetNextChar(fd, lc); | ||
struct Parser parser = { | ||
.fd = fd, .lineCount = lc, .token = token}; | ||
|
||
enum SYNTAX_ERROR error = prog(&parser); | ||
if (error != NO_ERROR) { | ||
printSyntaxError(error, lc); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
printf(GREEN "Parsing successful!" RESET "\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
var a = 80 // something | ||
if (a == 80) // something else | ||
for (int i = 0) 'a' '\n' banana '\0' | ||
4.4 | ||
int a[2] = {1, 2} | ||
def |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters