home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_07 / v7n7069a.txt < prev    next >
Text File  |  1989-09-05  |  7KB  |  249 lines

  1.  
  2. #ifndef TRUE
  3. #define TRUE
  4. #define FALSE 0
  5. #define FOREVER for(;;)
  6. #endif
  7.  
  8. /* Symbol Table Definitions */
  9. #define TABSIZ 353
  10. /* ctocxx.h - header file for C to C++ conversion tool - C.D. Havener */
  11. #define NOARGS 1
  12. #define WITH_ARGS 2
  13. #define SYMSIZ 40
  14.  
  15. typedef struct symbol  /* symbol table unit */
  16.         {
  17.         char name[SYMSIZ];
  18.         int type;
  19.         int muldef;
  20.         struct symbol *chain;  /* collision chain */
  21.         union
  22.             {
  23.             int ival;
  24.             long lval;
  25.             } uval;
  26.         }SYM,*SYMPTR;
  27.  
  28. ______________________________________________________________________________
  29.  
  30.  
  31. D            [0-9]
  32. L            [a-zA-Z_]
  33. H            [a-fA-F0-9]
  34. E            [Ee][+-]?{D}+
  35. FS            (f|F|l|L)
  36. IS            (u|U|l|L)*
  37.  
  38. %{
  39. #include <stdio.h>
  40. #include "ytab.h"
  41. #include "ctocxx.h"
  42. extern int lineno;
  43. extern int edit_mode;
  44. char file_name[132] = {0};
  45.  
  46. void count();
  47. void pound();
  48. %}
  49.  
  50. %%
  51. "/*"            { comment(); }
  52. "#line"            { pound(); }
  53. "#"            { pound(); }
  54. "near"            { count(); /* ignore */ };
  55. "far"            { count(); /* ignore */ };
  56. "cdecl"            { count(); /* ignore */  };
  57. "..."            { count(); return(INT); /* a way to ignore ... */ };
  58. "auto"            { count(); return(AUTO); }
  59. "break"            { count(); return(BREAK); }
  60. "case"            { count(); return(CASE); }
  61. "char"            { count(); return(CHAR); }
  62. "const"            { count(); return(CONST); }
  63. "continue"        { count(); return(CONTINUE); }
  64. "default"        { count(); return(DEFAULT); }
  65. "do"            { count(); return(DO); }
  66. "double"        { count(); return(DOUBLE); }
  67. "else"            { count(); return(ELSE); }
  68. "enum"            { count(); return(ENUM); }
  69. "extern"        { count(); return(EXTERN); }
  70. "float"            { count(); return(FLOAT); }
  71. "for"            { count(); return(FOR); }
  72. "goto"            { count(); return(GOTO); }
  73. "if"            { count(); return(IF); }
  74. "int"            { count(); return(INT); }
  75. "long"            { count(); return(LONG); }
  76. "register"        { count(); return(REGISTER); }
  77. "return"        { count(); return(RETURN); }
  78. "short"            { count(); return(SHORT); }
  79. "signed"        { count(); return(SIGNED); }
  80. "sizeof"        { count(); return(SIZEOF); }
  81. "static"        { count(); return(STATIC); }
  82. "struct"        { count(); return(STRUCT); }
  83. "switch"        { count(); return(SWITCH); }
  84. "typedef"        { count(); return(TYPEDEF); }
  85. "union"            { count(); return(UNION); }
  86. "unsigned"        { count(); return(UNSIGNED); }
  87. "void"            { count(); return(VOID); }
  88. "volatile"        { count(); return(VOLATILE); }
  89. "while"            { count(); return(WHILE); }
  90.  
  91. {L}({L}|{D})*        { count(); return(check_type()); }
  92.  
  93. 0[xX]{H}+{IS}?        { count(); return(CONSTANT); }
  94. 0[xX]{H}+{IS}?        { count(); return(CONSTANT); }
  95. 0{D}+{IS}?        { count(); return(CONSTANT); }
  96. 0{D}+{IS}?        { count(); return(CONSTANT); }
  97. {D}+{IS}?        { count(); return(CONSTANT); }
  98. {D}+{IS}?        { count(); return(CONSTANT); }
  99. '(\\.|[^\\'])+'        { count(); return(CONSTANT); }
  100.  
  101. {D}+{E}{FS}?        { count(); return(CONSTANT); }
  102. {D}*"."{D}+({E})?{FS}?    { count(); return(CONSTANT); }
  103. {D}+"."{D}*({E})?{FS}?    { count(); return(CONSTANT); }
  104.  
  105. \"(\\.|[^\\"])*\"    { count(); return(STRING_LITERAL); }
  106.  
  107. ">>="            { count(); return(RIGHT_ASSIGN); }
  108. "<<="            { count(); return(LEFT_ASSIGN); }
  109. "+="            { count(); return(ADD_ASSIGN); }
  110. "-="            { count(); return(SUB_ASSIGN); }
  111. "*="            { count(); return(MUL_ASSIGN); }
  112. "/="            { count(); return(DIV_ASSIGN); }
  113. "%="            { count(); return(MOD_ASSIGN); }
  114. "&="            { count(); return(AND_ASSIGN); }
  115. "^="            { count(); return(XOR_ASSIGN); }
  116. "|="            { count(); return(OR_ASSIGN); }
  117. ">>"            { count(); return(RIGHT_OP); }
  118. "<<"            { count(); return(LEFT_OP); }
  119. "++"            { count(); return(INC_OP); }
  120. "--"            { count(); return(DEC_OP); }
  121. "->"            { count(); return(PTR_OP); }
  122. "&&"            { count(); return(AND_OP); }
  123. "||"            { count(); return(OR_OP); }
  124. "<="            { count(); return(LE_OP); }
  125. ">="            { count(); return(GE_OP); }
  126. "=="            { count(); return(EQ_OP); }
  127. "!="            { count(); return(NE_OP); }
  128. ";"            { count(); return(';'); }
  129. "{"            { count(); return('{'); }
  130. "}"            { count(); return('}'); }
  131. ","            { count(); return(','); }
  132. ":"            { count(); return(':'); }
  133. "="            { count(); return('='); }
  134. "("            { count(); return('('); }
  135. ")"            { count(); return(')'); }
  136. "["            { count(); return('['); }
  137. "]"            { count(); return(']'); }
  138. "."            { count(); return('.'); }
  139. "&"            { count(); return('&'); }
  140. "!"            { count(); return('!'); }
  141. "~"            { count(); return('~'); }
  142. "-"            { count(); return('-'); }
  143. "+"            { count(); return('+'); }
  144. "*"            { count(); return('*'); }
  145. "/"            { count(); return('/'); }
  146. "%"            { count(); return('%'); }
  147. "<"            { count(); return('<'); }
  148. ">"            { count(); return('>'); }
  149. "^"            { count(); return('^'); }
  150. "|"            { count(); return('|'); }
  151. "?"            { count(); return('?'); }
  152.  
  153. [ \t\v\f]        { count(); }
  154. [\n]            { lineno++; count(); }
  155. .                       {; /* ignore bad characters */ }
  156.  
  157. %%
  158.  
  159. int yywrap()
  160.     {
  161.     return(1);
  162.     }
  163.  
  164. comment()
  165.     {
  166.     char c, c1;
  167.  
  168. loop:
  169.     while ((c = input()) != '*' && c != 0)
  170.     putchar(c);
  171.  
  172.     if ((c1 = input()) != '/' && c != 0)
  173.     {
  174.     unput(c1);
  175.     goto loop;
  176.     }
  177.  
  178.     if (c != 0)
  179.     putchar(c1);
  180.     }
  181.  
  182. int column = 0;
  183.  
  184. void count()
  185.     {
  186.     int i;
  187.  
  188.     for (i = 0; yytext[i] != '\0'; i++)
  189.     if (yytext[i] == '\n')
  190.         column = 0;
  191.     else if (yytext[i] == '\t')
  192.         column += 8 - (column % 8);
  193.     else
  194.         column++;
  195.  
  196.     stuff();
  197.   ECHO;
  198.     }
  199.  
  200. /*-------------------------------------------------------------------*/
  201. /* lex_input and unput - routines callable elsewhere since input and  */
  202. /* unput are macros */
  203. lex_input() { return input(); }
  204.  
  205. lex_unput(ch) int ch; { unput(ch); }
  206.  
  207. /*-------------------------------------------------------------------*/
  208. /* pound - handles # lines, extracts line number and file name */
  209. void pound()
  210.     {
  211.     char c;
  212.     char buf[132];
  213.     int i = 0;
  214.     int num = 0;
  215.     extern FILE *efd;
  216.     static int first_time = TRUE;
  217.     char cur_file[132];
  218.  
  219.     while ( ( c=input() ) != '\n' && c != 0 )
  220.     buf[i++] = c;
  221.     buf[i] = '\0';
  222.     if ( (i = sscanf(buf,"%d %s",&num,cur_file)) == 2 )
  223.     {
  224.     if ( first_time )
  225.        {
  226.        strcpy(file_name,cur_file); 
  227.        first_time = FALSE;
  228.        }
  229.     if ( strcmp(file_name,cur_file) == 0 )
  230.         {
  231.         lineno = num;
  232.         edit_mode = TRUE;
  233.         }
  234.     else
  235.         edit_mode = FALSE;
  236.     }
  237.     else
  238.     fprintf(stderr,"#line couldn't convert into a number, %s\n",buf);
  239.     }
  240.  
  241. /*----------------------------------------------------------------*/
  242. int check_type()
  243.     {
  244.     if ( findsym(yytext) )  /* added by cdh to handle typedef names */
  245.     return(TYPE_NAME);  /* since preloaded with int, char etc it does this a lot */
  246.     else
  247.     return(IDENTIFIER);
  248.     }
  249.