30628092 |
1 | |
2 | C<<1: The Programming Language |
3 | ============================== |
4 | |
5 | Feedback: xchaos@arachne.cz |
6 | Homepage: http://gpl.arachne.cz |
7 | |
8 | Copyright (G) 2004 Michael Polak, x@n.cz |
9 | C<<1 is available under terms of GNU Lesser Public License (LGPL) |
10 | This file is available under terms of GNU Free Documentation License |
11 | |
12 | 1. Introduction |
13 | --------------- |
14 | |
15 | There are various extensions and definitions of classical C language, |
16 | for example object oriented "C++" and "Objective C", minimalistic C--, |
17 | proprietary C# used by .Net project, etc. Many other modern languages |
18 | |
19 | C<<1 is designed to work as "stylesheet" for very classical ANSI C, and |
20 | it was specificaly tested to work fine with GNU C Compiler gcc. There is |
21 | no special C<<1 compiler or interpreter; instead, you are expected to |
22 | include special header file called cll1.h the same way you would include |
23 | let's say string or I/O library implemented in standard C library. Except |
24 | that you don't need to link your executable with any special library, |
25 | neither staticaly nor dynamicaly, and you don't have to configure your gcc |
26 | or make to do so. |
27 | |
28 | #include <cll1.h> |
29 | |
30 | Or #include "cll1.h", if cll1.h is not installed in your /usr/include |
31 | directory. That'it. No linking, no initialization, allocation, or so. |
32 | |
33 | C<<1 can be used for dummy, structured or object oriented programing, |
34 | whatever method you prefere. C<<1 focuses mainly on adding new complex |
35 | semantic structures into C, rather than inventing brand new syntax or class |
36 | hieararchy, or providing set of pre-defined library functions. To allow |
37 | that, most of C<<1 functions are implemented as macros for C preprocessor. |
38 | |
39 | 2. Getting started |
40 | ------------------ |
41 | |
42 | #include <cll1.h> |
43 | |
44 | program |
45 | { |
46 | puts("Hello World!"); |
47 | } |
48 | |
49 | Of course, int main(int argc,void **argv) can be still used. In fact, |
50 | macro "program" doesn't do much more than that ! Following program prints |
51 | all arguments: |
52 | |
53 | program |
54 | { |
55 | char *ptr; |
56 | |
57 | arguments |
58 | { |
59 | thisargument(ptr); |
60 | puts(ptr); |
61 | } |
62 | else |
63 | puts("Bleeeeh, no arguments supplied... :-("); |
64 | } |
65 | |
66 | Well, don't be surprised with "else" after "arguments". This is not the |
67 | last time in C<<1, when you will see C keywords somewhere you don't expect |
68 | them. Of course, you would like to use it this way, I guess: |
69 | |
70 | program |
71 | { |
72 | char *ptr; |
73 | |
74 | arguments |
75 | { |
76 | argument("-?") printf("This is just help!\n"); |
77 | else argument("-f") { nextargument(ptr) printf("Forced argument: %s\n",ptr); } |
78 | else { thisargument(ptr); printf("Simple argument: %s \n",ptr); } |
79 | } |
80 | else |
81 | puts("Bleeeeh, no arguments supplied... :-("); |
82 | } |
83 | |
84 | 2. Where is my main() funciton ?! |
85 | --------------------------------- |
86 | |
87 | If you want to use int main(int argc,void **argv) { } instead of |
88 | program { }, it's ok. Being fan of Basic and not Pascal, I don't |
89 | like the program keyword at all. In fact, by avoiding "program" construct |
90 | and using standard main() declaration, you would be still able to access |
91 | most of C<<1 functionality, but for example not the arguments() structure |
92 | mentioned above. |
93 | |
94 | 3. Ok, let's go on |
95 | ------------------ |
96 | |
97 | This is some code to send e-mail using unix sendmail: |
98 | (ok, nothing special, same as "echo .... | sendmail ....") |
99 | |
100 | program |
101 | { |
102 | paste("From: me@here\nSubject: Here we go...\n\nblah blah blah") |
103 | system("/usr/sbin/sendmail someone@somewhere"); |
104 | } |
105 | |
106 | This program prints exactly 6th column of /etc/passwd file |
107 | (ok, nothing special, same as "cut -f 6 -d : /etc/passwd") |
108 | |
109 | program |
110 | { |
111 | char *ptr; |
112 | parse("/etc/passwd") |
113 | { |
114 | column(ptr,_,':',6); |
115 | if(ptr)puts(ptr); |
116 | } |
117 | done; |
118 | } |
119 | |
120 | But next program prints 1st and 6th column of /etc/passwd. |
121 | (What is equivalent in bash ?) |
122 | |
123 | program |
124 | { |
125 | char *ptr; |
126 | int i; |
127 | parse("/etc/passwd") |
128 | { |
129 | columns(ptr,_,':',i) switch(i) |
130 | { |
131 | case 1: printf("%s...",ptr); break; |
132 | case 6: puts(ptr); |
133 | } |
134 | } |
135 | done; |
136 | } |
137 | |
138 | |
139 | 4. Groups of C<<1 macros |
140 | ------------------------ |
141 | |
142 | ! - macro is available only when using "program" instead of "main()" |
143 | |
144 | I. Unconditional iterations - without else |
145 | |
146 | every |
147 | iterate |
148 | repeat ! |
149 | |
150 | II. Conditional iterations - else can happen once |
151 | |
152 | find |
153 | arguments ! |
154 | argument |
155 | nextargument |
156 | |
157 | III. Conditional iterations - else can happen many times |
158 | |
159 | search |
160 | valid_split |
161 | valid_columns |
162 | |
163 | IV. Weird iterations (with something special) |
164 | |
165 | parse - [fail] - done |
166 | |
167 | V. Standalone sequences - they look like function calls, but they are not. |
168 | |
169 | insert |
170 | append |
171 | push |
172 | remove |
173 | sort |
174 | shell |
175 | paste |
176 | column |
177 | valid_column |
178 | ... |
179 | |
180 | VI. Well behaved seqences - can be used anywhere where functions can. |
181 | |
182 | create |
183 | string |
184 | goto_* |
185 | prefix |
186 | suffix |
187 | ... |
188 | |
189 | 5. Forbidden namespace |
190 | ---------------------- |
191 | |
192 | Variables starting with _ (underscored) followed by one or more capital |
193 | characters (A-Z) are reserved as C<<1 private compile-time namespace. |
194 | |
195 | 6. Compile time errors |
196 | ---------------------- |
197 | |
198 | - parse error at end of input |
199 | |
200 | You probably forgot to close some macro which must be obligatory |
201 | terminated by another macro - as "parse error" message suggests, |
202 | it is likely to be error in macro "parse() { } [ fail ] { } done; " |
203 | |
204 | :-) |
205 | |
206 | 7. We apologize for inconvenience |
207 | --------------------------------- |
208 | |
209 | This documentation file is unfortunately incomplete. |
210 | HTML online documentation is comming soon ... sooner ... or later... |