UNIX Free Pascal


.. lex - 3


 

{letter}({letter}|{digit})* begin yydone:=true; yyretval:=_IDENT; end;

\n ;

. ;

%%

 

function yywrap:integer;

begin

yywrap:=1;

end;

 

 

const

words:array[_AND.._XOR] of string=(

'AND',

'ASM',

'ARRAY',

'BEGIN',

'CASE',

'CONST',

'CONSTRUCTOR',

'DESTRUCTOR',

'DIV',

'DO',

'DOWNTO',

'ELSE',

'END',

'EXPORTS',

'FILE',

'FOR',

'FUNCTION',

'GOTO',

'IF',

'IMPLEMENTATION',

'IN',

'INHERITED',

'INLINE',

'INTERFACE',

'LABEL',

'LIBRARY',

'MOD',

'NIL',

'NOT',

'OBJECT',

'OF',

'OR',

'PACKED',

'PROCEDURE',

'PROGRAM',

'RECORD',

'REPEAT',

'SET',

'SHL',

'SHR',

'STRING',

'THEN',

'TO',

'TYPE',

'UNIT',

'UNTIL',

'USES',

'VAR',

'WHILE',

'WITH',

'XOR' );

var

kwcount:array [1..51] of integer;

token,i:integer;

 

begin

if paramcount<>1 then

begin

writeln(': ', paramstr(0), ' ');

exit;

end;

 

assign(yyinput,paramstr(1));

{$I-}

reset(yyinput);

if ioresult<>0 then

begin

writeln(' ', paramstr(1));

exit;

end;

for i:=_AND to _XOR do

kwcount[i]:=0;

 

token:=yylex;

while not eof(yyinput) do

begin

if token in [_AND.._XOR] then

inc(kwcount[token]);

token:=yylex;

end;

if token in [_AND.._XOR] then

inc(kwcount[token]);

for i:=_AND to _XOR do

if kwcount[i]<>0 then

writeln(' ', words[i], ' ', kwcount[i], ' ');

close(yyinput);

end.

 

13.67. . ; char s[] = "/*"; ! .

%{

uses lexlib;

const

STROKA=1;

COMMENT=2;

ANY=3;




- -  - -  - -