home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / tile-forth-2.1-base.tgz / tile-forth-2.1-base.tar / fsf / tile-forth / tst / calc.f83 < prev    next >
Text File  |  1991-09-14  |  3KB  |  117 lines

  1. \
  2. \  INFIX CALCULATOR 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: 22 February 1990
  17. \
  18. \  Dependencies:
  19. \       (forth) forth, parser
  20. \
  21. \  Description:
  22. \       Infix notation grammar definitions and semantic binding.
  23. \       Translates infix notation to postfix (forth).
  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 Infix Calculator definitions...) cr
  41.  
  42. #include parser.f83
  43.  
  44. parser forth definitions
  45.  
  46. vocabulary calculator ( -- )
  47.  
  48. symbol calc
  49.  
  50. parser calculator definitions
  51.  
  52. \ Factorized and left-to-right execution grammar for expressions
  53. \
  54. \ <calc> ::= <expr> <eoln> @ .
  55.  
  56. symbol expr
  57.  
  58. calc syntax expr non-terminal eoln non-terminal semantic (forth) . end.syntax
  59.  
  60. \ <expr> ::= <term> <expr0>
  61.  
  62. symbol term
  63. symbol expr0
  64.  
  65. expr syntax term non-terminal expr0 non-terminal no-semantic end.syntax
  66.  
  67. \ <expr0> ::= <expr1> <expr0>
  68. \          |  <empty>
  69.  
  70. symbol expr1
  71.  
  72. expr0 syntax expr1 non-terminal expr0 non-terminal no-semantic end.syntax
  73. expr0 syntax empty non-terminal no-semantic end.syntax
  74.  
  75. \ <expr1> ::= - <term> @ -
  76. \        |  + <term> @ +
  77.  
  78. symbol -
  79. symbol +
  80.  
  81. expr1 syntax - terminal term non-terminal semantic (forth) - end.syntax
  82. expr1 syntax + terminal term non-terminal semantic (forth) + end.syntax
  83.  
  84. \ <term> ::= <fact> <term0>
  85.  
  86. symbol fact
  87. symbol term0
  88.  
  89. term syntax fact non-terminal term0 non-terminal no-semantic end.syntax
  90.  
  91. \ <term0> ::= * <term> @ *
  92. \        |  / <term> @ /
  93. \          |  mod <term> @ mod
  94. \        |  <empty> 
  95.  
  96. symbol *
  97. symbol /
  98. symbol mod
  99.  
  100. term0 syntax * terminal term non-terminal semantic (forth) * end.syntax
  101. term0 syntax / terminal term non-terminal semantic (forth) / end.syntax
  102. term0 syntax mod terminal term non-terminal semantic (forth) mod end.syntax
  103. term0 syntax empty non-terminal no-semantic end.syntax
  104.  
  105. \ <fact> ::= ( <expr> ) 
  106. \         |  - <fact> @ negate
  107. \       |  <number>
  108.  
  109. symbol (
  110. symbol )
  111.  
  112. fact syntax ( terminal expr non-terminal ) terminal no-semantic end.syntax
  113. fact syntax - terminal fact non-terminal semantic (forth) negate end.syntax
  114. fact syntax number non-terminal no-semantic end.syntax
  115.  
  116. forth only
  117.