From 75ff98e4d65862ff5b36b533b4f6e3ea71ede1d5 Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Sat, 17 Sep 2016 03:22:53 +0000 Subject: cmake build --- chill/src/parse_expr.yy | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 chill/src/parse_expr.yy (limited to 'chill/src/parse_expr.yy') diff --git a/chill/src/parse_expr.yy b/chill/src/parse_expr.yy new file mode 100644 index 0000000..c2943c2 --- /dev/null +++ b/chill/src/parse_expr.yy @@ -0,0 +1,85 @@ +%{ +#include "chill_run_util.hh" +#include "parse_expr.ll.hh" + +extern int yydebug; + +void yyerror(const char*); +int yyparse(simap_vec_t** rel); + +static simap_vec_t* return_rel; // used as the return value for yyparse + +%} + +%union { + int val; + char* str_val; + simap_t* cond_item; + simap_vec_t* cond; +} + +%token NUMBER +%token LEVEL +%token VARIABLE + +%left LE GE EQ '<' '>' +%left '-' '+' '*' '/' + +/*the final output from this language should be an Omega Relation object*/ +%type cond prog +%type expr add_expr mul_expr neg_expr + +%% +prog : cond { return_rel = make_prog($1); } +; + +cond : expr '>' expr { $$ = make_cond_gt($1, $3); } + | expr '<' expr { $$ = make_cond_lt($1, $3); } + | expr GE expr { $$ = make_cond_ge($1, $3); } + | expr LE expr { $$ = make_cond_le($1, $3); } + | expr EQ expr { $$ = make_cond_eq($1, $3); } +; + +expr : add_expr { $$ = $1; } +; + +add_expr : add_expr '+' mul_expr { $$ = make_cond_item_add($1,$3); } + | add_expr '-' mul_expr { $$ = make_cond_item_sub($1,$3); } + | mul_expr { $$ = $1; } +; + +mul_expr : mul_expr '*' neg_expr { $$ = make_cond_item_mul($1,$3); } + | neg_expr { $$ = $1; } +; + +neg_expr : '-' neg_expr { $$ = make_cond_item_neg($2); } + | '(' expr ')' { $$ = $2; } + | NUMBER { $$ = make_cond_item_number($1); } + | LEVEL { $$ = make_cond_item_level($1); } + | VARIABLE { $$ = make_cond_item_variable($1); } +; +%% + +void yyerror(const char* msg) { + fprintf(stderr, "Parse error: %s", msg); +} + +simap_vec_t* parse_relation_vector(const char* expr) { + yydebug=0; + YY_BUFFER_STATE state; + + //if(yylex_init()) { + // TODO: error out or something + //} + + state = yy_scan_string(expr); + + if(yyparse()) { + // TODO: error out or something + } + + yy_delete_buffer(state); + yylex_destroy(); + return return_rel; +} + -- cgit v1.2.3-70-g09d2