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

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