]> www.ljiriste.work Git - SetSCAD.git/commitdiff
Create initial symbols for parsing trunk
authorLukáš Jiřiště <redacted>
Fri, 18 Sep 2026 13:13:07 +0000 (15:13 +0200)
committerLukáš Jiřiště <redacted>
Fri, 18 Sep 2026 13:13:07 +0000 (15:13 +0200)
inc/grammar.h [new file with mode: 0644]
src/parse_tree.c [new file with mode: 0644]

diff --git a/inc/grammar.h b/inc/grammar.h
new file mode 100644 (file)
index 0000000..8c4bbc5
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef GRAMMAR_H
+# define GRAMMAR_H
+
+# include "libft.h"
+
+// These strings should be regarded as constant
+// They are generated by xxd hence this type is forced
+
+extern unsigned char   grammar[];
+extern unsigned int            grammar_len;
+
+extern unsigned char   parsing_table[];
+extern unsigned int            parsing_table_len;
+
+typedef enum e_single_char_terminal
+{
+       RIGHT_SQUARE
+       LEFT_SQUARE
+       RIGHT_BRACKET
+       LEFT_BRACKET
+       RIGHT_CURLY
+       LEFT_CURLY
+       DIVIDE
+       TIMES
+       MINUS
+       PLUS
+       GREATER_THEN
+       LESS_THEN
+       OR
+       AND
+       Z
+       Y
+       X
+       N
+       U
+       BACKSLASH
+       EQUAL
+       COMMA
+       VERTICAL_BAR
+       SEMICOLON
+       DOT
+
+       single_char_terminal_count
+}      t_single_char_terminal;
+
+typedef enum e_keyword
+{
+       EXP = single_char_terminal_count,
+       MIRROR
+       TRANSLATE
+       ROTATE
+       FROM
+       LOAD
+       IN
+
+       keyword_count
+}      t_keyword;
+
+typedef enum e_other_terminals
+{
+       STRING = keyword_count,
+       INT,
+
+       terminal_count
+}      t_other_terminals;
+
+t_parse_tree_node      *parse(const char *file);
+
+#endif //GRAMMAR_H
diff --git a/src/parse_tree.c b/src/parse_tree.c
new file mode 100644 (file)
index 0000000..c51b753
--- /dev/null
@@ -0,0 +1,40 @@
+#include "grammar.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+const char     *g_keyword_strings[keyword_count] = {
+       [MINUS] = "-",
+       [DOT] = ".",
+       [COMMA] = ",",
+       [TIMES] = "*",
+       [PLUS] = "+",
+       [RIGHT_PARA] = ")",
+       [LEFT_PARA] = "(",
+       [EXP] = "e",
+       [FROM] = "FROM",
+       [ATOM] = "ATOM",
+       [N_OUT_OF_K] = "NOOK",
+       [SYSTEM] = "SYSTEM",
+       [INSTANTIATE] = "INST",
+};
+
+const char     *g_token_strings[terminal_count] = {
+       [EXP] = "EXP",
+       [DOT] = "DOT",
+       [FROM] = "FROM",
+       [ATOM] = "ATOM",
+       [COMMA] = "COMMA",
+       [N_OUT_OF_K] = "N_OUT_OF_K",
+       [TIMES] = "TIMES",
+       [PLUS] = "PLUS",
+       [RIGHT_PARA] = "RIGHT_PARA",
+       [LEFT_PARA] = "LEFT_PARA",
+       [SYSTEM] = "SYSTEM",
+       [INSTANTIATE] = "INSTANTIATE",
+       [WORD] = "WORD",
+       [INT] = "INT",
+       [MINUS] = "MINUS",
+};
+
+static int     is_single_char_terminal(char c)