From 99e2e923d0c77b02f3fb4ff648ea916954868606 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- works/life/compile-principle-experiment/2/hoc.y | 106 --------------------- works/life/compile-principle-experiment/2/makefile | 5 - 2 files changed, 111 deletions(-) delete mode 100644 works/life/compile-principle-experiment/2/hoc.y delete mode 100644 works/life/compile-principle-experiment/2/makefile (limited to 'works/life/compile-principle-experiment/2') diff --git a/works/life/compile-principle-experiment/2/hoc.y b/works/life/compile-principle-experiment/2/hoc.y deleted file mode 100644 index 14500bb..0000000 --- a/works/life/compile-principle-experiment/2/hoc.y +++ /dev/null @@ -1,106 +0,0 @@ -%{ -#include -#include -#include - -int yylex(); -int yyerror(const char * s); -void execerror(const char* s, const char* t); -void warning(const char* s, const char* t); - -double mem[26]; /* memory for variables 'a'..'z' */ -%} - -%union { /* stack type */ - double val; /* actual value */ - int index; /* index into mem[] */ -} -%token NUMBER -%token VAR -%type expr -%right '=' -%left '+' '-' -%left '*' '/' -%left UNARYMINUS -%% -list: /* nothing */ - | list '\n' - | list expr '\n' { printf("\t%.8g\n", $2); } - | list error '\n' { yyerrok; } - ; -expr: NUMBER - | VAR { $$ = mem[$1]; } - | VAR '=' expr { $$ = mem[$1] = $3; } - | expr '+' expr { $$ = $1 + $3; } - | expr '-' expr { $$ = $1 - $3; } - | expr '*' expr { $$ = $1 * $3; } - | expr '/' expr { - if ($3 == 0.0) - execerror("division by zero", ""); - $$ = $1 / $3; } - | '(' expr ')' { $$ = $2; } - | '-' expr %prec UNARYMINUS { $$ = -$2; } - ; -%% - /* end of grammar */ - -int lineno = 1; -#include -#include -jmp_buf begin; - -void fpecatch(int s); - -int main(int argc, char** argv) -{ - (void)setjmp(begin); - signal(SIGFPE, fpecatch); - yyparse(); -} - -int yylex() -{ - int c; - - while ((c=getchar()) == ' ' || c == '\t') - ; - if (c == EOF) - return 0; - if (c == '.' || isdigit(c)) { /* number */ - ungetc(c, stdin); - scanf("%lf", &yylval.val); - return NUMBER; - } - if (islower(c)) { - yylval.index = c - 'a'; /* ASCII only */ - return VAR; - } - if (c == '\n') - lineno++; - return c; -} - -int yyerror(const char *s) -{ - warning(s, (char *)0); - return 0; -} - -void execerror(const char* s, const char* t) -{ - warning(s, t); - longjmp(begin, 0); -} - -void fpecatch(int s) -{ - execerror("floating point exception", (char *) 0); -} - -void warning(const char* s, const char* t) -{ - fprintf(stderr, "%s", s); - if (t && *t) - fprintf(stderr, " %s", t); - fprintf(stderr, " near line %d\n", lineno); -} diff --git a/works/life/compile-principle-experiment/2/makefile b/works/life/compile-principle-experiment/2/makefile deleted file mode 100644 index 65bcca2..0000000 --- a/works/life/compile-principle-experiment/2/makefile +++ /dev/null @@ -1,5 +0,0 @@ -hoc: hoc.c - cc hoc.c -o hoc - -hoc.c: hoc.y - bison hoc.y -o hoc.c -- cgit v1.2.3