rsalz@uunet.uu.net (Rich Salz) (10/24/89)
Submitted-by: Edoardo Biagioni <biagioni@cs.unc.edu> Posting-number: Volume 20, Issue 50 Archive-name: fpc/part01 [ This does NOT include an FP language reference manual; they abound, including BSD documentation and Backus's Turing award lecture. /r$ ] This is FPC, a portable implementation of Backus's FP language. FPC translates FP programs to C source code which you can compile normally. FPC includes a short README file that tells you how to install it, and a 'man' page that tells you how to use it. It has been in use here at UNC for the last 2 years and has no known bugs. If you want more information, you can get a paper describing FPC by requesting the technical report TR88-027: "FPC: a translator for FP", by E. Biagioni, from: Department of Computer Science University of North Carolina at Chapel Hill Chapel Hill, North Carolina, 27514 U.S.A. Make sure you include a legible return address. Ed Biagioni biagioni@cs.unc.edu Department of Computer Science seismo!mcnc!unc!biagioni Chapel Hill, N.C. 27514, USA Disclaimer: this software is in the public domain. It is provided "as is", with no warranty; neither the author nor UNC have any responsibility or liability for any problems that may be caused by use or abuse of this software. # This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. -----cut here-----cut here-----cut here-----cut here----- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # README # makefile # fpc.1 # fpc.c # fpc.h # stdfp.h # fp.h # fpg.l # fpg.y echo shar: extracting README '(621 characters)' sed 's/^XX//' << \SHAR_EOF > README XXTo install fpc, run 'make' in this directory. Once you are satisfied XXthat fpc works correctly, you can update update the makefiles so that XXthe BIN and LIB variables contain the names of the directories where XXthe executables and the object libraries should reside. This must XXbe done to both 'makefile' and 'lib/makefile'. You can then run XX'make release'. XX XXI can be reached at the following address: XX XXEd Biagioni biagioni@cs.unc.edu Department of Computer Science XX seismo!mcnc!unc!biagioni Chapel Hill, N.C. 27514, USA XX XXbut the response time might be a few weeks since I'll be travelling quite XXa bit in the near future. SHAR_EOF if test 621 -ne "`wc -c README`" then echo shar: error transmitting README '(should have been 621 characters)' fi echo shar: extracting makefile '(2924 characters)' sed 's/^XX//' << \SHAR_EOF > makefile XXMAIN = /usr/local XXBIN = ${MAIN}/bin XXLIB = ${MAIN}/lib XXBINS = ${BIN}/fpc XXLIBS = ${LIB}/libfp.a ${LIB}/libdfp.a ${LIB}/libnfp.a XXSRC = fpg.l fpg.y fp.c fp.h stdfp.h fpc.c fpc.h parse.c parse.h code.c \ XX code.h expr.c mkffp.c mkprol.c makefile prims.fp XXCFLAGS = XX XXall: fpc fp.o debugfp.o nocheckfp.o lint XX cd lib; make ; cd .. XX XXclean: XX rm -f *.o y.tab.c lex.yy.c fpc mkffp lint XX XX.SUFFIXES: XX XX.SUFFIXES: .fp XX XX${BIN}/fpc: fpc XX rm -f ${BIN}/fpc XX cp fpc ${BIN}/fpc XX XX${LIB}/libfp.a: fp.o XX ar r ${LIB}/libfp.a fp.o XX ranlib ${LIB}/libfp.a XX XX${LIB}/libdfp.a: debugfp.o XX ar r ${LIB}/libdfp.a debugfp.o XX ranlib ${LIB}/libdfp.a XX XX${LIB}/libnfp.a: nocheckfp.o XX ar r ${LIB}/libnfp.a nocheckfp.o XX ranlib ${LIB}/libnfp.a XX XX${BIN}/mkffp: mkffp XX rm -f ${BIN}/mkffp XX cp mkffp ${BIN}/mkffp XX XX${BIN}/mkprol: mkprol XX rm -f ${BIN}/mkprol XX cp mkprol ${BIN}/mkprol XX XXfpc.o: fpc.c XX cc ${CFLAGS} -c fpc.c XX XXparse.o: parse.c XX cc ${CFLAGS} -c parse.c XX XXcode.o: code.c XX cc ${CFLAGS} -c code.c XX XXexpr.o: expr.c XX cc ${CFLAGS} -c expr.c XX XXfpc: y.tab.o fpc.o parse.o code.o expr.o XX rm -f fpc XX cc ${CFLAGS} -o fpc y.tab.o parse.o code.o expr.o fpc.o -ll XX XXlint: y.tab.c lex.yy.c fpc.c parse.c code.c expr.c fp.c XX lint -achx y.tab.c fpc.c parse.c code.c expr.c | grep -v yy | \ XX grep -v "^str" | grep -v "^_flsbuf" | \ XX grep -v "long assignment may lose accuracy" | \ XX grep -v "exit value declared inconsistently" > lint XX lint -abchux fp.c | grep -v yy | grep -v "^str" | \ XX grep -v "^_flsbuf" | \ XX grep -v "long assignment may lose accuracy" | \ XX grep -v "illegal structure pointer combination" | \ XX grep -v "exit value declared inconsistently" >> lint XX XXmkprol.o: mkprol.c XX cc ${CFLAGS} -c mkprol.c XX XXmkffp.o: mkffp.c XX cc ${CFLAGS} -c mkffp.c XX XXmkffp: y.tab.o fpc.o parse.o mkffp.o XX cc ${CFLAGS} -o mkffp y.tab.o parse.o mkffp.o fpc.o -ll XX XXmkprol: y.tab.o fpc.o parse.o mkprol.o XX cc ${CFLAGS} -o mkprol y.tab.o parse.o mkprol.o fpc.o -ll XX XXlex.yy.c: fpg.l XX lex -v fpg.l XX sed "s/fprintf/(void) fprintf/" lex.yy.c | \ XX sed "s/putc/(void) putc/" > /tmp/lex.yy.c XX mv /tmp/lex.yy.c lex.yy.c XX XXxlator.o: xlator.c XX cc ${CFLAGS} -c -O xlator.c XX XXy.tab.c: fpg.y XX yacc fpg.y XX echo "should have given 1 shift/reduce conflict (bu fn o ...)" XX XXy.tab.o: y.tab.c lex.yy.c XX cc ${CFLAGS} -c -O y.tab.c XX XXparse.c: parse.h fpc.h XX touch parse.c XX XXfp.c: fp.c.part1 fp.c.part2 XX cat fp.c.part1 fp.c.part2 > fp.c XX XXfp.o: fp.c fp.h stdfp.h XX cc ${CFLAGS} -c -O fp.c XX XXdebugfp.o: fp.c fp.h XX cp fp.c debugfp.c XX cc ${CFLAGS} -c -DDEBUG debugfp.c XX rm -f debugfp.c XX XXnocheckfp.o: fp.c fp.h XX cp fp.c nocheckfp.c XX cc ${CFLAGS} -c -O -DNOCHECK nocheckfp.c XX rm -f nocheckfp.c XX XXcode.c: parse.h code.h fpc.h fp.h stdfp.h XX touch code.c XX XXexpr.c: parse.h code.h fp.h stdfp.h XX touch expr.c XX XXfpc.c: fpc.h XX touch fpc.c XX XXrelease: all ${BINS} ${LIBS} XX cd lib ; make release ; cd .. XX echo release done XX XXprimslist: fp.c XX grep "^fp_data" fp.c | grep "(data)" | sed "s/^fp_data //" | \ XX sed "s/ (data)//" | sort > primslist SHAR_EOF if test 2924 -ne "`wc -c makefile`" then echo shar: error transmitting makefile '(should have been 2924 characters)' fi echo shar: extracting fpc.1 '(9433 characters)' sed 's/^XX//' << \SHAR_EOF > fpc.1 XX.TH FPC 1 "29 May 1986" XX.UC 4 XX.SH NAME XXfpc \- fp to C compiler XX.SH SYNOPSIS XX.B fpc XX[ XX.I options XX] ... XX.I file XX... XX.SH DESCRIPTION XX.I FPC XXis an fp compiler. It produces as output C source files XXrather than object files. XX.I FPC XXaccepts as arguments the names of the files to be XXcompiled. Arguments of the form XX.IR name.fp XXare taken to be fp source programs; each XXis compiled into the C source file XX.IR name.c. XXPrograms can be compiled as normal C source files; they must XXbe loaded using one of the switches XX.IR -lfp, XX.IR -lnfp, XX.IR -ldfp. XX.SH EXAMPLE XX.PP XXAs an example, we compile mmult.fp and ip.fp. Assume the XXfile mmult declares functions noop and matrixmult. XXThe resulting program will execute the function matrixmult. XXIt is assumed that ip.fp contains auxiliary functions XXneeded by noop or matrixmult or both. XXTo compile, do the following: XX.sp 1 XX fpc -mmatrixmult mmult.fp ip.fp XX.br XX cc -o mmult mmult.c ip.c -lfp XX.sp 1 XXThis will produce the file mmult which XX.br XX accepts input from the user, and XX.br XX applies matrixmult to it, and XX.br XX outputs the result. XX.sp 1 XXThe first command above could have been entered as two separate XXcommands: XX.sp 1 XX fpc -mmatrixmult mmult.fp XX.br XX fpc ip.fp XX.sp 1 XXThe two commands could have been given in either order. XX.SH OPTIONS XXThe following options are recognized by XX.IR FPC. XXNotice that options only apply to the first file name following XXthe option. XX.TP 8 XX.B \-v XX(verbose) prints on the standard output XXthe version number of the compiler and the names of XXthe functions being compiled. XX.TP XX.B \-d XX(debug) produces code to trace all function entries and XXexits and the arguments passed to them as well as the XXdata they return. The trace is printed on the standard XXerror output (stderr). XX.TP XX.B \-e XX(entry/exit) same as -d, except that it does not print XXthe arguments or the results of the functions. XX.TP XX.BI \-t fun XX(trace) like debug, but only for function XX.I fun. XX.TP XX.B \-n XX(no check) the arguments to functional forms are not XXchecked for correctness, and other optimizations are XXdone which should speed up execution but make error XXdetection and localization harder. It is expected that XXprograms compiled with -n will be loaded with the XXlibrary nfp. XX.TP XX.B \-m XX.br XX.ns XX.TP XX.BI \-m fun XXThe compiler assumes that the first file XXname following the -m switch (call it XX.I file.fp XX) requires a XX.I main XXprocedure. The XX.I main XXprocedure XX.sp 1 XX.ti 16 XXreads data from the standard input; XX.ti 16 XXcalls the `main' function on that data; XX.ti 16 XXprints the result of the call. XX.sp 1 XXIf the second form is used, the `main' function is XX.I fun; XXfor the first form, it is XX.I file. XX.TP XX.BI \-s XX(space) produces code to print out the maximum amount XXof space used by the program, as well as the number of XXcell allocations and de-allocations. Can only be used XXin conjunction with -m. XX.TP XX.B \-i XX(string input) can only be used with -m. Specifies that XXthe data obtained from the standard input be XXpassed to the main function as a string (a vector XXof characters), rather than XXas an ffp object. In other words, XX.IR abc XXwould be given XXto the `main' function as XX.IR \<'a, XX.IR 'b, XX.IR 'c\> XXrather than as the atom XX.IR abc. XX.TP XX.B \-o XX(string output) can only be used with -m. Specifies that XXthe data returned by the `main' function be output in XXraw form. The data may be a string or XXa vector of pairs \< XX.IR filename, XXstring\>, (e.g. \<\<file1, "yes, I am XXhere"\>, \<file2, "no, I am not here"\>\>). In XXboth cases, XXthe string or strings are printed without surrounding XXquotes. In the first case the string is printed on the XXstandard output; in the second case each of XXthe strings is printed to the file specified by XX.IR filename, XXwhich must be an fp atom. The file name XX.IR output XXspecifies the standard output. It is an error for the `main' XXfunction to return more than one instance of a given XX.IR filename. XX.TP XX.B \-p XX(parameters and options) specifies that if any command line XXoptions or parameters are present, the program should run XXimmediately, with \<\> as input, instead of waiting XXfor input from stdin. The arguments can then be obtained XXby calling the procedure arguments, (see later). If no command XXline arguments are given, input proceeds normally. XX.TP XX.B \-a XX(AST system) can only be used with -m, and ignores -p. An XXAST system is an XXapplicative state transition system. This option causes the XXprocedure XX.IR main XXto: XX.sp 1 XX.ti 16 XX(1) apply the `main' function to \<\<\>, \<\>\> XX.ti 16 XX(2) `main' must return \<output, state\> XX.ti 16 XX(3) print the output part of the result XX.ti 16 XX(4) read the standard input XX.ti 16 XX(5) create a pair \<data-read, state\> XX.ti 16 XX(6) call the `main' function on the pair XX.ti 16 XX(7) `main' must return \<output, new-state\> XX.ti 16 XX(8) print the output part of the result XX.ti 16 XX(9) set state to the second part of the result XX.ti 16 XX(10) if state is not nil, return to step (4) XX.sp 1 XXInput and output are done as specified by any of XXthe -i and -o options. If -i is specified, each input XXwill be a string of exactly one character, returned as soon XXas the character is available. XX.SH FILES XX.ta \w'/usr/c/occom 'u XXfile.fp input file XX.br XXfile.c output file XX.br XXfpc compiler XX.br XXlibfp.a run-time library XX.br XXlibdfp.a run-time library to test implementation of the primitives XX.br XXlibnfp.a run-time library for non-checking primitives XX.br XX.SH "SEE ALSO" XXJohn Backus, XX.I XXCan Programming Be Liberated from the von Neumann Style? XX.I XXA Functional Style and Its Algebra of Programs XX.br XXTuring Award lecture, Communications of the ACM, XXVolume 21, Number 8, August 1978 XX.SH MODIFICATIONS XXThe major syntactic differences between the language XXaccepted by FPC and the language described XXin the Backus paper are in the treatment of non-ascii XXcharacters. More specifically, the XX.IR define XXcharacter (three parallel strokes) disappears, the if XXcharacter (arrow to the right) is entered as ->, the XXapply-to-all symbol (alpha) is entered as XX.IR aa , XXthe compose symbol is entered as XX.IR o XX(lowercase O), XXand constants are preceded by XXan underscore instead of being overstruck. XXAlso, bottom will be generated by a call to XXthe primitive function XX.IR error, XXcharacters are entered as 'c or '\\c, and XXstrings (vectors of characters) are entered XXas "string". XXIn addition to the normal (left) insert functional XXform /, XXFPC provides tree insert \\/ and right insert \\. XXTree insert is used where the order of application XXis unimportant and may be expected to be more efficient XXon some systems or in some applications. XXUnary negation is given by XX.IR neg XXand - (minus) only accepts pairs of numbers. XX.PP XXSince there is a one-to-one XXmapping between fp functions and C procedures, characters XXnot allowed in C procedure names are not permitted in fp XXfunction names. XX.PP XXAs an example, the function ! XX(factorial) defined in XXthe paper would be written as XX.br XX.br XXDef sub1 - o [id, _1] XX.br XXDef eq0 eq o [id, _0] XX.br XXDef fac eq0 -> _1 ; * o [id, fac o sub1] XX.SH NEW FUNCTIONS XXFPC provides several functions that do not appear in the XXBackus paper, and several more are planned. XXThe description of the currently available ones follows. XX.PP XX.IR append XXmerges any number of vectors into a single vector. Any XXtop-level nils disappear. XX.IR trunc XXis the floor function, it converts a real to the nearest XXinteger that is less than or equal to it. XX.IR newline XXis a constant-valued function which returns the string XXthat signals a new line on the local system. The value XXreturned is a string instead of a character since the XXsystem may require several characters (e.g., <CR, LF>) to XXsignal an end of line. XX.IR implode XXaccepts an input string and returns a symbol the name of XXwhich is the same as the input string. XX.IR explode XXis the corresponding function which accepts a symbol and XXreturns the string corresponding XXto the symbol's name. XX.PP XXThe function XX.IR arguments XXreturns the command line arguments, if any, in the order given; XXnormal arguments are returned as strings, options are returned XXas the pair \<option-char, string\>, where string is the XXvalue of the option, if any, or nil otherwise. XX.PP XX.IR trace XXis an output function: it is functionally identical to id, XXexcept that it only accepts strings as input. As a side effect, XXthe string is printed on the standard output with no XXquotes around it. The program cannot redirect the output to XXa file. XX.PP XXThe following functions all take as input a string representing XXa file name. XX.IR filetype XXreturns a symbol from the set \{none, empty, data, text, XXbinary\} if the file does not exist, has no data, contains XXa valid FP object, contains text, or contains non-textual XXcharacters, respectively. All data files could be read as XXtext files. XX.PP XX.IR readfile XXreturns the FP object read from the given file. XX.IR inputfile XXreturns a string holding the text that was read from the XXgiven file. XX XX.SH DIAGNOSTICS XXUnless -lnfp is used, programs check that the number XXof storage cells they allocated and returned was the same, XXand complain XXif that is not the case, i.e. if there was an error in the XXreference counting. XX.PP XXWhenever bottom is encountered, the stack is dumped to XXstderr (if -n and -lnfp were not used), XXtogether with the inputs to each of the functions on the XXstack. This can be a large amount of data. XX.PP XXThe function XX.IR checkpoint XXis functionally identical to the primitive XX.IR id XXbut outputs its argument to the output stream. This is helpful XXfor tracing data flow in functions. XX.PP XX.SH BUGS XX.PP XXPlease report any bugs to the author. XX.SH AUTHOR XXEd Biagioni SHAR_EOF if test 9433 -ne "`wc -c fpc.1`" then echo shar: error transmitting fpc.1 '(should have been 9433 characters)' fi echo shar: extracting fpc.c '(6698 characters)' sed 's/^XX//' << \SHAR_EOF > fpc.c XX/* fpc: fp to c translator XX */ XX XX#include <stdio.h> XX#include <strings.h> XX#include "fpc.h" XXextern FILE * fopen (); XXextern char * sprintf (); XXextern int errno; XXextern char * sys_errlist []; XXextern int sys_nerr; XX XX/* here comes all the "exported" stuff, mostly flags showing which XX switches were given on the command line */ XXFILE * outf; XXint makemain; /* this and the following used for flag settings: -m */ XXchar mainfn [MAXIDLEN]; /* -mfname: the main function, if any */ XXint verbose; /* -v: print fpc version, functions being done */ XXint useparms; /* -p: if program has parms, input is <> */ XXint rstring; /* -i: read input as string, not fp object */ XXint wstring; /* -o: write output as string, not fp object */ XXint redirout; /* -c: output is of form: <<device op data>*> */ XX/* Typical system-independent devices are graphic, turtle, bitmap. XX For graphic, ops such as circle and line (with corresponding data XX cx cy r, or x1 y1 x2 y2), are available. Similarly for turtle we XX have <turtle move 2> and <turtle turnto west>. Not implemented. */ XXint makeast; /* -a: The main function is used in an AST system */ XXint makedeb; /* -d: trace all functions during execution */ XXint makeee; /* -e: trace function entry/exit (no params,res) */ XXint check; /* -n: do not check for illegal inputs */ XXint printspace; /* -s: print how much space was used and returned */ XXchar tracefns [MAXIDS] [MAXIDLEN]; /* the functions to be traced (-t) */ XXint traceptr; /* the first free slot */ XX/* end of the exported variables */ XX XXstatic int dostdio = 1; /* only if no file name is given */ XX XXstatic int badexit = 0; /* if syntax error was found, return (1) at end */ XX XXstatic void resetglobals () XX{ XX outf = stdout; XX makemain = 0; XX mainfn [0] = '\0'; XX rstring = 0; XX wstring = 0; XX redirout = 0; XX makeast = 0; XX makedeb = 0; XX printspace = 0; XX makeee = 0; XX check = 1; XX traceptr = 0; XX verbose = 0; XX useparms = 0; XX} XX XXstatic void clrmains () XX{ XX rstring = 0; XX wstring = 0; XX redirout = 0; XX makeast = 0; XX useparms = 0; XX printspace = 0; XX} XX XXstatic char * fname = 0; XX XXint main (argc, argv) XXint argc; XXchar *argv[]; XX{ XX FILE *dataIn; XX int argind, len; XX char outname [256]; XX int swind; XX char errbuf [256]; /* used for sprintf's */ XX extern void newfname (); XX void closerror (); XX char * syserror (); XX XX resetglobals (); XX for (argind = 1; argind < argc; argind++) XX { XX if (argv [argind] [0] != '-') XX { XX dostdio = 0; /* at least one file was given */ XX if (! makemain) XX clrmains (); XX fname = argv [argind]; XX len = strlen (fname); XX if ((fname [len - 3] != '.') || XX (fname [len - 2] != 'f') || XX (fname [len - 1] != 'p')) /* wrong extension */ XX { XX (void) sprintf (errbuf, XX "error in source file name (%s): should end in .fp\n", XX fname); XX yyerror (errbuf); XX continue; XX } XX newfname (fname, outname); XX/* use newfname so whatever code generator is attached can decide how XX to call the file, if any */ XX dataIn = fopen (argv [argind], "r"); XX if (*outname != '\0') XX outf = fopen (outname, "w"); XX else XX outf = stdout; XX if ((dataIn == 0) || (outf == 0)) XX { XX (void) sprintf (errbuf, "error opening file %s: %s\n", XX (dataIn == 0) ? fname : outname, syserror ()); XX yyerror (errbuf); XX continue; XX } XX if (makemain && (mainfn [0] == '\0')) XX { XX (void) strcpy (mainfn, fname); XX mainfn [len - 3] = '\0'; XX } XX fpcFile (dataIn, fname, outname); XX if ((outf != stdout) && (fclose (outf) != 0)) XX closerror (outname); XX else if (fclose (dataIn) != 0) XX closerror (outname); XX resetglobals (); XX } XX else /* we are parsing a switch */ XX for (swind = 1; (argv [argind] [swind] != '\0'); swind++) XX { XX switch (argv [argind] [swind]) XX { XX case 'v': XX verbose = 1; XX (void) printf ("fpc 1.0\n"); XX break; XX case 'm': XX makemain = 1; XX if (argv [argind] [swind + 1] != '\0') XX/* function name is also given */ XX (void) strcpy (mainfn, (argv [argind]) + swind + 1); XX argv [argind] [swind + 1] = '\0'; /* to break out of the loop */ XX break; XX case 'a': XX makeast = 1; XX break; XX case 'p': XX useparms = 1; XX break; XX case 'i': XX rstring = 1; XX break; XX case 'o': XX wstring = 1; XX break; XX case 'c': XX redirout = 1; XX break; XX case 'd': XX makedeb = 1; XX if (! check) XX (void) fprintf (stderr, XX "option -n conflicts with -d, ignored\n"); XX check = 1; XX break; XX case 'e': XX makeee = 1; XX if (! check) XX (void) fprintf (stderr, XX "option -n conflicts with -e, ignored\n"); XX check = 1; XX break; XX case 'n': XX check = (makedeb || makeee); XX if (check) XX (void) fprintf (stderr, XX "option -n conflicts with -%c, ignored\n", XX ((makedeb) ? 'd' : 'e')); XX break; XX case 's': XX printspace = 1; XX break; XX case 't': XX (void) strcpy (tracefns [traceptr++], (argv [argind]) + swind + 1); XX argv [argind] [swind + 1] = '\0'; /* to break out of the loop */ XX break; XX default: XX (void) sprintf (errbuf, "unknown option -%c", XX argv [argind] [swind]); XX yyerror (errbuf); XX } XX } XX } XX if (dostdio) XX fpcFile (stdin, "user input", "screen output"); XX return (badexit); /* makefile will abort if something didn't compile */ XX} XX XXstatic char * syserror () XX{ XX char syserr [256]; XX XX if (errno < sys_nerr) XX strcpy (syserr, sys_errlist [errno]); XX else XX (void) sprintf (syserr, "undocumented error number %d", errno); XX return (syserr); XX} XX XXstatic void closerror (filename) XXchar * filename; XX{ XX char errbuf [256]; XX XX (void) sprintf (errbuf, "error closing file \"%s\": %s\n", XX filename, syserror ()); XX yyerror (errbuf); XX} XX XXfpcFile (fptr, inname, outname) XXFILE *fptr; XXchar * inname, * outname; XX{ XX extern FILE * yyin; XX void putfileheader (); XX void putfiletail (); XX XX putfileheader (inname, outname); XX yyin = fptr; XX yyparse (); XX putfiletail (); XX} XX XXint current_line = 1; XX XXset_line (s) XXchar * s; XX{ XX while (((*s > '9') || (*s < '0')) && (*s != '\0')) XX s++; XX if (*s == '\0') XX return; XX (void) sscanf (s, "%d", ¤t_line); XX} XX XXinc_line () XX{ XX current_line++; XX} XX XXyyerror (s) XXchar * s; XX{ XX extern char yytext []; XX XX puterror (s, yytext); XX} XX XXputerror (s, t) XXchar * s; XXchar * t; XX{ XX extern char funname []; XX extern int inerror; XX XX if (! inerror) XX { XX if (fname != 0) XX (void) fprintf (stderr, "\"%s\", ", fname); XX (void) fprintf (stderr, "line %d: ", current_line); XX (void) fprintf (stderr, "%s in function %s", s, funname); XX if (*t != '\0') XX (void) fprintf (stderr, ", token is %s", t); XX (void) fprintf (stderr, "\n"); XX } XX inerror = 1; XX badexit = 1; XX} SHAR_EOF if test 6698 -ne "`wc -c fpc.c`" then echo shar: error transmitting fpc.c '(should have been 6698 characters)' fi echo shar: extracting fpc.h '(1357 characters)' sed 's/^XX//' << \SHAR_EOF > fpc.h XX/* fpc.h: defines some constants for array declarations */ XX XX#ifndef MAXIDS XX#define MAXIDS 256 /* the maximum number of identifiers in a table */ XX#endif XX XX#ifndef MAXIDLEN XX#define MAXIDLEN 64 /* max. number of characters in an identifier */ XX#endif XX XX/* here comes all the "exported" stuff, mostly flags showing which XX switches were given on the command line */ XXextern FILE * outf; XX XXextern int makemain; /* -m: make main calling the file name */ XXextern char mainfn [MAXIDLEN]; /* -mfname: the main function, if any */ XX XXextern int verbose; /* -v: print fpc version, functions being done */ XX XXextern int rstring; /* -i: read input as string, not fp object */ XXextern int wstring; /* -o: write output as string, not fp object */ XXextern int redirout; /* -c: output is of form: <<file data>*> */ XXextern int makeast; /* -a: The main function is used in an AST system */ XXextern int useparms; /* -p: if program has parms, input is <> */ XX XXextern int makedeb; /* -d: trace all functions during execution */ XXextern int makeee; /* -e: print functions being called/returned */ XXextern int check; /* -n: check for illegal arguments */ XXextern int printspace; /* -s: print how much space was used and returned */ XX XXextern char tracefns [MAXIDS] [MAXIDLEN]; /* the functions to be traced (-t) */ XXextern int traceptr; /* the first free slot */ XX XX/* end of the exported variables */ SHAR_EOF if test 1357 -ne "`wc -c fpc.h`" then echo shar: error transmitting fpc.h '(should have been 1357 characters)' fi echo shar: extracting stdfp.h '(1038 characters)' sed 's/^XX//' << \SHAR_EOF > stdfp.h XX/* stdfp.h: target file generated partly by fpc from source tmp.fp */ XX XX#define FALSEOBJ 0 XX#define TRUEOBJ 1 XX#define INTCONST 2 XX#define FLOATCONST 3 XX#define ATOMCONST 4 XX#define CHARCONST 5 XX#define NILOBJ 6 XX#define VECTOR 7 XX XXtypedef struct fp_object * fp_data; XX XXstruct fp_object XX{ XX short fp_type; XX short fp_ref; XX union XX { XX long fp_int; XX int fp_char; /* long for reasons of alignment in constant definitions */ XX char * fp_atom; XX float fp_float; XX fp_data fp_next; XX } fp_header; XX fp_data fp_entry; XX}; XX XXstruct fp_constant XX{ XX short fp_type; XX short fp_ref; XX long fp_value; XX fp_data fp_entry; XX}; XX XXstruct fp_floatc XX{ XX short fp_type; XX short fp_ref; XX float fp_value; XX}; XX XXstruct fp_charc XX{ XX short fp_type; XX short fp_ref; XX int fp_value; XX}; XX XXstruct stackframe XX{ XX char * st_name; XX fp_data st_data; XX struct stackframe * st_prev; XX}; XX XX#define inc_ref(d) ((d)->fp_ref++) XX#define dec_ref(d) if (((d)->fp_type == VECTOR) && \ XX (--((d)->fp_ref) <= 0)) returnvect (d) XX#define abs(n) ((n) < 0 ? - (n) : (n)) XX SHAR_EOF if test 1038 -ne "`wc -c stdfp.h`" then echo shar: error transmitting stdfp.h '(should have been 1038 characters)' fi echo shar: extracting fp.h '(997 characters)' sed 's/^XX//' << \SHAR_EOF > fp.h XX/* fp.h: header file for all fp programs translated to C using fpc. XX * declares types, defines, some externs XX */ XX XX#include "stdfp.h" XX XX/* #define MAXINT 0x7FFF /* for 16-bit fp_ints */ XX#define MAXINT 0x7FFFFFFF /* for 32-bit fp_ints */ XX/* #define MAXINT 0x7FFFFFFFFFFFFFFF /* for 64-bit fp_ints */ XX XX#define FNAMELEN 256 /* on UNIX, file names are under 256 chars */ XX XX/* this type is just for determining the size of a constant object */ XXstruct fp_const_size XX { XX short fp_const_type; XX short fp_const_ref; XX union {int fp_const_constant; XX char * fp_const_atom; } XX fp_const_header; XX }; XX XXstruct fp_atom XX{ XX short fp_type; XX short fp_ref; XX char * fp_atom; XX}; XX XX/* these values are used by the storage manager */ XX#define CONSTSIZE (sizeof (struct fp_const_size)) XX#define VECTSIZE (sizeof (struct fp_object)) XX XX#define fp_nil (& nilobj) XX#define fp_true (& tobj) XX#define fp_false (& fobj) XX XXextern struct fp_object nilobj; XXextern struct fp_object tobj; XXextern struct fp_object fobj; SHAR_EOF if test 997 -ne "`wc -c fp.h`" then echo shar: error transmitting fp.h '(should have been 997 characters)' fi echo shar: extracting fpg.l '(1085 characters)' sed 's/^XX//' << \SHAR_EOF > fpg.l XX%% XXDef { return (Def); } XX"->" { return (Then); } XX";" { return (Else); } XXo { return (Compose); } XXaa { return (Alpha); } XX"\\/" { return (Tree); } XX"/" { return (Insert); } XX"\\" { return (Rinsert); } XX"," { return (','); } XX"[" { return ('['); } XX"]" { return (']'); } XX"(" { return ('('); } XX")" { return (')'); } XX"<" { return ('<'); } XX">" { return ('>'); } XX"_" { return ('_'); } XXbu { return (Bu); } XXbur { return (Bur); } XXwhile { return (While); } XX"+" { return ('+'); } XX"*" { return ('*'); } XX"div" { return (Div); } XX"=" { return ('='); } XX"<=" { return (Leq); } XX">=" { return (Geq); } XX"!=" { return (Noteq); } XXT { return (TrueConst); } XXF { return (FalseConst); } XX[a-zA-Z][a-zA-Z0-9]* { return (Symbol); } XX[0-9]+r { return (Rsel); } XX"-"[0-9]+\.[0-9]* { return (Float); } XX[0-9]+\.[0-9]* { return (Float); } XX"-"[0-9]+ { return (Sel); } XX[0-9]+ { return (Sel); } XX"-" { return ('-'); } XX\"[^"]*\" { return (String); } XX\'\\. { return (CharConst); } XX\'. { return (CharConst); } XX^#\ [0-9]+\ \".*\" { set_line (yytext); } XX#.*\n { inc_line (); } XX\n { inc_line (); } XX. ; SHAR_EOF if test 1085 -ne "`wc -c fpg.l`" then echo shar: error transmitting fpg.l '(should have been 1085 characters)' fi echo shar: extracting fpg.y '(3413 characters)' sed 's/^XX//' << \SHAR_EOF > fpg.y XX%start FPProgram XX%token Def Symbol Sel Rsel Then Else Compose Alpha Insert Rinsert Tree XX%token Bu Bur While XX%token ',' '[' ']' '(' ')' '<' '>' '_' '+' '-' '*' '=' XX%token Div Geq Leq Noteq TrueConst FalseConst String CharConst Float XX%% XX XXFPProgram: FPDef XX | FPProgram FPDef XX ; XX XXFPDef: Def XX Symbol { parsefnstart (yytext); } XX Toplev { parsefnend (); } XX ; XX XXToplev: Comp XX Then XX { parsethen (); } XX Toplev XX Else XX { parseelse (); } XX Toplev XX { parseendif (); } XX | Bu XX { parsebustart (0); } XX Toplev XX { parsebufun (); } XX Object XX { parsebuobj (); } XX | Bur XX { parsebustart (1); } XX Toplev XX { parsebufun (); } XX Object XX { parsebuobj (); } XX | While XX { whilestart (); } XX Toplev XX { whilepred (); } XX Toplev XX { whilefun (); } XX | Comp XX ; XX XXComp: Expr XX | Expr XX Compose XX { parsecomp (); } XX Comp XX ; XX XXExpr: '(' XX { startcomp (); } XX Toplev XX { endcomp (); } XX ')' XX | Alpha XX Expr XX { parseaa (); } XX | '[' ']' XX { parsenil (); } XX | '[' XX { parseconstr (); } XX ToplevList XX ']' XX { constrnext (); endconstr (); } XX | Insert XX { parseinsert (0); } XX Expr XX { endinsert (); } XX | Rinsert XX { parseinsert (1); } XX Expr XX { endinsert (); } XX | Tree XX { parseinsert (2); } XX Expr XX { endinsert (); } XX | '_' Object XX | Sel XX { parsesel (yytext, 0); } XX | Rsel XX { parsesel (yytext, 1); } XX | Symbol XX { parsefncall (yytext); } XX | '+' XX { parsefncall ("plus"); } XX | '-' XX { parsefncall ("minus"); } XX | '*' XX { parsefncall ("times"); } XX | Div XX { parsefncall ("div"); } XX | '=' XX { parsefncall ("eq"); } XX | '<' XX { parsefncall ("less"); } XX | '>' XX { parsefncall ("greater"); } XX | Geq XX { parsefncall ("gequal"); } XX | Leq XX { parsefncall ("lequal"); } XX | Noteq XX { parsefncall ("notequal"); } XX ; XX XXToplevList: Toplev XX | ToplevList ',' XX { constrnext (); } XX Toplev XX XXObject: TrueConst XX { consttrue (); } XX | FalseConst XX { constfalse (); } XX | Sel XX { constnum (yytext); } XX | Symbol XX { constsym (yytext); } XX | String XX { conststr (yytext); } XX | CharConst XX { constchr (yytext); } XX | Float XX { constreal (yytext); } XX | '<' '>' XX { parsenil (); } XX | '<' XX { liststart (); } XX ObjList XX '>' XX { listend (); } XX | Def XX { constsym ("Def"); } XX | Alpha XX { constsym ("aa"); } XX | Compose XX { constsym ("o"); } XX | Div XX { constsym ("div"); } XX | Bu XX { constsym ("bu"); } XX | Bur XX { constsym ("bur"); } XX | While XX { constsym ("while"); } XX ; XX XXObjList: Object XX { listnext (); } XX | ObjList ',' XX Object XX { listnext (); } XX XX%% XX XX#include "lex.yy.c" XX XX#undef YYMAXDEPTH XX#define YYMAXDEPTH 2048 XX XXvoid parsefnstart (); XXvoid parsefnend (); XXvoid parsethen (); XXvoid parseelse (); XXvoid parseendif (); XXvoid parsebustart (); XXvoid parsebufun (); XXvoid parsebuobj (); XXvoid whilestart (); XXvoid whilepred (); XXvoid whilefun (); XXvoid parsecomp (); XXvoid startcomp (); XXvoid endcomp (); XXvoid parseaa (); XXvoid parseconstr (); XXvoid constrnext (); XXvoid endconstr (); XXvoid parseinsert (); XXvoid endinsert (); XXvoid parsesel (); XXvoid parsefncall (); XXvoid parsenil (); XXvoid consttrue (); XXvoid constfalse (); XXvoid constnum (); XXvoid constsym (); XXvoid conststr (); XXvoid constchr (); XXvoid constreal (); XXvoid liststart (); XXvoid listnext (); XXvoid listend (); XX SHAR_EOF if test 3413 -ne "`wc -c fpg.y`" then echo shar: error transmitting fpg.y '(should have been 3413 characters)' fi # End of shell archive exit 0 -- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net. Use a domain-based address or give alternate paths, or you may lose out.