source: devel-tools/trunk/LL1GrammarAnalyzers/LLAnalyzerInRfp2k9/src/GrScn.rf @ 4103

Last change on this file since 4103 was 4103, checked in by yura, 11 years ago
  • Copy from LLAnalyzerInRfp2k7.
  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1//
2// File: GRSCN.RF
3//
4// Project: GR
5//
6
7//
8// e.Tokens = { e.Token }.
9// e.Token = Key s.Key | Name s.Name | Char s.Char.
10// s.Key  = s.Word.
11// s.Name = s.Word.
12//
13
14$use Box;
15$use Class;
16$use Convert;
17$use Dos;
18$use StdIO;
19
20$func  ScanToken       s.Chl e.Line = s.TokenKey s.TokenInfo (e.Line1);
21$func  ScanIdRest     (e.IdChars)  e.Chars = s.TokenKey s.Word (e.Rest);
22$func  ScanComment     s.Chl e.Line = s.TokenKey s.TokenInfo (e.Line1);
23$func? IsComment         s.Char e.Line = e.Rest;
24$func? IsBlank           s.Char = ;
25$func? IsOneCharToken  s.Char = ;
26$func? IsCompoundToken  s.Char e.Line = s.Word e.Rest;
27
28$box ScanChl ScanLine;
29
30InitScanner  s.Chl =
31  <Store &ScanChl s.Chl>,
32  <Store &ScanLine >;
33
34TermScanner  =
35  <Store &ScanChl   >,
36  <Store &ScanLine  >;
37
38ReadToken  =
39  <Get &ScanChl> : s.Chl,
40  <Get &ScanLine> :: e.Line,
41  <ScanToken s.Chl e.Line> :: s.TokenKey s.TokenInfo (e.Line),
42  <Store &ScanLine e.Line>,
43    = s.TokenKey s.TokenInfo;
44
45ScanToken  s.Chl e.Line =
46  e.Line :
47  {
48  =
49    {
50    <ReadLineCh s.Chl> :: e.Line
51      = <ScanToken s.Chl e.Line>;
52      = Key Eof ();
53    };
54  s.Char e.Rest =
55    {
56    <IsComment s.Char e.Rest> :: e.Rest
57      = <ScanComment s.Chl e.Rest>;
58    <IsBlank s.Char>
59      = <ScanToken s.Chl e.Rest>;
60    <IsLetter s.Char>
61      = <ScanIdRest (s.Char) e.Rest>;
62    <IsOneCharToken s.Char>
63      = Key <ToWord s.Char> (e.Rest);
64    <IsCompoundToken s.Char e.Rest> :: s.Word e.Rest
65      = Key s.Word (e.Rest);
66      = Char s.Char (e.Rest);
67    };
68  };
69
70ScanComment s.Chl e.Line =
71  {
72  e.Line : e '*/' e.Rest
73    = <ScanToken s.Chl e.Rest>;
74    = {
75      <ReadLineCh s.Chl> :: e.Line
76        = <ScanComment s.Chl e.Line>;
77        = <PrintLnCh &StdErr "EOF in a comment">,
78          <Exit 1>,
79          Key Eof ();
80      };
81  };
82
83ScanIdRest  (e.IdChars) e.Rest =
84  {
85  e.Rest : s.Char e.Rest1,
86           \{ <IsLetter s.Char>; <IsDigit  s.Char>; s.Char : '_'; }
87    = <ScanIdRest (e.IdChars s.Char) e.Rest1>;
88    = Name <ToWord e.IdChars> (e.Rest);
89  };
90
91IsBlank  s.Char =
92  ' \n\t' : e s.Char e;
93
94IsOneCharToken  s.Char =
95  ':|;' : e s.Char e;
96
97IsCompoundToken
98  \{
99  '%%'     e.Rest = "%%" e.Rest;
100  '%token' e.Rest = "%token" e.Rest;
101  };
102
103IsComment
104  '/*' e.Rest = e.Rest;
Note: See TracBrowser for help on using the repository browser.