I've changed my mind and simply added another operator for the case to be able to use regular variables in expressions. So the use is "dice:base+bonus" for the normal case and "dice:base+random&bonus" for the case of spells with a random component.
I hope I got it right this time...
Code:
/* * Input types for the parser state table. */ typedef enum dice_input_e { [COLOR="Red"]DICE_INPUT_AMP,[/COLOR] DICE_INPUT_MINUS, DICE_INPUT_BASE, DICE_INPUT_DICE, DICE_INPUT_BONUS, DICE_INPUT_VAR, DICE_INPUT_DIGIT, DICE_INPUT_UPPER, DICE_INPUT_NULL, DICE_INPUT_MAX } dice_input_t;
Code:
/* Catch specific characters before checking bigger char categories. */ switch (c) { [COLOR="Red"] case '&': return DICE_INPUT_AMP;[/COLOR] case '-': return DICE_INPUT_MINUS; case '+': return DICE_INPUT_BASE; case 'd': return DICE_INPUT_DICE; case 'M': case 'm': return DICE_INPUT_BONUS; case '$': return DICE_INPUT_VAR; case '\0': return DICE_INPUT_NULL; default: break; }
Code:
/* * Get the next state, based on the type of input char. If it's a possible * number or varible name, we'll store the character in the token buffer. */ switch (input_type) { [COLOR="Red"]case DICE_INPUT_AMP:[/COLOR] case DICE_INPUT_BASE: case DICE_INPUT_DICE: case DICE_INPUT_VAR: case DICE_INPUT_NULL: state = dice_parse_state_transition(state, input_type); break; ...
Code:
static unsigned char state_table[DICE_STATE_MAX][DICE_INPUT_MAX] = { /* Input: &-+dm$DU0 */ /*[DICE_STATE_START] = */ /* A */ ".B.EHKB..", /*[DICE_STATE_BASE_DIGIT] = */ /* B */ "..CE..B.C", /*[DICE_STATE_FLUSH_BASE] = */ /* C */ "...EHKD..", /*[DICE_STATE_DICE_DIGIT] = */ /* D */ "...E..D..", /*[DICE_STATE_FLUSH_DICE] = */ /* E */ ".....KF..", /*[DICE_STATE_SIDE_DIGIT] = */ /* F */ "G...H.F.G", /*[DICE_STATE_FLUSH_SIDE] = */ /* G */ "....H....", /*[DICE_STATE_BONUS] = */ /* H */ ".....KI..", /*[DICE_STATE_BONUS_DIGIT] = */ /* I */ "......I.J", /*[DICE_STATE_FLUSH_BONUS] = */ /* J */ ".........", /*[DICE_STATE_VAR] = */ /* K */ ".......L.", /*[DICE_STATE_VAR_CHAR] = */ /* L */ "G.CEH..LM", /*[DICE_STATE_FLUSH_ALL] = */ /* M */ "........." };
Comment