Last change
on this file was 103, checked in by chronos, 8 years ago |
- Moved: All projects moved to subfolders for better maintenance of multiple projects.
|
File size:
804 bytes
|
Line | |
---|
1 | program interpreter;
|
---|
2 |
|
---|
3 | function IsWhiteSpace(C: Char): Boolean;
|
---|
4 | begin
|
---|
5 | Result := (C = ' ') or (C = #13) or (C = #10) or (C = #9);
|
---|
6 | end;
|
---|
7 |
|
---|
8 | procedure ShowError(Text: string);
|
---|
9 | begin
|
---|
10 | WriteLn(Text);
|
---|
11 | Halt;
|
---|
12 | end;
|
---|
13 |
|
---|
14 | function ReadChar: Char;
|
---|
15 | begin
|
---|
16 | if Eof then ShowError('Premature end of source');
|
---|
17 | Read(Result);
|
---|
18 | end;
|
---|
19 |
|
---|
20 | function ReadNext: string;
|
---|
21 | var
|
---|
22 | C: Char;
|
---|
23 | begin
|
---|
24 | Result := '';
|
---|
25 | C := ReadChar;
|
---|
26 | while IsWhiteSpace(C) do C := ReadChar;
|
---|
27 | while not IsWhiteSpace(C) do begin
|
---|
28 | Result := Result + C;
|
---|
29 | C := ReadChar;
|
---|
30 | end;
|
---|
31 | end;
|
---|
32 |
|
---|
33 | procedure Expect(Text: string);
|
---|
34 | var
|
---|
35 | Next: string;
|
---|
36 | begin
|
---|
37 | Next := ReadNext;
|
---|
38 | if Next <> Text then
|
---|
39 | ShowError('Expected ' + Text + ' but found ' + Next);
|
---|
40 | end;
|
---|
41 |
|
---|
42 | begin
|
---|
43 | WriteLn('Start');
|
---|
44 | Expect('begin');
|
---|
45 | Expect('end.');
|
---|
46 | WriteLn('Finished');
|
---|
47 | end.
|
---|
48 | {
|
---|
49 | |begin
|
---|
50 | |end.
|
---|
51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.