home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lr.zip / SAMPLE.GR < prev    next >
Text File  |  1993-05-15  |  4KB  |  156 lines

  1. *
  2. *   In the beginning of grammar definition file must
  3. *            be three symbols: 'LR('
  4. *
  5.  
  6. LR
  7. (
  8.  
  9. *
  10. *  After opening bracket must be set of obligatory and facultative
  11. *  options.
  12. *
  13.  
  14. *
  15. *  Option 'NAME' : specifies names (but not extensions) of the files
  16. *        that will be created during work of the parser.
  17. *
  18.  
  19.    NAME(SAMPLE)
  20.  
  21. *
  22. *   Option 'TITLE' : defines title for your grammar.
  23. *
  24.  
  25.    TITLE('Sample of grammar')
  26.  
  27. *
  28. *   Option 'STRUCT' : tells the parser to create
  29. *   STR-file and N-file.
  30. *
  31.  
  32.    STRUCT
  33.  
  34. *
  35. *   Option 'PRINT' : tells the parser to create LR-file.
  36. *
  37.  
  38.    PRINT
  39.  
  40. *
  41. *   Option 'RULES' : in brackets '()' that follow this option
  42. *   you must define your grammar using GDL.
  43. *
  44.  
  45.  
  46.    RULES
  47.    (
  48.  
  49.  
  50. *   The first <<rule>> after opening bracket '(' is assumed as
  51. *   start nonterminal for this grammar
  52. *   S( DECLARATION(ZERO) ASSIGN(REPEAT) )
  53. *      Nonterminal options:
  54. *          ZERO   -   means that previous nonterminal may repeat
  55. *                     0, 1 or more times
  56. *           REPEAT -   means that previous nonterminal may repeat
  57. *                      1 or more times
  58. *      Example:
  59. *         S ( ASSIGN ASSIGN )
  60. *         S ( DECLARATION DECLARATION ASSIGN )
  61. *
  62.  
  63.       S                 ( ASSIGNS )
  64.  
  65. *
  66. *   Here nonterminal ASSIGNS is defined two times it means that
  67. *   this nonterminal may be reduced as
  68. *   ( ASSIGNS ASSIGN ) or as ( ASSIGN ).
  69. *
  70.  
  71.       ASSIGNS           ( ASSIGNS ASSIGN )
  72.                         ( ASSIGN )
  73.  
  74.       ASSIGN            ( IDENTIFIER assign_sign E semi )
  75.       E                 ( ADD )
  76.                         ( SUB )
  77.                         ( T )
  78.       ADD               ( E plus T )
  79.       SUB               ( E minus T )
  80.       T                 ( MUL )
  81.                         ( DIV )
  82.                         ( F   )
  83.       MUL               ( T mul F )
  84.       DIV               ( T div F )
  85.       F                 ( NEG )
  86.                         ( IDENTIFIER )
  87.                         ( FLOAT )
  88.                         ( op E cp )
  89.       NEG               ( minus F )
  90.  
  91. *
  92. *  Nonterminal options:
  93. *     SECONDARY - means that previous nonterminal must be reduced
  94. *                 only when no other non-secondary nonterminals can
  95. *                 be reduced.
  96. *
  97.  
  98.       IDENTIFIER        ( ALPHA(SECONDARY) ALPHA_NUMERIC (ZERO) )
  99.  
  100. *
  101. *  Nonterminal options:
  102. *     OPTIONAL  - means that preceding nonterminal may repeat
  103. *                       0 or 1 times.
  104. *   Example:
  105. *      F ( p(optional) q ) means F ( p q ) or F ( q )
  106. *
  107.  
  108.       FLOAT             ( point(optional) DIGIT(repeat) EXP )
  109.       FLOAT             ( DIGIT(repeat) point _DIGIT(zero) EXP )
  110.       EXP               ( _e_ SIGN(optional) DIGIT(repeat) )
  111.  
  112. *
  113. *   Terminal options:
  114. *     CHOICE    - means that preceding string (enclosed in '') must be
  115. *                 replaced with one of it's component
  116. *     Example:
  117. *           SIGN ('+-'(CHOICE)) means SIGN ('+') or SIGN ('-')
  118. *
  119.  
  120.       SIGN              ( '+-'(CHOICE))
  121.       ALPHA             ( '_QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'(Choice) )
  122.       ALPHA_NUMERIC     ( '_QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789'(Choice) )
  123.  
  124.       minus             ( '-' )
  125.       plus              ( '+' )
  126.       div               ( '/' )
  127.       mul               ( '*' )
  128.  
  129.       semi              ( ';' )
  130.       DIGIT             ( '0123456789'(choice) )
  131.       _DIGIT            ( DIGIT )
  132.       _e_               ( 'eE'(choice) )
  133.       point             ( '.' )
  134.       op                ( '(' )
  135.       cp                ( ')' )
  136.       assign_sign       ( '=' )
  137.  
  138.    )
  139.  
  140.  
  141. *
  142. *  Here can be used any NONTERMINAL option with brackets '()' following
  143. *  it. In these brackets must be list of nonterminals. This usage means
  144. *  that mentioned nonterminals have this option (attribute)
  145. *  e.g. : OPTIONAL (minus) means that nonterminal 'minus' will
  146. *  be used as 'minus(optional)' during compilation of the grammar.
  147. *
  148.  
  149.  
  150.    IGNORE   ( semi op cp assign_sign minus plus mul div mod)
  151.    STRING   ( IDENTIFIER FLOAT )
  152.    OPTIONAL ( EXP )
  153.  
  154. )
  155.  
  156.