Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i can't take this anymore (parser backup) #5

Merged
merged 56 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
434f81c
backup: moments before disaster
wilyJ80 Dec 1, 2024
7b2e556
feat: start defining error enums
wilyJ80 Dec 1, 2024
fef3816
test: start parser test setup
wilyJ80 Dec 1, 2024
6cb7385
test: successfully setup tests for opRel grammar rule
wilyJ80 Dec 1, 2024
f63b584
test: setup tests for currently implemented fator parsing rules
wilyJ80 Dec 1, 2024
4a11df4
feat: fator simple array
wilyJ80 Dec 2, 2024
d27b128
test: fix fator neg test
wilyJ80 Dec 2, 2024
b0fce7e
test: fix fator neg tests
wilyJ80 Dec 2, 2024
c83efbf
test: start programming error messages
wilyJ80 Dec 2, 2024
20db7ff
test: setup error messages, todo: finish function
wilyJ80 Dec 2, 2024
e2b9ae3
test: finish error printing function
wilyJ80 Dec 2, 2024
d32e2a3
test: fator 1d array, no expr
wilyJ80 Dec 2, 2024
2feade3
test: remake error printing function
wilyJ80 Dec 2, 2024
75572a2
doc: add new language spec
wilyJ80 Dec 3, 2024
cf551fc
test: todo: finish close bracket test
wilyJ80 Dec 3, 2024
b887c24
test: complete simple array tests
wilyJ80 Dec 3, 2024
3bad29d
refactor: remove unused token parameter
wilyJ80 Dec 3, 2024
1da5431
test: single, accept overconsuming tokens?
wilyJ80 Dec 3, 2024
cb8cee1
doc: update README.md
wilyJ80 Dec 3, 2024
80c00d6
Parser object added for state persistence across calls (#4)
wilyJ80 Dec 4, 2024
9b89e42
test: start integration tests
wilyJ80 Dec 4, 2024
6401996
bug: token sign code is not persisted (garbage)
wilyJ80 Dec 4, 2024
1edc486
refactor: pass parser object by reference
wilyJ80 Dec 4, 2024
7557997
feat: major union overwriting bug corrected
wilyJ80 Dec 4, 2024
f9ec09f
test: finish invalid type test case
wilyJ80 Dec 4, 2024
45b1e7e
test: finish no var id integration test case
wilyJ80 Dec 4, 2024
c011648
test: finish invalid array subscript declaration integration test
wilyJ80 Dec 4, 2024
ffb1380
test: finish invalid array declaration bracket close on array dec
wilyJ80 Dec 4, 2024
ecd8956
test: add invalid variable initialization test
wilyJ80 Dec 5, 2024
72a4d62
test: add multiple variable declaration
wilyJ80 Dec 5, 2024
f49cb55
test: todo: multidimensional array declaration
wilyJ80 Dec 5, 2024
cd7c132
test: multidimensional array declaration error
wilyJ80 Dec 5, 2024
b9480f1
test: invalid array openings
wilyJ80 Dec 5, 2024
1500a59
test: invalid type inside array initialization
wilyJ80 Dec 5, 2024
6441cbe
test: finish bad array initialization case
wilyJ80 Dec 5, 2024
4e2db81
test: no function id in declaration
wilyJ80 Dec 5, 2024
2251561
test: function prototype opening failure
wilyJ80 Dec 5, 2024
2b7eefe
test: invalid function prototype param type
wilyJ80 Dec 5, 2024
657984f
test: add no id case for function prototype param
wilyJ80 Dec 5, 2024
a74f3e1
test: roll back wrong error
wilyJ80 Dec 6, 2024
e254d52
test: add no valid token after type of function proto
wilyJ80 Dec 6, 2024
8d6f9ca
test: finish unclosed proto array bracket param
wilyJ80 Dec 6, 2024
fea6f5d
test: 2d array continuation
wilyJ80 Dec 6, 2024
6ee91b0
test: 2d array closing on proto param
wilyJ80 Dec 6, 2024
30c252d
test: invalid array dimension in prot param
wilyJ80 Dec 6, 2024
653813f
doc: update README.md
wilyJ80 Dec 6, 2024
e85c8db
todo: replicate declVar logic with declProc
wilyJ80 Dec 6, 2024
72dbcd0
seconds before disaster
wilyJ80 Dec 6, 2024
0f691b9
refactor: prot function, todo make it lmao
wilyJ80 Dec 6, 2024
363a0df
refactor: prot param function for recursion
wilyJ80 Dec 6, 2024
a9ecb2b
test: colorized output for better feedback
wilyJ80 Dec 6, 2024
1f18317
test: remove color, todo: recursive prot param
wilyJ80 Dec 6, 2024
7f9fc0a
test: finish recursive proto param test
wilyJ80 Dec 6, 2024
447b6c6
feat: update main for manual testing (i feel lost)
wilyJ80 Dec 8, 2024
666a39c
feat: update main.c for manual testing feedback
wilyJ80 Dec 8, 2024
1313a0f
fix: incorrect def bool check that broke tests
wilyJ80 Dec 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@

# problemas

- [ ] Output colorido em testes
- [ ] Todo ID deve ser checado pelo parser se é reservado?
- [ ] Refactor indispensável no parser: remover erros que não serão usados
- [ ] Refatorar testes: setup e teardown
- [ ] Remover enums erros desnecessarias do parser
- [X] Objeto parser com seu proprio estado (token, file, line)
- [ ] Contador de linha esta funcionando no analisador sintatico?
- [ ] Parser testes unitarios + integracao
- [ ] Adicionar especificacao da linguagem `proc` e manter atualizada
- [ ] Refactor: remover transition.h e transition.c
- [ ] Refactor: organizar melhor as enums...
Expand Down
11 changes: 7 additions & 4 deletions build.sh
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 -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 -o croc
echo 'built main.'
gcc -g ./main.c ./lexer/*.c ./parser/*.c -o croc
echo 'built main.'
fi
73 changes: 73 additions & 0 deletions debug.c
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");
}
6 changes: 1 addition & 5 deletions doc/examples/code.proc
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}
prot a -
Loading
Loading