home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oxcc1433.zip / DOC / C.GRM < prev    next >
Text File  |  1995-11-06  |  17KB  |  976 lines

  1. /*--- C grammar with extensions for oxcc multipass compiler ---*/
  2. /* 
  3.     Norman D. Culver 
  4.     Oxbow Software
  5.     1323 S.E. 17th Street #662
  6.     Ft. Lauderdale, FL 33316
  7.     (305) 527-1663 Voice
  8.     (305) 760-7584 Fax
  9.     (305) 760-4679 Data
  10.     norman.culver@channel1.com
  11.     ndc@gcomm.com
  12.  
  13.     Copyright 1994 by Norman D. Culver, All Rights Reserved.
  14. */
  15. /* 
  16.     NOTE -- THE DEADWOOD IN THIS GRAMMAR IS THERE BECAUSE OF THE NEED TO
  17.     RUNTIME INTERPRET AND/OR REGENERATE SOURCE FROM THE AST TREE
  18.  
  19.     NOTE -- PRODUCTIONS TERMINATED WITH $$; DO NOT MAKE AST NODES
  20.  
  21.     NOTE -- THE COMPILER COMPILER DERIVES ANY UNFORCED TERMINALS
  22.  
  23.     NOTE -- THIS IS THE ACTUAL GRAMMAR USED BY THE PARSER GENERATOR `lrg'
  24. */
  25.  
  26. /* Force a couple of terminal symbol values */
  27. #1    {meta-name}
  28. #2    {typedef-name}
  29.  
  30. /*--- Operator Precedence. ---*/
  31.  
  32.   !(  '?'                      )
  33.   !(  '||'                     )
  34.   !(  '&&'                     )
  35.   !(  '|'                      )
  36.   !(  '^'                      )
  37.   !(  '&'                      )
  38.   !(  '=='  '!='               )
  39.   !(  '<'   '>'   '<='   '>='  )
  40.   !(  '<<'  '>>'               )
  41.   !(  '+'   '-'                )
  42.   !(  '*'   '/'   '%'          )
  43.  
  44. /*--- Phrase Structure Grammar ---*/
  45.  
  46. File
  47.     -> [Input]... <eof>        ;
  48.  
  49. Input
  50.     -> OuterDecl    $$;
  51.     -> FuncDef        $$;
  52.     -> Directive    $$;
  53.     -> OuterAnf        $$;
  54.     -> SegStuff        $$;
  55.  
  56. SegStuff
  57.     ->    __segdef__ DeclID [SegList] ';'    ;
  58.     ->    __seguse__ DeclID ';'            ;
  59.  
  60. SegList
  61.     ->    ConstExp \','...    $$;
  62.  
  63. FuncDef
  64.     -> [FrontSpec]        
  65.         FuncDeclarator                
  66.         [Attr]
  67.         [InnerDecl]...
  68.         FuncBody            ;
  69.  
  70. NestedFuncDef
  71.     -> FrontSpec        
  72.         FuncDeclarator
  73.         FuncBody            ;
  74.  
  75. FuncDeclarator
  76.     -> Declarator ;
  77.  
  78. FuncBody
  79.     -> LB
  80.         [DeclOrFunc]...
  81.         [StmtC]...
  82.        BodyExit                 ;
  83.  
  84. BodyExit
  85.     ->    RB    ;
  86.  
  87. OuterDecl
  88.     -> [FrontSpec] [InitDeclarator \','...] ';' 
  89.         => classify (typedef 'InitDeclarator' 'TypeAgain' 'ParenDeclarator' 
  90.             'DeclID' <identifier> {meta-name} {typedef-name})  ;
  91.  
  92. InnerDecl
  93.     -> FrontSpec [InitDeclarator \','...] ';'
  94.         => classify (typedef 'InitDeclarator' 'TypeAgain' 'ParenDeclarator' 
  95.             'DeclID' <identifier> {meta-name} {typedef-name}) ;
  96.  
  97. FrontSpec
  98.     -> TypeDefs                $$;
  99.     -> DeclarationSpec...    $$;
  100.  
  101. TypeDefs
  102.     -> TypeDef TdElem...                $$;
  103.     -> TypeDef Esu...                    $$;
  104.     -> TypeDef TypedefName                $$;
  105.     -> TypeDef TypeAgain \','...        $$;
  106.  
  107. TypeDef
  108.     -> typedef         ;
  109.  
  110. TdElem
  111.     ->    Type        $$;
  112.     ->    Qualifier    $$;
  113.  
  114. TypeAgain
  115.     -> TypedefName InitRHS    ;    /* reuse of computed typedef */
  116.     -> Identifier InitRHS    ;
  117.  
  118. DeclarationSpec
  119.     -> TypeSpec                $$;
  120.     -> StorageClassSpec        $$;
  121.     -> Qualifier            $$;
  122.     -> FuncTypeModifier        $$;
  123.  
  124. InitDeclarator
  125.     -> Declarator [Attr]            ;
  126.     -> Declarator [Attr] InitRHS    ;
  127.  
  128. Declarator
  129.     -> [Pointer] DirectDeclarator         $$;
  130.  
  131. Pointer
  132.     -> '*' [Qualifier]...                ;
  133.     -> '*' [Qualifier]... Pointer        ;
  134.  
  135. DirectDeclarator
  136.     -> DeclID                            $$;
  137.     -> ParenDeclarator                     $$;
  138.     -> DirectDeclarator ArrayDecl        $$;
  139.     -> DirectDeclarator FuncParams        $$;
  140.  
  141. DeclID
  142.     -> <identifier>    ;
  143.     -> {meta-name}    ;
  144.  
  145. ParenDeclarator
  146.     -> '(' Declarator ')' ;
  147.  
  148. ArrayDecl
  149.     -> '[' [BinopC] ']' ;
  150.  
  151. FuncParams
  152.     -> '(' [ParamList] ')' ;
  153.  
  154. ParamList
  155.     -> Param \','...            ;
  156.     -> Param \','... ',' '...'    ;
  157.     -> '...' ;
  158.  
  159. Param
  160.     -> SpecQual... InitDeclarator        ;
  161.     -> SpecQual... [NoNameDeclarator]    ;
  162.     -> Identifier ;
  163.  
  164. NoNameDeclarator
  165.     -> Pointer                            ;
  166.     -> [Pointer] DirectNoNameDeclarator    ;
  167.  
  168. DirectNoNameDeclarator
  169.     -> ParenNoNameDeclarator                        $$;
  170.     -> [DirectNoNameDeclarator] ArrayDecl            $$;
  171.     -> [DirectNoNameDeclarator] FuncParams            $$;
  172.  
  173. ParenNoNameDeclarator
  174.     -> '(' NoNameDeclarator ')' ;
  175.  
  176. InitRHS
  177.     -> '=' Init    ;
  178.  
  179. TypeSpec
  180.     -> Specs        $$;
  181.     -> DynType        $$;
  182.  
  183. DynType
  184.     -> TypedefName    $$;
  185.     -> TypeOf        $$;
  186.  
  187. Specs
  188.     -> Type            $$;
  189.     -> Esu            $$;
  190.  
  191. Esu
  192.     -> EnumSpec        $$;
  193.     -> StructSpec    $$;
  194.     -> UnionSpec    $$;
  195.  
  196. Type
  197.     -> void        ;
  198.     -> char        ;
  199.     -> short    ;
  200.     -> int        ;
  201.     -> long        ;
  202.     -> float    ;
  203.     -> double    ;
  204.     -> signed    ;
  205.     -> unsigned    ;
  206.     -> _segment    ;
  207.     -> __segment ;
  208.     
  209. FuncTypeModifier
  210.     -> inline        ;
  211.     -> __inline__    ;
  212.     -> __inline        ;
  213.     -> _cdecl        ;
  214.     -> __cdecl        ;
  215.     -> _pascal        ;
  216.     -> __pascal        ;
  217.     -> _fortran        ;
  218.     -> __fortran    ;
  219.     -> _interrupt    ;
  220.     -> __interrupt    ;
  221.     -> _ifunc        ;
  222.     -> _loadds        ;
  223.     -> __loadds        ;
  224.     -> _export        ;
  225.     -> __export        ;
  226.     -> _fastcall    ;
  227.     -> _saveregs    ;
  228.     -> __saveregs    ;
  229.     -> _syscall        ;
  230.     -> __syscall    ;
  231.     -> _stdcall        ;
  232.     -> __stdcall    ;
  233.  
  234. Qualifier
  235.     -> Based        ;
  236.     -> const        ;
  237.     -> volatile        ;
  238.     -> __volatile__    ;
  239.     -> _far            ;
  240.     -> __far        ;
  241.     -> _near        ;
  242.     -> __near        ;
  243.     -> _huge        ;
  244.     -> __huge        ;
  245.     -> _seg16        ;
  246.     -> __seg16        ;
  247.     -> _far16        ;
  248.     -> __far16        ;
  249.     -> register        ;
  250.  
  251. Based
  252.     -> _based '(' BaseExp ')'    $$;
  253.     -> __based '(' BaseExp ')'    $$;
  254.     
  255. BaseExp
  256.     ->  CastExp    ;
  257.     -> _self    ;
  258.     -> __self    ;
  259.  
  260. SpecQual
  261.     -> TypeSpec        $$;
  262.     -> Qualifier    $$;
  263.  
  264. TypedefName
  265.     -> {meta-name} => require ({meta-name} {typedef-name}) ;
  266.  
  267. TypeOf
  268.     -> typeof '(' CastExp ')'    ;
  269.  
  270. StorageClassSpec
  271.     -> extern        ;
  272.     -> static        ;
  273.     -> _ival        ;
  274.     -> auto            $$;
  275.  
  276. StructSpec    
  277.     -> struct Tag                                    ;
  278.     -> struct '{' StructMembers... '}'                ;
  279.     -> struct Tag '{' StructMembers... '}'            ;
  280.     -> _Packed struct '{' StructMembers... '}'        ;
  281.     -> _Packed struct Tag '{' StructMembers... '}'    ;
  282.  
  283. UnionSpec
  284.     -> union Tag    ;
  285.     -> union '{' StructMembers... '}'        ;
  286.     -> union Tag '{' StructMembers... '}'     ;
  287.  
  288. StructMembers
  289.     -> MemberSpec Members ';'    ;  /* Allow unnamed structs and unions etc. */
  290.  
  291. MemberSpec
  292.     -> [Qualifier]... Type...     $$;    /* restrictions should be removed */
  293.     -> [Qualifier]... Esu        $$;
  294.     -> [Qualifier]... DynType    $$;
  295.  
  296. Members
  297.     -> SMember \','... $$;
  298.  
  299. SMember
  300.     -> Member    $$;
  301.     -> Bitfield    $$;
  302.  
  303. Member
  304.     -> MemberDeclarator [Attr] ;
  305.     -> [Attr] ;
  306.  
  307. Bitfield
  308.     -> FieldSize [Attr] ;
  309.     -> MemberDeclarator FieldSize [Attr] ;
  310.  
  311. FieldSize
  312.     -> ':' BinopC ;
  313.  
  314. MemberDeclarator
  315.     -> [Pointer] DirectDeclarator    $$;
  316.  
  317. EnumSpec
  318.     -> enum Tag                                        ;
  319.     -> enum '{' Enumerator \','... [','] '}'        ;
  320.     -> enum Tag '{' Enumerator \','... [','] '}'    ;
  321.  
  322. Tag
  323.     -> <identifier> ;
  324.     -> {meta-name}    ;
  325.  
  326. Enumerator
  327.     -> EnumID            ;
  328.     -> EnumID EnumInit    ;
  329.  
  330. EnumID
  331.     -> <identifier> ;
  332.  
  333. EnumInit
  334.     -> '=' BinopC ;
  335.  
  336. Init
  337.     -> InitBlock    $$;
  338.     -> InitExp        $$;
  339.  
  340. InitBlock
  341.     -> '{' InitInner \','... [','] '}'    ;
  342.  
  343. InitExp
  344.     -> AssignExp        ;
  345.  
  346. InitInner
  347.     -> InitId InitBlock    $$;
  348.     -> InitId InitExp    $$;
  349.     -> InitBlock        $$;
  350.     -> InitExp            $$;
  351.  
  352. InitId
  353.     ->    AryElem...    '='        ;
  354.     ->    '.' InitLabel '='    ;
  355.     ->  InitLabel ':'         ;
  356.  
  357. AryElem
  358.     -> '[' InitElem ']'    $$;
  359.  
  360. InitElem
  361.     ->    Constant    ;
  362.  
  363. InitLabel
  364.     -> <identifier> ;
  365.     -> {meta-name}    ;
  366.  
  367. Attr
  368.     -> Attr1 '(' Constant ')' ')' ')'    ;
  369.     -> Attr1 ')' ')'                    ;
  370.     -> Attr1 '(' Identifier ')' ')' ')'    ;
  371.     -> Attr1 '(' Identifier ',' Constant ',' Constant ')' ')' ')'    ;
  372.  
  373. Attr1
  374.     -> __attribute__ '(' '(' AttrId    $$;
  375.  
  376. AttrId
  377.     -> <identifier> ;
  378.     -> {meta-name}    ;
  379.  
  380. /* Statements */
  381.  
  382. StmtC
  383.     -> ';'                                        ;            /*0*/
  384.     -> Exp ';'                                    ;            /*1*/
  385.     -> goto Identifier ';'                        ;            /*2*/
  386.     -> continue ';'                                ;            /*3*/
  387.     -> break ';'                                ;            /*4*/
  388.     -> return [RetExp] ';'                        ;            /*5*/
  389.     -> if '(' IfExp ')' IfStmtC                    ;            /*6*/
  390.     -> if '(' IfExp ')' IfStmtC else ElseStmtC    ;            /*7*/
  391.     -> switch '(' SwExp ')' SwStmtC                ;            /*8*/
  392.     -> while '(' WhileExp ')' WhileStmtC        ;            /*9*/
  393.     -> do DoStmtC while '(' DoExp ')' ';'        ;            /*10*/
  394.     -> for '(' [ForInit] FS1 [ForCond] FS2 [ForPost] ')' ForStmtC    ;    /*11*/
  395.     -> BlockC                                    ;            /*12*/
  396.     -> Label ':' [StmtC]                        ;            /*13*/
  397.     -> AsmStmt                                    ;            /*14*/
  398.     -> AnfBlock                                    ;            /*15*/
  399.  
  400. FS1
  401.     -> ';' ;
  402. FS2
  403.     -> ';' ;
  404.  
  405. RetExp
  406.     -> Exp    ;
  407.  
  408. IfExp
  409.     -> Exp    ;
  410.  
  411. SwExp
  412.     -> Exp    ;
  413.     
  414. WhileExp
  415.     -> Exp    ;
  416.  
  417. DoExp
  418.     -> Exp    ;
  419.  
  420. IfStmtC
  421.     -> StmtC    ;
  422.  
  423. ElseStmtC
  424.     -> StmtC    ;
  425.     
  426. DoStmtC
  427.     -> StmtC    ;
  428.  
  429. WhileStmtC
  430.     -> StmtC    ;
  431.     
  432. ForStmtC
  433.     -> StmtC    ;
  434.  
  435. SwStmtC
  436.     -> StmtC    ;
  437.  
  438. ForInit
  439.     -> Exp    ;
  440.  
  441. ForCond
  442.     -> Exp    ;
  443.  
  444. ForPost
  445.     -> Exp    ;
  446.  
  447. BlockC
  448.     -> BlockEntry
  449.         [Local]...
  450.         [DeclOrFunc]...
  451.         [StmtC]...
  452.        BlockExit                 ;
  453.  
  454. BlockEntry
  455.     ->    LB    ;
  456.  
  457. BlockExit
  458.     -> RB ;
  459.  
  460. DeclOrFunc
  461.     -> InnerDecl        $$;
  462.     -> NestedFuncDef    $$;
  463.  
  464. Local
  465.     -> __label__ LocalID ':' $$;
  466.  
  467. LocalID
  468.     -> <identifier>    ;
  469.     -> {meta-name}    ;
  470.  
  471. Label
  472.     ->    <identifier>                     ;
  473.     ->    {meta-name}                        ;
  474.     ->    default                         ;
  475.     ->    case ConstExp                     ;
  476.     ->    case ConstExp '...' ConstExp    ;
  477.  
  478. OuterAnf
  479.     ->    AnfBlock [';']    ;
  480.  
  481. AsmStmt
  482.     -> GccAsmStmt        $$;
  483.     -> MscAsmStmt        $$;
  484.  
  485. GccAsmStmt
  486.     -> asm '(' [AsmString]... [GccIOspec] ')' ';' ;
  487.  
  488. AsmString
  489.     -> String        ;
  490.  
  491. GccIOspec
  492.     -> CO [GccOutputList] CO [GccInputList] [ClobbersList]    $$;
  493.  
  494. GccOutputList
  495.     -> GccOutput \','...    $$;
  496.  
  497. GccInputList
  498.     -> GccInput \','...        $$;
  499.  
  500. ClobbersList
  501.     -> CO Clobbers \','...    $$;
  502.  
  503. GccOutput
  504.     -> String GccfixExp ;
  505.  
  506. GccInput
  507.     -> String GccfixExp ;
  508.     
  509. Clobbers
  510.     -> String            ;
  511.  
  512. GccfixExp
  513.     -> PostfixExp ;
  514.  
  515. MscAsmStmt
  516.     -> _asm [AsmElem]...            ;
  517.     -> _asm '{' [AsmAll]... '}'        ;
  518.     -> _asm '(' AsmEmit... ')'        ;
  519.     
  520. AsmAll
  521.     -> AsmElem        $$;
  522.     -> AsmUnixOp    $$;
  523.  
  524. AsmElem
  525.     -> AsmOp        $$;
  526.     -> AsmId        $$;
  527.     -> Constant        $$;
  528.     -> Type            $$;
  529.     -> AsmEmit        $$;
  530.  
  531. AsmOp
  532.     ->    '+'        ;
  533.     ->    '-'        ;
  534.     ->    '*'        ;
  535.     ->    '/'        ;
  536.     ->    '.'        ;
  537.     ->    '['        ;
  538.     ->    ']'        ;
  539.     ->    ','        ;
  540.     ->    ':'        ;
  541.  
  542. AsmUnixOp
  543.     ->    '%'        ;
  544.     ->    '$'        ;
  545.     ->    '('        ;
  546.     ->    ')'        ;
  547.  
  548. AsmId
  549.     -> <identifier>        ;
  550.     -> {meta-name}        ;
  551.  
  552. AsmEmit
  553.     ->    _emit Constant                    ;
  554.     -> _emit '(' Constant \','... ')'    ;
  555.  
  556. CO
  557.     -> ':'    ;
  558.  
  559. AnfBlock
  560.     -> __anf__ '{' [AnfStmt]... '}'    ;
  561.  
  562. AnfStmt
  563.     ->    AnfOp [AnfTarget] ';'    ;
  564.     ->    Label ':' [AnfStmt]        ;
  565.  
  566. AnfTarget
  567.     ->    AssignExp \','...        $$;
  568.  
  569. AnfOp
  570.     ->    DeclID        ;
  571.  
  572. /* Expressions */
  573.  
  574. Exp
  575.     -> AssignExp        ;
  576.     -> Exp ',' CommaExp    ;
  577.  
  578. CommaExp
  579.     -> AssignExp    ;    /* needed for regen source */
  580.  
  581. ConstExp
  582.     ->BinopC        ;
  583.  
  584. AssignExp
  585.     -> BinopC                    $$;
  586.     -> AssignLHS '+='  AssignExp ;        /* 1 */
  587.     -> AssignLHS '-='  AssignExp ;        /* 2 */
  588.     -> AssignLHS '*='  AssignExp ;        /* 3 */
  589.     -> AssignLHS '/='  AssignExp ;        /* 4 */
  590.     -> AssignLHS '<<=' AssignExp ;        /* 5 */
  591.     -> AssignLHS '>>=' AssignExp ;        /* 6 */
  592.     -> AssignLHS '%='  AssignExp ;        /* 7 */
  593.     -> AssignLHS '|='  AssignExp ;        /* 8 */
  594.     -> AssignLHS '^='  AssignExp ;        /* 9 */
  595.     -> AssignLHS '&='  AssignExp ;        /* 10 */
  596.     -> AssignLHS '='   AssignExp ;        /* 11 */
  597.  
  598. AssignLHS
  599.     -> CastExp ;
  600.  
  601. BinopC
  602.     -> BaseOrCast            $$;
  603.     -> BinopC '+'  BinopC    ;    /* 1 */
  604.     -> BinopC '-'  BinopC    ;    /* 2 */
  605.     -> BinopC '*'  BinopC    ;    /* 3 */
  606.     -> BinopC '/'  BinopC    ;    /* 4 */
  607.     -> BinopC '<<' BinopC    ;    /* 5 */
  608.     -> BinopC '>>' BinopC    ;    /* 6 */
  609.     -> BinopC '%'  BinopC    ;    /* 7 */
  610.     -> BinopC '|'  BinopC    ;    /* 8 */
  611.     -> BinopC '^'  BinopC    ;    /* 9 */
  612.     -> BinopC '&'  BinopC    ;    /* 10 */
  613.     -> BinopC '==' BinopC    ;    /* 11 */
  614.     -> BinopC '!=' BinopC    ;    /* 12 */
  615.     -> BinopC '<'  BinopC    ;    /* 13 */
  616.     -> BinopC '>'  BinopC    ;    /* 14 */
  617.     -> BinopC '<=' BinopC    ;    /* 15 */
  618.     -> BinopC '>=' BinopC    ;    /* 16 */
  619.     -> BinopC '||' BinopC    ;    /* 17 */
  620.     -> BinopC '&&' BinopC    ;    /* 18 */
  621.     -> BinopC '?'  BinopC ':' BinopC ;    /* 19 */
  622.     -> BinopC '?'  ':' BinopC ;    /* 20 */
  623.  
  624. BaseOrCast
  625.     ->    BasedPtr    $$;
  626.     ->    CastExp        $$;
  627.  
  628. BasedPtr
  629.     -> PostfixExp ':>' PostfixExp    ;
  630.  
  631. CastExp
  632.     -> UnaryExp                ;
  633.     -> '(' Cast ')' CastExp    ;
  634.  
  635. Cast
  636.     -> SpecQual... [NoNameDeclarator]    ;
  637.  
  638. UnaryExp
  639.     -> PostfixExp        $$;
  640.     -> PreIncrement        $$;
  641.     -> UnOpC  CastExp    $$;
  642.     -> SizeOf            $$;
  643.     -> AlignOf            $$;
  644.     -> SegName            $$;
  645.  
  646. UnOpC
  647.     -> '&'    ;
  648.     -> '*'    ;
  649.     -> '-'    ;
  650.     -> '~'    ;
  651.     -> '!'    ;
  652.  
  653. PreIncrement
  654.     -> '++' UnaryExp    ;
  655.     -> '--' UnaryExp    ;
  656.  
  657. PostIncrement
  658.     -> PostfixExp '++' ;
  659.     -> PostfixExp '--' ;
  660.  
  661. SizeOf
  662.     -> sizeof UnaryExp        ;
  663.     -> sizeof '(' Cast ')'    ;
  664.  
  665. AlignOf
  666.     -> __alignof__ UnaryExp        ;
  667.     -> __alignof__ '(' Cast ')'    ;
  668.  
  669. SegName
  670.     -> _segname '(' String ')'    ;
  671.     -> __segname '(' String ')'    ;
  672.  
  673. PostfixExp
  674.     -> PrimaryExp            $$;
  675.     -> ArrayElement            $$;
  676.     -> StructureElement        $$;
  677.     -> PointerElement        $$;
  678.     -> FunctionCall            $$;
  679.     -> PostIncrement        $$;
  680.    
  681. ArrayElement
  682.     -> ElemNameExp '[' ElemExp ']' ;
  683.  
  684. ElemNameExp
  685.     -> Identifier        ;
  686.     -> ArrayElement     ;
  687.     -> '(' Exp ')'        ;
  688.     -> PointerElement     ;
  689.     -> StructureElement ;
  690.     -> FunctionCall     ;
  691.     -> String            ;
  692.  
  693. ElemExp
  694.     ->    Exp ;
  695.  
  696. StructureElement
  697.     -> PostfixExp '.' ElementName ;
  698.  
  699. PointerElement
  700.     -> PostfixExp '->' ElementName ;     
  701.  
  702. ElementName
  703.     -> <identifier>    ;
  704.     -> {meta-name}    ;
  705.  
  706. FunctionCall
  707.     -> PostfixExp ArgList ;
  708.     
  709. ArgList
  710.     -> '(' [Args] ')' ;
  711.  
  712. Args
  713.     -> Arg \','... $$;
  714.  
  715. Arg
  716.     -> AssignExp        ;
  717.     -> ArgId AssignExp    ;
  718.  
  719. ArgId
  720.     -> ArgLabel ':'        $$;
  721.  
  722. ArgLabel
  723.     -> <identifier>        ;
  724.     -> {meta-name}        ;    
  725.  
  726. PrimaryExp
  727.     -> Constant                    $$;
  728.     -> Identifier                $$;
  729.     -> '(' Exp ')'                $$;
  730.     -> CompoundExp                $$;
  731.     -> String...                $$;
  732.  
  733. CompoundExp
  734.     -> '(' BlockC CompoundExit    ;
  735.  
  736. CompoundExit
  737.     ->    ')' ;
  738.  
  739. Identifier
  740.     -> <identifier>  ;
  741.  
  742. Constant
  743.     -> <int> ;            /*0*/
  744.     -> <long> ;            /*1*/
  745.     -> <ll>    ;            /*2*/
  746.     -> <uint> ;            /*3*/
  747.     -> <ulong> ;        /*4*/
  748.     -> <ull> ;            /*5*/
  749.  
  750.     -> <hex> ;            /*6*/
  751.     -> <lhex> ;            /*7*/
  752.     -> <llhex> ;        /*8*/
  753.     -> <uhex> ;            /*9*/
  754.     -> <ulhex> ;        /*10*/
  755.     -> <ullhex> ;        /*11*/
  756.  
  757.     -> <octal> ;        /*12*/
  758.     -> <loctal> ;        /*13*/
  759.     -> <lloctal> ;        /*14*/
  760.     -> <uoctal> ;        /*15*/
  761.     -> <uloctal> ;        /*16*/
  762.     -> <ulloctal> ;        /*17*/
  763.  
  764.     -> <float> ;        /*18*/
  765.     -> <double> ;        /*19*/
  766.     -> <ldouble> ;        /*20*/
  767.  
  768.     -> <literal> ;        /*21*/
  769.     -> <wliteral> ;        /*22*/
  770.  
  771. String
  772.     -> <string> ;
  773.     -> <wstring> ;
  774.  
  775. LB    -> '{' $$;
  776. RB    -> '}' $$;
  777.  
  778. Directive
  779.     -> <notline> ;
  780.     -> <linenum> ; /* this will never happen, linenum is expunged by doline */
  781.  
  782. /* Lexical grammar for c and c++ */
  783.  
  784. IGNORE             := spaces ;
  785.                 := comment ;
  786.                 := comment2 ;
  787.  
  788. "eof"            := (0 | 26 | 255) ;
  789.  
  790.  
  791. "linenum"        := line restofline => doline ;
  792. line            := '#line' ;
  793.  
  794. "notline"        := notline restofline ;
  795. notline            := '#' ;
  796.  
  797. "identifier"    := ident => dyntoken ;
  798. ident            := letter ;
  799.                 := ident letter ;
  800.                 := ident digit ;
  801.  
  802. "int"            := digits ;
  803.  
  804. "long"            := digits 'l' ;
  805.                 := digits 'L' ;
  806.  
  807. "uint"            := digits 'U' ;
  808.                 := digits 'u' ;
  809.  
  810. "ulong"            := digits 'LU' ;
  811.                 := digits 'UL' ;
  812.                 := digits 'ul' ;
  813.                 := digits 'lu' ;
  814.                 := digits 'lU' ;
  815.                 := digits 'Lu' ;
  816.                 := digits 'uL' ;
  817.                 := digits 'Ul' ;
  818.  
  819. "ll"            := digits 'LL' ;
  820.                 := digits 'll' ;
  821.  
  822. "ull"            := digits 'ull' ;
  823.                 := digits 'llu' ;
  824.                 := digits 'ULL' ;
  825.                 := digits 'LLU' ;
  826.                 
  827. digits            := digit ;
  828.                 := digits digit ;
  829.  
  830. "hex"            := hexx ;
  831.  
  832. "lhex"            := hexx 'l' ;
  833.                 := hexx 'L' ;
  834.  
  835. "uhex"            := hexx 'U' ;
  836.                 := hexx 'u' ;
  837.  
  838. "ulhex"            := hexx 'LU' ;
  839.                 := hexx 'UL' ;
  840.                 := hexx 'ul' ;
  841.                 := hexx 'lu' ;
  842.                 := hexx 'lU' ;
  843.                 := hexx 'Lu' ;
  844.                 := hexx 'uL' ;
  845.                 := hexx 'Ul' ;
  846.  
  847. "llhex"            := hexx 'LL' ;
  848.                 := hexx 'll' ;
  849.  
  850. "ullhex"        := hexx 'ull' ;
  851.                 := hexx 'llu' ;
  852.                 := hexx 'ULL' ;
  853.                 := hexx 'LLU' ;
  854.  
  855.  
  856. hexx            := '0x' hexdigit ;
  857.                 := '0X' hexdigit ;
  858.                 := hexx hexdigit ;
  859.  
  860. hexdigit        := '0'/'9' ;
  861.                 := a/f ;
  862.                 := A/F ;
  863.  
  864. "octal"            := oct ;
  865.  
  866. "loctal"        := oct 'l' ;
  867.                 := oct 'L' ;
  868.  
  869. "uoctal"        := oct 'U' ;
  870.                 := oct 'u' ;
  871.  
  872. "uloctal"        := oct 'LU' ;
  873.                 := oct 'UL' ;
  874.                 := oct 'ul' ;
  875.                 := oct 'lu' ;
  876.                 := oct 'lU' ;
  877.                 := oct 'Lu' ;
  878.                 := oct 'uL' ;
  879.                 := oct 'Ul' ;
  880.  
  881. "lloctal"        := oct 'LL' ;
  882.                 := oct 'll' ;
  883.  
  884. "ulloctal"        := oct 'ull' ;
  885.                 := oct 'llu' ;
  886.                 := oct 'ULL' ;
  887.                 := oct 'LLU' ;
  888.                 
  889. oct                := '0' octdigit ;
  890.                 := oct octdigit ;
  891. octdigit        := '0'/'7' ;
  892.  
  893. "double"        := flt ;
  894. "float"            := flt 'f' ;
  895.                 := flt 'F' ;
  896. "ldouble"        := flt 'l' ;
  897.                 := flt 'L' ;
  898.  
  899. flt                := rational ;
  900.                 := digits exp ;
  901.                 := rational exp ;
  902.  
  903. rational        := digits '.' ;
  904.                 := '.' digits ;
  905.                 := digits '.' digits ;
  906. exp                := 'e' digits  ;
  907.                 := 'E' digits ;
  908.                 := 'e-' digits ;
  909.                 := 'E-' digits ;
  910.                 := 'e+' digits ;
  911.                 := 'E+' digits ;
  912.  
  913. "literal"        := lit ;
  914. "wliteral"        := 'L' lit ;
  915. lit                := qt lchar... qt ;
  916. lchar            := ch ;
  917.                 := qt qt ;
  918.                 := '"' ;
  919.                 := '*' ;
  920.                 := '/' ;
  921.                 := escapes ; 
  922.  
  923. "string"        := str ;
  924. "wstring"        := 'L' str ;
  925.  
  926. str                := '"' [schar...] '"' ;
  927. schar            := ch ;
  928.                 := qt ;
  929.                 := '*' ;
  930.                 := '/' ;
  931.                 := escapes ;
  932.  
  933. escapes            := bs qt ;
  934.                 := bs ch ;
  935.                 := bs '"' ;
  936.                 := bs '*' ;
  937.                 := bs '/' ;
  938.                 := bs bs ;
  939.                 := bs lf ;
  940.  
  941. spaces            := space... ;
  942. space             := ( 9 | 10 | 12 | 32 ) ;
  943.  
  944. comment           := '/*' end '/' ;
  945. end               := endinstar ;
  946.                   := end noslash endinstar    ;
  947. endinstar         := stars ;
  948.                   := notstar stars ;
  949. stars             := '*'... ;
  950. notstar           := nostar    ;
  951.                   := notstar nostar    ;
  952. noslash           := (ch | notsl) ;
  953. notsl            := (10 | 12 | 39 | '"' | '*' | 92) ;
  954. nostar            := (ch | notst)    ;
  955. notst            := (10 | 12 | 39 | '"' | '/' | 92) ;
  956.  
  957.  
  958. comment2        := '//' restofline ;
  959.  
  960. restofline        := [(ch | noteol)]... ;
  961. noteol            := (39 | '"' | '/' | '*' | 92) ;
  962.  
  963. ch                := 1/254 ^(10 12 26 39 '"' '/' '*' 92) ;
  964.  
  965. letter            := a/z ;
  966.                 := A/Z ;
  967.                 := '_' ;
  968.  
  969. digit            := '0'/'9' ;
  970.  
  971. bs            := 92 ;
  972. qt            := 39 ;
  973. lf            := 10 ;
  974. /*--- End. ---*/
  975.  
  976.