commit ba3c25934e3a3db84382233671ff6ff57487a267
parent 9c83ac4e12d2d41c863281ada57c3c39c81b4644
Author: William Casarin <jb55@jb55.com>
Date: Fri, 29 Sep 2017 22:58:42 -0700
retab
Diffstat:
M | parser.y | | | 30 | +++++++++++++++--------------- |
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/parser.y b/parser.y
@@ -14,7 +14,7 @@ void yyerror(const char* s);
%}
%union {
- mpq_t rval;
+ mpq_t rval;
}
%token<rval> T_RATIO
@@ -34,30 +34,30 @@ calc:
;
line: T_NEWLINE
- | expr T_NEWLINE { mpq_out_str(stdout, 10, $1); printf("\n"); }
+ | expr T_NEWLINE { mpq_out_str(stdout, 10, $1); printf("\n"); }
;
-expr: T_RATIO { mpq_set($$, $1); }
- | expr T_PLUS expr { mpq_add($$, $1, $3); }
- | expr T_MINUS expr { mpq_sub($$, $1, $3); }
- | expr T_MULTIPLY expr { mpq_mul($$, $1, $3); }
- | expr T_DIVIDE expr { mpq_div($$, $1, $3); }
- | T_LEFT expr T_RIGHT { mpq_set($$, $2); }
+expr: T_RATIOw { mpq_set($$, $1); }
+ | expr T_PLUS expr { mpq_add($$, $1, $3); }
+ | expr T_MINUS expr { mpq_sub($$, $1, $3); }
+ | expr T_MULTIPLY expr { mpq_mul($$, $1, $3); }
+ | expr T_DIVIDE expr { mpq_div($$, $1, $3); }
+ | T_LEFT expr T_RIGHT { mpq_set($$, $2); }
;
%%
int main() {
- yyin = stdin;
+ yyin = stdin;
- do {
- yyparse();
- } while(!feof(yyin));
+ do {
+ yyparse();
+ } while(!feof(yyin));
- return 0;
+ return 0;
}
void yyerror(const char* s) {
- fprintf(stderr, "Parse error: %s\n", s);
- exit(1);
+ fprintf(stderr, "Parse error: %s\n", s);
+ exit(1);
}