Debian Codegraph @

ipl/packs/skeem/skfun.icn

raw
1 ############################################################################
2 #
3 # Name: skfun.icn
4 #
5 # Title: Scheme in Icon
6 #
7 # Author: Bob Alexander
8 #
9 # Date: March 23, 1995
10 #
11 # Description: see skeem.icn
12 #
13 ############################################################################
14
15 #
16 # skeem -- Scheme in Icon
17 #
18
19 #
20 # Function/syntax list format
21 #
22 # Each function and syntax defined appears in a definition list which is
23 # processed at skeem-initialization time. The following are the rules
24 # for function/syntax list entries:
25 #
26 # - Each entry begins with a procedure name and ends just preceding
27 # the next procedure name or the end of the list.
28 # - Rules regarding number of arguments:
29 # - If an entry contains the object "oneOrMore", then it requires
30 # at least one argument.
31 # - If an entry contains the object "twoOrMore", then it requires
32 # at least two arguments.
33 # - If an entry contains one number N, it requires exactly N
34 # arguements.
35 # - If an entry contains a number N followed by &null, the function
36 # requires at least N arguments.
37 # - If an entry contains a number N followed by a number M, the
38 # function requires at least N arguments but can take no more than
39 # M arguments.
40 # - If an entry contains no numbers but contains &null, the function
41 # can take any number of arguments.
42 # - If an entry contains no numbers and no &null, the procedure
43 # requires exactly one argument.
44 # - If an entry contains a string, then that string is used as the
45 # function's skeem-name rather that the name calculated from its
46 # Icon procedure name.
47 #
48
49 procedure InitFunctions()
50 every (
51 InitBasic | # basic syntaxes skbasic.icn
52 InitControl | # control functions skcontrl.icn
53 InitIO | # I/O functions skio.icn
54 InitList | # list & vector functions sklist.icn
55 InitMisc | # misc functions skmisc.icn
56 InitNumber | # number functions sknumber.icn
57 InitString | # string and char functions skstring.icn
58 \!InitUser())() # user-defined functions skuser.icn
59 end
60
61 procedure DefFunction(prcList,funType)
62 local item,funName,prc,minArgs,maxArgs,gotNull,special
63 /funType := Function
64 prc := get(prcList)
65 while \prc do {
66 funName := minArgs := maxArgs := gotNull := special := &null
67 repeat {
68 (item := get(prcList)) | {
69 item := &null
70 break
71 }
72 if type(item) == "procedure" then break
73 if type(item) == "integer" then /minArgs | maxArgs := item
74 else if /item then gotNull := "true"
75 else if type(item) == "string" then
76 (if item == ("oneOrMore" | "twoOrMore") then special
77 else funName) := item
78 }
79 if special === "oneOrMore" then minArgs := 1
80 else if special === "twoOrMore" then minArgs := 2
81 else if /minArgs then
82 if \gotNull then minArgs := 0
83 else minArgs := maxArgs := 1
84 else if /gotNull then
85 /maxArgs := minArgs
86 /funName := ProcName(prc)
87 #write("+++ ",funName,": ",image(prc),", ",image(minArgs),", ",
88 # image(maxArgs))
89 DefVar(funName,funType(prc,funName,minArgs,maxArgs))
90 prc := item
91 }
92 return
93 end
94
95 procedure DefSyntax(prc)
96 return DefFunction(prc,Syntax)
97 end
98
99 procedure ProcName(prc)
100 local nm
101 image(prc) ? {
102 tab(find(" ") + 1)
103 nm := ""
104 while nm ||:= tab(find("_")) do {
105 move(1)
106 nm ||:= if ="BANG" & pos(0) then "!"
107 else if ="2_" then "->"
108 else if ="P" & pos(0) then "?"
109 else "-"
110 }
111 nm ||:= tab(0)
112 }
113 return nm
114 end