program.g 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* The grammar of ISO-Pascal as given by the specification, BS6192: 1982. */
  2. {
  3. #include <alloc.h>
  4. #include <em_arith.h>
  5. #include <em_label.h>
  6. #include <em_code.h>
  7. #include <stb.h>
  8. #include "LLlex.h"
  9. #include "def.h"
  10. #include "f_info.h"
  11. #include "idf.h"
  12. #include "main.h"
  13. #include "node.h"
  14. #include "scope.h"
  15. #include "dbsymtab.h"
  16. }
  17. %lexical LLlex;
  18. %start LLparse, Program;
  19. /* ISO section 6.10, p. 137 */
  20. Program
  21. {
  22. struct def *df;
  23. arith dummy;
  24. }:
  25. ProgramHeading(&df)
  26. ';' Block(df) '.'
  27. {
  28. #ifdef DBSYMTAB
  29. if (options['g']) {
  30. C_ms_stb_cst(df->df_idf->id_text, N_MAIN, 0, (arith) 0);
  31. stb_string(df, D_END);
  32. }
  33. #endif /* DBSYMTAB */
  34. }
  35. | { df = new_def();
  36. df->df_idf = str2idf(FileName, 1);
  37. df->df_kind = D_MODULE;
  38. open_scope();
  39. GlobalScope = CurrentScope;
  40. df->prc_vis = CurrVis;
  41. }
  42. Module(df, &dummy)
  43. ;
  44. ProgramHeading(register struct def **df;):
  45. PROGRAM IDENT
  46. { program = *df = new_def();
  47. (*df)->df_idf = dot.TOK_IDF;
  48. (*df)->df_kind = D_PROGRAM;
  49. open_scope();
  50. GlobalScope = CurrentScope;
  51. (*df)->prc_vis = CurrVis;
  52. #ifdef DBSYMTAB
  53. if (options['g']) stb_string(*df, D_MODULE);
  54. #endif /* DBSYMTAB */
  55. }
  56. [
  57. '('
  58. ProgramParameters
  59. ')'
  60. { make_extfl(); }
  61. ]?
  62. ;
  63. ProgramParameters
  64. {
  65. struct node *Proglist;
  66. }:
  67. IdentifierList(&Proglist)
  68. { EnterProgList(Proglist); }
  69. ;