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 / progs / lindcode.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  98 lines

  1. ############################################################################
  2. #
  3. #    File:     lindcode.icn
  4. #
  5. #    Subject:  Program to produce Icon code from L-system specifications
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     August 19, 1993
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program reads a file of L-system specifications and build Icon
  18. #  code that creates a table of records containing the specifications.
  19. #
  20. #  If the option -e is given, symbols for which there is no definition
  21. #  are included in the table with themselves as replacement.
  22. #
  23. ############################################################################
  24. #
  25. #  See also:  lindrec.icn
  26. #
  27. ############################################################################
  28. #
  29. #  Links:  options
  30. #
  31. ############################################################################
  32.  
  33. link options
  34.  
  35. procedure main(args)
  36.    local allchar, rchar, line, prefix, symbol, rhs, file, name, spec
  37.    local value, c, opts, expand
  38.  
  39.    opts := options(args, "e")
  40.    expand := opts["e"]
  41.    write("   linden := table()\n")
  42.  
  43.    while line := read() do {
  44.       line ? {
  45.          if ="name:" then {
  46.             name := tab(0)
  47.             break
  48.             }
  49.          }
  50.       }
  51.  
  52.    repeat {
  53.  
  54.       allchar := rchar := ''
  55.  
  56.       prefix := "   linden[" || image(name) || "]"
  57.    
  58.       write(prefix, " := lsys_0l(\"\", table(), 0, 90)")
  59.    
  60.       while line := read() | exit() do
  61.          line ? {
  62.             if symbol := move(1) & ="->" then {
  63.                rchar ++:= symbol
  64.                rhs := tab(0)
  65.                write(prefix, ".rewrite[\"", symbol, "\"] := ", image(rhs))
  66.                allchar ++:= rhs
  67.                }
  68.          else if spec := tab(upto(':')) then {
  69.             move(1)
  70.             value := tab(0)
  71.             case spec of {
  72.                "axiom":  {
  73.                   allchar ++:= value
  74.                   write(prefix, ".axiom := ", image(value))
  75.                   }
  76.                "gener":  write(prefix, ".gener := ", integer(value))
  77.                "angle":  write(prefix, ".angle := ", real(value))
  78.                "length":  write(prefix, ".length := ", integer(value))
  79.                "name":   {
  80.                    name := value
  81.                    break
  82.                    }
  83.                }
  84.             }
  85.  
  86.          }
  87.  
  88.       if \expand then {
  89.          allchar --:= rchar
  90.          every c := image(!allchar) do
  91.             write(prefix, ".rewrite[", c, "] := ", c)
  92.          }
  93.  
  94.       }
  95.  
  96.  
  97. end
  98.