home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / tile-forth-2.1-bin.lha / lib / tile-forth / bnf.f83 < prev    next >
Text File  |  1996-10-12  |  4KB  |  147 lines

  1. \
  2. \  BACKUS-NAUR FORM GRAMMAR DEFINITIONS
  3. \
  4. \  Copyright (C) 1990 by Mikael R.K. Patel
  5. \
  6. \  Computer Aided Design Laboratory (CADLAB)
  7. \  Department of Computer and Information Science
  8. \  Linkoping University
  9. \  S-581 83 LINKOPING
  10. \  SWEDEN
  11. \
  12. \  Email: mip@ida.liu.se
  13. \
  14. \  Started on: 19 February 1990
  15. \
  16. \  Last updated on: 21 February 1990
  17. \
  18. \  Dependencies:
  19. \       (forth) forth, compiler, parser
  20. \
  21. \  Description:
  22. \       Definitions for Backus-Naur Meta Language grammar. Simplifies
  23. \       specification of grammar for the Parser Virtual Machine.
  24. \
  25. \  Copying:
  26. \       This program is free software; you can redistribute it and\or modify
  27. \       it under the terms of the GNU General Public License as published by
  28. \       the Free Software Foundation; either version 1, or (at your option)
  29. \       any later version.
  30. \
  31. \       This program is distributed in the hope that it will be useful,
  32. \       but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. \       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  34. \       GNU General Public License for more details.
  35. \
  36. \       You should have received a copy of the GNU General Public License
  37. \       along with this program; see the file COPYING.  If not, write to
  38. \       the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  39.  
  40. .( Loading Backus-Naur Form definitions...) cr
  41.  
  42. #include parser.f83
  43.  
  44. parser forth definitions
  45.  
  46. vocabulary backus-naur-form ( -- )
  47.  
  48. symbol bnf
  49.  
  50. forth compiler parser backus-naur-form definitions
  51.  
  52. \ Semantic actions for building Extended Backus-Naur Form (EBNF) grammar
  53.  
  54. variable current-syntax-symbol ( -- addr)
  55.  
  56. : first-syntax ( symbol -- )
  57.   >body dup current-syntax-symbol ! syntax
  58.  
  59. : next-syntax ( -- )
  60.   current-syntax-symbol @ syntax
  61.  
  62. : make-non-terminal ( symbol -- )
  63.   thread compile non-terminal
  64.  
  65. : make-terminal ( symbol -- )
  66.   thread compile terminal
  67.  
  68. : make-zero-or-one ( symbol -- )
  69.   thread compile zero-or-one
  70.  
  71. : make-zero-or-more ( symbol -- )
  72.   thread compile zero-or-more
  73.  
  74. : make-semantic ( symbol -- )
  75.   compile semantic thread [compile] end.syntax
  76.  
  77. : make-no-semantic ( -- )
  78.   compile no-semantic [compile] end.syntax
  79.  
  80. \ Grammar definition for Backus-Naur Form (BNF)
  81. \
  82. \ <bnf> ::= <head> <tail> <bnf>
  83. \        |  <eoln>
  84. symbol head
  85. symbol tail 
  86.  
  87. bnf syntax head non-terminal tail non-terminal bnf non-terminal no-semantic end.syntax 
  88. bnf syntax eoln non-terminal no-semantic end.syntax
  89.  
  90. \ <head> ::= <factor> ::= @ first-syntax
  91. \         |  | @ next-syntax
  92.  
  93. symbol factor 
  94. symbol :
  95. symbol =
  96. symbol |
  97.  
  98. head syntax factor non-terminal : terminal : terminal = terminal semantic first-syntax end.syntax
  99. head syntax | terminal semantic next-syntax end.syntax
  100.  
  101. \ <tail> ::= ' @ <entry> @ make-semantic
  102. \         |  <term> <tail>
  103. \         |  <empty> @ make-no-semantic
  104.  
  105. symbol @ 
  106. symbol term 
  107.  
  108. tail syntax @ terminal entry non-terminal semantic make-semantic end.syntax
  109. tail syntax term non-terminal tail non-terminal no-semantic end.syntax
  110. tail syntax empty non-terminal semantic make-no-semantic end.syntax
  111.  
  112. \ <term> ::= [ <factor> ] @ make-zero-or-one
  113. \         |  { <factor> } @ make-zero-or-more
  114. \         |  ' ' <entry> @ make-terminal
  115. \         |  <factor> @ make-non-terminal
  116. \         |  <entry> @ make-terminal
  117.  
  118. symbol [
  119. symbol ]
  120. symbol {
  121. symbol }
  122. symbol '
  123.  
  124. term syntax [ terminal factor non-terminal ] terminal semantic make-zero-or-one end.syntax
  125. term syntax { terminal factor non-terminal } terminal semantic make-zero-or-more end.syntax
  126. term syntax ' terminal entry non-terminal semantic make-terminal end.syntax
  127. term syntax factor non-terminal semantic make-non-terminal end.syntax
  128. term syntax entry non-terminal semantic make-terminal end.syntax
  129.  
  130. \ <factor> ::= ' < <entry> >
  131.  
  132. symbol < 
  133. symbol > 
  134.  
  135. factor syntax < terminal entry non-terminal > terminal no-semantic end.syntax
  136.  
  137. forth only
  138.  
  139.