source: devel-tools/trunk/LL1GrammarAnalyzers/LLAnalyzerInRfp2k9/src/GrPrn.rf @ 4111

Last change on this file since 4111 was 4111, checked in by yura, 11 years ago
  • Write annotated grammar to file.
  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1//
2// File GRPRN.RF
3//
4// Project: GR
5//
6
7$use StdIO;
8
9$func PrintSetLoop e.TkList = ;
10$func PrintSetRest e.TkList = ;
11
12PrintGrammar (e.Tokens) (e.Rules) =
13  <PrintLnCh &WriteFileCh "%token\n  ">,
14  <PrintSet e.Tokens>,
15  <PrintLnCh &WriteFileCh "\n%%\n">,
16  <PrintRules e.Rules>;
17
18PrintSet e.TkList =
19  <PrintCh &WriteFileCh "(">
20  <PrintSetLoop e.TkList>
21  <PrintCh &WriteFileCh ")">;
22
23PrintSetLoop
24  {
25  s1 s2 s3 s4 s5 v.Rest =
26    <PrintCh &WriteFileCh s1><PrintCh &WriteFileCh " | ">
27    <PrintCh &WriteFileCh s2><PrintCh &WriteFileCh " | ">
28    <PrintCh &WriteFileCh s3><PrintCh &WriteFileCh " | ">
29    <PrintCh &WriteFileCh s4><PrintCh &WriteFileCh " | ">
30    <PrintCh &WriteFileCh s5><PrintCh &WriteFileCh " | ">
31    <PrintCh &WriteFileCh "\n  ">,
32    = <PrintSetLoop v.Rest>;
33  s1 s2 s3 s4 s5 =
34    <PrintCh &WriteFileCh s1><PrintCh &WriteFileCh " | ">
35    <PrintCh &WriteFileCh s2><PrintCh &WriteFileCh " | ">
36    <PrintCh &WriteFileCh s3><PrintCh &WriteFileCh " | ">
37    <PrintCh &WriteFileCh s4><PrintCh &WriteFileCh " | ">
38    <PrintCh &WriteFileCh s5>;
39  e.Rest =
40    <PrintSetRest e.Rest>;
41  };
42
43PrintSetRest
44  {
45  s1 v.Rest =
46    <PrintCh &WriteFileCh s1><PrintCh &WriteFileCh " | "><PrintSetRest v.Rest>;
47  s1 =
48    <PrintCh &WriteFileCh s1>;
49  = ;
50  };
51
52PrintRules
53  {
54  $l e (sN e.Rules) e,
55    <PrintLnCh &WriteFileCh sN>,
56    \{
57    e.Rules : $l eL (e.Rhs) eR,
58      { eL : = ":"; = "|";} :: s.Prefix,
59      <PrintCh &WriteFileCh "        "><PrintCh &WriteFileCh s.Prefix><PrintCh &WriteFileCh "   ">
60      <PrintRhs e.Rhs>
61      <PrintLnCh &WriteFileCh>, $fail;
62    <PrintCh &WriteFileCh "        ;\n\n">,
63      $fail;
64    },
65    $fail;
66  e;
67  };
68
69PrintRhs
70  {
71  = <PrintCh &WriteFileCh "/* empty */">;
72  $l e (s.Tag s.Sym) e,
73    <PrintCh &WriteFileCh s.Sym>,
74    <PrintCh &WriteFileCh " "> $fail;
75  e = ;
76  };
77
78PrintAnnSym (e.Nullable) s.Sym =
79  {
80  e.Nullable : e s.Sym e
81    = <PrintCh &WriteFileCh "#">;
82    = ;
83  },
84  <PrintCh &WriteFileCh s.Sym>;
85
86PrintAnnRhs (e.Nullable) (e.Rhs) =
87  e.Rhs :
88  {
89  = <PrintCh &WriteFileCh "/* empty */">;
90  $l e (s.Tag s.Sym) e,
91    <PrintAnnSym (e.Nullable) s.Sym>,
92    <PrintCh &WriteFileCh " "> $fail;
93  e = ;
94  };
95
96PrintEnv
97  {
98  $l e (s.N (eV)) e,
99    <PrintLnCh &WriteFileCh><PrintCh &WriteFileCh s.N><PrintCh &WriteFileCh " ->\n  ">,
100    <PrintSet eV> $fail;
101  e = <PrintLnCh &WriteFileCh>;
102  };
Note: See TracBrowser for help on using the repository browser.