📄 commandline2.dpr
字号:
(* lexical analyzer template (TP Lex V3.0), V1.0 3-2-91 AG *)
(* global definitions: *)
program CommandLine2.dpr;
{$APPTYPE CONSOLE} //注意别忘了指定控制台模式
uses
//CommandLex单元是改写后的LexLib,重定义了get_char, unget_char和put_char三个函数,以便
//使用命令行参数作为解析对象。
SysUtils, Classes, CommandLex, Windows;
var
FileName: integer;
const
FNAME = 2;
function yylex: Integer;
procedure yyaction(yyruleno: Integer);
(* local definitions: *)
begin
(* actions: *)
case yyruleno of
1:
{* 忽略空格 *};
2:
{* 忽略空格 *};
3,
4,
5:
begin
writeln(format('用法是: %s [-help | -h | -? ] [-verbose | -v] [(-file| -f) filename]', [GetCommandLine]));
return(0);
end;
6,
7:
writeln('打开Verbose模式');
8,
9:
begin
//注意在TP Lex Yacc中因为关键字的原因Begin宏变成了Start函数
Start(FNAME);
FileName := 1;
end;
10:
begin
Writeln(format('使用了文件%s', [yytext]));
Start(0);
FileName := 2;
end;
11:
ECHO;
end;
end (*yyaction*);
(* DFA table: *)
type
YYTRec = record
cc: set of Char;
s: Integer;
end;
const
yynmarks = 71;
yynmatches = 71;
yyntrans = 82;
yynstates = 42;
yyk: array[1..yynmarks] of Integer = (
{ 0: }
{ 1: }
{ 2: }
{ 3: }
{ 4: }
1,
{ 5: }
11,
{ 6: }
11,
{ 7: }
1,
2,
{ 8: }
10,
11,
{ 9: }
10,
11,
{ 10: }
3,
11,
{ 11: }
4,
11,
{ 12: }
6,
11,
{ 13: }
8,
11,
{ 14: }
3,
10,
11,
{ 15: }
4,
10,
11,
{ 16: }
6,
10,
11,
{ 17: }
8,
10,
11,
{ 18: }
11,
{ 19: }
11,
{ 20: }
11,
{ 21: }
10,
11,
{ 22: }
10,
11,
{ 23: }
10,
11,
{ 24: }
11,
{ 25: }
11,
{ 26: }
11,
{ 27: }
10,
11,
{ 28: }
10,
11,
{ 29: }
10,
11,
{ 30: }
5,
11,
{ 31: }
11,
{ 32: }
9,
11,
{ 33: }
5,
10,
11,
{ 34: }
10,
11,
{ 35: }
9,
10,
11,
{ 36: }
11,
{ 37: }
10,
11,
{ 38: }
11,
{ 39: }
10,
11,
{ 40: }
7,
11,
{ 41: }
7,
10,
11
);
yym: array[1..yynmatches] of Integer = (
{ 0: }
{ 1: }
{ 2: }
{ 3: }
{ 4: }
1,
{ 5: }
11,
{ 6: }
11,
{ 7: }
1,
2,
{ 8: }
10,
11,
{ 9: }
10,
11,
{ 10: }
3,
11,
{ 11: }
4,
11,
{ 12: }
6,
11,
{ 13: }
8,
11,
{ 14: }
3,
10,
11,
{ 15: }
4,
10,
11,
{ 16: }
6,
10,
11,
{ 17: }
8,
10,
11,
{ 18: }
11,
{ 19: }
11,
{ 20: }
11,
{ 21: }
10,
11,
{ 22: }
10,
11,
{ 23: }
10,
11,
{ 24: }
11,
{ 25: }
11,
{ 26: }
11,
{ 27: }
10,
11,
{ 28: }
10,
11,
{ 29: }
10,
11,
{ 30: }
5,
11,
{ 31: }
11,
{ 32: }
9,
11,
{ 33: }
5,
10,
11,
{ 34: }
10,
11,
{ 35: }
9,
10,
11,
{ 36: }
11,
{ 37: }
10,
11,
{ 38: }
11,
{ 39: }
10,
11,
{ 40: }
7,
11,
{ 41: }
7,
10,
11
);
yyt: array[1..yyntrans] of YYTrec = (
{ 0: }
(cc: [#1..#31, '!'..',', '.'..#255]; s: 6),
(cc: [' ']; s: 4),
(cc: ['-']; s: 5),
{ 1: }
(cc: [#1..#31, '!'..',', '.'..#255]; s: 6),
(cc: [' ']; s: 4),
(cc: ['-']; s: 5),
{ 2: }
(cc: [#1..#31, '!'..',', '.'..#255]; s: 9),
(cc: [' ']; s: 7),
(cc: ['-']; s: 8),
{ 3: }
(cc: [#1..#31, '!'..',', '.'..#255]; s: 9),
(cc: [' ']; s: 7),
(cc: ['-']; s: 8),
{ 4: }
(cc: [' ']; s: 4),
{ 5: }
(cc: [#1..#31, '!'..'>', '@'..'e', 'g', 'i'..'u', 'w'..#255]; s: 6),
(cc: ['?']; s: 11),
(cc: ['f']; s: 13),
(cc: ['h']; s: 10),
(cc: ['v']; s: 12),
{ 6: }
(cc: [#1..#31, '!'..#255]; s: 6),
{ 7: }
(cc: [' ']; s: 7),
{ 8: }
(cc: [#1..#31, '!'..'>', '@'..'e', 'g', 'i'..'u', 'w'..#255]; s: 9),
(cc: ['?']; s: 15),
(cc: ['f']; s: 17),
(cc: ['h']; s: 14),
(cc: ['v']; s: 16),
{ 9: }
(cc: [#1..#31, '!'..#255]; s: 9),
{ 10: }
(cc: [#1..#31, '!'..'d', 'f'..#255]; s: 6),
(cc: ['e']; s: 18),
{ 11: }
(cc: [#1..#31, '!'..#255]; s: 6),
{ 12: }
(cc: [#1..#31, '!'..'d', 'f'..#255]; s: 6),
(cc: ['e']; s: 19),
{ 13: }
(cc: [#1..#31, '!'..'h', 'j'..#255]; s: 6),
(cc: ['i']; s: 20),
{ 14: }
(cc: [#1..#31, '!'..'d', 'f'..#255]; s: 9),
(cc: ['e']; s: 21),
{ 15: }
(cc: [#1..#31, '!'..#255]; s: 9),
{ 16: }
(cc: [#1..#31, '!'..'d', 'f'..#255]; s: 9),
(cc: ['e']; s: 22),
{ 17: }
(cc: [#1..#31, '!'..'h', 'j'..#255]; s: 9),
(cc: ['i']; s: 23),
{ 18: }
(cc: [#1..#31, '!'..'k', 'm'..#255]; s: 6),
(cc: ['l']; s: 24),
{ 19: }
(cc: [#1..#31, '!'..'q', 's'..#255]; s: 6),
(cc: ['r']; s: 25),
{ 20: }
(cc: [#1..#31, '!'..'k', 'm'..#255]; s: 6),
(cc: ['l']; s: 26),
{ 21: }
(cc: [#1..#31, '!'..'k', 'm'..#255]; s: 9),
(cc: ['l']; s: 27),
{ 22: }
(cc: [#1..#31, '!'..'q', 's'..#255]; s: 9),
(cc: ['r']; s: 28),
{ 23: }
(cc: [#1..#31, '!'..'k', 'm'..#255]; s: 9),
(cc: ['l']; s: 29),
{ 24: }
(cc: [#1..#31, '!'..'o', 'q'..#255]; s: 6),
(cc: ['p']; s: 30),
{ 25: }
(cc: [#1..#31, '!'..'a', 'c'..#255]; s: 6),
(cc: ['b']; s: 31),
{ 26: }
(cc: [#1..#31, '!'..'d', 'f'..#255]; s: 6),
(cc: ['e']; s: 32),
{ 27: }
(cc: [#1..#31, '!'..'o', 'q'..#255]; s: 9),
(cc: ['p']; s: 33),
{ 28: }
(cc: [#1..#31, '!'..'a', 'c'..#255]; s: 9),
(cc: ['b']; s: 34),
{ 29: }
(cc: [#1..#31, '!'..'d', 'f'..#255]; s: 9),
(cc: ['e']; s: 35),
{ 30: }
(cc: [#1..#31, '!'..#255]; s: 6),
{ 31: }
(cc: [#1..#31, '!'..'n', 'p'..#255]; s: 6),
(cc: ['o']; s: 36),
{ 32: }
(cc: [#1..#31, '!'..#255]; s: 6),
{ 33: }
(cc: [#1..#31, '!'..#255]; s: 9),
{ 34: }
(cc: [#1..#31, '!'..'n', 'p'..#255]; s: 9),
(cc: ['o']; s: 37),
{ 35: }
(cc: [#1..#31, '!'..#255]; s: 9),
{ 36: }
(cc: [#1..#31, '!'..'r', 't'..#255]; s: 6),
(cc: ['s']; s: 38),
{ 37: }
(cc: [#1..#31, '!'..'r', 't'..#255]; s: 9),
(cc: ['s']; s: 39),
{ 38: }
(cc: [#1..#31, '!'..'d', 'f'..#255]; s: 6),
(cc: ['e']; s: 40),
{ 39: }
(cc: [#1..#31, '!'..'d', 'f'..#255]; s: 9),
(cc: ['e']; s: 41),
{ 40: }
(cc: [#1..#31, '!'..#255]; s: 6),
{ 41: }
(cc: [#1..#31, '!'..#255]; s: 9)
);
yykl: array[0..yynstates - 1] of Integer = (
{ 0: } 1,
{ 1: } 1,
{ 2: } 1,
{ 3: } 1,
{ 4: } 1,
{ 5: } 2,
{ 6: } 3,
{ 7: } 4,
{ 8: } 6,
{ 9: } 8,
{ 10: } 10,
{ 11: } 12,
{ 12: } 14,
{ 13: } 16,
{ 14: } 18,
{ 15: } 21,
{ 16: } 24,
{ 17: } 27,
{ 18: } 30,
{ 19: } 31,
{ 20: } 32,
{ 21: } 33,
{ 22: } 35,
{ 23: } 37,
{ 24: } 39,
{ 25: } 40,
{ 26: } 41,
{ 27: } 42,
{ 28: } 44,
{ 29: } 46,
{ 30: } 48,
{ 31: } 50,
{ 32: } 51,
{ 33: } 53,
{ 34: } 56,
{ 35: } 58,
{ 36: } 61,
{ 37: } 62,
{ 38: } 64,
{ 39: } 65,
{ 40: } 67,
{ 41: } 69
);
yykh: array[0..yynstates - 1] of Integer = (
{ 0: } 0,
{ 1: } 0,
{ 2: } 0,
{ 3: } 0,
{ 4: } 1,
{ 5: } 2,
{ 6: } 3,
{ 7: } 5,
{ 8: } 7,
{ 9: } 9,
{ 10: } 11,
{ 11: } 13,
{ 12: } 15,
{ 13: } 17,
{ 14: } 20,
{ 15: } 23,
{ 16: } 26,
{ 17: } 29,
{ 18: } 30,
{ 19: } 31,
{ 20: } 32,
{ 21: } 34,
{ 22: } 36,
{ 23: } 38,
{ 24: } 39,
{ 25: } 40,
{ 26: } 41,
{ 27: } 43,
{ 28: } 45,
{ 29: } 47,
{ 30: } 49,
{ 31: } 50,
{ 32: } 52,
{ 33: } 55,
{ 34: } 57,
{ 35: } 60,
{ 36: } 61,
{ 37: } 63,
{ 38: } 64,
{ 39: } 66,
{ 40: } 68,
{ 41: } 71
);
yyml: array[0..yynstates - 1] of Integer = (
{ 0: } 1,
{ 1: } 1,
{ 2: } 1,
{ 3: } 1,
{ 4: } 1,
{ 5: } 2,
{ 6: } 3,
{ 7: } 4,
{ 8: } 6,
{ 9: } 8,
{ 10: } 10,
{ 11: } 12,
{ 12: } 14,
{ 13: } 16,
{ 14: } 18,
{ 15: } 21,
{ 16: } 24,
{ 17: } 27,
{ 18: } 30,
{ 19: } 31,
{ 20: } 32,
{ 21: } 33,
{ 22: } 35,
{ 23: } 37,
{ 24: } 39,
{ 25: } 40,
{ 26: } 41,
{ 27: } 42,
{ 28: } 44,
{ 29: } 46,
{ 30: } 48,
{ 31: } 50,
{ 32: } 51,
{ 33: } 53,
{ 34: } 56,
{ 35: } 58,
{ 36: } 61,
{ 37: } 62,
{ 38: } 64,
{ 39: } 65,
{ 40: } 67,
{ 41: } 69
);
yymh: array[0..yynstates - 1] of Integer = (
{ 0: } 0,
{ 1: } 0,
{ 2: } 0,
{ 3: } 0,
{ 4: } 1,
{ 5: } 2,
{ 6: } 3,
{ 7: } 5,
{ 8: } 7,
{ 9: } 9,
{ 10: } 11,
{ 11: } 13,
{ 12: } 15,
{ 13: } 17,
{ 14: } 20,
{ 15: } 23,
{ 16: } 26,
{ 17: } 29,
{ 18: } 30,
{ 19: } 31,
{ 20: } 32,
{ 21: } 34,
{ 22: } 36,
{ 23: } 38,
{ 24: } 39,
{ 25: } 40,
{ 26: } 41,
{ 27: } 43,
{ 28: } 45,
{ 29: } 47,
{ 30: } 49,
{ 31: } 50,
{ 32: } 52,
{ 33: } 55,
{ 34: } 57,
{ 35: } 60,
{ 36: } 61,
{ 37: } 63,
{ 38: } 64,
{ 39: } 66,
{ 40: } 68,
{ 41: } 71
);
yytl: array[0..yynstates - 1] of Integer = (
{ 0: } 1,
{ 1: } 4,
{ 2: } 7,
{ 3: } 10,
{ 4: } 13,
{ 5: } 14,
{ 6: } 19,
{ 7: } 20,
{ 8: } 21,
{ 9: } 26,
{ 10: } 27,
{ 11: } 29,
{ 12: } 30,
{ 13: } 32,
{ 14: } 34,
{ 15: } 36,
{ 16: } 37,
{ 17: } 39,
{ 18: } 41,
{ 19: } 43,
{ 20: } 45,
{ 21: } 47,
{ 22: } 49,
{ 23: } 51,
{ 24: } 53,
{ 25: } 55,
{ 26: } 57,
{ 27: } 59,
{ 28: } 61,
{ 29: } 63,
{ 30: } 65,
{ 31: } 66,
{ 32: } 68,
{ 33: } 69,
{ 34: } 70,
{ 35: } 72,
{ 36: } 73,
{ 37: } 75,
{ 38: } 77,
{ 39: } 79,
{ 40: } 81,
{ 41: } 82
);
yyth: array[0..yynstates - 1] of Integer = (
{ 0: } 3,
{ 1: } 6,
{ 2: } 9,
{ 3: } 12,
{ 4: } 13,
{ 5: } 18,
{ 6: } 19,
{ 7: } 20,
{ 8: } 25,
{ 9: } 26,
{ 10: } 28,
{ 11: } 29,
{ 12: } 31,
{ 13: } 33,
{ 14: } 35,
{ 15: } 36,
{ 16: } 38,
{ 17: } 40,
{ 18: } 42,
{ 19: } 44,
{ 20: } 46,
{ 21: } 48,
{ 22: } 50,
{ 23: } 52,
{ 24: } 54,
{ 25: } 56,
{ 26: } 58,
{ 27: } 60,
{ 28: } 62,
{ 29: } 64,
{ 30: } 65,
{ 31: } 67,
{ 32: } 68,
{ 33: } 69,
{ 34: } 71,
{ 35: } 72,
{ 36: } 74,
{ 37: } 76,
{ 38: } 78,
{ 39: } 80,
{ 40: } 81,
{ 41: } 82
);
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;
if (FileName < 2) then
Writeln('没有指定文件名');
readln;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -