diff --git a/Makefile b/Makefile index 06f86a9e7d9a94c0a63ff7286d5902895e6f1648..f4e71b9a54223d4995972db611d6467766a47a6a 100644 --- a/Makefile +++ b/Makefile @@ -1,54 +1,31 @@ -CC = gcc -#CC = cc -CFLAGS = -g -UDEBUGGING -LINTFLAGS = -UDEBUGGING -EXECS = datadec -#EXECS = datadec m2datadec +CC = gcc +#CC = cc +DEST = $(PREFIX)/usr +BINDIR = $(DEST)/bin +MANDIR = $(DEST)/man/man1 +CFLAGS = -g -UDEBUGGING -Wall +LDLIBS = +EXECS = datadec -datadec_srcs = datadec.c parser.c lexer.c struct.c decs.c optimize.c -datadec_objs = datadec.o parser.o lexer.o struct.o decs.o optimize.o -m2datadec_srcs = datadec.c parser.c lexer.c struct.c m2decs.c optimize.c -m2datadec_objs = datadec.o parser.o lexer.o struct.o m2decs.o optimize.o +datadec_srcs = datadec.c parser.c lexer.c struct.c decs.c optimize.c +datadec_objs = datadec.o parser.o lexer.o struct.o decs.o optimize.o all: $(EXECS) -install: - install -m 755 datadec $(PREFIX)/usr/local/bin/datadec - install -m 644 c-datadec.man $(PREFIX)/usr/man/man1/datadec.1 - -arch: $(EXECS) - cp -p $(EXECS) ../../$(ARCH) - cd ../../$(ARCH); chmod a+rx,ug+w $(EXECS) +install: $(EXECS) + install -m 755 $(EXECS) $(BINDIR) + install -m 644 c-datadec.man $(MANDIR)/datadec.1 clean: /bin/rm -f *.o a.out core $(EXECS) -lint: lint_datadec lint_m2datadec - -lint_datadec: $(datadec_srcs) - lint $(LINTFLAGS) $(datadec_srcs) >lint_datadec 2>&1 - -lint_m2datadec: $(m2datadec_srcs) - lint $(LINTFLAGS) $(m2datadec_srcs) >lint_m2datadec 2>&1 - -m2datadec: $(m2datadec_objs) - $(CC) -g -o m2datadec $(m2datadec_objs) - datadec: $(datadec_objs) $(CC) -g -o datadec $(datadec_objs) -datadec.o: datadec.c struct.h lexer.h parser.h decs.h optimize.h - -decs.o: decs.c struct.h decs.h - -lexer.o: lexer.c struct.h lexer.h - -m2decs.o: m2decs.c struct.h decs.h - -optimize.o: optimize.h struct.h optimize.c - -parser.o: parser.c struct.h lexer.h parser.h - -struct.o: struct.c struct.h - +datadec.o: struct.h lexer.h parser.h decs.h optimize.h +decs.o: struct.h decs.h +lexer.o: struct.h lexer.h +optimize.o: optimize.h struct.h +parser.o: struct.h lexer.h parser.h +struct.o: struct.h diff --git a/README b/README index 9c756726d9ccd9c9c87291287baef6c641839374..8168eb86bd97fe4a47736471fc4ad33ea12ca19b 100644 --- a/README +++ b/README @@ -21,7 +21,6 @@ illist = nil idtree = leaf( string id, illist l ) | node( idtree left, idtree right ) ; - What does this mean? The first rule declares that an intlist can take two basic "shapes" - diff --git a/c-datadec.man b/c-datadec.man index d1884280105895aba63ff91c6241bc23d4294398..657972c477e7b55c6a7b507bcd228295ffa0d2f4 100644 --- a/c-datadec.man +++ b/c-datadec.man @@ -43,10 +43,10 @@ The simplest use is to prepare an input file, such as which might (for example) contain: .nf TYPE { - IntList = Null or Cons( int first, IntList next ); - ILList = Null or Cons( IntList first, ILList next ); - IdTree = Leaf( string id ) - or Node( IdTree left, IdTree right ); + intlist = nil or cons( int first, intlist next ); + illist = nil or cons( intlist first, illist next ); + idtree = leaf( string id ) + or node( idtree left, idtree right ); } .fi To generate C code implementing these types, invoke: @@ -100,7 +100,7 @@ Similarly, the contents of the .I "global" section are placed in the C file, again with `@@' being used to split the global section into "top of file" and -"bottom at file" pieces. +"bottom of file" pieces. .PP Similarly, the contents of the @@ -149,7 +149,9 @@ Each type name is simply an identifier. also generates routines to write each type to an open FILE *. The method of printing each shape is governed by the presence or absence of a print rule. If no print rule is given, the constructor name is printed, -and then each parameter is written out using the appropriate print routine. +then an open bracket, +then each parameter is written out using the appropriate print routine, +with commas separating the parameters, then a close bracket. .PP If a print rule is given, each print element @@ -162,26 +164,24 @@ whereas a number (eg. 4) means that the .PP For example, we could augment the -.I "IdTree" +.I "idtree" type from the example given above with print rules: .nf TYPE { -IdTree = Leaf( string id ) "leaf(" 1 ")" - or Node( IdTree left, IdTree right ) "node(" 1 ",\\n" 2 ")"; +idtree = leaf( string id ) "leaf(" 1 ")" + or node( idtree left, idtree right ) "node( l=" 1 ", r=" 2 " )"; } .fi .PP -Now, an IdTree constructed as +Now, an idtree constructed as .nf -Node( Leaf( "hello" ), Node( Leaf( "there" ) ) ) +node( leaf( "hello" ), node( leaf( "there" ), leaf( "how are you" ) ) ) .fi would print as: .nf -node(leaf("hello"), -.br -node(leaf("there"))) +node( l=leaf("hello"), r=node(l=leaf("there"),r=leaf("how are you"))) .fi .SH SEE ALSO @@ -189,14 +189,19 @@ node(leaf("there"))) LALR, REX, Miranda Language Definition. .fi +.SH MISSING FEATURES +I must implement the missing free_TYPE functions sometime. +.PP +A cool extra would be a sprint_TYPE function to print into a string. +This should be a trivial modification on the code that prints to a file, +of course we don't know how long the generated string will need to be. + .SH BUGS Some single letter typenames (eg. "f" or "p") could clash with internal parameter names in the print routines, leading to syntax errors when you compile the files generated by datadec. .PP -Someday I'll get it to free up the types too! -.PP And, finally, one day I'll have to write the C++ and Java versions :-) .SH "AUTHOR" -Duncan C. White, D.White@surrey.ac.uk. +Duncan C. White, D.White@imperial.ac.uk. diff --git a/decs.c b/decs.c index 93559271082b704b5e880ace5503db7f36657862..6ca80f5456745972af725ad808f3128179bd4c77 100644 --- a/decs.c +++ b/decs.c @@ -1,5 +1,6 @@ #include #include +#include #include "struct.h" #include "decs.h" @@ -85,6 +86,16 @@ static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d; } +static void literalline( mesg ) char *mesg; +{ + int i; + + for( i=numtabs; i; i-- ) fputc( '\t', outfile ); + fputs( mesg, outfile ); + nl(); +} + + void make_declns( exports, globals, begin, d, base ) declnlist d; char *exports, *globals, *begin, *base; { printf( "datadec: Making data declarations in %s.[ch]\n", base ); @@ -154,7 +165,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init; { nl(); line( "/* Remaining contents of EXPORT section */" ); - line( exportptr ); + literalline( exportptr ); nl(); } @@ -182,7 +193,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de line( " * Automatically Generated by DataDec" ); line( " */\n" ); line( "#include " ); - line( "#include " ); + line( "#include " ); line( "#include \"%s.h\"\n\n", base ); globalptr=globals; @@ -213,7 +224,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de nl(); nl(); line( "/* Remaining contents of GLOBAL section */" ); - line( globalptr ); + literalline( globalptr ); nl(); } @@ -868,6 +879,10 @@ static void print_all_params( d, s ) declnlist d; shapelist s; for( p = s->params; p != NULL; p = p->next ) { print_param( s, p, d->Union ); + if( p->next != NULL ) + { + line( "fputc( ',', f );" ); + } } if( s->params ) { diff --git a/optimize.c b/optimize.c index cbf3cd9c445090d17b2e40aa278dabb7079a080c..e65c572e2dd6ca7fa2f1cc515d2ebe29e2adae3b 100644 --- a/optimize.c +++ b/optimize.c @@ -140,7 +140,6 @@ static BOOL tail_optimize( d ) decln d; shapelist s; printlist pl; param p; - int n; for( s = d->shapes; s != NULL; s = s->next ) { diff --git a/parser.c b/parser.c index a83538a643fc350a33e2fb8ac93c9d92eace0b92..55e7e826232f81f5273d07e8cca08a8cf7b75adc 100644 --- a/parser.c +++ b/parser.c @@ -27,7 +27,7 @@ #include #include -#include +#include #include "struct.h" #include "lexer.h" #include "parser.h" diff --git a/test/Makefile b/test/Makefile index 9bf14658cd8a63ca26dd0de4b37fc6bbc04a3185..41cd4231483075b47d20fefd9bfada75caf2cc45 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,6 @@ -#INC = /vol/lab/include CFLAGS = -g -UDEBUGGING TESTEXECS = ctest -AUTOCRAP = mtest.* mx.* ctest.* cx.? +AUTOCRAP = ctest.* cx.[och] all: $(TESTEXECS) @@ -11,21 +10,6 @@ clean: cx.c cx.h: cdata.in ../datadec ../datadec cx cdata.in -cx.o: cx.c cx.h - -ctest.o: ctest.c cx.h - -ctest: ctest.o cx.o - $(CC) -o ctest ctest.o cx.o - -mx.def mx.mod: m2data.in ../src/m2datadec - ../src/m2datadec mx m2data.in - -mx.sym: mx.def - -mx.o: mx.mod mx.sym - -mtest.o: mtest.mod mx.sym - -mtest: mtest.o mx.o - m2c $(M2FLAGS) $(M2LINKFLAGS) -o mtest -e mtest +ctest: ctest.o cx.o +cx.o: cx.h +ctest.o: cx.h