start working on parser

This commit is contained in:
2025-05-30 22:23:46 +01:00
parent ec894d4357
commit d18ff96f8f
8 changed files with 51 additions and 30 deletions

1
.gitignore vendored
View File

@@ -50,6 +50,7 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf
vcpkg_installed/
bin

View File

@@ -2,14 +2,14 @@
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64"
"intelliSenseMode": "linux-clang-x64",
"includePath": [
"${workspaceFolder}/**"
],
"defines": []
}
],
"version": 4

View File

@@ -14,21 +14,9 @@ int yywrap(void *) {
%%
\"((\\([\"\\\/bfnrt]|u[0-9a-fA-F]{4}))|[^\\\"\n])*\" {
return TOKEN_STRING;
}
\'((\\([\'\\\/bfnrt]|u[0-9a-fA-F]{4}))|[^\\\'\n])*\' {
return TOKEN_STRING;
}
((([0-9]+(\.[0-9]+)?)|(\.[0-9]+))(e((\-|\+)?([0-9]+(\.[0-9]+)?)))?) {
return TOKEN_NUMBER;
}
([0-9]+\/[0-9]+) {
return TOKEN_FRACTION;
}
"." { return TOKEN_DOT; }
"," {return TOKEN_COMMA; }
":" {return TOKEN_COLON; }
"not"[ \t]+"in" { return TOKEN_NOT_IN; }
"&&" { return TOKEN_AND; }
@@ -79,9 +67,21 @@ int yywrap(void *) {
[a-zA-Z_][a-zA-Z0-9_]* { return TOKEN_IDENTIFIER; }
"." { return TOKEN_DOT; }
"," {return TOKEN_COMMA; }
":" {return TOKEN_COLON; }
\"((\\([\"\\\/bfnrt]|u[0-9a-fA-F]{4}))|[^\\\"\n])*\" {
return TOKEN_STRING;
}
\'((\\([\'\\\/bfnrt]|u[0-9a-fA-F]{4}))|[^\\\'\n])*\' {
return TOKEN_STRING;
}
((([0-9]+(\.[0-9]+)?)|(\.[0-9]+))(e((\-|\+)?([0-9]+(\.[0-9]+)?)))?) {
return TOKEN_NUMBER;
}
([0-9]+\/[0-9]+) {
return TOKEN_FRACTION;
}
\n { return TOKEN_NEW_LINE; }
@@ -95,7 +95,7 @@ int yywrap(void *) {
. {
GET_STATE
fprintf(stderr, "%s:%u:%u: unexpected character '%s'\n", state->path, yylineno+1, COLUMN_NO+1, yytext);
fprintf(stderr, "%s:%u:%u error: unexpected character '%s'\n", state->path, yylineno, COLUMN_NO+1, yytext);
exit(1);
}
%%

View File

@@ -15,7 +15,7 @@ void lexer(LexerState state) {
Token * token_struct = create_token(
token,
yyget_lineno(scanner),
state.current_column,
state.current_column+1,
yyget_text(scanner)
);
darray_push(state.tokens, token_struct);

View File

@@ -7,9 +7,9 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdio.h>
int main() {
ar_memory_init();
const char * path = "test.ar";
DArray tokens;
@@ -33,7 +33,5 @@ int main() {
darray_free(&parsed,free_parsed_value);
ar_memory_init();
return 0;
}

View File

@@ -16,8 +16,11 @@ ParsedValue *parse_token(DArray *tokens, size_t *index) {
case TOKEN_NEW_LINE:
(*index)++;
return NULL;
case TOKEN_INDENT:
fprintf(stderr, "error: \n");
exit(EXIT_FAILURE);
default:
fprintf(stderr, "Panic: %s\n", "unreachable");
fprintf(stderr, "Panic: unreachable\n");
exit(EXIT_FAILURE);
}
}
@@ -40,6 +43,5 @@ void free_parsed_value(void *ptr) {
case AST_STRING:
free(tagged->data);
break;
// Add cases if needed
}
}

14
vcpkg-configuration.json Normal file
View File

@@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "a9eee3b18df395dbb8be71a31bd78ea441056e42",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}

6
vcpkg.json Normal file
View File

@@ -0,0 +1,6 @@
{
"dependencies": [
"bdwgc",
"json-c"
]
}