コード例 #1
0
ファイル: lyutils.c プロジェクト: bpross/Compiler-Design-Work
int yyprint_token(int symbol){
    stringnode_ref sn;
    yylval_token(symbol);
    print_tok(symbol);
    sn = intern_stringtable(st, yytext);
    return symbol;
}
コード例 #2
0
ファイル: main.c プロジェクト: bpross/Compiler-Design-Work
// Run cpp against the lines of the file.
void cpplines (FILE *pipe, char *filename) {
   int linenr = 1;
   int tokenct;
   char inputname[LINESIZE];
   char *base = basename(filename);
   /* Create new stringtable */
   stringtable_ref st = new_stringtable();
   stringnode_ref sn;
   strcpy (inputname, filename);
   /* For loop to run through the file */
   for (;;) {
      char buffer[LINESIZE];
      /* Get next line */
      char *fgets_rc = fgets (buffer, LINESIZE, pipe);
      /* If next line is NULL, loop is done */
      if (fgets_rc == NULL) break;
      /* Replace \n with '\0' */
      chomp (buffer, '\n');
      /* Scan and clean out symbols we dont want */
      int sscanf_rc = sscanf (buffer, "# %d \"%[^\"]\"",
                              &linenr, filename);
      if (sscanf_rc == 2) {
         printf ("Directive: line %d, file \"%s\"\n",
                 linenr, filename);
         continue;
      }
      char *savepos = NULL;
      char *bufptr = buffer;
      /* Run through the line and proccess each token */
      for (tokenct = 1;; ++tokenct) {
         char *token = strtok_r (bufptr, " \t\n", &savepos);
         bufptr = NULL;
         if (token == NULL) break;
         printf ("token %d.%d: [%s]\n",
                 linenr, tokenct, token);
         sn = intern_stringtable(st, token);
      }
   }
   remove_file_ext(base);
   strcat(base,".str");
   FILE *fp = fopen(base,"w");
   debugdump_stringtable(st,fp);
   fclose(fp);
}
コード例 #3
0
ファイル: astree.c プロジェクト: mtnash/oc
astree new_astree (int symbol, int filenr, int linenr, int offset,
                   cstring lex) {
   size_t size = sizeof (struct astree_rep);
   astree tree = malloc (size);
   assert (tree != NULL);
   tree->tag = astree_tag;
   tree->symbol = symbol;
   tree->filenr = filenr;
   tree->linenr = linenr;
   tree->offset = offset;
   tree->lexinfo = intern_stringtable(thestringtable,lex);
   assert (tree->lexinfo != NULL);
   tree->first = NULL;
   tree->last = NULL;
   tree->next = NULL;
   tree->blocknr = 0;
   tree->attrs = 0;
   DEBUGF ('f', "malloc (%d) = %p-> %d:%d.%d: %s: %p->\"%s\"\n",
           size, tree, tree->filenr, tree->linenr, tree->offset,
           get_yytname (tree->symbol), tree->lexinfo, tree->lexinfo);
   return tree;
}