Pristine Ack-5.5
[Ack-5.5.git] / lang / pc / comp / program.g
1 /* The grammar of ISO-Pascal as given by the specification, BS6192: 1982. */
2
3 {
4 #include        <alloc.h>
5 #include        <em_arith.h>
6 #include        <em_label.h>
7 #include        <em_code.h>
8 #include        <stb.h>
9
10 #include        "LLlex.h"
11 #include        "def.h"
12 #include        "f_info.h"
13 #include        "idf.h"
14 #include        "main.h"
15 #include        "node.h"
16 #include        "scope.h"
17 #include        "dbsymtab.h"
18 }
19
20 %lexical LLlex;
21
22 %start LLparse, Program;
23
24 /* ISO section 6.10, p. 137 */
25 Program
26 {
27         struct def *df;
28         arith dummy;
29 }:
30         ProgramHeading(&df)
31         ';' Block(df) '.'
32           {
33 #ifdef DBSYMTAB
34             if (options['g']) {
35                 C_ms_stb_cst(df->df_idf->id_text, N_MAIN, 0, (arith) 0);
36                 stb_string(df, D_END);
37             }
38 #endif /* DBSYMTAB */
39           }
40         | { df = new_def();
41             df->df_idf = str2idf(FileName, 1);
42             df->df_kind = D_MODULE;
43             open_scope();
44             GlobalScope = CurrentScope;
45             df->prc_vis = CurrVis;
46           }
47
48           Module(df, &dummy)
49 ;
50
51 ProgramHeading(register struct def **df;):
52         PROGRAM IDENT
53                         { program = *df = new_def();
54                           (*df)->df_idf = dot.TOK_IDF;
55                           (*df)->df_kind = D_PROGRAM;
56                           open_scope();
57                           GlobalScope = CurrentScope;
58                           (*df)->prc_vis = CurrVis;
59 #ifdef DBSYMTAB
60                           if (options['g']) stb_string(*df, D_MODULE);
61 #endif /* DBSYMTAB */
62                         }
63         [
64                 '('
65                 ProgramParameters
66                 ')'
67                                 { make_extfl(); }
68         ]?
69 ;
70
71 ProgramParameters
72 {
73         struct node *Proglist;
74 }:
75         IdentifierList(&Proglist)
76                                 { EnterProgList(Proglist); }
77 ;