When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
are you trying to generate parser source code from a grammar?
Yes
not sure why productions would be a double-pointer and why keywords need to be separated from terminals
keywords are really just terminals
For symbol table
Need to populate it with keywords at the beginning
So will need grammar for that
productions is an array of struct production
Anything else seems wrong?
it looks like an array of pointers to productions
why though
Keeping the productions themselves will be heavy right?
For passign around the grammar
that's why
but the grammar is just storing the pointer
why store a pointer to an array of pointers
and I would imagine that the grammar is passed around by pointer anyways
yes
it stores too much as that you can cheaply copy it around
so may as well put as much directly into the grammar as possible
unsigned int TERMINALS_BEGIN;
unsigned int TERMINALS_END;
unsigned int NON_TERMINALS_BEGIN;
unsigned int NON_TERMINALS_END;
is this bad?
I don't get why these are fully capitalized
constant
then why isn't it const
Because we have to set it later
after reading from file
The number of terminals and non terminals
what do you think?
typedef struct grammar {
production productions[MAX_PRODUCTIONS];
unsigned int n_terminals;
unsigned int n_productions;
unsigned int n_non_terminals;
char *terminal_to_string[MAX_TERMINALS];
char *non_terminal_to_string[MAX_NON_TERMINALS];
char *keywords[MAX_KEYWORDS];
int terminals_begin;
int terminals_end;
int non_terminals_begin;
int non_terminals_end;
hashmap string_to_terminal_map;
hashmap string_to_non_terminal_map;
hashmap first_sets_map;
hashmap follow_sets_map;
} grammar;
if you're going to pass around the grammar by pointer and you kinda have to do that, just do this
unless you want all of these arrays to be unrestricted in size
but then honestly, just don't use C for it
But MAX_PRODUCTIONS aint known
you can set a large limit on it
it really doesn't matter as long as you don't put it onto the stack, but dynamically allocate grammar
whether the arrays should be directly in the struct is debateable, but the hashmaps are probably just storing a pointer and a size
so there's likely no reason to point to them
all my hashmap functions require a pointer to the hashmap
instead of the hashmap itself
@cloud oak
yeah but you don't have to store a pointer
you can just create a pointer to the value you store whenever calling these functions
Create hashmap also returns pointer to hashmap
Then I will have to dereference create hashmap?
The code would be bad
so you can't even create a hashmap that's not heap-allocated? okay weird, maybe because it stores a FAM
in that case it would make sense to keep a pointer I suppose
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.
What's a FAM?
flexible array member
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.