-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.TXT
298 lines (262 loc) · 10.5 KB
/
README.TXT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
MSEpas/MSElang
Original: https://gitlab.com/mseide-msegui/mselang
Fork: https://github.com/mse-org/mselang
Release from fork: https://github.com/mse-org/mselang/releases
Copyright (c) 2013-2018 by Martin Schreiber
MSElang 2013-11-01
=======
In the beginning of 2013 I decided to make an own compiler for the MSEide+MSEgui project and started to experiment.
The reason is the development direction of Delphi since Delphi 7 which makes it less suitable for my tasks and
knowing that Free Pascal is closely following the same direction.
The design goals
----------------
Ultimate goal is to build the most productive universal programming environment,
usable from programming of microcontrollers to MSEgui projects.
1. Simple.
Reduce the language concepts one has to learn to the minimum, make them as orthogonal as possible.
2. Readable.
MSElang programs should read like a letter.
3. Easy to learn.
Because of 1. and 2. it should be suitable for pupils as first programming language.
4. Powerful
Allow to go down to the bare metal, it has pointers and pointer arithmetic. ;-)
Object orientated high level programming.
5. Fast running
State of the art optimizations.
6. Fast compiling
While defining the language keep in mind how it can be implemented efficiently.
The Steps
---------
At the beginning MSElang will be the language currently used in MSEgui project, a subset of Delphi 7 and FPC 2.6.2.
Later syntax changes are possible.
In order to develop and test the front-end there first will be an intermediate code interpreter which can be used in MSEifi projects
and in MSEgui report generator. Most likely there will be not much effort invested to make it fast at runtime
but compiletime must be lightning fast.
Later native code back-ends and a simple RTL will be added.
The time frame
--------------
3..5 years until a usable interpreter, additional 3..5 years for one or two native backends.
Experiments up to now
---------------------
Currently I am experimenting how to make a fast and nonetheless easy maintainable compiler frontend . Some ideas:
- There is a syntax generator program which transforms a grammar into Pascal structures. Example:
starttoken definition:
@whitespace
' ',#$0d,#$0a
macro:
{whitespace}
"@whitespace,
'{$',directive-^*
'{',comment0-^*
'//',linecomment0-^*"
more starttokens:
@keywordstart
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'
'q','r','s','t','u','v','w','x','y','z'
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'
'Q','R','S','T','U','V','W','X','Y','Z'
@identstart
'_',@keywordstart
@num
'0','1','2','3','4','5','6','7','8','9'
...
a contextline with branches:
start,nounit,
${whitespace}
'unit'.,unit0-
a transition context with a handler procedure:
nounit,,handlenouniterror
more contexts:
unit0,nounitname,handlenounitnameerror
${whitespace}
@identstart,ident^*,unit1
nounitname,,handlenounitnameerror
unit1,unit2,setunitname
unit2,semicolonexpected,
${whitespace}
';',start1-
...
transforms to the Pascal structures:
const
tks_none = 0;
tks_classes = $2468ACF1;
tks_private = $48D159E3;
tks_protected = $91A2B3C6;
tks_public = $2345678C;
tks_published = $468ACF19;
tk_unit = $8D159E33;
tk_uses = $1A2B3C66;
tk_implementation = $345678CD;
tk_const = $68ACF19B;
tk_var = $D159E337;
tk_type = $A2B3C66E;
...
tokens: array[0..25] of string = ('',
'.classes','.private','.protected','.public','.published',
'unit','uses','implementation','const','var','type','procedure','begin',
'dumpelements','abort','end','if','then','else','record','class','private',
'protected','public','published');
tokenids: array[0..25] of identty = (
$00000000,$2468ACF1,$48D159E3,$91A2B3C6,$2345678C,$468ACF19,$8D159E33,
$1A2B3C66,$345678CD,$68ACF19B,$D159E337,$A2B3C66E,$45678CDD,$8ACF19BB,
$159E3376,$2B3C66ED,$5678CDDB,$ACF19BB7,$59E3376E,$B3C66EDD,$678CDDBA,
$CF19BB75,$9E3376EB,$3C66EDD6,$78CDDBAD,$F19BB75B);
var
startco: contextty = (branch: nil; handle: nil;
continue: false; cut: false; restoresource: false;
pop: false; popexe: false; nexteat: false; next: nil;
caption: 'start');
nounitco: contextty = (branch: nil; handle: nil;
continue: false; cut: false; restoresource: false;
pop: false; popexe: false; nexteat: false; next: nil;
caption: 'nounit');
unit0co: contextty = (branch: nil; handle: nil;
continue: false; cut: false; restoresource: false;
pop: false; popexe: false; nexteat: false; next: nil;
caption: 'unit0');
nounitnameco: contextty = (branch: nil; handle: nil;
continue: false; cut: false; restoresource: false;
pop: false; popexe: false; nexteat: false; next: nil;
caption: 'nounitname');
unit1co: contextty = (branch: nil; handle: nil;
continue: false; cut: false; restoresource: false;
pop: false; popexe: false; nexteat: false; next: nil;
caption: 'unit1');
unit2co: contextty = (branch: nil; handle: nil;
continue: false; cut: false; restoresource: false;
pop: false; popexe: false; nexteat: false; next: nil;
caption: 'unit2');
...
const
bstart: array[0..5] of branchty = (
(flags: [bf_nt,bf_keyword,bf_eat];
dest: (context: @unit0co); stack: nil;
keyword: $8D159E33{'unit'}),
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @directiveco); stack: nil; keys: (
(kind: bkk_charcontinued; chars: ['{']),
(kind: bkk_char; chars: ['$']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @linecomment0co); stack: nil; keys: (
(kind: bkk_charcontinued; chars: ['/']),
(kind: bkk_char; chars: ['/']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt];
dest: (context: nil); stack: nil; keys: (
(kind: bkk_char; chars: [#10,#13,' ']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @comment0co); stack: nil; keys: (
(kind: bkk_char; chars: ['{']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: []; dest: (context: nil); stack: nil; keyword: 0)
);
bunit0: array[0..5] of branchty = (
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @directiveco); stack: nil; keys: (
(kind: bkk_charcontinued; chars: ['{']),
(kind: bkk_char; chars: ['$']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @linecomment0co); stack: nil; keys: (
(kind: bkk_charcontinued; chars: ['/']),
(kind: bkk_char; chars: ['/']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt];
dest: (context: nil); stack: nil; keys: (
(kind: bkk_char; chars: [#10,#13,' ']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @comment0co); stack: nil; keys: (
(kind: bkk_char; chars: ['{']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt,bf_push,bf_setparentbeforepush];
dest: (context: @identco); stack: @unit1co; keys: (
(kind: bkk_char; chars: ['A'..'Z','_','a'..'z']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: []; dest: (context: nil); stack: nil; keyword: 0)
);
bunit2: array[0..5] of branchty = (
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @directiveco); stack: nil; keys: (
(kind: bkk_charcontinued; chars: ['{']),
(kind: bkk_char; chars: ['$']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @linecomment0co); stack: nil; keys: (
(kind: bkk_charcontinued; chars: ['/']),
(kind: bkk_char; chars: ['/']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt];
dest: (context: nil); stack: nil; keys: (
(kind: bkk_char; chars: [#10,#13,' ']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt,bf_eat,bf_push,bf_setparentbeforepush];
dest: (context: @comment0co); stack: nil; keys: (
(kind: bkk_char; chars: ['{']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: [bf_nt,bf_eat];
dest: (context: @start1co); stack: nil; keys: (
(kind: bkk_char; chars: [';']),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: []),
(kind: bkk_none; chars: [])
)),
(flags: []; dest: (context: nil); stack: nil; keyword: 0)
);
...
- There is a small language independent kernel function in compiler which parses the source based on the above language data structure
and calls the language specific handler procedures.
Because it is small, the kernel can be highly optimised, even coding it in assembler or implementing in an FPGA should be possible.
- There is a central element hash list where the data and function structure of the program is stored.
Hierarchy is handled by storing the sum of the element ID's up to the root, possible collisions must be handled
by checking the path ID's.
- The data of unit implementation sections can be released with a mark/release mechanism in order to free not anymore used elements.
- Text tokens and keywords get a hash and a unique ID while reading the source.
The ID is a random number in order to minimize conflicts in the central element hash list.
- The compiler kernel maintains a single context stack, the context handler procedures use the stack to store intermediate information
and the central element hash list for persistent data.
Thoughts for a future syntax
----------------------------
- records, objects and classes could be unified in a single concept.
- instead of "begin"/"end" there could be a mandatory "end" in structured statements.
What will not be implemented
----------------------------
- Macros.
- Generics/templates, there will be functionality which makes them superfluous.
- "codepage aware AnsiStrings". ;-)
Martin