Naming things... how time consuming can this task be?
Anyway, here is a preliminar version of the basic structures for the rules:
struct Condition
{
TokenType cur_token;
TokenType pre_token;
TokenType next_token;
State cur_state;
};
struct Actions
{
std::vector<SingleAction> pre_actions;
std::vector<SingleAction> post_actions;
};
struct Rule // version 1
{
Condition cond;
Actions acts;
};
struct Rule : Condition, Actions // version 2 (I prefer this one)
{
// What else?
};
So far the function name could be something like
matches. Overloading operator == wouldn't be that a good idea.
The function could look something like this:
// kids: don't code like this :P
inline int Condition::matches(const Condition &other)
{
return cur_token == other.cur_token ? 1 + (pre_token == other.pre_token) + (next_token == other.next_token) + (cur_state == other.cur_state) : 0;
}
Quite simple: if the current token is the same, count it and all others that match, else 0.
What if two rules return the same value (there wouldn't be duplicates, just same number of matches)?
If many return values != 0 but the one with biggest return value is unique, that one would be chosen.
Even though, there sould be another evaluation like this one (var == other.var || var == NOTHING || other.var == NOTHING). So, matches must return two values: exact matches and matches with "empty" variables. A struct, vector or pair<> would do that.
Now, the way to decide which one to apply would be (order is quite important when coding this, not here
):
* The one with biggest return value for exact matches.
* If there's more than one with the same value, then the one of those with biggest total matches (those counting "empty" cases).
* If even that way there's more than one with both number of matches the same, what to do?
* If all returned 0 for exact matches, return the one with biggest total matches.
* If there's more than one with the same value, what to do?
* If both exact and total matches are 0, it's just a "NO MATCH". Apply default rule (easy to say, but what's the default rule?).
Feedback anyone?