Mercurial > hg > Members > kono > compiler-examples
changeset 11:c8e3b90ba2d9
check
author | kono |
---|---|
date | Fri, 28 Oct 2011 14:57:21 +0900 |
parents | 745c62bbc200 |
children | c5c4771a6be2 |
files | Makefile s-calc-r.c s-token.c s-yacc.y |
diffstat | 4 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Fri Nov 09 16:23:32 2007 +0900 +++ b/Makefile Fri Oct 28 14:57:21 2011 +0900 @@ -1,10 +1,10 @@ -TEST = s-imac +TEST = s-imac64 CC = gcc -CFLAGS = -g +CFLAGS = -g -O -Wall YYFLAGS = -v -# COMPILER = s-compile.o s-token.o -COMPILER = s-tree-compile.o s-token.o +COMPILER = s-compile.o s-token.o +# COMPILER = s-tree-compile.o s-token.o # COMPILER = s-yacc.o s-token.o # TARGET = token calc s-calc s-prefix s-rpn s-09 s-intel s-intel-r s-sparc s-rs6k s-m68k s-ppc s-imac @@ -37,6 +37,8 @@ $(CC) $(CFLAGS) -o $@ $^ s-imac: $(COMPILER) s-code-intel-mac.o $(CC) $(CFLAGS) -o $@ $^ +s-imac64: $(COMPILER) s-code-intel64-mac.o + $(CC) $(CFLAGS) -o $@ $^ s-sparc: $(COMPILER) s-code-sparc.o $(CC) $(CFLAGS) -o $@ $^ s-rs6k: $(COMPILER) s-code-rs6k.o
--- a/s-calc-r.c Fri Nov 09 16:23:32 2007 +0900 +++ b/s-calc-r.c Fri Oct 28 14:57:21 2011 +0900 @@ -15,6 +15,7 @@ static int mexpr(); static int term(); static int token(); +static void error(char *); static int @@ -159,6 +160,14 @@ } } +static int lineno = 0; + +void +error(char *msg) +{ + fprintf(stderr,"%s on line %d\n",msg, lineno); +} + int main() { @@ -170,6 +179,7 @@ d = expr(); printf("%s = 0x%08x = %d\n",buf,d,d); fflush(stdout); + lineno++; } return 0; }
--- a/s-token.c Fri Nov 09 16:23:32 2007 +0900 +++ b/s-token.c Fri Oct 28 14:57:21 2011 +0900 @@ -33,7 +33,7 @@ } if('0'<=c && c<='9') { /* Decimal */ d = c-'0'; - while(c= *ptr++) { + while((c= *ptr++)) { if('0'<=c && c<='9') { d = d*10 + (c - '0'); } else {
--- a/s-yacc.y Fri Nov 09 16:23:32 2007 +0900 +++ b/s-yacc.y Fri Oct 28 14:57:21 2011 +0900 @@ -19,6 +19,8 @@ #define YYSTYPE nodeptr static node *new_node(); +static void free_node(node *d); +static void code_generate(node *d); %} %% @@ -101,8 +103,7 @@ } static void -free_node(d) -node *d; +free_node(node *d) { if(d->left) { free_node(d->left); @@ -114,8 +115,7 @@ } static void -code_generate(d) -node *d; +code_generate(node *d) { int assign; if(!d) return; /* compiler internal error.. */