Annotation of researchv10no/cmd/spitbol/mincpp.spt, revision 1.1.1.1

1.1       root        1: -title mincpp: translate minimal conditional assembly stuff to cpp format
                      2: *
                      3: *      This program takes a MINIMAL program and translates all
                      4: *      conditional assembly statements to a format acceptable to
                      5: *      the C preprocessor (cpp).
                      6: *
                      7: *      MINIMAL                         CPP
                      8: *
                      9: *      .IF     sym                     #ifdef  sym
                     10: *      .THEN                           {nothing}
                     11: *      .ELSE                           #else
                     12: *      .FI                             #endif
                     13: *      .DEF    sym                     #define sym 1
                     14: *      .UNDEF  sym                     #undef  sym
                     15: *
                     16: *      Luckily, all MINIMAL conditional assembly statements start
                     17: *      with a "." in column 1.
                     18: *
                     19:        &stlimit = -1
                     20:        &anchor  = 1
                     21: *
                     22: *      build translation table.
                     23: *
                     24:        castbl = table( 5 )
                     25:        castbl['IF']       = '#ifdef'
                     26:        castbl['ELSE']     = '#else'
                     27:        castbl['FI']      = '#endif'
                     28:        castbl['DEF']      = '#define'
                     29:        castbl['UNDEF']   = '#undef'
                     30: *
                     31: *      obtain input and output files.
                     32: *
                     33:        terminal = 'enter minimal input file'
                     34:        input(.in,0,terminal)
                     35:        terminal = 'enter minimal/cpp output file'
                     36:        output(.out,1,terminal)
                     37: *
                     38: *      read statements and do quick check.
                     39: *
                     40: main   line = in                               :f(done)
                     41:        leq( substr(line,1,1),'.' )             :s(castmt)
                     42:        out  = line                             :(main)
                     43: *
                     44: *      here to do real translation
                     45: *
                     46: castmt opcode = symbol =
                     47:        line len(1) ( break( ' ' ) | rem ) . opcode
                     48: +              ( span( ' ' ) | '' )
                     49: +              ( ( len( 1 ) | '' ) rem . symbol )      :f(error)
                     50:        opcode = castbl[opcode]
                     51:        out    = differ( opcode ) opcode ' ' symbol 
                     52: +               (ident( opcode,'#define' ) ' 1','' )   :(main)
                     53: *
                     54: *      on error, show offensive line to person at teminal
                     55: *
                     56: error  terminal = 'error: ' line               :(main)
                     57: done
                     58: end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.