home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2-YACC.ZIP / EXAMPLE.Y < prev    next >
Text File  |  1983-12-31  |  2KB  |  122 lines

  1.  
  2.  %term ONE
  3.  %term TWO
  4.  %term THREE
  5.  %term FOUR
  6.  %term FIVE
  7.  %term SIX
  8.  %term SEVEN
  9.  %term EIGHT
  10.  %term NINE
  11.  %term DOT
  12. %%
  13. number    :front =
  14. {       float _L1L_;
  15. { _L1L_ = (float) _ap [0]._t1;
  16.                     _ap += 1; 
  17. --_ap; _ap[0]._t0 = _L1L_;
  18.   }
  19. }
  20.              |front DOT back =
  21. {       float _L1L_;
  22. { _L1L_ = (float) _ap [2]._t1 + _ap [0]._t0;
  23.                     _ap += 3; 
  24. --_ap; _ap[0]._t0 = _L1L_;
  25.   }
  26. };
  27. front    :id 
  28.              |front id =
  29. {       int _L1L_;
  30. { _L1L_ = 10 * _ap [1]._t1 + _ap [0]._t1;
  31.                     _ap += 2; 
  32. --_ap; _ap[0]._t1 = _L1L_;
  33.   }
  34. };
  35. back    :zero_th_digit fd 
  36.              |back inc_dig_pos fd =
  37. {       int _L1L_;
  38.        float _L2L_;
  39. { _L2L_ = _ap [2]._t0 + _ap [0]._t0;
  40.                     _ap += 4; 
  41. --_ap; _ap[0]._t1 = _L1L_;
  42. --_ap; _ap[0]._t0 = _L2L_;
  43.   }
  44. };
  45. fd    :id =
  46. {       float _L1L_;
  47. { _L1L_ = ( (float) _ap [0]._t1) / (power (10, _ap [1]._t1));
  48.                     _ap += 1; 
  49. --_ap; _ap[0]._t0 = _L1L_;
  50.   }
  51. };
  52. zero_th_digit    :=
  53. {     _ap -= 1;
  54. { _ap [0]._t1 = 1;
  55.                 }
  56. };
  57. inc_dig_pos    :=
  58. {     _ap -= 1;
  59. { _ap [0]._t1 = _ap [2]._t1 + 1;
  60.                 }
  61. };
  62. id    :ONE =
  63. {     _ap -= 1;
  64. { _ap [0]._t1 = 1;
  65.                 }
  66. }
  67.              |TWO =
  68. {     _ap -= 1;
  69. { _ap [0]._t1 = 2;
  70.                 }
  71. }
  72.              |THREE =
  73. {     _ap -= 1;
  74. { _ap [0]._t1 = 3;
  75.                 }
  76. }
  77.              |FOUR =
  78. {     _ap -= 1;
  79. { _ap [0]._t1 = 4;
  80.                 }
  81. }
  82.              |FIVE =
  83. {     _ap -= 1;
  84. { _ap [0]._t1 = 5;
  85.                 }
  86. }
  87.              |SIX =
  88. {     _ap -= 1;
  89. { _ap [0]._t1 = 6;
  90.                 }
  91. }
  92.              |SEVEN =
  93. {     _ap -= 1;
  94. { _ap [0]._t1 = 7;
  95.                 }
  96. }
  97.              |EIGHT =
  98. {     _ap -= 1;
  99. { _ap [0]._t1 = 8;
  100.                 }
  101. }
  102.              |NINE =
  103. {     _ap -= 1;
  104. { _ap [0]._t1 = 9;
  105.                 }
  106. };
  107.  
  108. %%
  109.  
  110.  
  111. #ifndef ATT_SIZE
  112. #define ATT_SIZE     150
  113. #endif
  114.  
  115. union _attr_elem {
  116.   float  _t0;
  117.   int  _t1;
  118. } _attr_stack [ATT_SIZE];
  119. union _attr_elem *_ap =      &_attr_stack [ATT_SIZE - 1];
  120.  
  121.  /* processed by a YACC preprocessor */ 
  122.