home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / packs / ibpag2 / beta2ref.ibp next >
Text File  |  2000-07-29  |  2KB  |  118 lines

  1. #
  2. # Ibpag2 source file for OT betacode-to-English converter.
  3. #
  4. # "Betacode" is the name used for the markers that the Thesaurus
  5. # Linguae Graecae uses to segment texts into works, books, chapters,
  6. # verses, etc.  The Michigan-Claremont scan of the Hebrew OT (BHS)
  7. # uses a subset of the betacode "language."  This file contains a
  8. # parser for that language that converts it into human readable form.
  9. #
  10. # Reads the standard input.  Sends the original text, with betacode
  11. # markers converted to human-readable form, to the standard output.
  12. #
  13.  
  14. %{
  15.  
  16. # These need to be global, because all of the actions modify them.
  17. # Remember that the default scope for a variable used in an action is
  18. # that action.
  19. #
  20. global betavals, blev
  21.  
  22. %}
  23.  
  24. %token INTVAL, STRVAL, LINE
  25.  
  26. %%
  27.  
  28. betalines    : betalines, betaline
  29.         | epsilon
  30.         ;
  31.  
  32. betaline    : '~', cvalue, xvalue, yvalue, '\n'
  33.                     { if integer(betavals[2]) then {
  34.                           write(betavals[1], " ",
  35.                             betavals[2], ":",
  36.                             betavals[3])
  37.                       }
  38.                       blev := 4 # global
  39.                     }
  40.         | LINE, '\n'        { write($1) }
  41.         ;
  42.  
  43. cvalue        : 'a', value, 'b', value, 'c', value
  44.                     { betavals[blev := 1] := $6 }
  45.         | 'c', value        { betavals[blev := 1] := $2 }
  46.         | epsilon
  47.         ;
  48.  
  49. xvalue        : 'x', value        { betavals[blev := 2] := $2 }
  50.         | 'x'            { if integer(betavals[2])
  51.                       then betavals[blev := 2] +:= 1
  52.                       else betavals[blev := 2]  := 1
  53.                     }
  54.         | epsilon        { if blev < 2 then
  55.                           betavals[2] := 1
  56.                     }
  57.         ;
  58.  
  59. yvalue        : 'y', value        { betavals[blev := 3] := $2 }
  60.         | 'y'            { betavals[blev := 3] +:= 1 }
  61.         | epsilon        { if blev < 3 then
  62.                           betavals[3] := 1
  63.                     }
  64.         ;
  65.  
  66. value        : INTVAL        { return $1 }
  67.         | STRVAL        { return $1 }
  68.         ;
  69.  
  70.  
  71. %%
  72.  
  73.  
  74. procedure iilex(infile)
  75.  
  76.     local line
  77.     # betavals is global
  78.     initial betavals := ["", 0, 0]
  79.  
  80.     while line := read(infile) do {
  81.     line ? {
  82.         if ="~" then {
  83.         suspend ord("~")
  84.         until pos(0) do {
  85.             case move(1) of {
  86.             "a"     : suspend ord("a")
  87.             "b"     : suspend ord("b")
  88.             "c"     : suspend ord("c")
  89.             "x"     : suspend ord("x")
  90.             "y"     : suspend ord("y")
  91.             default : stop("betacode error:  ", line)
  92.             }
  93.             if ="\"" then {
  94.             iilval := tab(find("\""))
  95.             suspend STRVAL
  96.             move(1)
  97.             } else {
  98.             if iilval := integer(tab(many(&digits)))
  99.             then suspend INTVAL
  100.             }
  101.         }
  102.         suspend ord("\n")
  103.         }
  104.         else {
  105.         iilval := line
  106.         suspend LINE
  107.         suspend ord("\n")
  108.         }
  109.     }
  110.     }
  111.  
  112. end
  113.  
  114.  
  115. procedure main()
  116.     return iiparse(&input)
  117. end
  118.