libdice/lib/dice_parse.y

43 lines
798 B
Plaintext
Raw Normal View History

2018-02-14 19:31:52 +01:00
%define api.pure full
%parse-param {void *scanner} {dice_t dice}
%lex-param {void *scanner}
2018-02-13 20:27:38 +01:00
%{
#include "dice.h"
2018-02-14 19:31:52 +01:00
extern int yylex(void *lval, void *scanner);
2018-02-13 20:27:38 +01:00
2018-02-14 19:31:52 +01:00
void yyerror(void *scanner, dice_t dice, char const *err)
2018-02-13 20:27:38 +01:00
{
}
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);
}
| TOK_DICESEP TOK_INTEGER
{
dice_set(dice, DICEOPTION_AMOUNT, 1);
dice_set(dice, DICEOPTION_SIDES, $2);
}
;