📄 magic.dpr
字号:
(* lexical analyzer template (TP Lex V3.0), V1.0 3-2-91 AG *)
(* global definitions: *)
(* 演示状态的用法 *)
program Magic;
{$APPTYPE CONSOLE}
uses
SysUtils, LexLib;
const
SMAGIC = 2;
function yylex: Integer;
procedure yyaction(yyruleno: Integer);
(* local definitions: *)
begin
(* actions: *)
case yyruleno of
1:
begin
Start(0);
write('Magic:');
ECHO;
end;
2:
start(SMAGIC);
3:
ECHO;
end;
end (*yyaction*);
(* DFA table: *)
type
YYTRec = record
cc: set of Char;
s: Integer;
end;
const
yynmarks = 20;
yynmatches = 20;
yyntrans = 28;
yynstates = 16;
yyk: array[1..yynmarks] of Integer = (
{ 0: }
{ 1: }
{ 2: }
{ 3: }
{ 4: }
3,
{ 5: }
3,
{ 6: }
1,
3,
{ 7: }
1,
3,
{ 8: }
3,
{ 9: }
1,
3,
{ 10: }
3,
{ 11: }
1,
3,
{ 12: }
3,
{ 13: }
1,
3,
{ 14: }
2,
3,
{ 15: }
1,
2,
3
);
yym: array[1..yynmatches] of Integer = (
{ 0: }
{ 1: }
{ 2: }
{ 3: }
{ 4: }
3,
{ 5: }
3,
{ 6: }
1,
3,
{ 7: }
1,
3,
{ 8: }
3,
{ 9: }
1,
3,
{ 10: }
3,
{ 11: }
1,
3,
{ 12: }
3,
{ 13: }
1,
3,
{ 14: }
2,
3,
{ 15: }
1,
2,
3
);
yyt: array[1..yyntrans] of YYTrec = (
{ 0: }
(cc: [#1..#9, #11..'l', 'n'..#255]; s: 5),
(cc: ['m']; s: 4),
{ 1: }
(cc: [#1..#9, #11..'l', 'n'..#255]; s: 5),
(cc: ['m']; s: 4),
{ 2: }
(cc: [#1..#9, #11..'l', 'n'..#255]; s: 6),
(cc: ['m']; s: 7),
{ 3: }
(cc: [#1..#9, #11..'l', 'n'..#255]; s: 6),
(cc: ['m']; s: 7),
{ 4: }
(cc: [#1..#9, #11..'`', 'b'..#255]; s: 5),
(cc: ['a']; s: 8),
{ 5: }
(cc: [#1..#9, #11..#255]; s: 5),
{ 6: }
(cc: [#1..#9, #11..#255]; s: 6),
{ 7: }
(cc: [#1..#9, #11..'`', 'b'..#255]; s: 6),
(cc: ['a']; s: 9),
{ 8: }
(cc: [#1..#9, #11..'f', 'h'..#255]; s: 5),
(cc: ['g']; s: 10),
{ 9: }
(cc: [#1..#9, #11..'f', 'h'..#255]; s: 6),
(cc: ['g']; s: 11),
{ 10: }
(cc: [#1..#9, #11..'h', 'j'..#255]; s: 5),
(cc: ['i']; s: 12),
{ 11: }
(cc: [#1..#9, #11..'h', 'j'..#255]; s: 6),
(cc: ['i']; s: 13),
{ 12: }
(cc: [#1..#9, #11..'b', 'd'..#255]; s: 5),
(cc: ['c']; s: 14),
{ 13: }
(cc: [#1..#9, #11..'b', 'd'..#255]; s: 6),
(cc: ['c']; s: 15),
{ 14: }
(cc: [#1..#9, #11..#255]; s: 5),
{ 15: }
(cc: [#1..#9, #11..#255]; s: 6)
);
yykl: array[0..yynstates - 1] of Integer = (
{ 0: } 1,
{ 1: } 1,
{ 2: } 1,
{ 3: } 1,
{ 4: } 1,
{ 5: } 2,
{ 6: } 3,
{ 7: } 5,
{ 8: } 7,
{ 9: } 8,
{ 10: } 10,
{ 11: } 11,
{ 12: } 13,
{ 13: } 14,
{ 14: } 16,
{ 15: } 18
);
yykh: array[0..yynstates - 1] of Integer = (
{ 0: } 0,
{ 1: } 0,
{ 2: } 0,
{ 3: } 0,
{ 4: } 1,
{ 5: } 2,
{ 6: } 4,
{ 7: } 6,
{ 8: } 7,
{ 9: } 9,
{ 10: } 10,
{ 11: } 12,
{ 12: } 13,
{ 13: } 15,
{ 14: } 17,
{ 15: } 20
);
yyml: array[0..yynstates - 1] of Integer = (
{ 0: } 1,
{ 1: } 1,
{ 2: } 1,
{ 3: } 1,
{ 4: } 1,
{ 5: } 2,
{ 6: } 3,
{ 7: } 5,
{ 8: } 7,
{ 9: } 8,
{ 10: } 10,
{ 11: } 11,
{ 12: } 13,
{ 13: } 14,
{ 14: } 16,
{ 15: } 18
);
yymh: array[0..yynstates - 1] of Integer = (
{ 0: } 0,
{ 1: } 0,
{ 2: } 0,
{ 3: } 0,
{ 4: } 1,
{ 5: } 2,
{ 6: } 4,
{ 7: } 6,
{ 8: } 7,
{ 9: } 9,
{ 10: } 10,
{ 11: } 12,
{ 12: } 13,
{ 13: } 15,
{ 14: } 17,
{ 15: } 20
);
yytl: array[0..yynstates - 1] of Integer = (
{ 0: } 1,
{ 1: } 3,
{ 2: } 5,
{ 3: } 7,
{ 4: } 9,
{ 5: } 11,
{ 6: } 12,
{ 7: } 13,
{ 8: } 15,
{ 9: } 17,
{ 10: } 19,
{ 11: } 21,
{ 12: } 23,
{ 13: } 25,
{ 14: } 27,
{ 15: } 28
);
yyth: array[0..yynstates - 1] of Integer = (
{ 0: } 2,
{ 1: } 4,
{ 2: } 6,
{ 3: } 8,
{ 4: } 10,
{ 5: } 11,
{ 6: } 12,
{ 7: } 14,
{ 8: } 16,
{ 9: } 18,
{ 10: } 20,
{ 11: } 22,
{ 12: } 24,
{ 13: } 26,
{ 14: } 27,
{ 15: } 28
);
var
yyn: Integer;
label
start, scan, action;
begin
start:
(* initialize: *)
yynew;
scan:
(* mark positions and matches: *)
for yyn := yykl[yystate] to yykh[yystate] do
yymark(yyk[yyn]);
for yyn := yymh[yystate] downto yyml[yystate] do
yymatch(yym[yyn]);
if yytl[yystate] > yyth[yystate] then
goto action; (* dead state *)
(* get next character: *)
yyscan;
(* determine action: *)
yyn := yytl[yystate];
while (yyn <= yyth[yystate]) and not (yyactchar in yyt[yyn].cc) do
inc(yyn);
if yyn > yyth[yystate] then
goto action;
(* no transition on yyactchar in this state *)
(* switch to new state: *)
yystate := yyt[yyn].s;
goto scan;
action:
(* execute action: *)
if yyfind(yyrule) then
begin
yyaction(yyrule);
if yyreject then
goto action;
end
else if not yydefault and yywrap then
begin
yyclear;
return(0);
end;
if not yydone then
goto start;
yylex := yyretval;
end (*yylex*);
begin
yylex;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -