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.
39 lines
781 B
39 lines
781 B
5 years ago
|
%{
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include "expression.h"
|
||
|
#include "parser.tab.h"
|
||
|
|
||
|
%}
|
||
|
|
||
|
%%
|
||
|
|
||
|
"\n" { return WEBDICE_TOKEN_EOL; }
|
||
|
-?[0-9]+ {
|
||
|
int64_t aux;
|
||
|
|
||
|
sscanf(yytext,"%ld",&aux);
|
||
|
yylval.exp.constant.id = WEBDICE_CONST;
|
||
|
yylval.exp.constant.value = aux;
|
||
|
return WEBDICE_TOKEN_CONST;
|
||
|
}
|
||
|
-?[0-9]+d[0-9]+ {
|
||
|
int64_t count,type;
|
||
|
|
||
|
sscanf(yytext,"%ldd%ld",&count,&type);
|
||
|
yylval.exp.roll.id = WEBDICE_ROLL;
|
||
|
yylval.exp.roll.count = count;
|
||
|
yylval.exp.roll.type = type;
|
||
|
return WEBDICE_TOKEN_ROLL;
|
||
|
}
|
||
|
"(" { return WEBDICE_TOKEN_LPAREN; }
|
||
|
")" { return WEBDICE_TOKEN_RPAREN; }
|
||
|
"*" { return WEBDICE_TOKEN_MUL; }
|
||
|
"/" { return WEBDICE_TOKEN_DIV; }
|
||
|
"+" { return WEBDICE_TOKEN_ADD; }
|
||
|
"-" { return WEBDICE_TOKEN_SUB; }
|
||
|
[ \t]+ {}
|
||
|
. { fprintf(stderr,"%s",yytext); return WEBDICE_TOKEN_EOL; }
|
||
|
|
||
|
%%
|