Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SDCL, part 01/03

11 views
Skip to first unread message

mun...@dmc.com

unread,
Jun 7, 1995, 3:00:00 AM6/7/95
to
Submitted-by: mun...@dmc.com
Posting-number: Volume 7, Issue 55
Archive-name: sdcl/part01

02-Jun-95 Dick Munroe mun...@acornsw.com

Changes:

1. added an on statusCondition { statements } block to sdcl.
2. Variable substitution ('varable') and quoted strings are preserved.
3. Loops emit $NEXT and $BREAK variables which are labels to be used
by DCL commands such as read which have /ERROR processing.

Use it in good health.

Dick Munroe
--------------------------------------------------------------------------------
This directory contains the SDCL (Structured DCL) compiler files. These
include the source files and the documentation files.

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_UNPACK_VERIFY"))'
$!
$! This archive created:
$! Name : SDCL
$! By : mun...@DMC.COM
$! Date : 2-JUN-1995 09:36:26.57
$! Using: VMS_SHARE 8.5-1, (C) 1993 Andy Harper, Kings College London UK
$!
$! Credit is due to these people for their original ideas:
$! James Gray, Michael Bednarek
$!
$! To unpack this archive:
$!+ Ensure that all parts are present, (3 at about 100 Blocks each).
$!+ Append all parts together to form one larger file.
$! Minimum of VMS 4.4 (VAX) / OpenVMS 1.0 (Alpha) is required.
$! Remove the headers of the first part, up to `cut here' line.
$! Execute file as a command procedure.
$!
$! The following file(s) will be created after unpacking:
$! 1. [.REF-LIB]AAAREADME.TXT;2
$! 2. [.REF-LIB]BUN.DCL;2
$! 3. [.REF-LIB]DEFS.H;5
$! 4. [.REF-LIB]LASER.DCL;3
$! 5. [.REF-LIB]LEX.C;4
$! 6. [.REF-LIB]MAKEFILE.COM;1
$! 7. [.REF-LIB]OUTPUT.C;4
$! 8. [.REF-LIB]SDCL.C;2
$! 9. [.REF-LIB]SDCL.MMS;4
$! 10. [.REF-LIB]SDCL.RNO;2
$! 11. [.REF-LIB]STACK.C;3
$! 12. [.REF-LIB]STMT.C;13
$! 13. [.REF-LIB]TCODES.H;5
$!
$ set="set"
$ set symbol/scope=(nolocal,noglobal)
$ f="SYS$SCRATCH:."+f$getjpi("","PID")+";"
$ if f$trnlnm("SHARE_UNPACK") .nes. "" then $ -
f=f$parse("SHARE_UNPACK_TEMP",f)
$ e="write sys$error ""%UNPACK"", "
$ w="write sys$output ""%UNPACK"", "
$ if .not. f$trnlnm("SHARE_UNPACK_LOG") then $ w = "!"
$ if f$getsyi("CPU") .gt. 127 then $ goto start
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto start
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$unpack:subroutine!P1=file,P2=chksum,P3=attrib,P4=size,P5=fileno,P6=filetotal
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'"
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn' File skipped"
$ delete 'f'*
$ exit
$dirok:
$ x=f$search(P1)
$ if x .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped"
$ delete 'f'*
$ exit
$file_absent:
$ w "-I-UNPACK, Unpacking ", P5, " of ", P6, " - ", P1, " - ", P4, " Blocks"
$ n=P1
$ if P3 .nes. "" then $ n=f
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT/NOJOURNAL 'f'/OUT='n'
PROCEDURE GetHex(s,p)LOCAL x1,x2;x1:=INDEX(t,SUBSTR(s,p,1))-1;x2:=INDEX(t,
SUBSTR(s,p+1,1))-1;RETURN 16*x1+x2;ENDPROCEDURE;PROCEDURE SkipPartsep LOCAL m;
LOOP m:=MARK(NONE);EXITIF m=END_OF(CURRENT_BUFFER);DELETE(m);EXITIF INDEX(
ERASE_LINE,"-+-+-+-+-+-+-+-+")=1;ENDLOOP;ENDPROCEDURE;
PROCEDURE ProcessLine LOCAL c,s,l,b,n,p;s := ERASE_LINE;c := SUBSTR(s,1,1);s :=
s-c;IF c = "X" THEN SPLIT_LINE; ENDIF;MOVE_HORIZONTAL(-1);l := LENGTH(s);p :=
1;LOOP EXITIF p > l;c := SUBSTR(s,p,1);p := p+1;CASE c FROM ' ' TO '`' ['`']
: COPY_TEXT(ASCII(GetHex(s,p))); p:=p+2;[' ']: p:=p+1;[INRANGE,OUTRANGE]
: COPY_TEXT(c);ENDCASE;ENDLOOP;ENDPROCEDURE;PROCEDURE Decode(b)LOCAL m;
POSITION(BEGINNING_OF(b));LOOP m:=MARK(NONE);EXITIF m=END_OF(b);DELETE(m);
IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+-")=1 THEN SkipPartSep;ELSE ProcessLine;
MOVE_HORIZONTAL(1);ENDIF;ENDLOOP;ENDPROCEDURE;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);t:="0123456789ABCDEF";f:=GET_INFO(
COMMAND_LINE,"file_name");o:=CREATE_BUFFER(f,f);Decode(o);WRITE_FILE(o,
GET_INFO(COMMAND_LINE,"output_file"));QUIT;
$ if p3 .eqs. "" then $ goto dl
$ open/write fdl &f
$ write fdl "RECORD"
$ write fdl P3
$ close fdl
$ w "-I-CONVRFM, Converting record format to ", P3
$ convert/fdl='f' 'f'-1 'f'
$ fa=f$getdvi(f$parse(f),"ALLDEVNAM")
$ Pa=f$getdvi(f$parse(P1),"ALLDEVNAM")
$ if fa .eqs. Pa then $ rename &f 'f$parse(P1)'
$ if fa .nes. Pa then $ copy &f 'f$parse(P1)'
$dl: delete 'f'*
$ checksum 'P1'
$ if checksum$checksum .nes. P2 then $ -
e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ exit
$ endsubroutine
$start:
$!
$ create 'f'
X02-Jun-95`20Dick`20Munroe`20mu...@acornsw.com
X
XChanges:
X
X1.`20added`20an`20on`20statusCondition`20`7B`20statements`20`7D`20block`20to
V`20sdcl.
X2.`20Variable`20substitution`20('varable')`20and`20quoted`20strings`20are`20pr
Veserved.
X3.`20Loops`20emit`20$NEXT`20and`20$BREAK`20variables`20which`20are`20labels`20
Vto`20be`20used
Xby`20DCL`20commands`20such`20as`20read`20which`20have`20/ERROR`20processing.
X
XUse`20it`20in`20good`20health.
X
XDick`20Munroe
X------------------------------------------------------------------------------
V--
XThis`20directory`20contains`20the`20SDCL`20(Structured`20DCL)`20compiler`20fil
Ves.`20These
Xinclude`20the`20source`20files`20and`20the`20documentation`20files.`20Here`20i
Vs`20what`20you
Xshould`20have`20if`20the`20tape`20restore`20worked`20ok:
X
XAAAREADME.TXT`09`09The`20file`20you`20are`20reading
X
XBUN.DCL`09`09`09Example`20of`20structured`20DCL`20code
X
XDEFS.H,`20LEX.C,`20OUTPUT.C,`20SDCL.C,`20STACK.C,`20STMT.C,
X`20`20TCODES.H`09`09Files`20with`20C`20source`20of`20SDCL`20compiler
X
XLASER.DCL,LASER.COM`09another`20example`20of`20SDCL`20input`20and`20generated
V`20ouput.
X
XMAKEFILE.COM`09`09Command`20procedure`20that`20makes`20SDCL.EXE
X
XSDCL.EXE`09`09The`20executable`20file`20created`20under`20VMS`204.1
X
XSDCLPROJ.DOC`09`09A`20detailed`20documentation`20on`20the`20inner`20workings
X`09`09`09of`20SDCL`20compiler.`20Formatted`20with`20UNIX`20nroff.
X`09`09`09Can`20be`20printed`20on`20any`20printer.
XSDCLPROJ.NR`09`09UNIX`20nroff`20source`20of`20SDCL.DOC
X
XSDCLPROJ.TEX`20`20`20`20`20`20`20`20`20`20`20`20The`20detailed`20documentation
V`20in`20TeX`20input`20form.
XMYFORMAT.TEX`20`20`20`20`20`20`20`20`20`20`20`20File`20included`20in`20SDCL.TE
VX`20when`20latter`20is`20run
X`09`09`09through`20TeX
X
XSDCL.MEM`09`09A`20brief`20guide`20to`20SDCL`20and`20and`20how`20to`20invoke`20
Vthe
X`09`09`09compiler
XSDCL.RNO`09`09DSR`20source`20for`20SDCL.MEM
X
XTo`20get`20SDCL`20up`20and`20running,`20you`20need`20the`20DEC`20C`20compiler.
V`20If`20you`20have`20it,
Xrun`20the`20command`20procedure`20in`20MAKEFILE.COM`20and`20then`20install`20S
VDCL`20as`20a
Xforeign`20command:
X
X`09$`20@makefile
X`09$!`20now`20in`20your`20login.com,`20add`20the`20line
X`09$`20sdcl`20:==`20$`5Bdirectory-path`5D:sdcl
X`09$!`20replace`20"directory-path"`20with`20the`20complete`20directory
X`09$!`20path`20name`20to`20where`20the`20sdcl.exe`20resides.
X
XIf`20you`20donot`20have`20the`20C`20compiler,`20you`20can`20simply`20use`20the
V`20executable`20
XSDCL.EXE`20included.`20It`20was`20created`20under`20VMS`204.1.`20
X
XI`20have`20compiled`20the`20sources`20with`20the`20UNIX`20C`20compiler`20on`20
Vthe`20SUN`20workstation
Xand`20HP-UX.`20The`20program`20runs`20without`20any`20change.`20This`20implies
V`20that`20you`20donot`20
Xhave`20the`20DEC`20C`20compiler,`20try`20using`20the`20DECUS`20C`20compiler.
V`20This`20may,`20hopefully
Xwork.
X
XI`20will`20welcome`20any`20comments,`20bug`20reports,`20fixes`20and`20any`20ot
Vher`20suggestions.
XIf`20you`20make`20any`20enhancements,`20please`20let`20me.
X
X`09Sohail`20Aslam
X`09Computer`20Science`20Department
X`09University`20of`20Colorado`20at`20Colorado`20Springs
X`09P.O.Box`207150
X`09Colorado`20Springs,`20CO`2080933-7150
X`09(303)`20593-3332
X
$ call unpack [.REF-LIB]AAAREADME.TXT;2 1147734313 "" 5 1 13
$!
$ create 'f'
X$`20!/*`20`20Bun`20--`20VMS`20DCL`20command`20procedure`20to`20bundle`20files
V`20into`20`20`20`20`20distribution`20package`20which`20can`20then`20be`20unbun
Vdled`20`20`20*/
X$`20!/*`20`20`20`20`20`20`20`20`20using`20UNIX`20shell.`20The`20output`20will
V`20be`20placed`20on`20the`20*/
X$`20!/*`20`20`20`20`20`20`20`20`20on`20the`20file`20given`20as`20the`20arg`20t
Vo`20this`20procedure`20`20`20`20`20*/
XIF(`20p1`20.eqs.`20""`20)`7B
X`20`20`20`20write`20sys$output`5C
X`20`20`20`20`09"Usage:`20bundle`20outfile`20(outfile`20will`20receive`20bundle
V)"
X`20`20`20`20exit`20`20`20`20/*`20DCL`20exit`20*/
X`7D
X/*`20if`20the`20file`20exists,`20open`20it,`20otherwise`20create`20it`20*/
Xopen/write/err=out_err`20fout`20'p1'
Xexist`20:=`20"TRUE"
Xout_err:
XIf(`20exist`20.nes.`20"TRUE"`20)`7B
X`20`20`20`20create`20'p1'
X`20`20`20`20open/write/err=give_up`20fout`20'p1'
X`7D
Xq`20:=`20"'"
Xfor(`20rc`20=`200;`20;`20)`7B`20`20`20`20/*`20no`20condition,`20no`20reinit`20
V*/
X`20`20`20`20inquire`20infile`20"File?`20"
X`20`20`20`20if(`20infile`20.eqs.`20""`20)
X`09break`20`20`20`20`20`20`20`20/*`20time`20to`20wrapup`20*/
X`20`20`20`20open/read/err=infile_err`20inf`20'infile'
X`20`20`20`20write`20fout`20"echo`20''infile'`201>`262"
X`20`20`20`20write`20fout`20"cat`20>''infile'`20<<''q'END`20OF`20''infile'''q'"
V
X`20`20`20`20rc`20=`20rc`20+`202`20`20
X`20`20`20`20done`20=`200
X`20`20`20`20while(`20done`20.eq.`200`20)`7B
X`09read/end=eof`20inf`20line
X`09write`20`20`20`20`20`20`20fout`20line
X`09rc`20=`20rc`20+`201
X`20`20`20`20`7D
X`20`20`20`20eof:`20close`20inf
X`20`20`20`20write`20fout`20"END`20OF`20''infile'"
X`20`20`20`20rc`20=`20rc`20+`201
X`20`20`20`20next
X`20`20`20`20/*
X`20`20`20`20`20come`20here`20if`20trouble`20opening`20'infile'
X`20`20`20`20*/
X`20`20`20`20infile_err:`20write`20sys$output`20`5C
X`09`09`20`20`20"error`20opening`20''infile'"
X`7D
Xif(`20rc`20.gt.`200`20)`7B
X`20`20`20`20write`20sys$output`20"''rc'`20records`20written`20to`20''p1'"
X`20`20`20`20close`20fout
X`7D
Xelse
X`20`20`20`20write`20sys$output`20"0`20records`20written`20out"
Xexit
$ call unpack [.REF-LIB]BUN.DCL;2 1041390686 "" 3 2 13
$!
$ create 'f'
X/*
X`20*`09This`20file`20contains`20the`20character`20class`20and`20token`20code
X`20*`09definitions`20that`20are`20used`20globally`20throuhout`20all`20files
X`20*`09used`20in`20the`20sdcl`20program.`20`20Hence`20all`20C`20source`20files
V
X`20*`09include`20this`20file.
X`20*
X**`200.001`20Dick`20Munroe`2003-Sep-90
X**`09Add`20DOLLAR`20as`20a`20special`20identifier.
X**
X**`200.002`20Dick`20Munroe`2015-Sep-90
X**`09Add`20parsing`20of`20identifier`20substitution`20in`20quoted`20strings.
X**
X**`20`200.003`20Dick`20Munroe`2030-May-95
X**`09Add`20parsing`20of`20identifier`20substitution.
X**
X**`20`200.004`20Dick`20Munroe`2001-Jun-95
X**`09Add`20ON`20blocks.
X**/
X
X#define`20`20MAXTOKENLEN`09133
X#define`20`20MAXCONDLEN`20`20`20`20`20255
X#define`20`20TRUE`09`09`20`201
X#define`20`20FALSE`09`09`20`200
X
X/*`20First,`20defines`20to`20avoid`20using`20numbers`20for`20charclasses.`20*/
V
X
X#define`20`20LETTER`20`20`20`20`200`20`20/*`20`5BA-Za-z_$`5D`20(notice`20_`20a
Vnd`20$`20are
X`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
V`20`20`20`20`20`20`20`20`20`20`20`20`20considered`20to`20be`20characters)`20*/
V
X#define`20`20DIGIT`20`20`20`20`20`201`20`20/*`20`5B0-9`5D`20*/
X#define`20`20ONECHAR`20`20`20`202`20`20/*`20()`7B`7D`5B`5D.;:#%?`20*/
X#define`20`20SLASH`20`20`20`20`20`203`20`20/*`20/`20`20*/
X#define`20`20STAR`20`20`20`20`20`20`204`20`20/*`20*`20*/
X#define`20`20WHITESPACE`205`20`20/*`20blank,tab,non-printing`20chars`20*/
X
X#define`20`20EOL`20`20`20`20`20`20`20`206`20`20/*`20/n`20*/
X#define`20`20DQUOTE`20`20`20`20`207`20`20/*`20"`20`20*/
X#define`20`20ENDFILE`20`20`20`208`20
X#define`09`20ERR`09`20`20`20`209
X#define`20`20SUBSTITUTE`2010`20/*`20'`20`20*/
X
X/*`20Use`20defines`20to`20set`20up`20token`20codes.`20`20*/
X
X#define`20`20IF`20`20`20`20`20`200`20`20/*`20keywords`20first,`20if`20*/
X#define`20`20ELSE`20`20`20`201
X#define`20`20WHILE`20`20`202
X#define`20`20FOR`20`20`20`20`203
X#define`20`20BREAK`20`20`204
X#define`20`20DO`20`20`20`20`20`2050`20`20`20/*`20this`20was`20added`20later`20
V*/
X#define`09`20ON`09`2051
X#define`20`20THEN`09`2052
X#define`09`20ON_WARNING`2053
X#define`09`20ON_ERROR`2054
X#define`09`20ON_SEVERE_ERROR`2055
X#define`09`20ON_CONTROL_Y`2056
X
X#define`20`20NEXT`20`20`20`205
X#define`20`20ID`20`20`20`20`20`206`20`20
X
X/*`20
X`20*`20`20If`20an`20identifier`20is`20not`20a`20keyword`20it`20might`20be`20on
Ve`20
X`20*`20`20of`20the`20following`20special`20single`20characters...`20
X`20*
X`20*/
X
X#define`20`20OPAREN`20`207
X#define`20`20CPAREN`20`208
X#define`20`20OBRACE`20`209
X#define`20`20CBRACE`20`2010
X#define`09`20SEMICOLON`20`2019
X#define`20`20BANG`2020
X#define`20`20POUND`2021
X#define`20`20PERCENT`2022
X#define`20`20AND`2023
X#define`20`20QUOTE`2024
X#define`20`20PLUS`2025
X#define`20`20COMMA`2026
X#define`20`20MINUS`2027
X#define`20`20DOT`2028
X#define`20`20COLON`2029
X#define`20`20LT`2030
X#define`20`20EQUAL`2031
X#define`20`20GT`2032`20
X#define`20`20QUESTION`2033
X#define`20`20AT`2034
X#define`20`20OBRACKET`2035
X#define`20`20BACKSLASH`2036
X#define`20`20CBRACKET`2037
X#define`20`20CIRCUMFLEX`2038
X#define`20`20GRAVE`2039
X#define`20`20VERTICAL`2040
X#define`20`20TILDE`2041
X#define`20`20DOLLAR`2042
X
X/*`20otherwise`20it`20is`20a`20single`20character.`20*/
X
X#define`20`20SCHAR`20`20`2011`20`20
X
X/*`20Blanks,tab,non-printing`20characters`20*/
X
X#define`20`20COMMENT`2012
X#define`20`20WSPACE`20`2013`20
X#define`20`20NEWLINE`2014
X#define`20`20FILEEND`2015
X#define`20`20STRING`20`2016`20`20/*`20"...."`20*/
X#define`20`20ERROR`20`20`2017
X#define`20`20INTEGER`2018
$ call unpack [.REF-LIB]DEFS.H;5 812794458 "" 6 3 13
$!
$ create 'f'
X/*`20print`20TeX`20DVI`20file`20on`20the`20LN03`20laser`20printer.`20The`20que
V`20is`20defined`20by`20the`20
X`20`20`20symbol`20LN03QUE.
X*/
Xbabble`20:=`20write`20sys$output
X
Xif(`20p1`20.eqs.`20"?"`20)`7B
Xtype`20sys$input
X#`20`20`20Usage:
X#`20`20`20`20`20`20`20laser`20file`20-nc`20-np`20-f`20s=n`20n=pcnt`20h=hoffset
V`20v=voffset`20p=totalpages`20b=batchsize
X#
X#`20`20`20where
X#`09file`20`20`20`20`20`20`20`20`20is`20the`20file`20created`20after`20TeXing
V`20or`20from`20a`20previous`20
X#`09`09`20`20`20`20`20laser`20command.`20Specify`20filename`20but`20no`20exten
Vsion`20if
X#`09`09`20`20`20`20`20it`20is`20.DVI`20files,`20specify`20the`20extension`20if
V`20you`20want
X#`09`09`20`20`20`20`20to`20simply`20print`20a`20file.
X#`09
X#`09-nc`20`09`20`20`20`20`20Donot`20run`20the`20file`20thru`20DVI`20to`20LN03
V`20conversion`20step
X#`09-np`09`20`20`20`20`20Donot`20submit`20the`20file`20to`20the`20laser`20prin
Vter`20queue
X#`09-f`09`20`20`20`20`20cause`20print/feed`20command`20instead`20of`20print/no
Vfeed`20which
X#`09`09`20`20`20`20`20is`20the`20default
X#`09s=n`09`20`20`20`20`20start`20processing`20.DVI`20file`20at`20this`20page
X#`09n=pcnt`20`20`20`20`20`20`20number`20of`20pages`20to`20process`20starting
V`20with`20the`20page`20
X#`09`09`20`20`20`20`20number`20specified`20with`20the`20"s=n"`20option
X#`09h=hoffset`20`20`20`20Move`20all`20output`20right`20by`20offset`20(specify
V`20in`20pts
X#`09`09`20`20`20`20`20300`20pts`20=`201inch`20)
X#`09v=voffset`20`20`20`20Insert`20vertical`20offset.
X#`09`09`20`20`20`20`20Note:`20hoffset`20and`20voffset`20are`20*ADDED*`20to`20T
VeX`20offsets
X#
X#`09p=totalpages`20Total`20number`20of`20pages`20in`20the`20document
X#`09b=batchsize`20`20Print`20document`20in`20batches`20of`20size`20"batchsize"
V`20pages
X#`09`09`20`20`20`20`20Ouput`20is`20placed`20in`20.LN3_1,`20.LN3_2`20etc`20for
V`20each`20batch
Xexit
X`7D
X
Xfeed`20:=`20"/NOFEED"
Xsend`20:=`20"YES"
Xconv`20:=`20"YES"
Xln03que`20:=`20"ttf5:"`20`20`20/*`20change`20this`20for`20your`20system`20*/
Xsp`20`20`20:=`20""
Xpcnt`20:=`20""
Xbugp`20=`202`20`20`20`20`20`20`20`20`20`20`20`20/*`20even`20integer`20is`20fal
Vse`20*/
Xhor`20:=`20"/h=0"
Xver`20:=`20"/v=0"
Xtotal_pages`20=`200`20`20`20`20`20/*`20print`20entire`20document`20as`20one`20
Vbatch`20*default*`20*/
X
Xfor(`20count`20=`202;`20p'count'`20.nes.`20"";`20count`20=`20(count`20+`201)
V`20)`7B
X`09if(`20p'count'`20.eqs.`20"-D"`20)`7B
X`09`20`20`20`20bugp`20=`201`09/*`20odd`20integer`20is`20true`20*/
X`09`20`20`20`20next`20`20`20`20`20`20`20`20/*`20go`20to`20next`20parameter`20*
V/
X`09`7D
X
X`09if(`20bugp`20)`7B
X`09`20`20`20`20val`20=`20f$string(`20p'count')
X`09`20`20`20`20babble`20"DEBUG:`20parameter`20''count':`20''val'"
X`09`7D
X
X`09if(`20p'count'`20.eqs.`20"-NP"`20)`20`20`20
X`09`20`20`20`20send`20:=`20"NO"`09/*`20don't`20send`20to`20printer`20*/
X`09else`20if(`20p'count'`20.eqs.`20"-NC"`20)
X`09`20`20`20`20conv`20:=`20"NO"`09/*`20no`20dvi`20to`20ln3`20*/
X`09else`20if(`20p'count'`20.eqs.`20"-F"`20)
X`09`20`20`20`20feed`20:=`20""`09`09/*`20do`20a`20feed`20*/
X`20`20`20`20`20`20`20`20else`20`7B`20`20`20`20`20`20`20`20`20`20`20`20`20`20
V`20
X`09`20`20`20`20val`20=`20f$string(`20p'count')
X`20`20`20`20`20`20`20`20`20`20`20`20fc`20`20=`20f$extract(`200,1,val)
X`09`20`20`20`20pval`20=`20f$extract(`202,`20f$length(val)-2,`20val`20)
X
X`09`20`20`20`20if(`20fc`20.eqs.`20"S"`20)`7B
X`09`09sp`20:=`20"/"'val'
X`09`20`20`20`20`20`20`20`20if(`20bugp`20)
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"DEBUG:`20startpage`20''sp'"
X`20`20`20`20`20`20`20`20`20`20`20`20`7D
X`09`20`20`20`20else`20if(`20fc`20.eqs.`20"N"`20)`7B
X`09`09pcnt`20:=`20"/"'val'
X`09`20`20`20`20`20`20`20`20if(`20bugp`20)
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"DEBUG:`20pagecount`20''pcnt'"
V
X`20`20`20`20`20`20`20`20`20`20`20`20`7D
X`09`20`20`20`20else`20if(`20fc`20.eqs.`20"H"`20)`7B
X`09`09hor`20:=`20"/"'val'
X`09`20`20`20`20`20`20`20`20if(`20bugp`20)
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"DEBUG:`20hoffset`20''hor'"
X`09`20`20`20`20`7D
X`09`20`20`20`20else`20if(`20fc`20.eqs.`20"V"`20)`7B
X`09`09ver`20:=`20"/"'val'
X`09`20`20`20`20`20`20`20`20if(`20bugp`20)
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"DEBUG:`20voffset`20''ver'"
X`09`20`20`20`20`7D
X`09`20`20`20`20else`20if(`20fc`20.eqs.`20"P"`20)`7B
X`09`09total_pages`20=`20f$integer(`20pval`20)
X`09`20`20`20`20`20`20`20`20if(`20bugp`20)
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"DEBUG:`20total_pages`20''f$st
Vring(total_pages)'"
X`09`20`20`20`20`7D
X`09`20`20`20`20else`20if(`20fc`20.eqs.`20"B"`20)`7B
X`09`09batch_size`20=`20f$integer(`20pval`20)
X`09`20`20`20`20`20`20`20`20if(`20bugp`20)
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"DEBUG:`20batch_size`20''f$str
Ving(batch_size)'"
X`09`20`20`20`20`7D
X`09`20`20`20`20else
X`09`09babble`20"Strange`20option`20''val'`20ignored"
X`09`7D
X`7D
X
Xif(`20p1`20.nes.`20""`20)`7B
X`20`20`20`20if(`20conv`20.eqs.`20"YES"`20)`7B
X`09if(`20total_pages`20.eq.`200`20)`7B
X`20`20`20`20`09`20`20`20`20dvi2lng`20'p1'`20'sp'`20'pcnt'
X`20`20`20`20`09`20`20`20`20ln03topp`20'p1'`20'hor'`20'ver'
X`20`20`20`20`09`20`20`20`20dele`20*.typ;*,*.lng;*,*.lnh;*
X`20`20`20`20`09`20`20`20`20ln3`20:=`20'p1'".ln3"
X`09`7D
X`09else`20`7B
X`09`20`20`20`20if(`20(batch_size`20.gt.`20total_pages)`20.or.`20(batch_size`20
V.le.`200)`20)
X`09`09batch_size`20=`20total_pages
X
X`09`20`20`20`20batch_no`20=`200
X`09`20`20`20`20end_page`20=`20batch_size
X
X`09`20`20`20`20for(`20start_page`20=`201;`20end_page`20.le.`20total_pages;`20)
V`7B
X`09`09str_val`20=`20f$string(start_page`20)
X`09`09sp`20:=`20"/s="'str_val'
X`09`09count`20=`20end_page`20-`20start_page`20+`201
X`09`09str_val`20=`20f$string(count)`20`20`20`20/*`20number`20of`20pages`20*/
X`09`09pcnt`20:=`20"/n="'str_val'
X
X`09`09if(`20bugp`20.eq.`202`20)`7B
X`09`09`20`20`20`20dvi2lng`20'p1'`20'sp'`20'pcnt'
X`09`09`20`20`20`20ln03topp`20'p1'`20'hor'`20'ver'
X`09`09`7D
X
X`09`09batch_no`20=`20batch_no`20+`201
X`09`09str_val`20=`20f$string(batch_no)
X`09`09ln3`20:=`20'p1'".ln3_"'str_val'
X
X`09`09if(`20.not.`20bugp`20)
X`09`09`20`20`20`20rename`20'p1'.ln3`20'ln3'
X
X`09`20`20`20`20`20`20`20`20if(`20bugp`20)`7B
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"DEBUG:`20sp`20`20`20`20`20`20
V`20''sp'"
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"`20`20`20`20`20`20`20pcnt`20
V`20`20`20`20''pcnt'"
X`09`20`20`20`20`20`20`20`20`20`20`20`20babble`20"`20`20`20`20`20`20`20ln3_file
V`20''ln3'"
X`09`09`7D
X`09`09
X`09`09if(`20send`20.eqs.`20"YES")`7B
X`09`09`20`20`20`20babble`20"Submitting`20''ln3'"
X`09`09`20`20`20`20print/nofeed/que='ln03que'`20'ln3'/passall
X`09`09`7D
X
X`09`09start_page`20=`20start_page`20+`20batch_size
X`09`09if(`20start_page`20.gt.`20total_pages`20)
X`09`09`20`20`20`20end_page`20=`20total_pages+1`20`20/*`20this`20will`20stop`20
Vthe`20loop`20*/
X`09`09else`20`7B
X`09`09`20`20`20`20end_page`20=`20start_page`20+`20batch_size`20-`201
X`09`09`20`20`20`20if(`20end_page`20.gt.`20total_pages`20)
X`09`09`09end_page`20=`20total_pages
X`09`09`7D
X
X`09`20`20`20`20`7D`20`20/*`20end`20for`20*/
X`09`20`20`20`20if(`20.not.`20bugp`20)`7B
X`09`20`20`20`20`20`20`20`20dele`20*.typ;*,*.lng;*,*.lnh;*
X`09`7D
X`20`20`20`20`7D
X`20`20`20`20if(`20send`20.eqs.`20"YES"`20.and.`20total_pages`20.eq.`200)`7B
X`09if(`20conv`20.eqs.`20"NO"`20)`20
X`09`20`20`20`20ln3`20:=`20'p1'
X
X`20`20`20`20`09babble`20"submitting`20''ln3'"
X`09if(`20.not.`20bugp`20)`7B
X`09`20`20`20`20if(`20feed`20.eqs.`20"/NOFEED"`20)
X`20`20`20`20`09`20`20`20`20`20`20`20`20print/nofeed/que='ln03que'`20'ln3'/pass
Vall
X`09`20`20`20`20else
X`09`20`20`20`20`20`20`20`20print/que='ln03que'`20`20'ln3'
X`09`7D
X`20`20`20`20`7D
X`7D
Xelse`20`7B
X`20`20`20`20babble`20"Type`20""laser`20?""`20for`20usage`20details"
X`7D
Xexit
$ call unpack [.REF-LIB]LASER.DCL;3 218647510 "" 11 4 13
$!
$ create 'f'
X/*
X**`20`20`09Function`20lex`20returns`20the`20token`20string`20and`20tokencode
V`20from`20standard`20input.
X**`20`20`09The`20lex`20routine`20is`20table`20driven.`20The`20two`20tables`20"
Vnextstate"`20and`20"output"
X**`20`20`09were`20developed`20by`20hand.`20`20These`20tables`20are`20external
V`20to`20this`20file.`20`20They
X**`20`20`09reside`20in`20"tcodes.h"`20are`20included`20in`20this`20file.
X**
X**`200.001`20Dick`20Munroe`2003-Sep-90
X**`09Make`20$`20equivalent`20to`20#.
X**
X**`200.002`20Dick`20Munroe`2015-Sep-90
X**`09Teach`20lex`20about`20variable`20substitution`20within`20quoted`20strings
V.
X**
X**`20`200.003`20Dick`20Munroe`2001-Jun-95
X**`09Teach`20lex`20about`20ON`20blocks.
X**/
X
X#include`20<ctype.h>
X#include`20<stdio.h>
X#include`20"tcodes.h"
X#include`20"defs.h"
X
X/*`20Variables`20that`20need`20to`20retain`20their`20values`20across`20calls
V`20to`20lex.`20*/
X
Xstatic`20int`20state`20=`200;
Xstatic`20int`20nextchar;
X/*
X`20*
X`20*`09External`20FILE`20variable`20infile`20is`20initialized`20by`20the`20sdc
Vl.c
X`20*`09module.`20`20It`20points`20either`20to`20stdin`20or`20to`20a`20user-spe
Vcified
X`20*`09input`20file.
X`20*/
X
Xextern`20FILE`20*infile;
X
Xint`20lex(token)
X`20`20`20`20char`20*token;
X`20`20`20`20`7B
X`09/*`20
X`09`20*`09The`20findclass`20array`20is`20used`20for`20quick`20lookups`20of`20
V
X`09`20*`09character`20class`20of`20a`20character.`20`20The`20ordinal
X`09`20*`09value`20of`20a`20character`20is`20used`20as`20an`20index`20into
X`09`20*`09this`20array.`20`20The`20value`20found`20at`20the`20location
X`09`20*`09indexed`20by`20this`20ordinal`20value`20will`20be`20the`20character
V
X`09`20*`09class`20for`20this`20input`20index`20character.`20`20Since`20it
X`09`20*`09will`20be`20used`20continously`20throughout`20program
X`09`20*`09execution`20and`20it`20is`20only`20used`20by`20function`20lex()
X`09`20*`09the`20array`20is`20static.`20`20The`20comments`20used`20in`20the
X`09`20*`09initialization`20section`20for`20the`20array`20correspond
X`09`20*`09to`20the`20decimal`20ascii`20values`20the`20rows`20represent.
X`09`20*
X`09`20*/
X
X`09static`20int`20findclass`5B`5D`20=
X`09`7B`09`20
X/*`20`200`20*/`09`20WHITESPACE,
X
X/*`20`201`20-`2010`20*/`09`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20WHITESP
VACE,`20WHITESPACE,
X`09`09`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20EOL,
X
X/*`2011`20-`2020`20*/`09`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20WHITESPAC
VE,`20WHITESPACE,
X`09`09`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,
X
X/*`2021`20-`2030`20*/`09`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20WHITESPAC
VE,`20WHITESPACE,
X`09`09`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,`20WHITESPACE,
X
X/*`2031`20-`2040`20*/`09`20WHITESPACE,`20WHITESPACE,`20ONECHAR,`20DQUOTE,`20ON
VECHAR,
X`09`09`20LETTER,`20ONECHAR,`20ONECHAR,`20SUBSTITUTE,`20ONECHAR,
X
X/*`2041`20-`2050`20*/`20`09`20ONECHAR,`20STAR,`20ONECHAR,`20ONECHAR,`20ONECHAR
V,
X`09`09`20ONECHAR,`20SLASH,`20DIGIT,`20DIGIT,`20DIGIT,`20
X
X/*`2051`20-`2060`20*/`09`20DIGIT,`20DIGIT,`20DIGIT,`20DIGIT,`20DIGIT,`20
X`09`09`20DIGIT,`20DIGIT,`20ONECHAR,`20ONECHAR,`20ONECHAR,
X
X/*`2061`20-`2070`20*/`09`20ONECHAR,`20ONECHAR,`20ONECHAR,`20ONECHAR,`20LETTER,
V
X`09`09`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
X
X/*`2071`20-`2080`20*/`09`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
X`09`09`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
X
X/*`2081`20-`2090`20*/`09`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
X`09`09`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
X
X/*`2091`20-`20100`20*/`09`20ONECHAR,`20ONECHAR,`20ONECHAR,`20ONECHAR,`20LETTER
V,
X`09`09`20ONECHAR,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
X
X/*`20101`20-`20110`20*/`20`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
X`09`09`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
X
X/*`20111`20-`20120`20*/`09`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,
V`20`20
X`09`09`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20LETTER,`20`20
X
X/*`20121`20-`20127`20*/`09`20LETTER,`20LETTER,`20ONECHAR,`20ONECHAR,`20ONECHAR
V,
X`09`09`20ONECHAR
X`09`7D;
X
X`09int`20i`20=`200,`20out`20=`200,`20class;
X
X`09/*
X`09`20*`20`20While`20the`20output`20state`20is`20non-zero,`20indicating`20a`20
Vcomplete`20
X`09`20*`20`20token`20has`20not`20been`20found...
X`09`20*/
X`20`20`20`20`20`20`20`20while`20(!out)`7B
X`09`09if`20(state)
X`09`09`09/*`20`20and`20if`20the`20maximum`20token`20length`20has`20not`20been
V
X`09`09`09`20*`20exceeded...
X`09`09`09`20*/
X`09`09`09if`20(i`20<`20MAXTOKENLEN)
X`09`09`09`20`20`20`20token`5Bi++`5D`20=`20nextchar;
X
X`09`09nextchar`20=`20getc(infile);
X
X`09`09/*
X`09`09`20*`20`20Find`20out`20the`20character`20class`20of`20this`20next`20inpu
Vt
X`09`09`20*`20`20character.`20`20Use`20this`20value`20to`20determine`20what
X`09`09`20*`20`20the`20output`20and`20nextstate`20states`20should`20be`20for
X`09`09`20*`20`20the`20DFA`20scanner.
X`09`09`20*/
X
X`09`09/*`20If`20the`20next`20character`20is`20EOF...`20*/
X
X`09`09class`20=`20(nextchar`20!=`20EOF)?`20findclass`5Bnextchar`5D`20:`20ENDFI
VLE;
X
X`09`09out`20=`20output`5Bstate`5D`5Bclass`5D;
X`09`09state`20=`20nextstate`5Bstate`5D`5Bclass`5D;
X`09`7D
X`09token`5Bi`5D`20=`20'`5C0';
X`09/*`20
X`09`20*`20Output`20contains`20the`20tokencode.`20If`20it`20is`20ID,`20check`20
Vfor`20keywords
X`09`20*`20by`20searching`20table`20of`20keywords.
X`20`09`20*/
X`09if`20(out`20==`20ID)
X`09`20`20`20`20out`20=`20iskeyword(token);
X`09else`20`20if`20(out`20==`20SCHAR)
X`09`20`20`20`20out`20=`20isspecialonechar(token`5B0`5D);
X
X`09/*`20here's`20the`20token`20code`20*/`09
X`09return(out);
X`20`20`20`20`7D`20
X
Xint`20iskeyword(token)
X`20`20`20`20char`20*token;
X/*
X**`20`20This`20function`20compares`20the`20input`20parameter`20string`20with
V`20a`20struct`20array
X**`20`20of`20keywords`20to`20determine`20if`20the`20input`20token`20is`20a`20k
Veyword.`20`20The
X**`20`20way`20the`20array`20is`20arranged`20function`20iskeyword`20returns`20e
Vither`20
X**`20`20the`20token`20code`20of`20the`20keyword`20if`20it`20is`20one,`20or`20t
Vhe`20generic`20
X**`20`20token`20code`20ID`20if`20the`20inputted`20token`20is`20not`20a`20keywo
Vrd.
X**
X**`20`20Note`20that`20since`20the`20"$"`20parses`20as`20an`20identifier`20this
V`20routine`20is`20the
X**`20`20place`20where`20it`20gets`20converted`20into`20a`20DOLLAR`20token`20ra
Vther`20than`20an
X**`20`20IDENTIFIER`20token.
X**/
X`20`20`20`20`7B
X`09int`20i`20=`200;
X`09char`20buf`5BMAXTOKENLEN`5D`20;
X`09static`20struct`20kwdtype
X`09`7B
X`09`09char`20*kw;
X`09`09int`20tokevalue;
X`09`7D
X`09kwdtable`20`5B`5D`20=
X`09`7B
X`09`09"if",`20IF,
X`09`09"else",`20ELSE,
X`09`09"while",`20WHILE,
X`09`09"for",`20FOR,
X`09`09"break",`20BREAK,
X`09`09"next",`20NEXT,
X`09`09"do",`20DO,
X`09`09"$",`20DOLLAR,
X`09`09"on",`20ON,
X`09`09"then",`20THEN,
X`09`09"warning",`20ON_WARNING,
X`09`09"error",`20ON_ERROR,
X`09`09"severe_error",`20ON_SEVERE_ERROR,
X`09`09"control_y",`20ON_CONTROL_Y,
X`09`09NULL,`20ID
X`09`7D;
X
X`09/*
X`09**`20Make`20the`20comparison`20for`20the`20keywords`20be`20caseless.
X`09*/
X
X`09for`20(i`20=`200`20;
X`09`20`20`20`20`20(buf`5Bi`5D`20=`20_tolower(*(token+i)))`20!=`200`20;
X`09`20`20`20`20`20i++)`20`7B`7D`20;
X
X`09for`20(i`20=`200`20;
X`09`20`20`20`20`20kwdtable`5Bi`5D.kw`20!=`20(char`20*)`20NULL`20;
X`09`20`20`20`20`20i++`20)
X`09`7B
X`09`09if`20(strcmp(kwdtable`5Bi`5D.kw,`20buf)`20==`200)
X`09`09`20`20`20`20return(kwdtable`5Bi`5D.tokevalue);
X`09`7D
X`09return(kwdtable`5Bi`5D.tokevalue);
X`20`20`20`20`7D
X
Xint`20isspecialonechar(token)
X`20`20`20`20char`20token;
X/*
X`20*`09The`20inputted`20token`20is`20compared`20with`20each`20of`20the`20chara
Vcters
X`20*`09found`20in`20actual_char`20which`20is`20an`20array`20of`20structures.
V`20`20If`20
X`20*`09a`20match`20is`20found`20then`20the`20corresponding`20value`20to`20retu
Vrn`20for
X`20*`09this`20function`20is`20contained`20in`20the`20tvalue`20of`20that`20fiel
Vd`20of
X`20*`09actual_char.`20`20If`20no`20match`20is`20found`20SCHAR`20is`20returned.
V
X`20*/
X`20`20`20`20`7B
X`09static`20struct`20`7B
X`09`09char`20specchar;
X`09`09int`20`20tvalue;
X`09`7D`20actual_char`5B`5D`20=`20`7B
X`09`09'"',`20DQUOTE,
X`09`09'#',`20POUND,
X`09`09'$',`20DOLLAR,
X`09`09'(',`20OPAREN,
X`09`09')',`20CPAREN,
X`09`09';',`20SEMICOLON,
X`09`09'`5C`5C',`20BACKSLASH,
X`09`09'`7B',`20OBRACE,
X`09`09'`7D',`20CBRACE,
X`09`09'0',`20SCHAR
X`09`7D;
X
X`09int`20i;
X`09for`20(i`20=`200;`20actual_char`5Bi`5D.specchar`20!=`20'0';`20i++)
X`09`09if`20(actual_char`5Bi`5D.specchar`20==`20token)
X`09`09`20`20`20`20return(actual_char`5Bi`5D.tvalue);
X`09return(actual_char`5Bi`5D.tvalue);
X`20`20`20`20`7D
$ call unpack [.REF-LIB]LEX.C;4 1852443729 "" 13 5 13
$!
$ create 'f'
X$`20define`20src$`20sys$disk:`5B`5D
X$`20define`20obj$`20sys$disk:`5B`5D
X$`20define`20exe$`20sys$disk:`5B`5D
X$`20CC`20/obj=OBJ$:SDCL.obj/noopt/debug/nolist/include_path=inc$`20SRC$:SDCL.C
V
X$`20CC`20/obj=OBJ$:LEX.obj/noopt/debug/nolist/include_path=inc$`20SRC$:LEX.C
X$`20CC`20/obj=OBJ$:OUTPUT.obj/noopt/debug/nolist/include_path=inc$`20SRC$:OUTP
VUT.C
X$`20CC`20/obj=OBJ$:STACK.obj/noopt/debug/nolist/include_path=inc$`20SRC$:STACK
V.C
X$`20CC`20/obj=OBJ$:STMT.obj/noopt/debug/nolist/include_path=inc$`20SRC$:STMT.C
V
X$`20link/exec=EXE$:SDCL.EXE/notrace`20`09`09OBJ$:SDCL.OBJ,`09`09obj$:lex.obj,
V`09`09obj$:output.obj,`09`09obj$:stack.obj,`09`09obj$:stmt.obj,`09`09src$:sdcl
V.opt/options
X$`20link/exec=EXE$:SDCL-DEBUG.EXE/debug`20`09`09OBJ$:SDCL.OBJ,`09`09obj$:lex.o
Vbj,`09`09obj$:output.obj,`09`09obj$:stack.obj,`09`09obj$:stmt.obj,`09`09src$:s
Vdcl.opt/options
X$`20write`20sys$output`20"Executables`20complete"
X$`20write`20sys$output`20"Build`20complete"
$ call unpack [.REF-LIB]MAKEFILE.COM;1 -
1683368202 "FORMAT STREAM_LF;CARRIAGE_CONTROL CARRIAGE_RETURN" 2 6 13
$!
$ create 'f'
X/*
X**`09All`20functions`20within`20this`20file`20are`20for`20formatting`20and`20p
Verforming
X**`09the`20output`20of`20the`20DCL`20output`20code.`20`20Included`20here`20are
V`20the
X**`09functions`20outdone(),`20outch(),`20emitstring(),`20emitlabel(),
X**`09emitqstring(),`20emittarget(),`20itoa(),`20reverse(),`20and`20genlab().
X**
X**`09Also`20within`20this`20file`20is`20a`20function`20for`20outputting`20a
X**`09string`20(usually`20indicating`20an`20error)`20passed`20to`20it.`20`20The
V
X**`09name`20of`20the`20function`20is`20errmsg().
X**
X**`200.001`20Dick`20Munroe`2003-Sep-90
X**`09Add`20a`20function`20to`20actually`20emit`20lines`20much`20longer`20than
V`20MAXCOL.
X*/
X
X#include`20<stdio.h>
X#include`20"defs.h"
X
X/*`20
X`20*`09MAXCOL`20is`20the`20maximum`20number`20of`20columns`20in`20the`20
X`20*`09output`20line.`20`20MAXBUF`20is`20one`20greater`20to`20allow`20for
X`20*`09appending`20a`20NULL`20character`20to`20make`20a`20string.`20
X`20*/
X
X#define`20MAXCOL`0980
X#define`20MAXBUF`20`20MAXCOL`20+`201
X
X/*
X`20*`09outbuf`5B`5D`20and`20outp`20are`20the`20output`20buffer`20and`20index
V`20
X`20*`09into`20same.`20`20These`20two`20variables`20are`20used`20in`20building
V`20and`20
X`20*`09outputting`20the`20final`20output`20from`20the`20sdcl`20program.
X`20*
X`20*`09External`20variable`20outfile`20is`20initialized`20within`20sdcl.c.
X`20*`09It`20points`20to`20either`20stdout`20or`20to`20a`20user-specified`20out
Vput
X`20*`09file.
X`20*/
X
Xstatic`20char`20outbuf`5BMAXBUF`5D;
Xstatic`20outp`20=`20(-1);
Xextern`20FILE`20*outfile;
X
Xvoid`20itoa(int,`20char*)`20;
Xvoid`20reverse(char*)`20;
X
Xvoid`20outdone()
X/*
X`20*`09This`20function`20flushes`20the`20contents`20of`20outbuf`20to`20stdout
V`20and
X`20*`09resets`20outp`20to`20-1.`20`20This`20is`20the`20only`20function`20withi
Vn`20this
X`20*`09file`20that`20makes`20a`20direct`20call`20to`20the`20fprintf()`20functi
Von`20and
X`20*`09hence`20is`20the`20only`20function`20that`20produces`20any`20output.`20
V`20It`20is
X`20*`09used`20by`20most`20of`20the`20other`20functions`20within`20this`20file.
V
X`20*/
X`20`20`20`20`7B
X`09/*`20Append`20a`20newline`20and`20NULL`20characters,`20output,`20and`20set
V`20outp.`20*/
X
X`09outbuf`5B++outp`5D`20=`20'`5Cn';
X`09outbuf`5B++outp`5D`20=`20'`5C0';
X`09fputs(outbuf,`20outfile`20);
X`09outp`20=`20(-1);
X`20`20`20`20`7D
X
Xvoid`20outch(c)
X`20`20`20`20char`20c;
X/*`09
X`20*`09This`20function`20places`20its`20character`20input`20parameter`20into
V`20outbuf.
X`20*`09Insertion`20of`20DCL`20continuation`20characters`20are`20also`20handled
V`20here.
X`20*`09When`20a`20newline`20character`20is`20received`20by`20this`20function
V`20outbuf`20is
X`20*`09flushed`20by`20a`20call`20to`20outdone().
X`20*/
X`20`20`20`20`7B
X`09/*`20If`20c`20is`20a`20newline`20it`20is`20a`20signal`20to`20flush`20outbuf
V`5B`5D.`20*/
X`09if`20(c`20==`20'`5Cn')
X`09`09outdone();
X`09/*`20
X`09`20*`09Otherwise`20if`20there`20are`20now`20two`20less`20than`20the`20maxim
Vum
X`09`20*`09characters`20currently`20in`20outbuf`5B`5D`20add`20a`20dcl`20continu
Vation
X`09`20*`09character`20and`20flush`20the`20buffer.`20`20Begin`20a`20new`20outbu
Vf,
X`09`20*`09without`20a`20prepended`20dollar`20sign.`20`20The`20first`20characte
Vr
X`09`20*`09of`20this`20new`20outbuf`5B`5D`20will`20be`20the`20inputted`20charac
Vter`20c.
X`09`20*/
X`09else`20if`20(outp`20==`20MAXCOL`20-`202)`20`7B
X`09`09outbuf`5B++outp`5D`20=`20'-';
X`09`09outdone();
X`09`09outbuf`5B++outp`5D`20=`20c;
X`09`7D
X`09/*`20Otherwise`20simply`20append`20c`20to`20outbuf`5B`5D.`20*/
X`09else
X`09`09outbuf`5B++outp`5D`20=`20c;
X`20`20`20`20`7D
X
Xvoid`20emitstring(string)
X`20`20`20`20char`20*string;
X/*
X`20*`09The`20characters`20in`20string`20are`20placed`20in`20the`20output`20buf
Vfer
X`20*`09one`20character`20at`20a`20time.`20`20Function`20outch()`20does`20the
X`20*`09necessary`20bookeeping`20to`20prevent`20too`20many`20characters
X`20*`09being`20placed`20in`20outbuf`5B`5D.
X`20*/
X`20`20`20`20`7B
X`09char`20c;
X
X`09while`20(c`20=`20*string++)
X`09`09outch(c);
X`20`20`20`20`7D
X
Xvoid`20emitlabel(label)
X`20`20`20`20int`20label;
X/*
X`20*`09This`20function`20converts`20integer`20intput`20label`20into`20a`20stri
Vng`20of
X`20*`09characters.`20`20To`20this`20string`20it`20appends`20`20a`20colon,`20an
Vd`20a`20blank
X`20*`09character.`20`20This`20character`20label`20is`20then`20added`20to`20out
Vbuf.
X`20*/
X`20`20`20`20`7B
X`09/*`20
X`09`20*`09Allow`20five`20characters`20for`20the`20number,`20one`20each`20for
X`09`20*`09the`20colon,`20blank,`20and`20NULL`20characters`20for`20a`20total
X`09`20*`09of`20eight`20characters`20in`20str.
X`09`20*/
X`09char`20str`5B8`5D;
X
X`09/*`20Convert`20label`20from`20integer`20to`20character,`20placing`20result
V`20into`20str.*/
X`09itoa(label,`20str);
X
X`09/*`20Add`20colon,`20blank,`20and`20NULL`20characters`20to`20str.`20*/
X`09str`5B5`5D`20=`20':';
X`09str`5B6`5D`20=`20'`20';
X`09str`5B7`5D`20=`20'`5C0';
X
X`09/*`20Send`20the`20character`20version`20label`20to`20outbuf`5B`5D.`20*/
X`09emitstring(str);
X`20`20`20`20`7D
X
Xvoid`20emittarget(label)
X`20`20`20`20int`20label;
X/*
X`20*`09This`20function`20converts`20integer`20intput`20label`20into`20a`20stri
Vng`20of
X`20*`09characters.`20`20To`20this`20string`20it`20appends`20`20a`20blank
X`20*`09character.`20`20This`20character`20label`20is`20then`20added`20to`20out
Vbuf.
X`20*`09This`20function`20is`20almost`20exactly`20like`20emitlabel`20except`20t
Vhat
X`20*`09no`20colon`20is`20appended`20to`20the`20character`20string.`20`20This
V`20is
X`20*`09used`20whenever`20a`20target`20must`20be`20specified`20after`20a`20goto
V`20is
X`20*`09generated`20from`20within`20statements.c.
X`20*/
X`20`20`20`20`7B
X`09/*`20
X`09`20*`09Allow`20five`20characters`20for`20the`20number`20and`20one`20for
X`09`20*`09the`20NULL`20character`20for`20a`20total`20of`20six`20characters`20i
Vn`20str.
X`09`20*/
X`09char`20str`5B6`5D;
X
X`09itoa(label,`20str);
X`09str`5B5`5D`20=`20'`5C0';
X`09emitstring(str);
X`20`20`20`20`7D
X
Xvoid`20emitqstring(str)
X`20`20`20`20char`20*str;
X/*
X`20*`09This`20procedure`20is`20called`20whenever`20a`20quoted`20string`20is`20
Vto
X`20*`09be`20output.`20`20It`20insures`20that`20the`20string`20is`20not`20broke
Vn`20by
X`20*`09a`20newline`20character.`20`20It`20compares`20the`20length`20of`20the
V`20
X`20*`09string`20to`20be`20output`20to`20the`20amount`20of`20room`20currently
V`20remaining
X`20*`09in`20outbuf.`20`20If`20there`20isn't`20enough`20room`20in`20outbuf`20to
V`20contain
X`20*`09the`20output`20string`20a`20dash`20is`20appended`20to`20outbuf`20to`20i
Vndicate
X`20*`09line`20continuation.`20`20Then`20a`20newline`20is`20appended`20and`20th
Ve`20string
X`20*`09is`20sent`20to`20outbuf.
X`20*/
X`20`20`20`20`7B
X`09int`20i,c`20;
X
X`09/*`20
X`09`20*`09Check`20to`20see`20if`20outbuf`20has`20enough`20room`20left`20to`20h
Vold
X`09`20*`09the`20string`20that`20is`20to`20be`20output.`20`20If`20not`20append
V`20a
X`09`20*`09dash`20and`20a`20newline`20character`20to`20outbuf`20and`20flush`20i
Vt
X`09`20*`09by`20calling`20emitstring.
X`09`20*/
X`09c`20=`20strlen(str)`20;
X
X`09/*
X`09**`20If`20the`20quoted`20string`20will`20fit`20completely`20within`20the`20
Vbuffer,
X`09**`20transfer`20it`20and`20exit.
X`09*/
X
X`09if`20(c`20+`20outp`20+`203`20<`20MAXCOL)
X`09`7B
X`09`20`09while`20(c`20=`20*str++)
X`09`09`09outch(c);
X`09`09return`20;
X`09`7D`20;
X
X`09/*
X`09**`20Flush`20the`20current`20buffer`20before`20emitting`20the`20string.`20
V`20There`20is`20a
X`09**`20race`20between`20this`20logic`20and`20the`20logic`20in`20outch`20that
V`20prevents`20using
X`09**`20emitstring`20to`20continue`20and`20terminate`20the`20current`20line.
X`09*/
X
X`09outbuf`5B++outp`5D`20=`20'-'`20;
X`09outbuf`5B++outp`5D`20=`20'`20'`20;
X`09outdone()`20;
X`09
X`09/*
X`09**`20If`20the`20string`20will`20fit`20completely`20within`20the`20buffer,
X`09**`20move`20it.
X`09*/
X
X`09if`20(c`20+`203`20<`20MAXCOL)
X`09`7B
X`09`20`09while`20(c`20=`20*str++)
X`09`09`09outch(c);
X`09`09return`20;
X`09`7D`20;
X
X`09/*`20
X`09**`20The`20string`20will`20not`20fit`20completely`20within`20the`20buffer,
V
X`09**`20output`20the`20part`20that`20won't`20fit`20and`20then`20move`20the`20r
Vest.
X`09*/
X`09
X`09for`20(`20;
X`09`20`20`20`20`20c`20>=`20MAXCOL`20-`203`20;
X`09`20`20`20`20`20c--`20)
X`09`7B
X`09`09i`20=`20*str++`20;
X`09`09fputc(`20i,`20outfile`20)`20;
X`09`7D`20;
X
X`09while`20(c`20=`20*str++)
X`09`09outch(c);
X`20`20`20`20`7D
X
Xvoid`20emitlstring(str)
X`20`20`20`20char`20*str;
X/*
X`20*`09This`20procedure`20is`20called`20whenever`20a`20literal`20string`20is
V`20to
X`20*`09be`20output.`20`20It`20insures`20that`20the`20string`20is`20not`20broke
Vn`20by
X`20*`09either`20a`20newline`20or`20continuation`20character.`20`20
X`20*/
X`20`20`20`20`7B
X`09int`20c;
X
X`09/*`20
X`09**`20If`20there`20has`20been`20anything`20buffered,`20flush`20it`20and`20du
Vmp`20the
X`09**`20string`20to`20the`20output`20file`20without`20going`20through`20outbuf
V.
X`09*/
X
X`09if`20(outp`20!=`20-1)
X`09`7B
X`09`09outdone()`20;
X`09`7D`20;
X
X`09/*`20Output`20the`20rest`20of`20the`20input`20string.`20*/
X`09while`20(c`20=`20*str++)
X`09`09fputc(c,`20outfile);
X`20`20`20`20`7D
X
Xvoid`20itoa(n,`20str)
X`20`20`20`20int`20n;
X`20`20`20`20char`20str`5B`5D;
X/*
X`20*`09Converts`20the`20integer`20n`20into`20its`20string`20representation.
X`20*/
X`20`20`20`20`7B
X`09int`20i`20=`200,`20sign;
X
X`09/*`20Save`20the`20sign`20of`20n`20and`20make`20n`20positive`20if`20its`20ne
Vgative.`20*/
X`09if`20((sign`20=`20n)`20<`200)
X`09`09n`20=`20-n;
X
X`09/*`20Generate`20the`20digits`20in`20reverse`20order.`20`20*/
X`09do
X`09`7B
X`09`09str`5Bi++`5D`20=`20n`20%`2010`20+`20'0';
X`09`7D`20while`20((n`20/=`2010)`20>`200);
X
X`09/*`20If`20n`20was`20negative`20add`20a`20minus`20sign`20,`20then`20append
V`20a`20NULL.`20*/
X`09if`20(sign`20<`200)
X`09`09str`5Bi++`5D`20=`20'-';
X`09str`5Bi`5D`20=`20'`5C0';
X
X`09/*`20Reverse`20the`20string.`20*/
X`09reverse(str);
X`20`20`20`20`7D
X
Xvoid`20reverse(str)
X`20`20`20`20char`20str`5B`5D;
X/*`20
X`20*`09Reverses`20the`20digits`20in`20an`20inputted`20string.`20`20The`20rever
Vsal
X`20*`09is`20done`20in`20place.
X`20*/
X`20`20`20`20`7B
X`09int`20c,`20i,`20j;
X
X`09for`20(i`20=`200,`20j`20=`20strlen(str)`20-`201;`20i`20<`20j;`20i++,`20j--)
V`20`7B
X`09`09c`20=`20str`5Bi`5D;
X`09`09str`5Bi`5D`20=`20str`5Bj`5D;
X`09`09str`5Bj`5D`20=`20c;
X`09`7D
X`20`20`20`20`7D
X
Xint`20genlab()
X/*
X`20*`09This`20function`20increments`20a`20static`20integer.`20This`20will`20
X`20*`09generate`20a`20new`20value`20that`20can`20be`20used`20as`20a`20label
X`20*`09during`20code`20generation.
X`20*/
X`20`20`20`20`7B
X`09static`20int`20label`20=`2023000;
X`09return(label++);
X`20`20`20`20`7D
X
Xvoid`20errmsg(string)
X`20`20`20`20char`20*string;
X`20`20`20`20`7B
X`09fputs(string,`20stderr);
X`20`20`20`20`7D
$ call unpack [.REF-LIB]OUTPUT.C;4 1058558356 "" 16 7 13
$!
$ create 'f'
X
X/*`20
X`20*`20`09This`20file`20contains`20the`20main`20driver`20for`20sdcl`20preproce
Vssor.
X`20*
X`20*`09This`20program`20accepts`20as`20input`20a`20file`20written`20in`20sdcl.
V`20`20This`20
X`20*`09language`20is`20an`20enhanced`20version`20of`20DCL.`20`20It`20includes
V`20however
X`20*`09the`20for,`20while,`20do`20while,`20if,`20if-else,`20next,`20and`20brea
Vk.`20The`20syntax
X`20*`09for`20these`20statements`20is`20almost`20exactly`20as`20in`20C.`20`20Th
Ve`20ouput
X`20*`09of`20this`20program`20is`20a`20file`20that`20is`20standard`20DCL.`20`20
VThis`20language`20
X`20*`09can`20be`20summarized`20in`20BNF`20as`20follows:
X`20*
X`20*`09`09program`09`09`7C`20statement
X`20*`09`09`09`09`7C`20program`20statement
X`20*
X`20*`09`09statement`09`7C`20if`20(`20condition`20)`20statement
X`20*`09`09`09`09`7C`20if`20(`20condition`20)`20statement`20else`20statement
X`20*`09`09`09`09`7C`20while`20(`20condition`20)`20statement
X`20*`09`09`09`09`7C`20for`20(`20initialize;`20condition;`20reinitialize`20)`20
V
X`20*`09`09`09`09`09statement
X`20*`09`09`09`09`7C`20do`20statment`20while`20(condition)
X`20*`09`09`09`09`7C`20break
X`20*`09`09`09`09`7C`20next
X`20*`09`09`09`09`7C`20`7B`20program`20`7D
X`20*`09`09`09`09`7C`20other
X`20*
X`20*
X`20*`09All`20the`20main`20driver`20function`20does`20is`20perform`20an`20initi
Val`20call`20to
X`20*`09the`20lexical`20scanner`20(to`20"prime`20the`20pump")`20and`20then`20re
Vpeatedly`20call
X`20*`09function`20statement().`20`20This`20function`20calls`20one`20of`20a`20s
Veries`20of`20semantic
X`20*`09functions`20depending`20on`20what`20the`20first`20token`20on`20an`20inp
Vut`20line`20is.
X`20*`09The`20execution`20ends`20when`20the`20EOF`20token`20is`20encountered.
X`20*
X`20*`09The`20seven`20files`20that`20make`20up`20the`20sdcl`20processor`20are
X`20*
X`20*`09`09sdcl.c`09`09-`20main`20driver`20and`20non-terminal`20routines.
X`20*`09`09statements.c`09-`20handles`20statements`20such`20as`20if,`20while,
V`20etc.
X`20*`09`09scan_lex.c`09-`20does`20all`20scanning`20for`20input`20tokens.
X`20*`09`09output.c`09-`20holds`20all`20code`20generation`20functions
X`20*`09`09stack.c`09`09-`20provides`20stack`20and`20manipulation`20functions
X`20*`09`09defs.h`09`09-`20token`20code`20and`20character`20class`20definitions
V.
X`20*`09`09tcodes.h`09-`20nextstate`20and`20output`20tables`20for`20scanner.
X`20*/
X
X#include`20<stdio.h>
X#include`20"defs.h"
X#ifdef`20vax11c
X#include`20descrip
X#endif
X
Xextern`20int`20tokencode;
XFILE`20*infile,`20*outfile;
X
Xmain(argc,`20argv)
X`20`20`20`20int`20argc;
X`20`20`20`20char`20*argv`5B`5D;
X`20`20`20`20`7B
X`09int`20extern_files`20=`20FALSE;
X`09int`20xeq_flag`20`20`20`20`20=`20FALSE;
X`09extern`20char`20*make_out_file();
X`09extern`20FILE`20*efopen();
X`09extern`20int`20statement(int);
X#ifdef`20vax11c
X`09char`20dcl_command`5B80`5D;
X`09$DESCRIPTOR`20(`20cmd,`20dcl_command`20);`20/*`20struct`20for`20lib$docomma
Vn`20*/
X#endif
X`09/*
X`09`20*`09If`20the`20user`20has`20specified`20input`20and`20output`20files`20(
Vsignified
X`09`20*`09by`20argc`20equaling`203)`20open`20them`20for`20reading`20and`20writ
Ving.`20`20Also
X`09`20*`09set`20a`20boolean`20indicating`20these`20files`20exist.`20`20This`20
Vboolean`20will`20
X`09`20*`09be`20used`20at`20program`20end`20to`20close`20these`20files.
X`09`20*
X`09`20*/
X`09infile`20=`20stdin;
X`09outfile`20=`20stdout;
X`09if`20(argc`20==`204`20)`7B
X`09`09infile`20=`20efopen(argv`5B1`5D,`20"r");
X`09`09outfile`20=`20efopen(argv`5B2`5D,`20"w");
X`09`09argv`5B1`5D`20=`20argv`5B2`5D;
X`09`09extern_files`20=`20TRUE;
X`09`09if`20(strcmp(`20argv`5B3`5D,`20"-x"`20)`20==`200`20)
X`09`09`20`20`20`20xeq_flag`20=`20TRUE;
X`09`7D
X`09else`20if`20(argc`20==`203`20)`7B
X`09`09infile`20=`20efopen(argv`5B1`5D,`20"r");
X`09`09if`20(strcmp(`20argv`5B2`5D,`20"-x"`20)`20==`200`20)`20`7B
X`09`09`20`20`20`20xeq_flag`20=`20TRUE;
X`09`09`20`20`20`20argv`5B1`5D`20=`20make_out_file(`20argv`5B1`5D`20);
X`09`09`20`20`20`20outfile`20=`20efopen(argv`5B1`5D,`20"w");
X`09`09`7D
X`09`09else`7B
X`09`09`20`20`20`20outfile`20=`20efopen(argv`5B2`5D,`20"w");
X`09`09`20`20`20`20argv`5B1`5D`20=`20argv`5B2`5D;
X`09`09`7D
X`09`09extern_files`20=`20TRUE;
X`09`7D
X`09else`20if`20(argc`20==`202)`7B`20`20/*`20infile`20only`20*/
X`09`09if`20(strcmp(`20argv`5B1`5D,`20"-x"`20)`20!=`200`20)`20`7B
X`09`09`20`20`20`20infile`20=`20efopen(argv`5B1`5D,`20"r");
X`09`09`20`20`20`20argv`5B1`5D`20=`20make_out_file(`20argv`5B1`5D`20);
X`09`09`20`20`20`20outfile`20=`20efopen(argv`5B1`5D,`20"w");
X`09`09`20`20`20`20extern_files`20=`20TRUE;
X`09`09`7D
X`09`09else
X`09`09`20`20`20`20fprintf(stderr,"Cannot`20execute`20from`20sys$output`5Cn");
V
X`09`7D
X`09/*
X`09`20*`09Keep`20going`20until`20EOF`20but`20first,`20get`20the
X`09`20*`09first`20nonblank`20token`20via`20a`20call`20to`20scan().
X`09`20*/
X`09scan();
X`09while(`20tokencode`20!=`20FILEEND`20)
X`09`09statement(1);
X
X`09/*`20If`20the`20user`20specified`20input`20and`20output`20files`20close`20t
Vhem.`20*/
X`09if`20(extern_files)`20`7B
X`09`09fclose(infile);
X`09`09fclose(outfile);
X`09`7D
X#ifdef`20vax11c
X`09if`20(`20xeq_flag`20)`7B
X`09`09strcpy(`20dcl_command,`20"@"`20);
X`09`09strcat(`20dcl_command,`20argv`5B1`5D`20);
X`09`09exit`20(`20lib$do_command`20(`20`26cmd`20)`20);
X`09`7D
X#endif
X`7D
X
XFILE`20*efopen(`20name,`20mode`20)
X`20`20`20`20char`20*name,`20*mode;
X`20`20`20`20`7B
X`09FILE`20*fp;
X`09fp`20=`20fopen(`20name,`20mode`20);
X`09if`20(fp`20==`20NULL`20)`7B
X`09`20`20`20`20fprintf(stderr,`20"Trouble`20opening`20%s,`20abort`5Cn",`20name
V`20);
X`09`20`20`20`20exit(`201`20);
X`09`7D
X`09return(`20fp`20);
X`20`20`20`20`7D
X
Xchar`20*make_out_file`20(`20s`20)
X`20`20`20`20char`20*s;
X`20`20`20`20/*
X`20`20`20`20make`20.com`20filename`20out`20of`20filename`20in`20s.
X`20`20`20`20*/
X`20`20`20`20`7B
X`09int`20i;
X`09char`20*new;
X`09for`20(i`20=`200;`20s`5Bi`5D;`20i++`20)
X`09`20`20`20`20if`20(`20s`5Bi`5D`20==`20'.'`20)`7B
X`09`09s`5Bi`5D`20=`20'`5C0';
X`09`09break;
X`09`20`20`20`20`7D
X`09new`20=`20malloc(`20strlen(s)`20+`206`20);
X`09strcpy(`20new,`20s`20);
X`09strcat(`20new,`20".com"`20);
X`09return`20(`20new`20);
X`20`20`20`20`7D
$ call unpack [.REF-LIB]SDCL.C;2 1108661829 "" 9 8 13
$!
$ create 'f'
X.ifdef`20ALPHA
Xexe`20=`20exe-axp
Xobj`20=`20obj-axp
Xopt`20=`20opt-axp
Xcflags`20=`20/obj=$(MMS$TARGET_NAME).$(obj)/noopt/debug/nolist/include_path=in
Vc$/standard=vaxc
X
X.else
Xexe`20=`20exe
Xobj`20=`20obj
Xopt`20=`20opt
Xcflags`20=`20/obj=$(MMS$TARGET_NAME).$(obj)/noopt/debug/nolist/include_path=in
Vc$
X.endif
+-+-+-+-+-+-+-+- END OF PART 1 +-+-+-+-+-+-+-+-
--
Dick Munroe Internet: mun...@acornsw.com
Acorn Software, Inc.
267 Cox St. Office: (508) 568-1618 x16
Hudson, Ma. 01749 USA FAX: (508) 562-1133
--
Dick Munroe Internet: mun...@acornsw.com
Acorn Software, Inc.
267 Cox St. Office: (508) 568-1618 x16
Hudson, Ma. 01749 USA FAX: (508) 562-1133

0 new messages