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.
 
 
 
 
 

60 lines
1.2 KiB

#include <string.h>
#include <math.h>
#include "expression.h"
#include "parser.tab.h"
#include "lex.yy.h"
void console_print (const char* str){
fprintf(stderr,"%s\n",str);
}
void output_print (const char* str){
printf("%s\n",str);
}
int yyerror(void* scanner, void* lvalp, char* str){
console_print(str);
return 0;
}
void webdice(char* str){
union expression* root;
struct expression_result result;
int length;
char* out_block;
console_print("A");
yyscan_t scanner;
console_print("B");
yylex_init(&scanner);
console_print("C");
yy_scan_string (str, scanner);
console_print("D");
if(yyparse((void*) scanner, &root) == 0 && root != NULL){
result = resolve(root);
length = strlen(result.text) + 4 * ceill(log10l(result.max)) + 100;
out_block = (char*) malloc(length * sizeof(char));
sprintf(out_block,"<p>%s = <span title=\"min: %Lf, expected: %Lf, max: %Lf\">%Lf</span></p>", result.text, result.min, result.expected, result.max, result.actual);
output_print(out_block);
free(out_block);
}else{
output_print("<p>Error!</p>");
}
yylex_destroy(scanner);
}
int main(){
#ifdef YYDEBUG
yydebug = 1;
#endif
webdice("1d4\n");
webdice("cenas\n");
webdice("5\n");
return 0;
}