May 24th, 2007

Chieftain

(no subject)

/* atomize a string */
atomize:
say atomyze('2**3*4/3*4/(wer+er)**3*(4/456*23)')
exit
atomyze:
lbr = '('
rbr = ')'
plus = '+'
minus = '-'
powerS = '^t'
power = '**'
star = '*'
slash = '/'
atoms = arg(1)
makeatom(lbr)
makeatom(rbr)
makeatom(plus)
makeatom(minus)
makeatom(power)
atoms = translate(atoms,powerS,power)
makeatom(star)
makeatom(powerS)
atoms = translate(atoms,power,powerS)
makeatom(slash)
return atoms
Makeatom: Procedure Expose Atoms
sta = arg(1)
i = 0
do forever
   stai = index(atoms,sta,i+1)
   if stai = 0 then
      leave
   atoms=delstr(atoms,stai,length(sta))
   atoms=insert(' 'sta' ',atoms,stai-1)
   i = stai+2
end
return ''
Chieftain

(no subject)

/* Program to read from the keyboard and interpret TeX instructions */

Say 'TeX interpreter running... '
Say 'Type q to terminate this VM'
Say

start:
Signal On error
Signal On syntax
Signal On failure
Signal On halt
Trace Off
Prev = ' '

Do Forever
    erase 'q@@.*'
    erase 'dviscr.dlg'
    say
    say 'Ready; '  substr(time(l),1,8)
    parse pull @_@
    if @_@ = 'q' then
       exit
    call lineout 'q@@.tex',@_@
    call lineout 'q@@.tex','\bye'
    call lineout 'q@@.tex' /* Close */
    'rplain q@@.tex'
    'v q@@.dvi'
End

Error:
    Say 'IEE601:- Application returned an errorlevel' rc
    signal start

Syntax:
    Say 'IEE602:-'  errortext(rc) '(error' rc')'
    signal start

Failure:
    Say 'IEE603:- uninitialized variable, or failure in system service'
    Signal start

Halt:
    Say '2F3:- CTRL-BREAK intercepted'
    Signal start