home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / sampler / 02 / parser / main3.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-09-06  |  1.7 KB  |  75 lines

  1. {MAIN3.PAS}
  2.  
  3. Program ParseEngine;
  4.  
  5. {
  6. Description:  Main program for demonstration of parsing Pascal source
  7. Author:       Karl Gerhard
  8. Date:         7/25/87
  9. Application:  IBM PC and compatibles
  10. }
  11.  
  12. {$R+}
  13. CONST
  14.   grammar_name = 'grammar3.pas';
  15.   input_name = 'input3.pas';
  16.   log_name = 'log.pas';
  17.   stackmax = 250;
  18.   input_max = 10000;
  19.  
  20. TYPE
  21.   stdstr = string[250];
  22.   stack_type = string[stackmax];
  23.   input_array_type = array[1..input_max] of char;
  24.  
  25. VAR
  26.   input_array : input_array_type;
  27.   grammar : array[1..100] of stdstr;
  28.   plevel,token_ptr,input_line,v_length, input_length, gr_length : integer;
  29.   FLOG,FN         : text;
  30.   FIN : file;
  31.   statement, the_token : stdstr;
  32.   parts_of_speech     : stdstr;
  33.  
  34. {$i debug     logging routines }
  35. {$i strlib3   string functions }
  36. {$i parslib3  parser itself    }
  37. {$i parse3    parser itself    }
  38. {$i textrd3   read input       }
  39.  
  40. BEGIN  { ---  Program  Main ---- }
  41. assign(FLOG,log_name);
  42. rewrite(FLOG);
  43.  
  44. { read grammar }
  45. assign(FN,grammar_name);
  46. reset(FN);
  47. gr_length := 0;
  48. while not eof(FN) do begin
  49.   gr_length := gr_length + 1;
  50.   readln(FN,grammar[gr_length]);
  51. end;
  52. close(FN);
  53.  
  54. assign(FIN,input_name);
  55. textblockread(input_array,FIN);
  56.  
  57. clrscr;
  58. writeln(' PARSER  Part 3                              kpg 7/14/87');
  59.  
  60. { parse statement }
  61. window(10,4,80,22); gotoxy(1,1);
  62. token_ptr := 1;
  63. the_token := getoken;
  64. if parse(1, 'START') then writeln(' GO')
  65. else writeln('  Parse failed.');
  66. logging(' == End of ',' run');
  67. close(FLOG);
  68. window(1,1,80,25); gotoxy(20,24);
  69. write(' Enter to continue or BRK (Log is saved)');     readln(statement);
  70.  
  71. close(FIN);
  72. writeln; writeln('  End of Demo');
  73. END.
  74. {***}
  75.