home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Docs / cxref-1.4a.lha / parse.y < prev    next >
Encoding:
Lex Description  |  1997-12-07  |  35.1 KB  |  1,433 lines

  1. %{
  2. /***************************************
  3.   $Header: /home/amb/cxref/RCS/parse.y 1.29 1997/11/20 19:19:07 amb Exp $
  4.  
  5.   C Cross Referencing & Documentation tool. Version 1.4a.
  6.  
  7.   C parser.
  8.   ******************/ /******************
  9.   Written by Andrew M. Bishop
  10.  
  11.   This file Copyright 1995,96,97 Andrew M. Bishop
  12.   It may be distributed under the GNU Public License, version 2, or
  13.   any higher version.  See section COPYING of the GNU Public license
  14.   for conditions under which this file may be redistributed.
  15.   ***************************************/
  16.  
  17. #include <string.h>
  18. #include "parse-yy.h"
  19. #include "cxref.h"
  20. #include "memory.h"
  21.  
  22. /*+ A structure to hold the information about an object. +*/
  23. typedef struct _stack
  24. {
  25.  char *name;                    /*+ The name of the object. +*/
  26.  char *type;                    /*+ The type of the object. +*/
  27.  char *qual;                    /*+ The type qualifier of the object. +*/
  28. }
  29. stack;
  30.  
  31. #define yylex cxref_yylex
  32.  
  33. static int cxref_yylex(void);
  34.  
  35. static void yyerror(char *s);
  36.  
  37. /*+ When in a header file, some stuff can be skipped over quickly. +*/
  38. extern int in_header;
  39.  
  40. /*+ A flag that is set to true when typedef is seen in a statement. +*/
  41. int in_typedef=0;
  42.  
  43. /*+ The scope of the function / variable that is being examined. +*/
  44. static int scope;
  45.  
  46. /*+ The variable must be LOCAL or EXTERNAL or GLOBAL, so this checks and sets that. +*/
  47. #define SCOPE ( scope&(LOCAL|EXTERNAL|EXTERN_H|EXTERN_F) ? scope : scope|GLOBAL )
  48.  
  49. /*+ When in a function or a function definition, the behaviour is different. +*/
  50. static int in_function=0,in_funcdef=0,in_funcbody=0;
  51.  
  52. /*+ The parsing stack +*/
  53. static stack first={NULL,NULL,NULL},  /*+ first value. +*/
  54.             *list=NULL,               /*+ list of all values. +*/
  55.             *current=&first;          /*+ current values. +*/
  56.  
  57. /*+ The depth of the stack +*/
  58. static int depth=0,             /*+ currently in use. +*/
  59.            maxdepth=0;          /*+ total malloced. +*/
  60.  
  61. /*+ Declarations that are in the same statement share this comment. +*/
  62. static char* common_comment=NULL;
  63.  
  64. /*+ When inside a struct / union / enum definition, this is the depth. +*/
  65. static int in_structunion=0;
  66.  
  67. /*+ When inside a struct / union definition, this is the component type. +*/
  68. static char *comp_type=NULL;
  69.  
  70. /*+ To solve the problem where a type name is used as an identifier. +*/
  71. static int in_type_spec=0;
  72.  
  73.  
  74. /*++++++++++++++++++++++++++++++++++++++
  75.   Reset the current level on the stack.
  76.   ++++++++++++++++++++++++++++++++++++++*/
  77.  
  78. static void reset(void)
  79. {
  80.  current->name=NULL;
  81.  current->type=NULL;
  82.  current->qual=NULL;
  83. }
  84.  
  85.  
  86. /*++++++++++++++++++++++++++++++++++++++
  87.   Push a level onto the stack.
  88.   ++++++++++++++++++++++++++++++++++++++*/
  89.  
  90. static void push(void)
  91. {
  92.  if(list==NULL)
  93.    {
  94.     list=(stack*)Malloc(8*sizeof(struct _stack));
  95.     list[0]=first;
  96.     maxdepth=8;
  97.    }
  98.  else if(depth==maxdepth)
  99.    {
  100.     list=Realloc(list,(maxdepth+8)*sizeof(struct _stack));
  101.     maxdepth+=8;
  102.    }
  103.  
  104.  depth++;
  105.  current=&list[depth];
  106.  
  107.  reset();
  108. }
  109.  
  110.  
  111. /*++++++++++++++++++++++++++++++++++++++
  112.   Pop a level from the stack.
  113.   ++++++++++++++++++++++++++++++++++++++*/
  114.  
  115. static void pop(void)
  116. {
  117.  reset();
  118.  
  119.  depth--;
  120.  current=&list[depth];
  121. }
  122.  
  123.  
  124. /*++++++++++++++++++++++++++++++++++++++
  125.   Reset the Parser, ready for the next file.
  126.   ++++++++++++++++++++++++++++++++++++++*/
  127.  
  128. void ResetParser(void)
  129. {
  130.  in_typedef=0;
  131.  scope=0;
  132.  in_function=0;
  133.  in_funcdef=0;
  134.  in_funcbody=0;
  135.  depth=0;
  136.  maxdepth=0;
  137.  if(list) Free(list);
  138.  list=NULL;
  139.  current=&first;
  140.  reset();
  141.  common_comment=NULL;
  142.  in_structunion=0;
  143.  comp_type=NULL;
  144.  in_type_spec=0;
  145. }
  146.  
  147. %}
  148.  
  149. /* Expected conflicts: 17 shift/reduce */
  150.  
  151. %token IDENTIFIER TYPE_NAME LITERAL STRING_LITERAL ELLIPSES
  152. %token MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
  153. %token EQ_OP NE_OP PTR_OP AND_OP OR_OP DEC_OP INC_OP LE_OP GE_OP
  154. %token LEFT_SHIFT RIGHT_SHIFT
  155. %token SIZEOF
  156. %token TYPEDEF EXTERN STATIC AUTO REGISTER CONST VOLATILE VOID INLINE
  157. %token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE
  158. %token STRUCT UNION ENUM
  159. %token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
  160. %token ASM
  161.  
  162. %start file
  163.  
  164. %%
  165.  
  166. /*-------------------- Top level --------------------*/
  167.  
  168. file
  169.     : /* Empty */
  170.     | program
  171.     ;
  172.  
  173. program
  174.     : top_level_declaration
  175.     | program top_level_declaration
  176.     ;
  177.  
  178. top_level_declaration
  179.     : declaration
  180.                 { scope=0; reset(); common_comment=NULL; in_typedef=0; }
  181.     | function_definition
  182.                 { scope=0; reset(); common_comment=NULL; in_typedef=0; }
  183.     | asm_statement         /*+ GNU Extension +*/
  184.     | null_statement
  185.     ;
  186.  
  187. /*-------------------- Declarations --------------------*/
  188.  
  189. declaration_list
  190.     : declaration
  191.                 { scope=0; reset(); common_comment=NULL; in_typedef=0; }
  192.     | declaration_list declaration
  193.                 { scope=0; reset(); common_comment=NULL; in_typedef=0;
  194.                   $$=$2; }
  195.     ;
  196.  
  197. declaration
  198.     : declaration_specifiers initialized_declarator_list ';'
  199.                 { in_type_spec=0; }
  200.     | declaration_specifiers ';'
  201.                 { in_type_spec=0; }
  202.     ;
  203.  
  204. declaration_specifiers
  205.         : declaration_specifiers1
  206.                 { if(!in_typedef) {common_comment=GetCurrentComment(); SetCurrentComment(common_comment);} }
  207.     ;
  208.  
  209. declaration_specifiers1
  210.     : storage_class_specifier
  211.     | storage_class_specifier declaration_specifiers1
  212.                 { if($1) $$=ConcatStrings(3,$1," ",$2); else $$=$2; }
  213.     | type_specifier
  214.                 { if(!current->type) current->type=$1; }
  215.     | type_specifier declaration_specifiers1
  216.                 { if(!current->type) current->type=$1;
  217.                   $$=ConcatStrings(3,$1," ",$2); }
  218.     | type_qualifier
  219.     | type_qualifier declaration_specifiers1
  220.                 { $$=ConcatStrings(3,$1," ",$2); }
  221.     ;
  222.  
  223. /* Initialised declarator list */
  224.  
  225. initialized_declarator_list
  226.     : initialized_declarator
  227.     | initialized_declarator_list ',' { in_type_spec=1; } initialized_declarator
  228.     ;
  229.  
  230. initialized_declarator
  231.     : initialized_declarator1
  232.                 {
  233.                  if(!in_function && !in_funcdef && !in_structunion)
  234.                    {
  235.                     char* specific_comment=GetCurrentComment();
  236.                     if(!common_comment)   SetCurrentComment(specific_comment); else
  237.                     if(!specific_comment) SetCurrentComment(common_comment);   else
  238.                     if(common_comment!=specific_comment) SetCurrentComment(ConcatStrings(3,common_comment," ",specific_comment)); else
  239.                                           SetCurrentComment(common_comment);
  240.                    }
  241.  
  242.                  if(in_typedef)
  243.                    {
  244.                     char* vname=strstr($1,current->name);
  245.                     SeenTypedefName(current->name,vname[strlen(current->name)]=='('?-1:1);
  246.                     if(!in_header)
  247.                        SeenTypedef(current->name,ConcatStrings(3,current->qual,current->type,$1));
  248.                    }
  249.                  else
  250.                     if(in_function==2)
  251.                        SeenFunctionArg(current->name,ConcatStrings(3,current->qual,current->type,$1));
  252.                     else
  253.                       {
  254.                        char* vname=strstr($1,current->name);
  255.                        if(vname[strlen(current->name)]!='(' && IsATypeName(current->type)!='f')
  256.                          {
  257.                           if((in_funcbody==0 || scope&EXTERN_F) && !in_structunion && !(in_header==GLOBAL && scope&EXTERN_H))
  258.                              SeenVariableDefinition(current->name,ConcatStrings(3,current->qual,current->type,$1),SCOPE);
  259.                           else
  260.                              if(in_funcbody)
  261.                                 SeenScopeVariable(current->name);
  262.                          }
  263.                        else
  264.                          {
  265.                           SeenFunctionProto(current->name,in_funcbody);
  266.                           DownScope();
  267.                          }
  268.                       }
  269.  
  270.                  if(in_function==3) in_function=0;
  271.                 }
  272.     ;
  273.  
  274. initialized_declarator1
  275.     : declarator
  276.     | declarator asm_label  /*+ GNU Extension +*/
  277.     | declarator initializer_part
  278.     | declarator asm_label initializer_part /* GNU Extension */
  279.     ;
  280.  
  281. initializer_part
  282.     : '=' initializer
  283.     ;
  284.  
  285. initializer_list
  286.     : initializer
  287.     | initializer_list ',' initializer
  288.     ;
  289.  
  290. initializer
  291.     : assignment_expression
  292.     | '{' '}'
  293.     | '{' initializer_list '}'
  294.     | '{' initializer_list ',' '}'
  295.     ;
  296.  
  297.  
  298. /* Abstract declarator */
  299.  
  300. abstract_declarator
  301.     : pointer
  302.     | pointer direct_abstract_declarator
  303.                 { $$=ConcatStrings(2,$1,$2); }
  304.     | direct_abstract_declarator
  305.     ;
  306.  
  307. direct_abstract_declarator
  308.     : '(' abstract_declarator ')'
  309.                 { $$=ConcatStrings(3,$1,$2,$3);
  310.                   { int i=0; while($2[i] && $2[i]=='*') i++; if(!$2[i]) in_type_spec=0; } }
  311.     | '[' ']'
  312.                 { $$=ConcatStrings(2,$1,$2); }
  313.     | direct_abstract_declarator '[' ']'
  314.                 { $$=ConcatStrings(3,$1,$2,$3); }
  315.     | '[' constant_expression ']'
  316.                 { $$=ConcatStrings(3,$1,$2,$3); }
  317.     | direct_abstract_declarator '[' constant_expression ']'
  318.                 { $$=ConcatStrings(4,$1,$2,$3,$4); }
  319.     | '(' ')'
  320.                 { $$=ConcatStrings(2,$1,$2); }
  321.     | direct_abstract_declarator '(' ')'
  322.                 { $$=ConcatStrings(3,$1,$2,$3); }
  323.     | '(' parameter_type_list ')'
  324.                 { $$=ConcatStrings(3,$1,$2,$3); }
  325.     | direct_abstract_declarator '(' parameter_type_list ')'
  326.                 { $$=ConcatStrings(4,$1,$2,$3,$4); }
  327.     ;
  328.  
  329. /* Declarator */
  330.  
  331. declarator
  332.     : direct_declarator
  333.                 { in_type_spec=0; }
  334.     | pointer direct_declarator
  335.                 { in_type_spec=0; $$=ConcatStrings(2,$1,$2); }
  336.     ;
  337.  
  338. pointer
  339.     : '*'
  340.     | '*' type_qualifier_list
  341.                 { $$=ConcatStrings(3,$1," ",$2); }
  342.     | '*' pointer
  343.                 { $$=ConcatStrings(2,$1,$2); }
  344.     | '*' type_qualifier_list pointer
  345.                 { $$=ConcatStrings(4,$1," ",$2,$3); }
  346.     ;
  347.  
  348. direct_declarator
  349.     : simple_declarator
  350.     | '(' declarator ')'
  351.                 { if($2[0]=='*' && $2[1]==' ') { $2=&$2[1]; $2[0]='*'; }
  352.                   $$=ConcatStrings(4," ",$1,$2,$3);
  353.                 }
  354.     | array_declarator
  355.     | function_direct_declarator
  356.     ;
  357.  
  358. simple_declarator
  359.     : IDENTIFIER
  360.                 { $$=ConcatStrings(2," ",$1); current->name=$1;
  361.                   if(!current->type) current->type="int";
  362.                   if(in_funcdef==1 && in_function!=3 && !in_structunion) SeenScopeVariable($1); }
  363.     ;
  364.  
  365. array_declarator
  366.     : direct_declarator '[' ']'
  367.                 { $$=ConcatStrings(3,$1,$2,$3); }
  368.         | direct_declarator '[' { in_type_spec=0; } constant_expression { in_type_spec=1; } ']'
  369.                 { $$=ConcatStrings(4,$1,$2,$4,$6); }
  370.     ;
  371.  
  372. /*-------------------- Storage class and types --------------------*/
  373.  
  374. name
  375.     : IDENTIFIER
  376.     ;
  377.  
  378. storage_class_specifier
  379.     : AUTO
  380.                 { $$=NULL; }
  381.     | EXTERN
  382.                 { $$=NULL;
  383.                   if(in_funcbody) scope|=EXTERN_F;
  384.                   else if(in_header) scope|=EXTERN_H;
  385.                   else scope|=EXTERNAL; }
  386.     | REGISTER
  387.                 { $$=NULL; }
  388.     | STATIC
  389.                 { $$=NULL; scope |= LOCAL; }
  390.     | TYPEDEF
  391.                 { $$=NULL;
  392.                   in_typedef=1; if(!in_header) SeenTypedef(NULL,NULL);
  393.                   common_comment=GetCurrentComment(); }
  394.     | INLINE                /* GNU Extension */
  395.                 { $$=NULL; scope |= INLINED; }
  396.     ;
  397.  
  398. type_qualifier_list
  399.     : type_qualifier
  400.     | type_qualifier_list type_qualifier
  401.                 { $$=ConcatStrings(3,$1," ",$2); }
  402.     ;
  403.  
  404. type_qualifier
  405.     : CONST
  406.                 { if(!current->type) current->qual=ConcatStrings(3,current->qual,$1," "); }
  407.     | VOLATILE
  408.                 { if(!current->type) current->qual=ConcatStrings(3,current->qual,$1," "); }
  409.     ;
  410.  
  411. /* Types */
  412.  
  413. type_specifier
  414.     : type_specifier1
  415.                 { in_type_spec=1; }
  416.     ;
  417.  
  418. type_specifier1
  419.     : enumeration_type_specifier
  420.     | floating_type_specifier
  421.     | integer_type_specifier
  422.     | structure_type_specifier
  423.     | typedef_name
  424.     | union_type_specifier
  425.     | void_type_specifier
  426.     ;
  427.  
  428. floating_type_specifier
  429.     : FLOAT
  430.     | DOUBLE
  431.     | DOUBLE LONG
  432.                 { $$=ConcatStrings(3,$1," ",$2); }
  433.     | LONG DOUBLE
  434.                 { $$=ConcatStrings(3,$1," ",$2); }
  435.     ;
  436.  
  437. integer_type_specifier
  438.     : integer_type_specifier_part
  439.     | integer_type_specifier_part type_qualifier
  440.                 { $$=ConcatStrings(3,$1," ",$2); }
  441.     | integer_type_specifier integer_type_specifier_part
  442.                 { $$=ConcatStrings(3,$1," ",$2); }
  443.     ;
  444.  
  445. integer_type_specifier_part
  446.     : SIGNED
  447.     | UNSIGNED
  448.     | CHAR
  449.     | SHORT
  450.     | INT
  451.     | LONG
  452.     ;
  453.  
  454. typedef_name
  455.     : TYPE_NAME
  456.     ;
  457.  
  458. void_type_specifier
  459.     : VOID
  460.     ;
  461.  
  462. type_name
  463.     : declaration_specifiers
  464.                 { in_type_spec=0; }
  465.     | declaration_specifiers abstract_declarator
  466.                 { in_type_spec=0; $$=ConcatStrings(2,$1,$2); }
  467.     ;
  468.  
  469. /* Enumerated types */
  470.  
  471. enumeration_type_specifier
  472.     : enumeration_type_definition
  473.     | enumeration_type_reference
  474.     ;
  475.  
  476. enumeration_type_definition
  477.     : ENUM '{'
  478.                 { push();
  479.                   if(!in_header)
  480.                     {
  481.                      if(in_structunion) SeenStructUnionComp($1,in_structunion);
  482.                      else               SeenStructUnionStart($1);
  483.                     }
  484.                   in_structunion++; }
  485.           enumeration_definition_list '}'
  486.                 { pop(); in_structunion--;
  487.                   if(!in_structunion && !current->type) current->type=ConcatStrings(2,$1," {...}");
  488.                   if(!in_header && !in_structunion && in_typedef) SeenStructUnionEnd();
  489.                   $$=ConcatStrings(5,$1," ",$2,$4,$5); }
  490.     | ENUM enumeration_tag '{'
  491.                 { push();
  492.                   if(!in_header)
  493.                     {
  494.                      if(in_structunion) SeenStructUnionComp(ConcatStrings(3,$1," ",$2),in_structunion);
  495.                      else               SeenStructUnionStart(ConcatStrings(3,$1," ",$2));
  496.                     }
  497.                   in_structunion++; }
  498.           enumeration_definition_list '}'
  499.                 { pop(); in_structunion--;
  500.                   if(!in_structunion && !current->type) current->type=ConcatStrings(3,$1," ",$2);
  501.                   if(!in_header && !in_structunion) SeenStructUnionEnd();
  502.                   $$=ConcatStrings(7,$1," ",$2," ",$3,$5,$6);}
  503.     ;
  504.  
  505. enumeration_definition_list
  506.     : enumeration_definition_list1
  507.     | enumeration_definition_list1 ',' /* Not ANSI, but common */
  508.     ;
  509.  
  510. enumeration_definition_list1
  511.     : enumeration_constant_definition
  512.     | enumeration_definition_list1 ',' enumeration_constant_definition
  513.                 { $$=ConcatStrings(3,$1,$2,$3); }
  514.     ;
  515.  
  516. enumeration_constant_definition
  517.     : enumeration_constant
  518.                 { if(!in_header) SeenStructUnionComp($1,in_structunion); }
  519.     | enumeration_constant '=' assignment_expression /* Should be constant expression */
  520.                 { $$=ConcatStrings(3,$1,$2,$3); if(!in_header) SeenStructUnionComp($1,in_structunion); }
  521.     ;
  522.  
  523. enumeration_constant
  524.     : IDENTIFIER
  525.     ;
  526.  
  527. enumeration_type_reference
  528.     : ENUM enumeration_tag
  529.                 { $$=ConcatStrings(3,$1," ",$2); }
  530.     ;
  531.  
  532. enumeration_tag
  533.     : IDENTIFIER
  534.     | TYPE_NAME
  535.     ;
  536.  
  537. /* Structures */
  538.  
  539. structure_type_specifier
  540.     : structure_type_definition
  541.     | structure_type_reference
  542.     ;
  543.  
  544. structure_type_definition
  545.     : STRUCT '{'
  546.                 { push();
  547.                   if(!in_header)
  548.                     {
  549.                      if(in_structunion) SeenStructUnionComp($1,in_structunion);
  550.                      else               SeenStructUnionStart($1);
  551.                     }
  552.                   in_structunion++; }
  553.     field_list '}'
  554.                 { pop(); in_structunion--;
  555.                   if(!in_structunion && !current->type) current->type=ConcatStrings(2,$1," {...}");
  556.                   if(!in_header && !in_structunion && in_typedef) SeenStructUnionEnd();
  557.                   $$=ConcatStrings(5,$1," ",$2,$4,$5); }
  558.     | STRUCT structure_tag '{'
  559.                 { push();
  560.                   if(!in_header)
  561.                     {
  562.                      if(in_structunion) SeenStructUnionComp(ConcatStrings(3,$1," ",$2),in_structunion);
  563.                      else               SeenStructUnionStart(ConcatStrings(3,$1," ",$2));
  564.                     }
  565.                   in_structunion++; }
  566.     field_list '}'
  567.                 { pop(); in_structunion--;
  568.                   if(!in_structunion && !current->type) current->type=ConcatStrings(3,$1," ",$2);
  569.                   if(!in_header && !in_structunion) SeenStructUnionEnd();
  570.                   $$=ConcatStrings(7,$1," ",$2," ",$3,$5,$6);}
  571.     ;
  572.  
  573. structure_type_reference
  574.     : STRUCT structure_tag
  575.                 { $$=ConcatStrings(3,$1," ",$2); }
  576.     ;
  577.  
  578. structure_tag
  579.     : IDENTIFIER
  580.     | TYPE_NAME
  581.     ;
  582.  
  583. /* Unions */
  584.  
  585. union_type_specifier
  586.     : union_type_definition
  587.     | union_type_reference
  588.     ;
  589.  
  590. union_type_definition
  591.     : UNION '{'
  592.                 { push();
  593.                   if(!in_header)
  594.                     {
  595.                      if(in_structunion) SeenStructUnionComp($1,in_structunion);
  596.                      else               SeenStructUnionStart($1);
  597.                     }
  598.                   in_structunion++; }
  599.     field_list '}'
  600.                 { pop(); in_structunion--;
  601.                   if(!in_structunion && !current->type) current->type=ConcatStrings(2,$1," {...}");
  602.                   if(!in_header && !in_structunion && in_typedef) SeenStructUnionEnd();
  603.                   $$=ConcatStrings(5,$1," ",$2,$4,$5); }
  604.     | UNION union_tag '{'
  605.                 { push();
  606.                   if(!in_header)
  607.                     {
  608.                      if(in_structunion) SeenStructUnionComp(ConcatStrings(3,$1," ",$2),in_structunion);
  609.                      else               SeenStructUnionStart(ConcatStrings(3,$1," ",$2));
  610.                     }
  611.                   in_structunion++; }
  612.     field_list '}'
  613.                 { pop(); in_structunion--;
  614.                   if(!in_structunion && !current->type) current->type=ConcatStrings(3,$1," ",$2);
  615.                   if(!in_header && !in_structunion) SeenStructUnionEnd();
  616.                   $$=ConcatStrings(7,$1," ",$2," ",$3,$5,$6);}
  617.     ;
  618.  
  619. union_type_reference
  620.     : UNION union_tag
  621.                 { $$=ConcatStrings(3,$1," ",$2); }
  622.     ;
  623.  
  624. union_tag
  625.     : IDENTIFIER
  626.     | TYPE_NAME
  627.     ;
  628.  
  629. /* Struct or Union */
  630.  
  631. field_list
  632.     : field_list1
  633.     | field_list field_list1
  634.                 { $$=ConcatStrings(2,$1,$2); }
  635.     ;
  636.  
  637. field_list1
  638.     : structure_type_definition ';'
  639.                 { $$ = ConcatStrings(3, $1, " ", $2);
  640.                   if(!in_header) SeenStructUnionComp($1,in_structunion); }
  641.     | union_type_definition ';'
  642.                 { $$ = ConcatStrings(3, $1, " ", $2);
  643.                   if(!in_header) SeenStructUnionComp($1,in_structunion); }
  644.     | component_declaration
  645.     ;
  646.  
  647. component_declaration
  648.     : type_specifier
  649.                 { comp_type=$1; }
  650.           component_declarator_list ';'
  651.                 { $$=ConcatStrings(3,$1,$3,$4); reset(); in_type_spec=0; }
  652.     | type_qualifier_list type_specifier
  653.                 { comp_type=ConcatStrings(3,$1," ",$2); }
  654.           component_declarator_list ';'
  655.                 { $$=ConcatStrings(4,$1,$2,$4,$5); reset(); in_type_spec=0; }
  656.     | type_specifier type_qualifier_list
  657.                 { comp_type=ConcatStrings(3,$1," ",$2); }
  658.           component_declarator_list ';'
  659.                 { $$=ConcatStrings(4,$1,$2,$4,$5); reset(); in_type_spec=0; }
  660.     ;
  661.  
  662. component_declarator_list
  663.     : component_declarator
  664.                 { if(!in_header) SeenStructUnionComp(ConcatStrings(2,comp_type,$1),in_structunion); }
  665.     | component_declarator_list ',' component_declarator
  666.                 { $$=ConcatStrings(3,$1,$2,$3);
  667.                   if(!in_header) SeenStructUnionComp(ConcatStrings(2,comp_type,$3),in_structunion); }
  668.     ;
  669.  
  670. component_declarator
  671.     : simple_component
  672.     | bit_field
  673.     ;
  674.  
  675. simple_component
  676.     : declarator
  677.                 { if(in_function==2) { DownScope(); pop(); in_function=0; } }
  678.     ;
  679.  
  680. bit_field
  681.     : ':' width
  682.                 { $$=ConcatStrings(2,$1,$2); }
  683.     | declarator ':' width
  684.                 { $$=ConcatStrings(3,$1,$2,$3); }
  685.     ;
  686.  
  687. width
  688.     : assignment_expression /* Should be expression */
  689.     ;
  690.  
  691. component_name
  692.     : IDENTIFIER
  693.     | TYPE_NAME
  694.     ;
  695.  
  696. /*-------------------- Functions --------------------*/
  697.  
  698. /* Function Definition */
  699.  
  700. function_definition
  701.     : function_specifier
  702.                 { pop(); in_funcbody=1; in_function=0; }
  703.           compound_statement
  704.                 { in_funcbody=in_function=0; DownScope(); SeenFunctionDefinition(NULL); }
  705.     ;
  706.  
  707. function_specifier
  708.     : function_specifier1
  709.                 { char *func_type,*fname=strstr($1,(current-1)->name),*parenth=strstr($1,"(");
  710.                   if(parenth>fname)
  711.                      {parenth[0]=0;func_type=ConcatStrings(3,(current-1)->qual,(current-1)->type,$1);}
  712.                   else
  713.                     {
  714.                      int open=1;
  715.                      char *argbeg=strstr(&parenth[1],"("),*argend;
  716.                      argbeg[1]=0;
  717.                      for(argend=argbeg+2;*argend;argend++)
  718.                        {
  719.                         if(*argend=='(') open++;
  720.                         if(*argend==')') open--;
  721.                         if(!open) break;
  722.                        }
  723.                      func_type=ConcatStrings(4,(current-1)->qual,(current-1)->type,$1,argend);
  724.                     }
  725.                   SeenFunctionDefinition(func_type);
  726.                 }
  727.     ;
  728.  
  729. function_specifier1
  730.     : function_declarator
  731.     | declaration_specifiers function_declarator
  732.                 { $$=ConcatStrings(3,current->qual,current->type,$2); }
  733.     | function_declarator declaration_list
  734.     | declaration_specifiers function_declarator declaration_list
  735.                 { $$=ConcatStrings(3,current->qual,current->type,$2); }
  736.     ;
  737.  
  738. /* Function Declaration */
  739.  
  740. function_declarator
  741.     : function_declarator0
  742.                 { push(); in_function=2; }
  743.     ;
  744.  
  745. function_declarator0
  746.     : function_direct_declarator
  747.     | pointer function_direct_declarator
  748.                 { $$=ConcatStrings(2,$1,$2); }
  749.     ;
  750.  
  751. function_direct_declarator
  752.     : function_declarator1 '('
  753.                 { push(); if(in_function==0) UpScope();
  754.                   if(in_function==0 && !in_funcdef) in_function=1; if(in_function!=3) in_funcdef++; }
  755.           function_declarator2 ')'
  756.                 { pop();  if(in_function!=3) in_funcdef--; if(in_funcdef==0) in_function=3;
  757.                   $$=ConcatStrings(4,$1,$2,$4,$5); }
  758.     ;
  759.  
  760. function_declarator1
  761.     : direct_declarator
  762.                 {
  763.                   if(!in_funcdef && !in_function && !in_funcbody) SeenFunctionDeclaration(current->name,SCOPE);
  764.                   in_type_spec=0;
  765.                 }
  766.     ;
  767.  
  768. function_declarator2
  769.     : /* Empty */
  770.                 { if(in_function==1 && in_funcdef==1) SeenFunctionArg("void","void");
  771.                   if(in_structunion) $$=NULL; else $$="void"; }
  772.     | parameter_type_list
  773.     | identifier_list
  774.     ;
  775.  
  776. identifier_list
  777.     : IDENTIFIER
  778.                 { if(in_function==1 && in_funcdef==1 && in_funcbody==0) { SeenFunctionArg($1,NULL); SeenScopeVariable($1); } }
  779.     | identifier_list ',' IDENTIFIER
  780.                 { if(in_function==1 && in_funcdef==1 && in_funcbody==0) { SeenFunctionArg($3,NULL); SeenScopeVariable($3); }
  781.                   $$=ConcatStrings(3,$1,$2,$3); }
  782.     ;
  783.  
  784. parameter_type_list
  785.     : parameter_list
  786.     | parameter_list ',' ELLIPSES
  787.                 { if(in_function==1 && in_funcdef==1 && in_funcbody==0) SeenFunctionArg($3,$3);
  788.                   $$=ConcatStrings(3,$1,$2,$3); }
  789.     ;
  790.  
  791. parameter_list
  792.     : parameter_declaration
  793.                 { if(in_function==1 && in_funcdef==1 && in_funcbody==0) SeenFunctionArg(strcmp("void",$1)?current->name:"void",$1);
  794.                   in_type_spec=0; }
  795.     | parameter_list ',' parameter_declaration
  796.                 { if(in_function==1 && in_funcdef==1 && in_funcbody==0) SeenFunctionArg(current->name,$3);
  797.                   in_type_spec=0; $$=ConcatStrings(3,$1,$2,$3); }
  798.     ;
  799.  
  800. parameter_declaration
  801.     : declaration_specifiers declarator
  802.                 { in_type_spec=0; $$=ConcatStrings(2,$1,$2); }
  803.     | declaration_specifiers
  804.                 { in_type_spec=0; }
  805.     | declaration_specifiers abstract_declarator
  806.                 { in_type_spec=0; $$=ConcatStrings(2,$1,$2); }
  807.     ;
  808.  
  809. /*-------------------- Statements --------------------*/
  810.  
  811. statement
  812.     : asm_statement         /*+ GNU Extension +*/
  813.     | compound_statement
  814.     | conditional_statement
  815.     | iterative_statement
  816.     | labeled_statement
  817.     | switch_statement
  818.     | break_statement
  819.     | continue_statement
  820.     | expression_statement
  821.     | goto_statement
  822.     | null_statement
  823.     | return_statement
  824.     ;
  825.  
  826. statement_list
  827.     : statement
  828.     | statement_list statement
  829.     ;
  830.  
  831. /* Compound statement */
  832.  
  833. compound_statement
  834.     : '{'
  835.                 { UpScope(); reset(); }
  836.       compound_statement_body
  837.                 { DownScope(); }
  838.       '}'
  839.     ;
  840.  
  841. compound_statement_body
  842.     : /* Empty */
  843.     | inner_declaration_list
  844.     | statement_list
  845.     | inner_declaration_list statement_list
  846.     ;
  847.  
  848. inner_declaration_list
  849.     : declaration_list
  850.     ;
  851.  
  852. /* Conditional statements */
  853.  
  854. conditional_statement
  855.     : if_statement
  856.     | if_else_statement
  857.     ;
  858.  
  859. if_else_statement
  860.     : IF '(' expression ')' statement ELSE statement
  861.     ;
  862.  
  863. if_statement
  864.     : IF '(' expression ')' statement
  865.     ;
  866.  
  867. /* Iterative statements */
  868.  
  869. iterative_statement
  870.     : do_statement
  871.     | for_statement
  872.     | while_statement
  873.     ;
  874.  
  875. do_statement
  876.     : DO statement WHILE '(' expression ')' ';'
  877.     ;
  878.  
  879. for_statement
  880.     : FOR '(' for_expressions ')' statement
  881.     ;
  882.  
  883. for_expressions
  884.     : ';' ';'
  885.     | expression ';' ';'
  886.     | ';' expression ';'
  887.     | ';' ';' expression
  888.     | ';' expression ';' expression
  889.     | expression ';' ';' expression
  890.     | expression ';' expression ';'
  891.     | expression ';' expression ';' expression
  892.     ;
  893.  
  894. while_statement
  895.     : WHILE '(' expression ')' statement
  896.     ;
  897.  
  898. /* Label Statements */
  899.  
  900. labeled_statement               /* Allows for no statement following a label. */
  901.     : case_label ':'
  902.     | named_label ':'
  903.     | default_label ':'
  904.     ;
  905.  
  906. case_label
  907.     : CASE constant_expression
  908.     ;
  909.  
  910. default_label
  911.     : DEFAULT
  912.     ;
  913.  
  914. named_label
  915.     : IDENTIFIER
  916.     ;
  917.  
  918. /* Switch statement */
  919.  
  920. switch_statement
  921.     : SWITCH '(' expression ')' statement
  922.     ;
  923.  
  924. /* Other Statements */
  925.  
  926. break_statement
  927.     : BREAK ';'
  928.  
  929. continue_statement
  930.     : CONTINUE ';'
  931.     ;
  932.  
  933. expression_statement
  934.     : expression ';'
  935.     ;
  936.  
  937. goto_statement
  938.     : GOTO IDENTIFIER ';'
  939.     ;
  940.  
  941. null_statement
  942.     : ';'
  943.     ;
  944.  
  945. return_statement
  946.     : RETURN ';'
  947.     | RETURN expression ';'
  948.     ;
  949.  
  950. /*-------------------- Expressions --------------------*/
  951.  
  952. expression
  953.     : comma_expression
  954.     ;
  955.  
  956. /* Precedence 1 */
  957.  
  958. comma_expression
  959.     : assignment_expression
  960.     | comma_expression ',' assignment_expression
  961.                 { $$=ConcatStrings(3,$1,$2,$3); }
  962.     ;
  963.  
  964. /* Precedence 2 */
  965.  
  966. assignment_expression
  967.     : conditional_expression
  968.     | named_label_address
  969.     | unary_expression assignment_op assignment_expression
  970.     | unary_expression assignment_op '{' assignment_expression_list '}'
  971.     ;
  972. assignment_op
  973.         : '='
  974.         | MUL_ASSIGN
  975.         | DIV_ASSIGN
  976.         | MOD_ASSIGN
  977.         | ADD_ASSIGN
  978.         | SUB_ASSIGN
  979.         | LEFT_ASSIGN
  980.         | RIGHT_ASSIGN
  981.         | AND_ASSIGN
  982.         | XOR_ASSIGN
  983.         | OR_ASSIGN
  984.         ;
  985.  
  986. /* Precedence 3 */
  987.  
  988. conditional_expression
  989.     : logical_or_expression
  990.     | logical_or_expression '?' expression ':' conditional_expression
  991.                 { $$=ConcatStrings(5,$1,$2,$3,$4,$5); }
  992.     | logical_or_expression '?'            ':' conditional_expression /* GNU Extension */
  993.                 { $$=ConcatStrings(4,$1,$2,$3,$4); }
  994.     ;
  995.  
  996. /* Precedence 4 */
  997.  
  998. logical_or_expression
  999.     : logical_and_expression
  1000.     | logical_or_expression OR_OP logical_and_expression
  1001.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1002.     ;
  1003.  
  1004. /* Precedence 5 */
  1005.  
  1006. logical_and_expression
  1007.     : bitwise_or_expression
  1008.     | logical_and_expression AND_OP bitwise_or_expression
  1009.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1010.     ;
  1011.  
  1012. /* Precedence 6 */
  1013.  
  1014. bitwise_or_expression
  1015.     : bitwise_xor_expression
  1016.     | bitwise_or_expression '|' bitwise_xor_expression
  1017.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1018.     ;
  1019.  
  1020. /* Precedence 7 */
  1021.  
  1022. bitwise_xor_expression
  1023.     : bitwise_and_expression
  1024.     | bitwise_xor_expression '^' bitwise_and_expression
  1025.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1026.     ;
  1027.  
  1028. /* Precedence 8 */
  1029.  
  1030. bitwise_and_expression
  1031.     : equality_expression
  1032.     | bitwise_and_expression '&' equality_expression
  1033.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1034.     ;
  1035.  
  1036. /* Precedence 9 */
  1037.  
  1038. equality_expression
  1039.     : relational_expression
  1040.     | equality_expression equality_op relational_expression
  1041.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1042.     ;
  1043. equality_op
  1044.     : EQ_OP
  1045.     | NE_OP
  1046.     ;
  1047.  
  1048. /* Precedence 10 */
  1049.  
  1050. relational_expression
  1051.     : shift_expression
  1052.     | relational_expression relational_op shift_expression
  1053.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1054.     ;
  1055. relational_op
  1056.     : '<'
  1057.     | LE_OP
  1058.     | '>'
  1059.     | GE_OP
  1060.     ;
  1061.  
  1062. /* Precedence 11 */
  1063.  
  1064. shift_expression
  1065.     : additive_expression
  1066.     | shift_expression shift_op additive_expression
  1067.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1068.     ;
  1069. shift_op
  1070.     : LEFT_SHIFT
  1071.     | RIGHT_SHIFT
  1072.     ;
  1073.  
  1074. /* Precedence 12 */
  1075.  
  1076. additive_expression
  1077.     : multiplicative_expression
  1078.     | additive_expression add_op multiplicative_expression
  1079.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1080.     ;
  1081. add_op
  1082.     : '+'
  1083.     | '-'
  1084.     ;
  1085.  
  1086. /* Precedence 13 */
  1087.  
  1088. multiplicative_expression
  1089.     : unary_expression
  1090.     | multiplicative_expression mult_op unary_expression
  1091.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1092.     ;
  1093. mult_op
  1094.     : '*'
  1095.     | '/'
  1096.     | '%'
  1097.     ;
  1098.  
  1099. /* Precedence 14 */
  1100.  
  1101. unary_expression
  1102.     : address_expression
  1103.     | bitwise_negation_expression
  1104.     | cast_expression
  1105.     | indirection_expression
  1106.     | logical_negation_expression
  1107.     | predecrement_expression
  1108.     | preincrement_expression
  1109.     | sizeof_expression
  1110.     | unary_minus_expression
  1111.     | unary_plus_expression
  1112.     | postfix_expression
  1113.     ;
  1114.  
  1115. address_expression
  1116.     : '&' unary_expression
  1117.     ;
  1118.  
  1119. bitwise_negation_expression
  1120.     : '~' unary_expression
  1121.                 { $$=ConcatStrings(2,$1,$2); }
  1122.     ;
  1123.  
  1124. cast_expression
  1125.     : '(' type_name ')' unary_expression
  1126.                 { $$=ConcatStrings(4,$1,$2,$3,$4); }
  1127.     | '(' type_name ')' '{' assignment_expression_list '}' /* GNU Extension */
  1128.     | '(' type_name ')' '{' named_assignment_list '}' /* GNU Extension */
  1129.     ;
  1130.  
  1131. indirection_expression
  1132.     : '*' unary_expression
  1133.     ;
  1134.  
  1135. logical_negation_expression
  1136.     : '!' unary_expression
  1137.                 { $$=ConcatStrings(2,$1,$2); }
  1138.     ;
  1139.  
  1140. predecrement_expression
  1141.     : DEC_OP unary_expression
  1142.     ;
  1143.  
  1144. preincrement_expression
  1145.     : INC_OP unary_expression
  1146.     ;
  1147.  
  1148. sizeof_expression
  1149.     : SIZEOF '(' type_name ')'
  1150.                 { $$=ConcatStrings(4,$1,$2,$3,$4); }
  1151.     | SIZEOF unary_expression
  1152.                 { $$=ConcatStrings(2,$1,$2); }
  1153.     ;
  1154.  
  1155. unary_minus_expression
  1156.     : '-' unary_expression
  1157.                 { $$=ConcatStrings(2,$1,$2); }
  1158.     ;
  1159.  
  1160. unary_plus_expression
  1161.     : '+' unary_expression
  1162.                 { $$=ConcatStrings(2,$1,$2); }
  1163.     ;
  1164.  
  1165. /* Precedence 15 */
  1166.  
  1167. postfix_expression
  1168.     : component_selection_expression
  1169.     | function_call
  1170.     | function_call_direct
  1171.                 { if(!IsAScopeVariable($1)) SeenFunctionCall($1); }
  1172.     | postdecrement_expression
  1173.     | postincrement_expression
  1174.     | subscript_expression
  1175.     | primary_expression
  1176.     ;
  1177.  
  1178. component_selection_expression
  1179.     : direct_component_selection
  1180.     | indirect_component_selection
  1181.     ;
  1182.  
  1183. direct_component_selection
  1184.     : postfix_expression '.' component_name
  1185.     ;
  1186.  
  1187. indirect_component_selection
  1188.     : postfix_expression PTR_OP component_name
  1189.     ;
  1190.  
  1191. function_call
  1192.     : postfix_expression '(' ')'
  1193.     | postfix_expression '(' expression_list ')'
  1194.     ;
  1195.  
  1196. function_call_direct
  1197.     : name '(' ')'
  1198.     | name '(' expression_list ')'
  1199.     ;
  1200.  
  1201. postdecrement_expression
  1202.     : postfix_expression DEC_OP
  1203.     ;
  1204.  
  1205. postincrement_expression
  1206.     : postfix_expression INC_OP
  1207.     ;
  1208.  
  1209. subscript_expression
  1210.     : postfix_expression '[' expression ']'
  1211.     ;
  1212.  
  1213. primary_expression
  1214.     : name
  1215.                 { CheckFunctionVariableRef($1,in_funcbody); }
  1216.     | LITERAL
  1217.     | string_literal
  1218.     | parenthesized_expression
  1219.     ;
  1220. string_literal
  1221.     : STRING_LITERAL
  1222.     | string_literal STRING_LITERAL
  1223.         ;
  1224.  
  1225. parenthesized_expression
  1226.     : '(' expression ')'
  1227.                 { $$=ConcatStrings(3,$1,$2,$3); }
  1228.     | '(' { push(); } compound_statement { pop(); } ')' /* GNU Extension */
  1229.     ;
  1230.  
  1231. /* Other expressions */
  1232.  
  1233. constant_expression
  1234.     : expression
  1235.     ;
  1236.  
  1237. expression_list
  1238.     : assignment_expression
  1239.     | expression_list ',' assignment_expression
  1240.     ;
  1241.  
  1242. /*-------------------- GNU Extensions --------------------*/
  1243.  
  1244. /* ASM Statements */
  1245.  
  1246. asm_statement
  1247.     : asm_type '(' string_literal ')' ';'
  1248.     | asm_type '(' string_literal ':' asm_inout_list ')' ';'
  1249.     | asm_type '(' string_literal ':' asm_inout_list ':' asm_inout_list ')' ';'
  1250.     | asm_type '(' string_literal ':' asm_inout_list ':' asm_inout_list ':' asm_clobber_list ')' ';'
  1251.     ;
  1252.  
  1253. asm_type
  1254.     : ASM
  1255.     | ASM VOLATILE
  1256.     | VOLATILE ASM
  1257.     ;
  1258.  
  1259. asm_inout_list
  1260.     : /* Empty */
  1261.     | asm_inout
  1262.     | asm_inout_list ',' asm_inout
  1263.     ;
  1264.  
  1265. asm_inout
  1266.     : string_literal '(' expression ')'
  1267.     ;
  1268.  
  1269. asm_clobber_list
  1270.     : /* Empty */
  1271.     | string_literal
  1272.     | asm_clobber_list ',' string_literal
  1273.     ;
  1274.  
  1275. asm_label
  1276.     : ASM '(' string_literal ')'
  1277.     ;
  1278.  
  1279. /* Named label address */
  1280.  
  1281. named_label_address
  1282.     : AND_OP named_label
  1283.     ;
  1284.  
  1285. /* Assignment of structure / union */
  1286.  
  1287. assignment_expression_list
  1288.     : assignment_expression_list_item
  1289.     | assignment_expression_list ',' assignment_expression_list_item
  1290.     ;
  1291.  
  1292. assignment_expression_list_item
  1293.     : /* Empty */
  1294.     | assignment_expression
  1295.     | '{' assignment_expression_list '}'
  1296.     ;
  1297.  
  1298. named_assignment
  1299.     : component_name ':' assignment_expression
  1300.     | component_name ':' '{' assignment_expression_list '}'
  1301.     | '.' component_name '=' assignment_expression
  1302.     | '.' component_name '=' '{' assignment_expression_list '}'
  1303.     ;
  1304.  
  1305. named_assignment_list
  1306.     : named_assignment
  1307.     | named_assignment_list ',' named_assignment
  1308.     ;
  1309.  
  1310. %%
  1311.  
  1312. #if YYDEBUG
  1313.  
  1314. static int   last_yylex[11];
  1315. static char *last_yylval[11];
  1316. static int count=0,modcount=0;
  1317.  
  1318. #endif /* YYDEBUG */
  1319.  
  1320.  
  1321.  /*++++++++++++++++++++++++++++++++++++++
  1322.   Stop parsing the current file, due to an error.
  1323.  
  1324.   char *s The error message to print out.
  1325.   ++++++++++++++++++++++++++++++++++++++*/
  1326.  
  1327. static void yyerror( char *s )
  1328. {
  1329. #if YYDEBUG
  1330.  int i;
  1331. #endif
  1332.  
  1333.  fflush(stdout);
  1334.  fprintf(stderr,"%s:%d: cxref: %s\n\n",parse_file,parse_line,s);
  1335.  
  1336. #if YYDEBUG
  1337.  
  1338.  fprintf(stderr,"The previous 10, current and next 10 symbols are:\n");
  1339.  
  1340.  for(i=count>10?count-11:0,modcount=i%11;i<count-1;i++,modcount=i%11)
  1341. #ifdef YYBISON
  1342.     fprintf(stderr,"%3d | %3d : %16s : %s\n",i+1-count,last_yylex[modcount],last_yylex[modcount]>255?yytname[last_yylex[modcount]-255]:"",last_yylval[modcount]);
  1343. #else
  1344.     fprintf(stderr,"%3d | %3d : %s\n",i+1-count,last_yylex[modcount],last_yylval[modcount]);
  1345. #endif
  1346.  
  1347. #ifdef YYBISON
  1348.  fprintf(stderr,"  0 | %3d : %16s : %s\n",yychar,yychar>255?yytname[yychar-255]:"",yylval);
  1349. #else
  1350.  fprintf(stderr,"  0 | %3d : %s\n",yychar,yylval);
  1351. #endif
  1352.  
  1353.  for(i=0;i<10;i++)
  1354.    {
  1355.     yychar=yylex();
  1356.     if(!yychar)
  1357.       {fprintf(stderr,"END OF FILE\n");break;}
  1358. #ifdef YYBISON
  1359.     fprintf(stderr,"%3d | %3d : %16s : %s\n",i+1,yychar,yychar>255?yytname[yychar-255]:"",yylval);
  1360. #else
  1361.     fprintf(stderr,"%3d | %3d : %s\n",i+1,yychar,yylval);
  1362. #endif
  1363.    }
  1364.  
  1365.  fprintf(stderr,"\n");
  1366.  
  1367. #endif /* YYDEBUG */
  1368.  
  1369.  /* Finish off the input. */
  1370.  
  1371. #undef yylex
  1372.  
  1373.  if(yychar)
  1374.     while((yychar=yylex()));
  1375. }
  1376.  
  1377.  
  1378.  /*++++++++++++++++++++++++++++++++++++++
  1379.   Call the lexer, the feedback from the parser to the lexer is applied here.
  1380.  
  1381.   int cxref_yylex Returns the value from the lexer, modified due to parser feedback.
  1382.   ++++++++++++++++++++++++++++++++++++++*/
  1383.  
  1384. static int cxref_yylex(void)
  1385. {
  1386.  static int last_yyl=0;
  1387.  int yyl=yylex();
  1388.  
  1389.  if(yyl==TYPE_NAME)
  1390.     if(in_type_spec || last_yyl==TYPE_NAME ||
  1391.        last_yyl==CHAR || last_yyl==SHORT || last_yyl==INT || last_yyl==LONG ||
  1392.        last_yyl==SIGNED || last_yyl==UNSIGNED ||
  1393.        last_yyl==FLOAT || last_yyl==DOUBLE)
  1394.        yyl=IDENTIFIER;
  1395.  
  1396.  last_yyl=yyl;
  1397.  
  1398. #if YYDEBUG
  1399.  
  1400.  last_yylex [modcount]=yyl;
  1401.  last_yylval[modcount]=yylval;
  1402.  
  1403.  if(yyl)
  1404.    {
  1405.     count++;
  1406.     modcount=count%11;
  1407.    }
  1408.  else
  1409.    {
  1410.     count=0;
  1411.     modcount=0;
  1412.    }
  1413.  
  1414. #if YYDEBUG == 2
  1415.  
  1416.  if(yyl)
  1417. #ifdef YYBISON
  1418.     printf("#parse.y# %6d | %16s:%4d | %3d : %16s : %s\n",count,parse_file,parse_line,yyl,yyl>255?yytname[yyl-255]:"",yylval);
  1419. #else
  1420.     printf("#parse.y# %6d | %16s:%4d | %3d : %s\n",count,parse_file,parse_line,yyl,yylval);
  1421. #endif /* YYBISON */
  1422.  else
  1423.     printf("#parse.y# %6d | %16s:%4d | END OF FILE\n",count,parse_file,parse_line);
  1424.  
  1425.  fflush(stdout);
  1426.  
  1427. #endif /* YYDEBUG==2 */
  1428.  
  1429. #endif /* YYDEBUG */
  1430.  
  1431.  return(yyl);
  1432. }
  1433.