diff options
Diffstat (limited to 'works/life/compile-principle-experiment')
-rw-r--r-- | works/life/compile-principle-experiment/1/hoc.y | 65 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/1/makefile | 5 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/2/hoc.y | 106 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/2/makefile | 5 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/3/lex.l | 17 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/3/main.c | 107 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/3/main.h | 25 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/3/makefile | 22 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/3/syn.y | 42 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/4/lex.l | 20 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/4/main.c | 279 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/4/main.h | 41 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/4/makefile | 22 | ||||
-rw-r--r-- | works/life/compile-principle-experiment/4/syn.y | 39 |
14 files changed, 0 insertions, 795 deletions
diff --git a/works/life/compile-principle-experiment/1/hoc.y b/works/life/compile-principle-experiment/1/hoc.y deleted file mode 100644 index c4452ad..0000000 --- a/works/life/compile-principle-experiment/1/hoc.y +++ /dev/null @@ -1,65 +0,0 @@ -%{ -#define YYSTYPE double /* data type of yacc stack */ -#include <stdio.h> -#include <ctype.h> -#include <math.h> - -int yylex(); -int yyerror(const char * s); -%} -%token NUMBER -%left '+' '-' /* left associative, same precedence */ -%left '*' '/' '%' /* left assoc., higher precedence */ -%left UNARYMINUS -%% -list: /* nothing */ - | list '\n' - | list expr '\n' { printf("%lf\n", $2); } - ; -expr: NUMBER { $$ = $1; } - | expr '+' expr { $$ = $1 + $3; } - | expr '-' expr { $$ = $1 - $3; } - | expr '*' expr { $$ = $1 * $3; } - | expr '/' expr { $$ = $1 / $3; } - | expr '%' expr { $$ = fmod($1, $3); } - | '-' expr %prec UNARYMINUS { $$ = -$2; } - | '(' expr ')' { $$ = $2; } - ; -%% - -int lineno = 1; - -int main(int argc, char** argv) -{ - yyparse(); - return 0; -} - -int yylex() -{ - int c; - - do { - c = getchar(); - } while (c == ' ' || c == '\t'); - - if (c == EOF) - return 0; - - if (c == '.' || isdigit(c)) { - ungetc(c, stdin); - scanf("%lf", &yylval); - return NUMBER; - } - - if (c == '\n') - lineno++; - - return c; -} - -int yyerror(const char* s) -{ - fprintf(stderr, "Error occured near line %d\n", lineno); - return 0; -} diff --git a/works/life/compile-principle-experiment/1/makefile b/works/life/compile-principle-experiment/1/makefile deleted file mode 100644 index 65bcca2..0000000 --- a/works/life/compile-principle-experiment/1/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 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 <stdio.h> -#include <ctype.h> -#include <math.h> - -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 <val> NUMBER -%token <index> VAR -%type <val> 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 <signal.h> -#include <setjmp.h> -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 diff --git a/works/life/compile-principle-experiment/3/lex.l b/works/life/compile-principle-experiment/3/lex.l deleted file mode 100644 index ddea92d..0000000 --- a/works/life/compile-principle-experiment/3/lex.l +++ /dev/null @@ -1,17 +0,0 @@ -%{ -#include "main.h" -#include "syn.h" -%} -%option noyywrap -%% -[ \t] { ; } /* skip blanks and tabs */ -[0-9]+\.?|[0-9]*\.[0-9]+ { - sscanf(yytext, "%lf", &yylval.val); return NUMBER; } -[a-zA-Z][a-zA-Z0-9]* { - Symbol *s; - if ((s=cru_symbol_lookup(yytext)) == 0) - s = cru_symbol_install(yytext, UNDEF, (SymbolValue)0.0); - yylval.sym = s; - return s->type == UNDEF ? VAR : s->type; } -\n { lineno++; return '\n'; } /* everything else */ -. { return yytext[0]; } diff --git a/works/life/compile-principle-experiment/3/main.c b/works/life/compile-principle-experiment/3/main.c deleted file mode 100644 index 7cd8c28..0000000 --- a/works/life/compile-principle-experiment/3/main.c +++ /dev/null @@ -1,107 +0,0 @@ -#include "main.h" - -#include "syn.h" - -#include <errno.h> -#include <math.h> -#include <setjmp.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -static Symbol *symlist = 0; /* symbol table: linked list */ - -void *emalloc(size_t n) /* check return from malloc */ -{ - void *p = malloc(n); - if (p == 0) - execerror("out of memory", (char *)0); - return p; -} - -Symbol *cru_symbol_lookup(const char *name) { - for (Symbol *sp = symlist; sp != NULL; sp = sp->next) - if (strcmp(sp->name, name) == 0) - return sp; - return NULL; -} - -Symbol *cru_symbol_install(const char *name, int type, SymbolValue value) { - Symbol *sp = (Symbol *)emalloc(sizeof(Symbol)); - sp->name = emalloc(strlen(name) + 1); - strcpy(sp->name, name); - sp->type = type; - sp->value = value; - sp->next = symlist; - symlist = sp; - return sp; -} - -jmp_buf begin; -int lineno; - -void warning(const char *s, const char *t) { - fprintf(stderr, "%s", s); - if (t) - fprintf(stderr, " %s", t); - fprintf(stderr, " near line %d\n", lineno); -} - -void yyerror(const char *s) { warning(s, NULL); } - -void execerror(const char *s, const char *t) { - warning(s, t); - longjmp(begin, 0); -} - -double errcheck(double result, const char *name) { - if (errno == EDOM) { - errno = 0; - execerror(name, "argument out of domain"); - } else if (errno == ERANGE) { - errno = 0; - execerror(name, "result out of range"); - } - return result; -} - -double Log(double x) { return errcheck(log(x), "log"); } -double Log10(double x) { return errcheck(log10(x), "log10"); } -double Sqrt(double x) { return errcheck(sqrt(x), "sqrt"); } -double Exp(double x) { return errcheck(exp(x), "exp"); } -double Pow(double x, double y) { return errcheck(pow(x, y), "exponentiation"); } -double integer(double x) { return (double)(long)x; } - -static struct { /* Constants */ - char *name; - double cval; -} consts[] = { - {"PI", 3.14159265358979323846}, {"E", 2.71828182845904523536}, - {"GAMMA", 0.57721566490153286060}, {"DEG", 57.29577951308232087680}, - {"PHI", 1.61803398874989484820}, -}; - -static struct { /* Built-ins */ - char *name; - double (*func)(); -} builtins[] = { - {"sin", sin}, {"cos", cos}, {"atan", atan}, - {"log", Log}, {"log10", Log10}, {"exp", Exp}, - {"sqrt", Sqrt}, {"int", integer}, {"abs", fabs}, -}; - -void init() { - for (int i = 0; i < sizeof(consts) / sizeof(*consts); i++) - cru_symbol_install(consts[i].name, VAR, (SymbolValue)consts[i].cval); - for (int i = 0; i < sizeof(builtins) / sizeof(*builtins); i++) { - cru_symbol_install(builtins[i].name, BLTIN, (SymbolValue)builtins->func); - } -} - -int main(int argc, char **argv) { - init(); - (void)setjmp(begin); - yyparse(); - - return 0; -} diff --git a/works/life/compile-principle-experiment/3/main.h b/works/life/compile-principle-experiment/3/main.h deleted file mode 100644 index 9bd6e56..0000000 --- a/works/life/compile-principle-experiment/3/main.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -typedef union SymbolValue { - double val; - double (*ptr)(); -} SymbolValue; - -typedef struct Symbol { - char *name; - int type; - SymbolValue value; - struct Symbol *next; -} Symbol; - -Symbol *cru_symbol_lookup(const char *name); -Symbol *cru_symbol_install(const char *name, int type, SymbolValue value); - -double Pow(double x, double y); - -int yylex(); -int yyparse(); -void yyerror(const char *s); - -extern int lineno; -void execerror(const char *s, const char *t); diff --git a/works/life/compile-principle-experiment/3/makefile b/works/life/compile-principle-experiment/3/makefile deleted file mode 100644 index cf6333c..0000000 --- a/works/life/compile-principle-experiment/3/makefile +++ /dev/null @@ -1,22 +0,0 @@ -main: main.o lex.o syn.o - cc lex.o syn.o main.o -o main - -main.o: main.c main.h syn.h - cc -c -o main.o main.c - -lex.c: lex.l - flex -o lex.c lex.l - -lex.o: lex.c syn.h main.h - cc -c -o lex.o lex.c - -syn.c syn.h: syn.y - bison syn.y -d -o syn.c - -syn.o: syn.c syn.h main.h - cc -c -o syn.o syn.c - -PHONY: clean - -clean: - rm -f *.o lex.c syn.c syn.h main diff --git a/works/life/compile-principle-experiment/3/syn.y b/works/life/compile-principle-experiment/3/syn.y deleted file mode 100644 index 80abb17..0000000 --- a/works/life/compile-principle-experiment/3/syn.y +++ /dev/null @@ -1,42 +0,0 @@ -%{ -#include "main.h" -#include <stdio.h> -%} -%union { - double val; /* actual value */ - Symbol *sym; /* symbol table pointer */ -} -%token <val> NUMBER -%token <sym> VAR BLTIN UNDEF -%type <val> expr asgn -%right '=' -%left '+' '-' -%left '*' '/' -%left UNARYMINUS -%right '^' /* exponentiation */ -%% -list: /* nothing */ - | list '\n' - | list asgn '\n' - | list expr '\n' { printf("\t%.8g\n", $2); } - | list error '\n' { yyerrok; } - ; -asgn: VAR '=' expr { $$=$1->value.val=$3; $1->type = VAR; } - ; -expr: NUMBER - | VAR { if ($1->type == UNDEF) - execerror("undefined variable", $1->name); - $$ = $1->value.val; } - | BLTIN '(' expr ')' { $$ = (*($1->value.ptr))($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 '^' expr { $$ = Pow($1, $3); } - | '(' expr ')' { $$ = $2; } - | '-' expr %prec UNARYMINUS { $$ = -$2; } - ; -%% diff --git a/works/life/compile-principle-experiment/4/lex.l b/works/life/compile-principle-experiment/4/lex.l deleted file mode 100644 index e7731ca..0000000 --- a/works/life/compile-principle-experiment/4/lex.l +++ /dev/null @@ -1,20 +0,0 @@ -%{ -#include "main.h" -#include "syn.h" -%} -%option noyywrap -%% -[ \t] { ; } /* skip blanks and tabs */ -[0-9]+\.?|[0-9]*\.[0-9]+ { - Symbol *s = cru_symbol_install("", UNDEF, (SymbolValue)0.0); - sscanf(yytext, "%lf", &s->value.val); - yylval.sym = s; - return NUMBER; } -[a-zA-Z][a-zA-Z0-9]* { - Symbol *s; - if ((s=cru_symbol_lookup(yytext)) == 0) - s = cru_symbol_install(yytext, UNDEF, (SymbolValue)0.0); - yylval.sym = s; - return s->type == UNDEF ? VAR : s->type; } -\n { lineno++; return '\n'; } /* everything else */ -. { return yytext[0]; } diff --git a/works/life/compile-principle-experiment/4/main.c b/works/life/compile-principle-experiment/4/main.c deleted file mode 100644 index 258ccc7..0000000 --- a/works/life/compile-principle-experiment/4/main.c +++ /dev/null @@ -1,279 +0,0 @@ -#include "main.h" - -#include "syn.h" - -#include <errno.h> -#include <math.h> -#include <setjmp.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -static Symbol *symlist = 0; /* symbol table: linked list */ - -void *emalloc(size_t n) /* check return from malloc */ -{ - void *p = malloc(n); - if (p == 0) - execerror("out of memory", (char *)0); - return p; -} - -Symbol *cru_symbol_lookup(const char *name) { - for (Symbol *sp = symlist; sp != NULL; sp = sp->next) - if (strcmp(sp->name, name) == 0) - return sp; - return NULL; -} - -Symbol *cru_symbol_install(const char *name, int type, SymbolValue value) { - Symbol *sp = (Symbol *)emalloc(sizeof(Symbol)); - sp->name = emalloc(strlen(name) + 1); - strcpy(sp->name, name); - sp->type = type; - sp->value = value; - sp->next = symlist; - symlist = sp; - return sp; -} - -jmp_buf begin; -int lineno; - -void warning(const char *s, const char *t) { - fprintf(stderr, "%s", s); - if (t) - fprintf(stderr, " %s", t); - fprintf(stderr, " near line %d\n", lineno); -} - -void yyerror(const char *s) { warning(s, NULL); } - -void execerror(const char *s, const char *t) { - warning(s, t); - longjmp(begin, 0); -} - -double errcheck(double result, const char *name) { - if (errno == EDOM) { - errno = 0; - execerror(name, "argument out of domain"); - } else if (errno == ERANGE) { - errno = 0; - execerror(name, "result out of range"); - } - return result; -} - -double Log(double x) { return errcheck(log(x), "log"); } -double Log10(double x) { return errcheck(log10(x), "log10"); } -double Sqrt(double x) { return errcheck(sqrt(x), "sqrt"); } -double Exp(double x) { return errcheck(exp(x), "exp"); } -double Pow(double x, double y) { return errcheck(pow(x, y), "exponentiation"); } -double integer(double x) { return (double)(long)x; } - -static struct { /* Constants */ - char *name; - double cval; -} consts[] = { - {"PI", 3.14159265358979323846}, {"E", 2.71828182845904523536}, - {"GAMMA", 0.57721566490153286060}, {"DEG", 57.29577951308232087680}, - {"PHI", 1.61803398874989484820}, -}; - -static struct { /* Built-ins */ - char *name; - double (*func)(); -} builtins[] = { - {"sin", sin}, {"cos", cos}, {"atan", atan}, - {"log", Log}, {"log10", Log10}, {"exp", Exp}, - {"sqrt", Sqrt}, {"int", integer}, {"abs", fabs}, -}; - -int initcode(); -int execute(Inst *p); - -void init() { - initcode(); - for (int i = 0; i < sizeof(consts) / sizeof(*consts); i++) - cru_symbol_install(consts[i].name, VAR, (SymbolValue)consts[i].cval); - for (int i = 0; i < sizeof(builtins) / sizeof(*builtins); i++) { - cru_symbol_install(builtins[i].name, BLTIN, (SymbolValue)builtins->func); - } -} - -int main(int argc, char **argv) { - init(); - (void)setjmp(begin); - yyparse(); - execute(prog); - - return 0; -} - -#define NSTACK 256 -static Datum stack[NSTACK]; /* the stack */ -static Datum *stackp; /* next free spot on stack */ - -#define NPROG 2000 -Inst prog[NPROG]; /* the machine */ -Inst *progp; /* next free spot for code generation */ -Inst *pc; /* program counter during execution */ - -int initcode() /* initialize for code generation */ -{ - stackp = stack; - progp = prog; - return 0; -} - -int push(Datum d) /* push d onto stack */ -{ - if (stackp >= &stack[NSTACK]) - execerror("stack overflow", (char *)0); - *stackp++ = d; - return 0; -} - -Datum pop() /* pop and return top elem from stack */ -{ - if (stackp <= stack) - execerror("stack underflow", (char *)0); - return *--stackp; -} - -int constpush() /* push constant onto stack */ -{ - Datum d; - d.val = ((Symbol *)*pc++)->value.val; - push(d); - return 0; -} - -int varpush() /* push variable onto stack */ -{ - Datum d; - d.sym = (Symbol *)(*pc++); - push(d); - return 0; -} - -int bltin() /* evaluate built-in on top of stack */ -{ - Datum d; - d = pop(); - d.val = (*(double (*)())(*pc++))(d.val); - push(d); - return 0; -} - -int eval() /* evaluate variable on stack */ -{ - Datum d; - d = pop(); - if (d.sym->type == UNDEF) - execerror("undefined variable", d.sym->name); - d.val = d.sym->value.val; - push(d); - return 0; -} - -int add() /* add top two elems on stack */ -{ - Datum d1, d2; - d2 = pop(); - d1 = pop(); - d1.val += d2.val; - push(d1); - return 0; -} - -int sub() /* subtract top of stack from next */ -{ - Datum d1, d2; - d2 = pop(); - d1 = pop(); - d1.val -= d2.val; - push(d1); - return 0; -} - -int mul() { - Datum d1, d2; - d2 = pop(); - d1 = pop(); - d1.val *= d2.val; - push(d1); - return 0; -} - -int mydiv() { - Datum d1, d2; - d2 = pop(); - if (d2.val == 0.0) - execerror("division by zero", (char *)0); - d1 = pop(); - d1.val /= d2.val; - push(d1); - return 0; -} - -int negate() { - Datum d; - d = pop(); - d.val = -d.val; - push(d); - return 0; -} - -int power() { - Datum d1, d2; - extern double Pow(); - d2 = pop(); - d1 = pop(); - d1.val = Pow(d1.val, d2.val); - push(d1); - return 0; -} - -int assign() /* assign top value to next value */ -{ - Datum d1, d2; - d1 = pop(); - d2 = pop(); - if (d1.sym->type != VAR && d1.sym->type != UNDEF) - execerror("assignment to non-variable", d1.sym->name); - d1.sym->value.val = d2.val; - d1.sym->type = VAR; - push(d2); - return 0; -} - -int print() /* pop top value from stack, print it */ -{ - Datum d; - d = pop(); - printf("\t%.8g\n", d.val); - return 0; -} - -Inst *code(Inst f) /* install one instruction or operand */ -{ - Inst *oprogp = progp; - if (progp >= &prog[NPROG]) - execerror("program too big", (char *)0); - *progp++ = f; - return oprogp; -} - -int execute(Inst *p) /* run the machine */ -{ - for (pc = p; *pc != STOP;) - (*(*pc++))(); - return 0; -} - -int mypop() { - pop(); - return 0; -} diff --git a/works/life/compile-principle-experiment/4/main.h b/works/life/compile-principle-experiment/4/main.h deleted file mode 100644 index 96bd9e7..0000000 --- a/works/life/compile-principle-experiment/4/main.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -typedef union SymbolValue { - double val; - double (*ptr)(); -} SymbolValue; - -typedef struct Symbol { - char *name; - int type; - SymbolValue value; - struct Symbol *next; -} Symbol; - -Symbol *cru_symbol_lookup(const char *name); -Symbol *cru_symbol_install(const char *name, int type, SymbolValue value); - -double Pow(double x, double y); - -int yylex(); -int yyparse(); -void yyerror(const char *s); - -extern int lineno; -void execerror(const char *s, const char *t); - -typedef union Datum { /* interpreter stack type */ - double val; - Symbol *sym; -} Datum; -extern Datum pop(); -int mypop(); - -typedef int (*Inst)(); /* machine instruction */ -#define STOP (Inst)0 - -extern Inst prog[]; -extern int eval(), add(), sub(), mul(), mydiv(), negate(), power(); -extern int assign(), bltin(), varpush(), constpush(), print(); - -extern Inst *code(Inst f); diff --git a/works/life/compile-principle-experiment/4/makefile b/works/life/compile-principle-experiment/4/makefile deleted file mode 100644 index 756cdcb..0000000 --- a/works/life/compile-principle-experiment/4/makefile +++ /dev/null @@ -1,22 +0,0 @@ -main: main.o lex.o syn.o - cc -g lex.o syn.o main.o -o main - -main.o: main.c main.h syn.h - cc -g -c -o main.o main.c - -lex.c: lex.l - flex -o lex.c lex.l - -lex.o: lex.c syn.h main.h - cc -g -c -o lex.o lex.c - -syn.c syn.h: syn.y - bison syn.y -d -o syn.c - -syn.o: syn.c syn.h main.h - cc -g -c -o syn.o syn.c - -PHONY: clean - -clean: - rm -f *.o lex.c syn.c syn.h main diff --git a/works/life/compile-principle-experiment/4/syn.y b/works/life/compile-principle-experiment/4/syn.y deleted file mode 100644 index ebe113f..0000000 --- a/works/life/compile-principle-experiment/4/syn.y +++ /dev/null @@ -1,39 +0,0 @@ -%{ -#include "main.h" -#include <stdio.h> -#define code2(c1,c2) code(c1); code(c2) -#define code3(c1,c2,c3) code(c1); code(c2); code(c3) -%} -%union { - Symbol *sym; /* symbol table pointer */ - double val; - Inst *inst; /* machine instruction */ -} -%token <sym> NUMBER VAR BLTIN UNDEF -%right '=' -%left '+' '-' -%left '*' '/' -%left UNARYMINUS -%right '^' /* exponentiation */ -%% -list: /* nothing */ - | list '\n' - | list asgn '\n' { code2(mypop, STOP); return 1; } - | list expr '\n' { code2(print, STOP); return 1; } - | list error '\n' { yyerrok; } - ; -asgn: VAR '=' expr { code3(varpush,(Inst)$1,assign); } - ; -expr: NUMBER { code2(constpush, (Inst)$1); } - | VAR { code3(varpush, (Inst)$1, eval); } - | asgn - | BLTIN '(' expr ')' { code2(bltin, (Inst)$1->value.ptr); } - | '(' expr ')' - | expr '+' expr { code(add); } - | expr '-' expr { code(sub); } - | expr '*' expr { code(mul); } - | expr '/' expr { code(mydiv); } - | expr '^' expr { code(power); } - | '-' expr %prec UNARYMINUS { code(negate); } - ; -%% |