Example #1
0
int main(int argc, char **argv)
{
   string fname; int tok;
   //if (argc!=2) {fprintf(stderr,"usage: a.out filename\n"); exit(1);}
   fname= argv[1];
   EM_open(fname);
   for(;;) {
      tok=yylex();
      if (tok==0) break;
      switch(tok) {
      case ID: case STRING:
         printf("%s (%s)\n",tokname(tok),yylval.sval);
         break;
      case INT:
         printf("%s (%d)\n",tokname(tok),yylval.ival);
         break;
      case FLOAT:
         printf("%s (%s)\n", tokname(tok), yylval.sval);
         break;
      default:
         printf("%s \n",tokname(tok));
      }
   }
   return 0;
}
Example #2
0
File: driver.c Project: oyzh/tiger
int main(int argc, char **argv) {
 string fname; int tok;
 if (argc!=2) {
   fprintf(stderr,"usage: a.out filename\n");
   exit(1);
 }
 fname=argv[1];
 EM_reset(fname);
 for(;;) {
   tok=yylex();
   if (tok==0) break;
   switch(tok) {
   case ID: case STRING:
     printf("%10s %4d %s\n",tokname(tok),EM_tokPos,yylval.sval);
     //   printf("%10s %4d\n",tokname(tok),EM_tokPos);
     break;
   case INT:
     printf("%10s %4d %d\n",tokname(tok),EM_tokPos,yylval.ival);
     break;
   default:
     printf("%10s %4d\n",tokname(tok),EM_tokPos);
   }
 }
 return 0;
}
Example #3
0
main()
{	struct xx *p;
	int i;
	printf("#include \"awk.def\"\n");
	printf("obj nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for(p=proc;p->token!=0;p++)
		if(p==proc || strcmp(p->name, (p-1)->name))
			printf("extern obj %s();\n",p->name);
	for(p=proc;p->token!=0;p++)
		table[p->token-FIRSTTOKEN]=p->name;
	printf("obj (*proctab[%d])() = {\n", SIZE);
	for(i=0;i<SIZE;i++)
		if(table[i]==0) printf("/*%s*/\tnullproc,\n",tokname(i+FIRSTTOKEN));
		else printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for(p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for(i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}
Example #4
0
int main(int argc, char **argv) {
	string fname; int tok;
	if (argc!=2) {
		fprintf(stderr,"usage: a.out filename\n"); 
		exit(1);
	}
	fname=argv[1];
	EM_reset(fname);
	for(;;) {
		tok=yylex();
		if (tok==0) break;
		
		if(strcmp("BAD_TOKEN", tokname(tok)) == 0) assert("Invalid Token");
		 
		// here is unit-test i'm lazy --
		if(strcmp("WHILE", tokname(tok)) != 0) assert("Program failed");
		
		switch (tok) {
		case ID: case STRING:
			printf("%10s %4d %s\n",tokname(tok),EM_tokPos,yylval.sval);
			break;
		case INT:
			printf("%10s %4d %d\n",tokname(tok),EM_tokPos,yylval.ival);
			break;
		default:
			printf("%10s %4d\n",tokname(tok),EM_tokPos);
		}
	}
	return 0;
}
Example #5
0
int
main()
{	struct xx *p;
	int i;
	printf("#include \"awk.def.h\"\n");
	printf("obj nullproc();\n");
	for(p=proc;p->token!=0;p++)
		if(p==proc || strcmp(p->name, (p-1)->name))
			printf("extern obj %s();\n",p->name);
	for(p=proc;p->token!=0;p++)
		table[p->token-FIRSTTOKEN]=p->name;
	printf("const objfunc proctab[%d] = {\n", SIZE);
	for(i=0;i<SIZE;i++)
		if(table[i]==0) printf("/*%s*/\tnullproc,\n",tokname(i+FIRSTTOKEN));
		else printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	exit(0);
}
Example #6
0
void
xml::visit (token &n)
{
  printf ("%*s%s", indent, "", tokname (n.tok));
  if (n.loc.first_line)
    printf ("[" YELLOW "%d:%d" R "-" YELLOW "%d:%d" R "]",
            n.loc.first_line, n.loc.first_column,
            n.loc.last_line, n.loc.last_column);
#if 0
  printf (": " WHITE "\"%s\"" R "\n", escape (n.string).c_str ());
#else
  printf (": " WHITE "<<%s>>" R "\n", n.string.c_str ());
#endif
}
Example #7
0
void
lexer::pimpl::verbose (int tok, char const *type, YYLTYPE const *lloc, char const *text, int leng)
{
#if LEXER_VERBOSE
  printf ("[%d:%d-%d:%d]: %s <<%s>> (%s)\n",
          lloc->first_line,
          lloc->first_column,
          lloc->last_line,
          lloc->last_column,
	  tokname (tok),
          escaped (text, leng).c_str (),
          type);
#endif
}
Example #8
0
int mainloop()
{
  unsigned cmd;
  nodep myLine;
  extern int phys_pcode;
  extern int row, scol, ecol;
  int curserr;

  for (;;) {
    here(1);
    checkfar(1);
    printt5("mainloop, cursor %x, ocursor %x, srch_row %d, srch_real %d, look.=%x\n",
	    cursor, ocursor, srch_row, srch_real, lookaheadchar);
    hist_mark();
    printt0("back from hist_mark()\n");
    if (lookaheadchar == AL_NOP || lookaheadchar == ' ')
      lookaheadchar = 0;
    /*
     * Redisplay unconditionally, not just when there's no
     * typeahead, because often there is typeahead of the
     * terminating character, like comma or right paren.
     * Ideally the redisplay should be done only if dirty
     * from the keyboard driver when we are ready for real
     * input.
     */
    newrange(FALSE);
    display(FALSE);

    /*
     * ocursor is set by arrow keys to indicate that that's
     * where the arrow keys left the cursor.  Only if it
     * was set (possibly in them middle of a token) and
     * hasn't moved since do we want to leave it alone.
     */
    here(2);
    checkfar(2);
    if (cursor != ocursor) {
      /* don't do if moves are in type-ahead */
      find_phys_cursor( curr_window, cursor,anywflag);
      anywflag = FALSE;
      phys_pcode = kcget( -1, cursor );
      flusht();
    }
    here(3);
    ocursor = NIL;
    CheckAt = NIL;
    CodeChanged = FALSE;
    if( autsave &&  ascount++ > autsave ) {
      ascount = 0;
      if( work_fname( curr_workspace ) )  {
	save(0);
	statusLine();
      }
      else
	warning( ER(220,"autosave`Automatic Save is engaged but there is no file name.") );

    }
    here(4);
    cmd = topcmd( srch_row, srch_real, srch_real+srch_width, cursnode );
    printt2("mainloop: topcmd returns %s (%d)\n", tokname(cmd), cmd);

    mark_line( cursor, SMALL_CHANGE );

    do_command(cmd);

    here(5);
    checkfar(3);
    /* never leave the cursor on a list or below hide */
    cursor = hidebound(realcp( cursor ));

    mark_line( cursor, SMALL_CHANGE );
    curserr = node_flag(cursor) & NF_ERROR;
    if( curserr && !WhereDeclsChanged )
    {
       NodeNum cltype = ntype( t_up_to_line(cursor));
       if( ntype_info(cltype) & F_DECLARE||highType( cltype ) ) 
       {
	  WhereDeclsChanged = my_block(cursor);
	  printt1("mainloop: WhereDeclsChanged=%x\n",
		  WhereDeclsChanged);
       }
    }

    /*
     * Whenever a graft, etc takes place we check to see
     * if changes are being made to a declaration.  If they
     * are then we set WhereDeclsChanged.  If it has been
     * set when we get back here we recompile its declaration
     * block.
     */
    if (CheckSpeed && WhereDeclsChanged && 
	(CheckSpeed >= 4 || CodeChanged || 
	 WhereDeclsChanged != OldDeclsChanged) )
    {
       if( CheckSpeed < 4 && WhereDeclsChanged != OldDeclsChanged )
       {
	  nodep decswap;
	  decswap = OldDeclsChanged;
	  OldDeclsChanged = WhereDeclsChanged;
	  WhereDeclsChanged = decswap;
	  printt1("mainloop: WhereDeclsChanged=%x (2)\n",
		  WhereDeclsChanged);
       }
       
       if( WhereDeclsChanged )
       {
	  clr_node_flag(WhereDeclsChanged, NF_TCHECKED);
	  here(4);
	  checkfar(4);
	  c_comp_decls(my_scope(WhereDeclsChanged),
		       WhereDeclsChanged,
		       CheckSpeed < 6 ? TC_NOSTUBS :
		       (TC_DESCEND | TC_FULL) );
	  here(5);
	  checkfar(5);
	  WhereDeclsChanged = NIL;
       }
    }

    /*
     * Typecheck the current line.  This was added late in the
     * game, and isn't really the best way of doing things.
     * Every time we return from a command, we typecheck
     * the current line (or if CheckAt has already been set
     * by a skip down routine, we typecheck there).  We
     * don't typecheck declarations.
     */
    printt2("CheckAt=%x, cursor=%x\n", CheckAt, cursor);
    if (!CheckAt && (curserr||is_undid(cursor))) CheckAt = cursor;
    if( CheckAt && CheckSpeed )
    {
       myLine = t_up_to_line(CheckAt);
       if (!( highType(ntype(myLine)) ||
	      (ntype_info(ntype(myLine)) & F_DECLARE)) )
       {
	  printt2("mainloop: c_typecheck(%x, 0, %x)\n",
		  (int)myLine,  TC_NOSTUBS|TC_ONERROR);
	  c_typecheck(myLine, 0, TC_NOSTUBS|TC_ONERROR );
	  here(6);
	  checkfar(6);
       }
    }

    /* if code was changed, clear chance at resuming */
    if( CodeChanged )
       clear_resume();
#ifdef CHECKSUM
    cscheck();
#endif
  }
}