lexlist.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. {
  2. Lex listing routines.
  3. This module provides some routines to produce a readable representation
  4. of the generated DFA tables (the routines are only used when Lex is run
  5. with the verbose option /v).
  6. If this module is compiled with defined conditional `debug', the list file
  7. will contain extensive debugging output (position table, state positions,
  8. etc.).
  9. Copyright (c) 1990-92 Albert Graef <[email protected]>
  10. Copyright (C) 1996 Berend de Boer <[email protected]>
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. $Revision: 1.2 $
  23. $Modtime: 96-08-01 6:28 $
  24. $History: LEXLIST.PAS $
  25. *
  26. * ***************** Version 2 *****************
  27. * User: Berend Date: 96-10-10 Time: 21:16
  28. * Updated in $/Lex and Yacc/tply
  29. * Updated for protected mode, windows and Delphi 1.X and 2.X.
  30. }
  31. unit LexList;
  32. interface
  33. uses
  34. LexBase;
  35. procedure listDFATable;
  36. (* list DFA table *)
  37. implementation
  38. uses LexTable;
  39. procedure listTrans(cc : CClassPtr; next_state : Integer);
  40. (* list a transition in the format
  41. cc : next_state *)
  42. begin
  43. write(yylst, cclassOrCharStr(cc^):30, ' : ', next_state:5);
  44. end(*listTrans*);
  45. {$ifdef debug}
  46. procedure listPosTable;
  47. (* lists the position table *)
  48. var
  49. p, i : Integer;
  50. begin
  51. if n_pos=0 then exit;
  52. writeln(yylst);
  53. for p := 1 to n_pos do
  54. with pos_table^[p] do
  55. begin
  56. write(yylst, p:5, ' ');
  57. if pos_type=char_pos then
  58. write(yylst, singleQuoteStr(c):20)
  59. else if pos_type=cclass_pos then
  60. write(yylst, cclassStr(cc^):20)
  61. else if pos_type=mark_pos then
  62. if pos=0 then
  63. write(yylst, '# (rule '+intStr(rule)+')':20)
  64. else
  65. write(yylst, '/ (rule '+intStr(rule)+')':20);
  66. write(yylst, ' ':5);
  67. for i := 1 to size(follow_pos^) do
  68. if follow_pos^[i]>0 then write(yylst, follow_pos^[i]:5, ' ');
  69. writeln(yylst);
  70. end;
  71. writeln(yylst);
  72. end(*listPosTable*);
  73. {$endif}
  74. procedure listDFATable;
  75. var k, state : Integer;
  76. begin
  77. {$ifdef debug}
  78. (* list position table: *)
  79. writeln(yylst);
  80. writeln(yylst, '( positions : )');
  81. listPosTable;
  82. (* list state table: *)
  83. writeln(yylst);
  84. writeln(yylst, '( states : )');
  85. {$endif}
  86. writeln(yylst);
  87. for state := 0 to pred(n_states) do
  88. begin
  89. writeln(yylst);
  90. write(yylst, state);
  91. with state_table^[state] do
  92. begin
  93. if final then
  94. write(yylst, '* :')
  95. else
  96. write(yylst, ' :');
  97. {$ifdef debug}
  98. for k := 1 to size(state_pos^) do
  99. write(yylst, ' ', state_pos^[k]:5);
  100. {$else}
  101. for k := 1 to size(state_pos^) do
  102. with pos_table^[state_pos^[k]] do
  103. if (pos_type=mark_pos) and (pos=0) then
  104. write(yylst, ' ', rule:5);
  105. {$endif}
  106. writeln(yylst);
  107. for k := trans_lo to trans_hi do
  108. with trans_table^[k] do
  109. begin
  110. listTrans(cc, next_state);
  111. writeln(yylst);
  112. end;
  113. end;
  114. end;
  115. end(*listDFATable*);
  116. end(*LexList*).