Commit 020f10e7fb04595863dc7fb7b6c85074cdee486f

Authored by Alain Prouté
1 parent 03958653

*** empty log message ***

anubis_dev/compiler2/src/common.anubis
... ... @@ -42,6 +42,12 @@ public type Tree:
42 42 of_type (Position, Tree type, Tree term).
43 43  
44 44  
  45 +
  46 +
  47 + *** [] Syntax errors.
  48 +
  49 +public type SyntaxError:
  50 +
45 51  
46 52  
47 53  
... ...
anubis_dev/compiler2/src/postparser_1.anubis 0 → 100644
  1 +
  2 +
  3 + _____ ___. .__ ________
  4 + / _ \ ____ __ _\_ |__ |__| ______ \_____ \
  5 + / /_\ \ / \| | \ __ \| |/ ___/ / ____/
  6 + / | \ | \ | / \_\ \ |\___ \ / \
  7 + \____|__ /___| /____/|___ /__/____ > \_______ \
  8 + \/ The \/ Anubis \/ 2 \/ Project \/
  9 +
  10 +
  11 + Name of this file: postparser_1.anubis
  12 +
  13 + Purpose of this file: The postparser.
  14 +
  15 +
  16 +
  17 + Authors (Name [initials]): Alain Proute' [AP]
  18 +
  19 + Updates ([initials] (date) comment):
  20 + [AP] (2007 jul 18) Creation of this file.
  21 +
  22 + ---------------------------------------------------------------------------------------
  23 +
  24 +read common.anubis
  25 +
  26 +
  27 +
  28 +public define Result(SyntaxError,WeakParagraph)
  29 + postparse
  30 + (
  31 + Tree paragraph,
  32 + ).
  33 +
  34 +
  35 +
  36 +
  37 + --- That's all for the public part ! --------------------------------------------------
  38 +
  39 +
  40 +
  41 +
  42 +
  43 +
  44 +
0 45 \ No newline at end of file
... ...
anubis_dev/compiler2/src/preparser_1.apg
... ... @@ -8,9 +8,9 @@
8 8 \/ The \/ Anubis \/ 2 \/ Project \/
9 9  
10 10  
11   - Name of this file: parser_1_v2.apg
  11 + Name of this file: preparser_1.apg
12 12  
13   - Purpose of this file: second version of the Anubis 2 parser.
  13 + Purpose of this file: The preparser of the Anubis 2 compiler.
14 14  
15 15  
16 16  
... ... @@ -22,24 +22,16 @@
22 22 ---------------------------------------------------------------------------------------
23 23  
24 24  
25   - This APG file defines the Anubis 2 parser. It is made of two parts:
26   -
27   - - the 'preparser' which is defined using APG,
28   - - the actual 'parser', which is an ordinary Anubis program calling the preparser and
29   - performing some postparsing.
  25 + This APG file defines the Anubis 2 preparser. It is made of two parts:
30 26  
31 27  
32 28  
33 29 #APG
34   -
35   -
  30 +
36 31 read common.anubis
37   - read dictionary_1.anubis
38   - read memory_1.anubis
39   -
40   -
41   - *** [] The preparser.
42 32  
  33 + The type 'Tree' is defined in 'common.anubis'.
  34 +
43 35  
44 36  
45 37 #preparser
... ... @@ -82,16 +74,16 @@ right y_juxtapos .
82 74  
83 75 Types of grammar symbols.
84 76  
  77 +type (PARAGRAPH) One .
85 78 type (Tree) TREE .
86 79  
87   -type (Position) y_comma .
88 80 type ((Position,String)) y_equals y_parameter y_symbol y_forall y_iplus y_unary_keyword .
89 81 type ((Position,String)) y_binary_keyword y_or y_and y_implies y_minus y_plus y_dot .
90 82 type ((Position,String)) y_star y_caret y_white y_juxtapos .
91 83 type ((Position,List(DecimalDigit))) y_decimal .
92 84 type ((Position,List(HexadecimalDigit))) y_hexadecimal .
93 85 type ((Position,List(Word8))) y_string .
94   -type (Position) y_lpar y_lbracket y_lbrace y_lparcolon .
  86 +type (Position) y_comma y_lpar y_lbracket y_lbrace y_lparcolon .
95 87  
96 88  
97 89  
... ... @@ -102,17 +94,20 @@ extra (State) comp_state .
102 94  
103 95 #
104 96  
105   - The axiom is the grammar is 'TREE'. In other words, the parser reads one paragraph
106   - at a time.
107 97  
  98 + Modules:
  99 +
  100 +MODULE: /* empty */ .
  101 +MODULE: PARAGRAPH(_) MODULE .
  102 +
108 103  
109 104 Paragraphs:
110 105  
111   -TREE(e):
112   - TREE(e) y_end_of_par .
  106 +PARAGRAPH(postparse(e)):
  107 + y_par_begin TREE(e) y_par_end .
113 108  
114   -TREE(if p is (pos,sign) then binary(pos,sign,e,empty)):
115   - TREE(e) y_equals(p) y_end_of_par .
  109 +PARAGRAPH(if p is (pos,sign) then postparse(binary(pos,sign,e,empty))):
  110 + y_par_begin TREE(e) y_equals(p) y_par_end .
116 111  
117 112  
118 113  
... ... @@ -224,133 +219,3 @@ TREE(of_type(pos,type,term)):
224 219 #
225 220  
226 221  
227   -
228   - *** [] Postparsing.
229   -
230   - The above grammar is quite simple, too simple it may seem in order to represent all
231   - constructions of the Anubis 2 language. Nevertheless, it is able to handle all
232   - constructions, but this may need some 'postparsing'. We now show how usual
233   - constructions are realized.
234   -
235   -
236   - *** [] Lists.
237   -
238   - The expression [a . b] is realized as:
239   -
240   - [ ] (unary exfix)
241   - |
242   - . (binary infix y_star)
243   - / \
244   - a b
245   -
246   - The expression [a,b,c,d] is realized as a bracketed tuple.
247   -
248   -
249   -
250   - *** [] Conditionals.
251   -
252   - The keyword 'if' is a unary (prefix) keyword, whilst 'is' is a binary keyword. Hence,
253   -
254   - if test is { a then A, ..., z then Z} else E
255   -
256   - is realized as:
257   -
258   - if
259   - |
260   - is
261   - / \
262   - test else
263   - / \
264   - { } E
265   - |
266   - ,
267   - / \
268   - then \
269   - / \ \
270   - a A \
271   - .
272   - .
273   - .
274   - ,
275   - / \
276   - then \
277   - / \ \
278   - y Y \
279   - then
280   - / \
281   - z Z
282   -
283   -
284   - The boolean conditional 'if A then B else C' is realizd as:
285   -
286   - if
287   - |
288   - then
289   - / \
290   - A else
291   - / \
292   - B C
293   -
294   -
295   -
296   - *** [] Local definitions.
297   -
298   - The local definition 'with x = a, y = b, z = c, t' is realized as:
299   -
300   - with (multi keyword)
301   - |
302   - ,
303   - / \
304   - = \
305   - / \ \
306   - x a \
307   - ,
308   - / \
309   - = \
310   - / \ \
311   - y b \
312   - ,
313   - / \
314   - = \
315   - / \ \
316   - z c \
317   - t
318   -
319   -
320   - *** [] Chain association.
321   -
322   - The precedence level y_equals is actually not right associative but 'chain'
323   - associative. This level contains the following signs (but not only):
324   -
325   - = < > =< >=
326   -
327   - and an expression like:
328   -
329   - a < b = c >= d
330   -
331   - is read as:
332   -
333   - (a < b) & (b = c) & (c >= d)
334   -
335   - regardless of the meaning of '&'. This is 'chain association', which is handled by
336   - postparsing. For performance reasons, it is transformed actually into:
337   -
338   - with y = b, z = c, (a < y) & (y = z) & (z >= d)
339   -
340   - in order to avoid computing 'b' and 'c' two times.
341   -
342   - The above expression is comming out of the parser like this:
343   -
344   - <
345   - / \
346   - a =
347   - / \
348   - b >=
349   - / \
350   - c d
351   -
352   -
353   -
354   -
355   -
356   -
357 222 \ No newline at end of file
... ...