Created
May 9, 2021 03:20
-
-
Save dntf-studio/959e9510e2736b584bb36c27f5d3a91a to your computer and use it in GitHub Desktop.
小数あり四則演算。変数なし。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#include <stdio.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <math.h> | |
double y; | |
%} | |
%union{ | |
int ival; | |
float fval; | |
double dval; | |
} | |
%token LF | |
%token <dval> NUMBER | |
%token PLUS MINUS DIV MULTI | |
%type <dval> list expr input | |
%left '+' '-' | |
%left '*' '/' | |
%% | |
input : /* empty */ | |
| input list | |
; | |
list : expr LF { | |
y = $1; | |
printf("r>%g\n",y); | |
} | |
expr : NUMBER | |
| expr '+' expr {$$ = $1 + $3;} | |
| expr '-' expr {$$ = $1 - $3;} | |
| expr '*' expr {$$ = $1 * $3;} | |
| expr '/' expr {$$ = $1 / $3;} | |
; | |
%% | |
int main(void){ | |
//yyparse(); | |
if(yyparse()){ | |
printf("Err:%s",stderr); | |
return 1; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment