home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 5.ddi / PARSER.ZIP / CPP.GRM < prev    next >
Encoding:
Text File  |  1989-04-25  |  5.0 KB  |  207 lines

  1.  
  2. /* C++ Grammar ...so far.  by John M. Dlugosz */
  3.  
  4. /* TOKENS. */
  5.  
  6.    <error>
  7.    <identifier>  => KW_SEARCH
  8.    <operator>    => OP_SEARCH
  9.    <punctuator>  => OP_SEARCH
  10.    <number>
  11.    <string>
  12.    <eof>
  13.    <type>
  14.  
  15. /* KEYWORDS. */
  16.  
  17.    auto break case cdecl char class const continue default delete do
  18.    double else enum extern far float for friend goto huge if inline int
  19.    interrupt long near new operator overload pascal private protected
  20.    public register return short signed sizeof static struct switch this
  21.    typedef union unsigned virtual void volatile while
  22.  
  23. /* OPERATORS. */
  24.  
  25.    || &&
  26.    < <= == > >=
  27.    + - * / %
  28.    ? ++ -- '->'
  29.    ! ~ ^ '|' & >> <<
  30.    = <<= != %= &= *= += -= /= |= >>= ^=
  31.  
  32. /* PUNCTUATORS. */
  33.  
  34.    '...' . , : ; [ ] { } ( ) ::
  35.  
  36. /* NONTERMINALS. */
  37.  
  38. Input -> File_and_tell <eof>
  39.  
  40. File_and_tell -> File      => AllDoneNow  1   /* normal completion */
  41.  
  42. File -> Item | File Item
  43.  
  44. Item -> Declaration
  45.    /* or Definition.  not in yet. */
  46.  
  47.  
  48. /**************************************************************
  49. To recognize a declaration, the storage class and type appear
  50. once.  They are remembered.  Each declaration is seperated by
  51. commas, and share the same type.  The FinishedDeclarator calls
  52. an action for each one found.
  53. ****************/
  54.  
  55. Declaration
  56.    -> StorageClass Type_w/const Declarators ;
  57.  
  58. Declarators
  59.    -> FinishedDeclarator
  60.    -> FinishedDeclarator , Declarators
  61.  
  62. FinishedDeclarator -> Declarator Initializer?  => Declaration 1
  63.  
  64. /*********************************/
  65.  
  66.  
  67. Initializer?
  68.    ->
  69.    -> = Expression
  70.    -> = { Expression-List }
  71. /* -> ( Expression-List ) */
  72.  
  73. Expression-List
  74.    -> Expression
  75.    -> Expression Expression-List
  76.  
  77.  
  78. StorageClass
  79.    ->            => StoreStorage 0
  80.    -> static     => StoreStorage 1
  81.    -> extern     => StoreStorage 2
  82.    -> typedef    => StoreStorage 3
  83.    -> auto       => StoreStorage 4
  84.    -> register   => StoreStorage 5
  85.  
  86. Type_w/const  /* const may appear before or after the type name */
  87.    -> Const/Volatile? Type Const/Volatile?       => StoreBaseConstVol
  88.  
  89. Type
  90.    -> char            => StoreType 1
  91.    -> signed char     => StoreType 2
  92.    -> unsigned char   => StoreType 3
  93.    -> int             => StoreType 4
  94.    -> short           => StoreType 4
  95.    -> short int       => StoreType 4
  96.    -> signed int      => StoreType 4
  97.    -> signed short    => StoreType 4
  98.    -> signed short int      => StoreType 4
  99.    -> unsigned        => StoreType 5
  100.    -> unsigned int    => StoreType 5
  101.    -> unsigned short    => StoreType 5
  102.    -> unsigned short int    => StoreType 5
  103.    -> long            => StoreType 6
  104.    -> signed long     => StoreType 6
  105.    -> unsigned long   => StoreType 7
  106.    -> float           => StoreType 8
  107.    -> double          => StoreType 9
  108.    -> long double     => StoreType 10
  109.    -> void            => StoreType 11
  110.    -> enum Tag        => StoreType 12
  111.    -> Class Tag       => StoreType 13
  112.    -> union Tag       => StoreType 14
  113.  
  114. Tag
  115.    -> <identifier>    => StoreTag 1
  116.    -> <type>          => StoreTag 2
  117.  
  118. Class
  119.    -> struct
  120.    -> class
  121.  
  122. OverloadableOp -> * | / | = | + /* and all the others */
  123.  
  124. Elipses? -> | '...'
  125.  
  126. /* Declarations */
  127.  
  128. Declarator
  129.    -> Decl2
  130.    -> ReachAttribute * Const/Volatile? Declarator    => TypeModifier 3
  131.    -> ReachAttribute & Const/Volatile? Declarator    => TypeModifier 4
  132.  
  133. Decl2
  134.    -> Decl2 ( Arg-Declaration-List )       => TypeModifier 1
  135.    -> Decl2 [ ConstExp? ]                  => TypeModifier 2
  136.    -> Decl3
  137.  
  138. Decl3
  139.    -> Dname          => Dname 1
  140.    -> ( Declarator )
  141.  
  142. Const/Volatile?  /* const or volotile, neither, or both */
  143.   ->                   => ConstVol 0
  144.   -> const             => ConstVol 1
  145.   -> volatile          => ConstVol 2
  146.   -> const volatile    => ConstVol 3
  147.   -> volatile const    => ConstVol 3
  148.  
  149.  
  150. ReachAttribute
  151.   ->         => ReachType 0
  152.   -> near    => ReachType 4
  153.   -> far     => ReachType 8
  154.  
  155. Dname
  156.   -> SimpleDname
  157.   -> <type> :: SimpleDname
  158.  
  159. SimpleDname
  160.   -> <identifier>
  161.   -> <type>
  162.   -> ~ <type>
  163.   -> Operator-FunctionName
  164.  
  165. Operator-FunctionName
  166.    -> operator OverloadableOp  /* overload operator */
  167.    -> operator <type> /* conversion operator */
  168.        /* this should really allow any abstract type definition, not just
  169.           a simple type name.  I'll change it later */
  170.    -> operator <identifier>  /* ERROR production */
  171.  
  172.  
  173. /* Argument list for function declarations */
  174.  
  175. Arg-Declaration-List
  176.    -> Start-Nested-Type A-Decl-List? Elipses? End-Nested-Type
  177.  
  178. Start-Nested-Type    -> =>  NestedType 1
  179. End-Nested-Type      -> =>  NestedType 0
  180.  
  181. A-Decl-List?
  182.    ->
  183.    -> A-Decl-List
  184.  
  185. A-Decl-List
  186.    -> A-Decl-List , Argument-Declaration
  187.    -> Argument-Declaration
  188.  
  189. Argument-Declaration
  190.    -> StorageClass Type_w/const Declarator  => Declaration 2
  191.  
  192. /* Expressions */
  193.  
  194. ConstExp?
  195.    ->
  196.    -> ConstExp
  197.  
  198. ConstExp -> Expression    /* semantics will check */
  199.  
  200. Expression
  201.    /* stub out for now */
  202.    -> <identifier>
  203.    -> <number>
  204.    -> <string>
  205.  
  206.  
  207.