Вариант исправленный, но никто не тестил

  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
$ENTRY Go{
= <Prout <UnLexer <Preprocessor <Bracket <Lexer <GetSymbol <Card> (1)(1)>>>>>>;
}
Class {
s.Char = <DoClass
s.Char
(UpLetter 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
(LoLetter 'abcdefghijklmnopqrstuvwxyz')
(Digit '1234567890')
(EOF '!')
>;
}
DoClass {
s.Char (s.Class s.Char e.Tail) e.Classes = s.Class;
s.Char (s.Class s.OtherChar e.Tail)e.Classes = <DoClass s.Char (s.Class e.Tail) e.Classes>;
s.Char (s.Class) e.Classes = <DoClass s.Char e.Classes>;
s.Char = Other;
}
GetSymbol {
'!' e.Text (s.Line)(s.Col) = ('!' EOF s.Line s.Col);
'\n' e.Text(s.Line)(s.Col) = ('\n' Other s.Line s.Col) <GetSymbol e.Text (<Inc s.Line>) (1)>;
s.Char e.Text (s.Line)(s.Col) = (s.Char <Class s.Char> s.Line s.Col) <GetSymbol e.Text (s.Line)(<Inc s.Col>)>;
}
Inc {
e.Arg = <Add 1 e.Arg>;
}
Lexer {
(' ' Other s.Line s.Col)e.Tail = <Lexer e.Tail>;
(';' Other s.Line s.Col)e.Tail = (Semicolon (s.Line s.Col) ';' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
(':' Other s.Line s.Col)e.Tail = (Colon (s.Line s.Col) ':' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
('<' Other s.Line s.Col)e.Tail = (OpenCall (s.Line s.Col) '\<' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
('>' Other s.Line s.Col)e.Tail = (CloseCall (s.Line s.Col) '\>' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
('(' Other s.Line s.Col)e.Tail = (OpenBracket (s.Line s.Col) '\(' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
(')' Other s.Line s.Col)e.Tail = (CloseBracket (s.Line s.Col) '\)' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
('{' Other s.Line s.Col)e.Tail = (OpenBlock (s.Line s.Col) '{' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
('}' Other s.Line s.Col)e.Tail = (CloseBlock (s.Line s.Col) '}' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
('=' Other s.Line s.Col)e.Tail = (Assign (s.Line s.Col) '=' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
('&' Other s.Line s.Col)e.Tail = (Ref (s.Line s.Col) '&' (s.Line <Inc s.Col>)) <Lexer e.Tail>;
('!' EOF s.Line s.Col)e.Tail = (EOF (s.Line s.Col) '!' (s.Line <Inc s.Col>));
('e' LoLetter s.Line s.Col) ('.' Other s.LineDot s.ColDot) e.Tail =
<ReadVariable 'e' s.Line s.Col () e.Tail>;
('s' LoLetter s.Line s.Col) ('.' Other s.LineDot s.ColDot) e.Tail =
<ReadVariable 'e' s.Line s.Col () e.Tail>;
('t' LoLetter s.Line s.Col) ('.' Other s.LineDot s.ColDot) e.Tail =
<ReadVariable 'e' s.Line s.Col () e.Tail>;
(s.Char s.Class s.Line s.Col)(' ' s.Class1 s.Line1 s.Col1)e.Tail = (Char (s.Line s.Col) s.Char (s.Line1 s.Col1))<Lexer e.Tail>;
(s.Char Digit s.Line s.Col)e.Tail = '('Number(s.Line s.Col) s.Char<GetNumber e.Tail>;
(s.Char UpLetter s.Line s.Col) e.Tail = '('Name(s.Line s.Col) s.Char<GetName e.Tail>;
('\'' Other s.Line s.Col) e.Tail = <ReadChars e.Tail>;
}
ReadVariable {
s.VarType s.StartVarLine s.StartVarCol (e.Name) (s.Letter UpLetter s.Line s.Col) e.Tail =
<ReadVariable s.VarType s.StartVarLine s.StartVarCol (<PushBack (e.Name) s.Letter>) e.Tail>;
s.VarType s.StartVarLine s.StartVarCol (e.Name) (s.Letter LoLetter s.Line s.Col) e.Tail =
<ReadVariable s.VarType s.StartVarLine s.StartVarCol (<PushBack (e.Name) s.Letter>) e.Tail>;
s.VarType s.StartVarLine s.StartVarCol (e.Name) (s.Letter Digit s.Line s.Col) e.Tail =
<ReadVariable s.VarType s.StartVarLine s.StartVarCol (<PushBack (e.Name) s.Letter>) e.Tail>;
s.VarType s.StartVarLine s.StartVarCol (e.Name) e.Tail =
(Variable (s.StartVarLine s.StartVarCol) s.VarType (e.Name)) <Lexer e.Tail>;
}
ReadChars {
('\'' Other s.Line s.Col) e.Tail = <Lexer e.Tail>;
(EOF EOF s.Line s.Col) e.Tail = (Error (s.Line s.Col) 'Uclosed quote at end of file') (EOF (s.Line s.Col));
('\\' Other s.Line s.Col) e.Tail = <ReadChars-HandleEscape e.Tail>;
('\n' LoLetter s.Line s.Col) e.Tail = (Error (s.Line s.Col) 'Unclosed quote at end of line') <Lexer e.Tail>;
(s.Char s.Class s.Line s.Col) e.Tail =
(Char (s.Line s.Col) s.Char) <ReadChars e.Tail>;
}
ReadChars-HandleEscape {
('n' LoLetter s.Line s.Col) e.Tail = (Char (s.Line s.Col) '\n') <ReadChars e.Tail>;
('t' LoLetter s.Line s.Col) e.Tail = (Char (s.Line s.Col) '\t') <ReadChars e.Tail>;
('\\' LoLetter s.Line s.Col) e.Tail = (Char (s.Line s.Col) '\\') <ReadChars e.Tail>;
('\'' LoLetter s.Line s.Col) e.Tail = (Char (s.Line s.Col) '\'') <ReadChars e.Tail>;
/* ('x' LoLetter s.Line s.Col) e.Tail = <ReadChars-HandleEscape-HexCode e.Tail>; */
('\n' LoLetter s.Line s.Col) e.Tail = <ReadChars e.Tail>;
(s.Other s.Class s.Line s.Col) e.Tail = (Error (s.Line s.Col) 'Bad symbol in escape') <ReadChars e.Tail>;
}
GetNumber {
(s.Char Digit s.Line s.Col)e.Tail = s.Char <GetNumber e.Tail>;
(' ' Other s.Line s.Col)e.Tail = (s.Line s.Col)')'<Lexer e.Tail>;
(s.Char s.Class s.Line s.Col)e.Tail = (s.Line s.Col)')'<Lexer (s.Char s.Class s.Line s.Col)e.Tail>;
}
GetName {
(s.Char UpLetter s.Line s.Col)e.Tail = s.Char<GetName e.Tail>;
(s.Char LoLetter s.Line s.Col)e.Tail = s.Char<GetName e.Tail>;
(s.Char Digit s.Line s.Col)e.Tail = s.Char<GetName e.Tail>;
('-' Other s.Line s.Col)e.Tail = '-'<GetName e.Tail>;
(' ' Other s.Line s.Col)e.Tail = (s.Line s.Col)')'<Lexer e.Tail>;
(s.Char s.Class s.Line s.Col)e.Tail = (s.Line s.Col)')'<Lexer (s.Char s.Class s.Line s.Col)e.Tail>;
}
Bracket {
e.Head'('e.Token')'e.Tail = e.Head(e.Token)<Bracket e.Tail>;
e.Body = e.Body;
}
UnLexer {
(s.Domen (e.BeginLine e.BeginCol) e.Lex (e.EndLine e.EndCal))(s.Domen1 (e.BeginLine e.BeginCol1) e.Lex1 (e.EndLine e.EndCal1))e.Tail =
e.Lex ' ' <UnLexer (s.Domen1 (e.BeginLine e.BeginCol1) e.Lex1 (e.EndLine e.EndCal1))e.Tail>;
(s.Domen (e.BeginLine e.BeginCol) e.Lex (e.EndLine e.EndCal))(s.Domen1 (e.BeginLine1 e.BeginCol1) e.Lex1 (e.EndLine1 e.EndCal1))e.Tail =
e.Lex '\n' <UnLexer (s.Domen1 (e.BeginLine1 e.BeginCol1) e.Lex1 (e.EndLine1 e.EndCal1))e.Tail>;
(EOF (e.BeginLine e.BeginCol) e.Lex (e.EndLine e.EndCal)) = e.Lex;
}
Preprocessor {
e.H (s.D1 (s.BL s.BC) '<' (s.EL s.EC))(Name (s.BL1 s.BC1) s.N (s.EL1 s.EC1))(s.D2 (s.BL2 s.BC2)'>'(s.EL2 s.EC2))e.T =
e.H(s.D1(s.BL s.BC)'<'(s.EL s.EC))(Name(s.BL1 s.BC1)Mu(s.EL1 <+ 2 s.BC1>))(Name(s.BL1 <+ 2 s.BC1>)s.N(s.EL1 <+ 2 s.EC1>))(s.D2(s.BL2 <+ 2 s.BC2>)'>'(s.EL2 <+ 2 s.EC2>))<Preprocessor e.T>;
(EOF e.EOF) = (EOF e.EOF);
}