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

  1. {ACTIONS.PAS}
  2.  
  3. {
  4. Description:  Action procedures for demonstration of parsing Pascal source.
  5. Author:       Karl Gerhard
  6. Date:         9/30/87
  7. Application:  IBM PC and compatibles
  8. }
  9.  
  10.  
  11. {---------  Individual Action Procedures ------------}
  12. Procedure print;
  13. { print and clear the print_string }
  14. Begin
  15. write(indent_string + print_string);
  16. logging(' === ps',indent_string + print_string);
  17. print_string := '';
  18. End;
  19.  
  20. Procedure printno;
  21. { print and clear the print_string with no indent }
  22. Begin
  23. write(print_string);
  24. logging(' == psn',print_string);
  25. print_string := '';
  26. End;
  27.  
  28. Procedure deletespace;
  29. { delete last char (space) of print string }
  30. Begin
  31. if length(print_string) < 1 then writeln(#13#10,' - - > @ds error');
  32. delete(print_string, length(print_string),1);
  33. End;
  34.  
  35. Procedure newline;
  36. { print CRLF }
  37. Begin
  38. writeln;
  39. End;
  40.  
  41. Procedure indent;
  42. { append two indentation spaces }
  43. Begin
  44. indent_string := indent_string  + '  ';
  45. End;
  46.  
  47. Procedure undent;
  48. { remove two indentation spaces }
  49. Begin
  50. if length(indent_string) < 2 then writeln(#13#10,'- - > @und error');
  51. delete(indent_string,1,2);
  52. End;
  53.  
  54. {---------  Main Action Decoder ------------}
  55. Procedure actions(action:stdstr);
  56. { Decode action and execute it}
  57.  
  58. Begin
  59. delete(action,1,1);
  60. if action = 'ps' then print
  61. else if action = 'psn' then printno
  62. else if action = 'ind' then indent
  63. else if action = 'und' then undent
  64. else if action = 'nl'  then newline
  65. else if action = 'ds'  then deletespace
  66. else error('actions','unknown action in grammar');
  67. End;
  68.