From: Lukáš Jiřiště Date: Fri, 18 Sep 2026 13:13:07 +0000 (+0200) Subject: Create initial symbols for parsing X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=refs%2Fheads%2Ftrunk;p=SetSCAD.git Create initial symbols for parsing --- diff --git a/inc/grammar.h b/inc/grammar.h new file mode 100644 index 0000000..8c4bbc5 --- /dev/null +++ b/inc/grammar.h @@ -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 index 0000000..c51b753 --- /dev/null +++ b/src/parse_tree.c @@ -0,0 +1,40 @@ +#include "grammar.h" +#include +#include +#include + +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)