home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 3.ddi / PARSE.ZIP / CPP.GRM < prev    next >
Encoding:
Text File  |  1989-06-07  |  6.2 KB  |  274 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.  
  59. Declarators?
  60.    ->
  61.    -> Declarators
  62.  
  63. Declarators
  64.    -> FinishedDeclarator
  65.    -> FinishedDeclarator , Declarators
  66.  
  67. FinishedDeclarator -> Declarator Initializer?  => Declaration 1
  68.                    -> Decl2 ( 1+Expression-List )  => Declaration 1
  69.                       /* constructor */
  70.  
  71. /*********************************/
  72.  
  73.  
  74. Initializer?
  75.    ->
  76.    -> = Expression
  77.    -> = { 1+Expression-List }
  78.  
  79. Arg-Initializer?
  80.    ->
  81.    -> = Expression
  82.  
  83. 1+Expression-List  /* a non-empty list */
  84.    -> Expression
  85.    -> Expression , 1+Expression-List
  86.  
  87.  
  88. StorageClass
  89.    ->            => StoreStorage 0
  90.    -> MustStorageClass
  91.  
  92. MustStorageClass
  93.    -> static     => StoreStorage 1
  94.    -> extern     => StoreStorage 2
  95.    -> typedef    => StoreStorage 3
  96.    -> auto       => StoreStorage 4
  97.    -> register   => StoreStorage 5
  98.    -> inline     => StoreStorage 6
  99.  
  100.  
  101. Type_w/const  /* const may appear before or after the type name */
  102.    ->                                            => StoreType 0
  103.    -> Const/Volatile? Type Const/Volatile?       => StoreBaseConstVol
  104.  
  105.  
  106. Type
  107.    -> char            => StoreType 1
  108.    -> signed char     => StoreType 2
  109.    -> unsigned char   => StoreType 3
  110.    -> int             => StoreType 4
  111.    -> short           => StoreType 4
  112.    -> short int       => StoreType 4
  113.    -> signed int      => StoreType 4
  114.    -> signed short    => StoreType 4
  115.    -> signed short int      => StoreType 4
  116.    -> unsigned        => StoreType 5
  117.    -> unsigned int    => StoreType 5
  118.    -> unsigned short    => StoreType 5
  119.    -> unsigned short int    => StoreType 5
  120.    -> long            => StoreType 6
  121.    -> signed long     => StoreType 6
  122.    -> unsigned long   => StoreType 7
  123.    -> float           => StoreType 8
  124.    -> double          => StoreType 9
  125.    -> long double     => StoreType 10
  126.    -> void            => StoreType 11
  127.    -> enum Tag        => StoreType 12
  128.    -> AggrDef         => StoreType 13
  129.  
  130.  
  131. /* class/struct/union stuff */
  132.  
  133. PureAggrDef
  134.    -> AggrType Tag AggrBody?
  135.  
  136. AggrDef
  137.    -> PureAggrDef
  138.    -> AggrType AggrBody
  139.  
  140. AggrType
  141.    -> Class
  142.    -> union       => AggrForm 0
  143.  
  144. Class
  145.    -> struct      => AggrForm 1
  146.    -> class       => AggrForm 2
  147.  
  148. Tag
  149.    -> <identifier>    => StoreTag 1
  150.    -> <type>          => StoreTag 2
  151.  
  152. /* members of a class/struct/union */
  153.  
  154.  
  155. AggrBody?
  156.    ->             => StoreAggrBody 0
  157.    -> AggrBody    => StoreAggrBody 1
  158.  
  159. AggrBody
  160.    -> { Aggr-Member-List }
  161.  
  162. Aggr-Member-List
  163.    -> Start-Nested-Type A-Member-List? End-Nested-Type
  164.  
  165. A-Member-List?
  166.    ->
  167.    -> A-Member-List
  168.  
  169. A-Member-List
  170.    -> A-Member-List  Member-Declaration
  171.    -> Member-Declaration
  172.  
  173. Member-Declaration
  174.    -> Friend? StorageClass Type_w/const Declarator Initializer? ;  => Declaration 3
  175.    -> ProtectionSpecifier :
  176.  
  177. ProtectionSpecifier
  178.    -> public        => ProtectionSpecifier 0
  179.    -> private       => ProtectionSpecifier 2
  180.    -> protected     => ProtectionSpecifier 3
  181.  
  182. Friend?
  183.    ->         => IsFriend 0
  184.    -> friend  => IsFriend 1
  185.  
  186.  
  187.  
  188.  
  189. OverloadableOp -> * | / | = | + /* and all the others */
  190.  
  191. Elipses? -> | '...'
  192.  
  193. /* Declarations */
  194.  
  195. Declarator
  196.    -> Decl2
  197.    -> ReachAttribute * Const/Volatile? Declarator    => TypeModifier 3
  198.    -> ReachAttribute & Const/Volatile? Declarator    => TypeModifier 4
  199.  
  200. Decl2
  201.    -> Decl2 ( Arg-Declaration-List )       => TypeModifier 1
  202.    -> Decl2 [ ConstExp? ]                  => TypeModifier 2
  203.    -> Decl3
  204.  
  205. Decl3
  206.    -> Dname          => Dname 1
  207.    -> ( Declarator )
  208.  
  209. Const/Volatile?  /* const or volotile, neither, or both */
  210.   ->                   => ConstVol 0
  211.   -> const             => ConstVol 1
  212.   -> volatile          => ConstVol 2
  213.   -> const volatile    => ConstVol 3
  214.   -> volatile const    => ConstVol 3
  215.  
  216.  
  217. ReachAttribute
  218.   ->         => ReachType 0
  219.   -> near    => ReachType 4
  220.   -> far     => ReachType 8
  221.  
  222. Dname
  223.   -> SimpleDname
  224.   -> <type> :: SimpleDname
  225.  
  226. SimpleDname
  227.   -> <identifier>
  228.   -> <type>
  229.   -> ~ <type>
  230.   -> Operator-FunctionName
  231.  
  232. Operator-FunctionName
  233.    -> operator OverloadableOp  /* overload operator */
  234.    -> operator <type> /* conversion operator */
  235.        /* this should really allow any abstract type definition, not just
  236.           a simple type name.  I'll change it later */
  237.    -> operator <identifier>  /* ERROR production */
  238.  
  239.  
  240. /* Argument list for function declarations */
  241.  
  242. Arg-Declaration-List
  243.    -> Start-Nested-Type A-Decl-List? Elipses? End-Nested-Type
  244.  
  245. Start-Nested-Type    -> =>  NestedType 1
  246. End-Nested-Type      -> =>  NestedType 0
  247.  
  248. A-Decl-List?
  249.    ->
  250.    -> A-Decl-List
  251.  
  252. A-Decl-List
  253.    -> A-Decl-List , Argument-Declaration
  254.    -> Argument-Declaration
  255.  
  256. Argument-Declaration
  257.    -> MustStorageClass Type_w/const Declarator Arg-Initializer? => Declaration 2
  258.  
  259. /* Expressions */
  260.  
  261. ConstExp?
  262.    ->
  263.    -> ConstExp
  264.  
  265. ConstExp -> Expression    /* semantics will check */
  266.  
  267. Expression
  268.    /* stub out for now */
  269.    -> <identifier>
  270.    -> <number>
  271.    -> <string>
  272.  
  273.  
  274.