libdice/lib/dice_parse.y
Florian Stinglmayr 92b909158c add tiny expression library and make it a dice expression parser
Use tiny expression library (from Github) and expand it to provide
dice expression parsing. This needs more testing obviously.
2018-02-17 10:52:46 +01:00

48 lines
903 B
Plaintext

%define api.pure full
%parse-param {void *scanner} {dice_t dice}
%lex-param {void *scanner}
%{
#include "dice.h"
extern int yylex(void *lval, void *scanner);
void yyerror(void *scanner, dice_t dice, char const *err)
{
dice_set(dice, DICEOPTION_ERROR, err);
}
int yywrap(void)
{
return 1;
}
%}
%union {
char *str;
int integer;
double number;
}
%token TOK_DICESEP
%token <integer> TOK_INTEGER
%%
dice: TOK_INTEGER TOK_DICESEP TOK_INTEGER
{
dice_set(dice, DICEOPTION_AMOUNT, $1);
dice_set(dice, DICEOPTION_SIDES, $3);
YYACCEPT;
}
| TOK_DICESEP TOK_INTEGER
{
dice_set(dice, DICEOPTION_AMOUNT, 1);
dice_set(dice, DICEOPTION_SIDES, $2);
YYACCEPT;
}
;