You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

48 lines
1.1 KiB

%{
#include <stdlib.h>
#include "expression.h"
int yylex();
int yyerror(void* scanner, void* lvalp, char* str);
%}
%pure-parser
%lex-param {void *scanner}
%parse-param {void *scanner} {union expression** root}
%union {
union expression* exp;
}
%token WEBDICE_TOKEN_EOL
%token <exp> WEBDICE_TOKEN_CONST
%token <exp> WEBDICE_TOKEN_ROLL
%token WEBDICE_TOKEN_LPAREN
%token WEBDICE_TOKEN_RPAREN
%left WEBDICE_TOKEN_ADD
%left WEBDICE_TOKEN_SUB
%left WEBDICE_TOKEN_MUL
%left WEBDICE_TOKEN_DIV
%type <exp> expression
%start lines
%%
expression: expression WEBDICE_TOKEN_ADD expression { $$ = webdice_add($1,$3); }
| expression WEBDICE_TOKEN_SUB expression { $$ = webdice_sub($1,$3); }
| expression WEBDICE_TOKEN_MUL expression { $$ = webdice_mul($1,$3); }
| expression WEBDICE_TOKEN_DIV expression { $$ = webdice_div($1,$3); }
| WEBDICE_TOKEN_CONST { $$ = $1; }
| WEBDICE_TOKEN_ROLL { $$ = $1; }
| WEBDICE_TOKEN_LPAREN expression WEBDICE_TOKEN_RPAREN { $$ = $2; }
;
lines:
| lines WEBDICE_TOKEN_EOL {}
| lines expression WEBDICE_TOKEN_EOL { (*root) = $2; }
;
%%