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

  1. ############################################################################
  2. #
  3. #    File:     proto.icn
  4. #
  5. #    Subject:  Program to show Icon syntactic forms
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     January 3, 1993
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #     This program doesn't "do" anything.  It just contains an example of
  18. #  every syntactic form in Version 7 of Icon (or close to it).  It might
  19. #  be useful for checking programs that process Icon programs.  Note, however,
  20. #  that it does not contain many combinations of different syntactic forms.
  21. #
  22. ############################################################################
  23. #
  24. #  Program note:
  25. #
  26. #     This program is divided into procedures to avoid overflow with
  27. #  default values for Icon's translator and linker.
  28. #
  29. ############################################################################
  30. #
  31. #  Links: options
  32. #
  33. #  Requires:  co-expressions
  34. #
  35. ############################################################################
  36.  
  37. link options
  38.  
  39. record three(x,y,z)
  40. record zero()
  41. record one(z)
  42.  
  43. invocable all
  44.  
  45. global line, count
  46.  
  47. procedure main()
  48.    expr1()
  49.    expr2()
  50.    expr3()
  51.    expr4(1,2)
  52.    expr4{1,2}
  53.    expr5(1,2,3,4)
  54. end
  55.  
  56. procedure expr1()
  57.    local x, y, z
  58.    local i, j
  59.    static e1
  60.  
  61.    initial e1 := 0
  62.  
  63.    exit()            # get out before there's trouble
  64.  
  65.    ()
  66.    {}
  67.    ();()
  68.    []
  69.    [,]
  70.    x.y
  71.    x[i]
  72.    x[i:j]
  73.    x[i+:j]
  74.    x[i-:j]
  75.    (,,,)
  76.    x(,,,)
  77.    not x
  78.    |x
  79.    !x
  80.    *x
  81.    +x
  82.    -x
  83. end
  84.  
  85. procedure expr2()
  86.    local x, i, y, j, c1, c2, s1, s2, a2, k, a1
  87.  
  88.    .x
  89.    /x
  90.    =x
  91.    ?x
  92.    \x
  93.    ~x
  94.    @x
  95.    ^x
  96.    x \ i
  97.    x @ y
  98.    i ^ j
  99.    i * j
  100.    i / j
  101.    i % j
  102.    c1 ** c2
  103.    i + j
  104.    i - j
  105.    c1 ++ c2
  106.    c1 -- c2
  107.    s1 || s2
  108.    a1 ||| a2
  109.    i < j
  110.    i <= j
  111.    i = j
  112.    i >= j
  113.    i > j
  114.    i ~= j
  115.    s1 << s2
  116.    s1 == s2
  117.    s1 >>= s2
  118.    s1 >> s2
  119.    s1 ~== s2
  120.    x === y
  121.    x ~=== y
  122.    x | y
  123.    i to j
  124.    i to j by k
  125.    x := y
  126.    x <- y
  127.    x :=: y
  128.    x <-> y
  129.    i +:= j
  130.    i -:= j
  131.    i *:= j
  132. end
  133.  
  134. procedure expr3()
  135.    local i, j, c1, c2, s1, s2, a1, a2, x, y, s
  136.  
  137.    i /:= j
  138.    i %:= j
  139.    i ^:= j
  140.    i <:= j
  141.    i <=:= j
  142.    i =:= j
  143.    i >=:= j
  144.    i ~=:= j
  145.    c1 ++:= c2
  146.    c1 --:= c2
  147.    c1 **:= c2
  148.    s1 ||:= s2
  149.    s1 <<:= s2
  150.    s1 <<=:= s2
  151.    s1 ==:= s2
  152.    s1 >>=:= s2
  153.    s1 >>:= s2
  154.    s1 ~==:= s2
  155.    s1 ?:= s2
  156.    a1 |||:= a2
  157.    x ===:= y
  158.    x ~===:= y
  159.    x &:= y
  160.    x @:= y
  161.    s ? x
  162.    x & y
  163.    create x
  164.    return
  165.    return x
  166.    suspend x
  167.    suspend x do y
  168.    fail
  169. end
  170.  
  171. procedure expr4()
  172.    local e1, e2, e, x, i, j, size, s, e3, X_
  173.  
  174.    while e1 do break
  175.    while e1 do break e2
  176.    while e1 do next
  177.    case e of {
  178.      x:   fail
  179.      (i > j) | 1    :  return
  180.      }
  181.    case size(s) of {
  182.      1:   1
  183.      default:  fail
  184.      }
  185.    if e1 then e2
  186.    if e1 then e2 else e3
  187.    repeat e
  188.    while e1
  189.    while e1 do e2
  190.    until e1
  191.    until e1 do e2
  192.    every e1
  193.    every e1 do e2
  194.    x
  195.    X_
  196.    &cset
  197.    &null
  198.    "abc"
  199.    "abc_
  200.     cde"
  201.    'abc'
  202.    'abc_
  203.     cde'
  204.    "\n"
  205.    "^a"
  206.    "\001"
  207.    "\x01"
  208.    1
  209.    999999
  210.    36ra1
  211.    3.5
  212.    2.5e4
  213.    4e-10
  214. end
  215.  
  216. procedure expr5(a,b,c[])
  217. end
  218.