libdice/lib/dice_parse.y

63 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2018-02-14 19:31:52 +01:00
%define api.pure full
%define api.prefix {dp}
2018-02-14 19:31:52 +01:00
%parse-param {void *scanner} {dice_t dice}
%lex-param {void *scanner}
2018-02-13 20:27:38 +01:00
%{
#include "dice.h"
extern int dplex(void *lval, void *scanner);
2018-02-13 20:27:38 +01:00
void dperror(void *scanner, dice_t dice, char const *err)
2018-02-13 20:27:38 +01:00
{
dice_set(dice, DICEOPTION_ERROR, err);
2018-02-13 20:27:38 +01:00
}
int dpwrap(void)
2018-02-13 20:27:38 +01:00
{
return 1;
}
%}
%union {
char *str;
int integer;
double number;
}
%token TOK_DICESEP TOK_FUDGE
2018-02-13 20:27:38 +01:00
%token <integer> TOK_INTEGER
%%
dice: TOK_INTEGER TOK_DICESEP TOK_INTEGER
{
dice_set(dice, DICEOPTION_AMOUNT, $1);
dice_set(dice, DICEOPTION_SIDES, $3);
YYACCEPT;
2018-02-13 20:27:38 +01:00
}
| TOK_DICESEP TOK_INTEGER
{
dice_set(dice, DICEOPTION_AMOUNT, 1);
dice_set(dice, DICEOPTION_SIDES, $2);
YYACCEPT;
}
| TOK_DICESEP TOK_FUDGE
{
dice_set(dice, DICEOPTION_AMOUNT, 1L);
dice_set(dice, DICEOPTION_FUDGE, 1L);
YYACCEPT;
}
| TOK_INTEGER TOK_DICESEP TOK_FUDGE
{
dice_set(dice, DICEOPTION_AMOUNT, $1);
dice_set(dice, DICEOPTION_FUDGE, 1L);
YYACCEPT;
2018-02-13 20:27:38 +01:00
}
;