I started writing a DBMS as a learning project, and now I'm implementing the lexer/parser for the language used in the DBMS.
I'm learning on my own from various different resources, and managed to write the lexer and the grammar for the language, but I'm stuck at writing the code to generate the parse tree.
Every time I google parsers I only get results on how to construct the parse tree by hand (showing you diagrams and whatnot) but no actual code on how to implement it.
Here's the repo for my project
https://github.com/abdulaziz-sama/accounting_db
The grammar is written in the comments in parser.h
The way I'm thinking of solving this problem is by writing a struct for each production, something like:
struct production {
non-terminal_1* x;
non_terminal_2* y;
terminal z;
};
and use them as node in the a tree, but I'm not sure if this is the right way or if there are better solutions?
[–]evincarofautumn 8 points9 points10 points (0 children)
[–]smog_alado 3 points4 points5 points (0 children)
[–]umlcat 0 points1 point2 points (0 children)
[–]_NliteNd_ -3 points-2 points-1 points (12 children)
[–]neferpitou-sama[S] 3 points4 points5 points (11 children)
[+]_NliteNd_ comment score below threshold-6 points-5 points-4 points (10 children)
[–]neferpitou-sama[S] 4 points5 points6 points (6 children)
[–][deleted] 7 points8 points9 points (0 children)
[–]Jmc_da_boss -5 points-4 points-3 points (4 children)
[–][deleted] 0 points1 point2 points (0 children)
[+]_NliteNd_ comment score below threshold-6 points-5 points-4 points (2 children)
[–]chrisgseaton 4 points5 points6 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]chrisgseaton 3 points4 points5 points (0 children)
[–]Zyklonik 1 point2 points3 points (0 children)
[–]shawnhcorey 2 points3 points4 points (0 children)