Category : Pascal Source Code
Archive   : LEX_YACC.ZIP
Filename : TABLE.L

 
Output of file : TABLE.L contained in archive : LEX_YACC.ZIP

{ TABLE.L: Lex demonstration program for the use of character tables;
accepts identifiers, signed integers, whitespace and newline as input
and prints out the names of the matched tokens; unrecognized characters
are converted to and echoed as '?' (ASCII 63). }

uses LexLib;

{ redefined input functions that remap characters: }
function input : char; forward;
procedure unput(c : char); forward;

%T
1 Aa
2 Bb
3 Cc
{ ... }
26 Zz
27 \ \t
28 +
29 -
30 0
31 1
{ ... }
39 9
40 \n
%T

letter [A-Z]
digit [0-9]

%%

{letter}({letter}|{digit})* write(' ');
[+-]?{digit}+ write(' ');
" "+ write(' ');
\n writeln('');
. write(yytext[1]);

%%

(* implementation of input functions and main program: *)

var buf : string; (* lookahead buffer *)
function input : char;
var c : char;
begin
if length(buf)>0 then
(* get char from lookahead buffer: *)
begin
input := buf[1];
delete(buf, 1, 1)
end
else
begin
(* get character from input file (converting line end
to newline, and handling end of file): *)
if eof(yyin) then
c := #0
else if eoln(yyin) then
begin
c := #10; (* newline *)
readln(yyin)
end
else
read(yyin, c);
(* remap characters: *)
case c of
#0: input := #0;
'a'..'z': input := chr(succ(ord(c)-ord('a')));
'A'..'Z': input := chr(succ(ord(c)-ord('A')));
' ', #9: input := #27;
'+': input := #28;
'-': input := #29;
'0'..'9': input := chr(ord(c)-ord('0')+30);
#10: input := #40;
else input := '?'; (* denotes illegal character *)
end;
end
end(*input*);
procedure unput(c : char);
begin
buf := c+buf
end(*unput*);

begin
buf := '';
if yylex=0 then (* done *)
end.

  3 Responses to “Category : Pascal Source Code
Archive   : LEX_YACC.ZIP
Filename : TABLE.L

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/