home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / os2 / pgen_2 / expr_par.pgn < prev    next >
Encoding:
Text File  |  1993-06-04  |  1.5 KB  |  71 lines

  1. /*    EXPR_PAR.PGN produces EXPR_PAR.C.
  2.     Copyright (C) 1992    Keith L. Robertson    All Rights Reserved
  3.  
  4.     Grammar file for the EXPR expression evaluator PGEN example.
  5.     Modify .PGN and reproduce .C using "PGEN -IC EXPR_PAR.PGN >EXPR_PAR.C"
  6. */
  7. #include "expr_lex.h"    /* Lexical analyzer for expr. */
  8. #include "expr_sem.h"    /* Semantic action declarations. */
  9. #define        STACK_INC    20
  10. [  # Tokens
  11.     REAL,        IDENTIFIER,
  12.     ','  COMMA,    ';'  SEMICOLON,
  13.     '='  EQUAL 1r,
  14.     '('  OPEN_P,    ')'  CLOSE_P,
  15.     '+'  PLUS  2,    '-'  MINUS 2,
  16.     '*'  TIMES 3,    '/'  DIVIDE 3,
  17.     '^'  POWER 4,    '?'  QUESTION,
  18.     LIST,
  19.     KILL,
  20.     LISP,
  21.     HELP,
  22. ]
  23.  
  24. #-----------------
  25. Session
  26.     | { [Command] ';' ... }
  27.         # ';' is a required separator, optional terminator.
  28.         # Empty command (";;") is harmless.
  29.     ;
  30. Command
  31.     | Expression        @ expr_print
  32.     | KILL Kill_ID_List    @ finish_kill
  33.     | LIST            @ list
  34.     | LISP [LISP]        @ lisp
  35.     | HELP            @ session_help
  36.     | '?'            @ session_help
  37.     | error            @ session_error
  38.     ;
  39.  
  40. Kill_ID_List
  41.     | { Kill_ID [','] ... }+
  42.         # ',' is an optional separator, invalid as a terminator.
  43.     ;
  44. Kill_ID
  45.     | IDENTIFIER                @ kill_ident
  46.     ;
  47.  
  48. Expression
  49.     | IDENTIFIER '=' Expression        @ expr_assign
  50.     | '(' Expression ')'            @ expr_paren
  51.     | IDENTIFIER '(' Expression ')'        @ function_call
  52.     | 5  Unary  Expression            @ unary
  53.     |    Expression '^'    Expression    @ power
  54.     | 3  Expression Binary2    Expression    @ binary2
  55.     | 2  Expression Binary1    Expression    @ binary1
  56.     | IDENTIFIER                @ look_up_ident
  57.     | REAL
  58.     ;
  59.  
  60. Binary2
  61.     | '*'
  62.     | '/'
  63.     ;
  64. Binary1
  65.     | '+'
  66.     | '-'
  67.     ;
  68. Unary
  69.     | Binary1
  70.     ;
  71.