Exemplo n.º 1
0
void print_uri(uri_type *in)
{
	print_token(&in->scheme);
	print_token(&in->hostport.text);
	print_token(&in->pathquery);
	print_token(&in->fragment);
}
Exemplo n.º 2
0
/* code list 3-11_postfix.c */
void postfix(void)
{
    /* output the postfix of the expression. 
    The expression string, the stack, and top
    are global. */
    char symbol;
    precedence token;
    int n = 0;
    int top = 0; // place eos on stack
    stack[0] = eos;
    for (token = get_token(&symbol, &n); token != eos;
        token = get_token(&symbol, &n))
    {
        if (token == operand)
            printf("%c", symbol);
        else if (token == rparen)
        {
            // unstack tokens until left parenthesis
            while (stack[top] != lparen)
                print_token(delete(&top));
            delete(&top); // discard left parenthesis
        }
        else
        {
            /* remove and print symbols whose isp is 
            greater than or equal to current token's icp */
            while (isp[stack[top]] >= icp[token])
                print_token(delete(&top));
            add(&top, token);
        }    
    }
    while ((token = delete(&top)) != eos)
        print_token(token);
    printf("\n");
}
void draw_with_both_tokens(int x_position, int x_item_position) {
	int remaining_line_width = SCREEN_WIDTH;
	
    if (x_item_position < x_position) {
		remaining_line_width -= draw_left_border();
		remaining_line_width -= draw_empty_spaces(x_item_position);
		remaining_line_width -= print_item();
		remaining_line_width -= draw_empty_spaces(x_position - x_item_position - 1);
		remaining_line_width -= print_token();
		draw_empty_spaces(REMAINING_LINE_WIDTH_WITHOUT_RIGHT_BORDER);
		draw_right_border(); 
      	} else if (x_item_position > x_position) {
		remaining_line_width -= draw_left_border();
		remaining_line_width -= draw_empty_spaces(x_position);
		remaining_line_width -= print_token();
		remaining_line_width -= draw_empty_spaces(x_item_position - x_position - 1);
		remaining_line_width -= print_item();
		draw_empty_spaces(REMAINING_LINE_WIDTH_WITHOUT_RIGHT_BORDER);
		draw_right_border(); 
      	} else if (x_item_position == x_position) {
		remaining_line_width -= draw_left_border();
		remaining_line_width -= draw_empty_spaces(x_position);
		remaining_line_width -= print_token();
		draw_empty_spaces(REMAINING_LINE_WIDTH_WITHOUT_RIGHT_BORDER);
		draw_right_border();
		}
}
Exemplo n.º 4
0
void
output_red (state const *s, reductions const *reds, FILE *fout)
{
  bitset no_reduce_set;
  int j;
  int source = s->number;

  /* Two obstacks are needed: one for the enabled reductions, and one
     for the disabled reductions, because in the end we want two
     separate edges, even though in most cases only one will actually
     be printed. */
  struct obstack dout;
  struct obstack eout;

  no_reduce_bitset_init (s, &no_reduce_set);
  obstack_init (&dout);
  obstack_init (&eout);

  for (j = 0; j < reds->num; ++j)
    {
      bool defaulted = false;
      bool firstd = true;
      bool firste = true;
      rule_number ruleno = reds->rules[j]->number;
      rule *default_reduction = NULL;

      if (yydefact[s->number] != 0)
        default_reduction = &rules[yydefact[s->number] - 1];

      /* Build the lookahead tokens lists, one for enabled transitions and one
         for disabled transistions. */
      if (default_reduction && default_reduction == reds->rules[j])
        defaulted = true;
      if (reds->lookahead_tokens)
        {
          int i;
          for (i = 0; i < ntokens; i++)
            if (bitset_test (reds->lookahead_tokens[j], i))
              {
                if (bitset_test (no_reduce_set, i))
                  firstd = print_token (&dout, firstd, symbols[i]->tag);
                else
                  {
                    if (! defaulted)
                      firste = print_token (&eout, firste, symbols[i]->tag);
                    bitset_set (no_reduce_set, i);
                  }
              }
        }

      /* Do the actual output. */
      conclude_red (&dout, source, ruleno, false, firstd, fout);
      conclude_red (&eout, source, ruleno, true, firste && !defaulted, fout);
    }
  obstack_free (&dout, 0);
  obstack_free (&eout, 0);
  bitset_free (no_reduce_set);
}
Exemplo n.º 5
0
Arquivo: printing.c Projeto: fwum/fwum
/*
Print a list of tokens to stdout, mostly for debugging purposes
*/
void print_tlist(linked_list *list) {
    if(ll_empty(list)) {
        return;
    }
    linked_iter iterator = ll_iter_head(list);
    parse_token *current = ll_iter_next(&iterator);
    while(ll_iter_has_next(&iterator)) {
        print_token(current);
        current = ll_iter_next(&iterator);
    }
    print_token(current);
}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {
    FILE *input_file;
    Token* tk;

    if (argc <= 1) {
        fprintf(stderr, "Usage:\n");
        fprintf(stderr, "  %s <input file>\n", argv[0]);
        return 1;
    }

    initialize_lex();
    
    input_file = fopen(argv[1], "r");
    tk = NULL;
    while (next_useful_token(input_file, &tk) && tk != NULL) {
       print_token(tk); 
    }

    print_identifiers();
    freeLex();
    fclose(input_file);
    if (tk == NULL) 
        return 0;
    return 1;
}
Exemplo n.º 7
0
int print_gdbmi_async_record(gdbmi_async_record_ptr param)
{
    int result;

    if (!param)
        return 0;

    result = print_token(param->token);
    if (result == -1)
        return -1;

    result = print_gdbmi_async_record_choice(param->async_record);
    if (result == -1)
        return -1;

    result = print_gdbmi_async_class(param->async_class);
    if (result == -1)
        return -1;

    result = print_gdbmi_result(param->result);
    if (result == -1)
        return -1;

    return 0;
}
Exemplo n.º 8
0
static void print_extended(FILE* fp, ast_t* ast, size_t indent, bool type)
{
  for(size_t i = 0; i < indent; i++)
    fprintf(fp, in);

  ast_t* child = ast->child;
  bool parens = type || (child != NULL) || (ast->type != NULL);

  if(parens)
    fprintf(fp, type ? "[" : "(");

  print_token(fp, ast->t);

  if(ast->symtab != NULL)
    fprintf(fp, ":scope");

  fprintf(fp, "\n");

  while(child != NULL)
  {
    print(fp, child, indent + 1, false);
    child = child->sibling;
  }

  if(ast->type != NULL)
    print(fp, ast->type, indent + 1, true);

  if(parens || type)
  {
    for(size_t i = 0; i < indent; i++)
      fprintf(fp, in);

    fprintf(fp, type ? "]" : ")");
  }
}
Exemplo n.º 9
0
int main(int argc, char **argv) {
    FILE *file = NULL;
    FILE *out = NULL;
    
    if (argc < 2) {
        fprintf(stderr, "Pass filename as argument.\n");
        return 1;
    }
    file = fopen(argv[1], "r");
    if (argc == 3) {
        out = fopen(argv[2], "w");
    } else {
        out = stdout;
    }

    while (1) {
        struct token_t *token = get_token(file);
        print_token(out, token);

        if (token->type == EOF_T || token->type == ERROR) {
            free_token(token);
            break;
        } else {
            free_token(token);
        }
    }

    fclose(file);
    fclose(out);
    
    return 0;
}
Exemplo n.º 10
0
// ID && NUM && ...
static TreeNode *
_factor(void) {
	TreeNode *t = NULL;
	switch(token) {
		case LPAREN:
			_match(LPAREN);
			t = _exp();
			_match(RPAREN);
			break;
		case NUM:
			t = new_exp_node(ConstK);
			t->attr.val = atoi(token_string);
			_match(NUM);
			break;
		case ID:
			t = new_exp_node(IdK);
			t->attr.name = copy_string(token_string);
			_match(ID);
			break;
		default :
			_syntax_error("Unexpected token.\n");
			print_token(token, token_string);
			token = get_token();
	}
	return t;
}
Exemplo n.º 11
0
int main(int argc, char *argv[]) {
  char *filename;
  token_t tk;

  if (argc <= 1) {
    init_smt_stdin_lexer(&lexer);
  } else {
    filename = argv[1];
    if (init_smt_file_lexer(&lexer, filename) < 0) {
      perror(filename);
      exit(2);
    }
  }

  do {
    tk = next_smt_token(&lexer);
    if (tk >= SMT_TK_OPEN_STRING) {
      printf("*** Error ***\n");
    }
    print_token(tk);
  } while (tk != SMT_TK_EOS);

  close_lexer(&lexer);

  return 0;
}
Exemplo n.º 12
0
static void
print_stream(const char *fname) {
	fprintf(OutputFile, "File %s:", fname);
	if (!OpenStream(fname)) {
		fprintf(OutputFile, " cannot open\n");
		return;
	}

	fprintf(OutputFile, " showing token stream:\nnl_cnt, tk_cnt: tokens");

	lex_token = EOL;
	do {
		if (TOKEN_EQ(lex_token, EOL)) {
			fprintf(OutputFile, "\n%u,%u:",
				lex_nl_cnt, lex_tk_cnt
			);
		}
		else {
			print_token(OutputFile, lex_token);
		}
	} while (NextStreamTokenObtained());

	fprintf(OutputFile, "\n");

	CloseStream();

}
Exemplo n.º 13
0
int main(int argc, char** argv) {
	static const int BUFSIZE = 1024;
	byte buffer[BUFSIZE];

	byte *start;
	byte *end;
	size_t count;

	rlstate s;
	html5token token;
	html5rl_init(&s);

	bool done = false;
	while (!done) {
		count = fread(buffer, sizeof(byte), BUFSIZE, stdin);
		if (count <= 0) {
			html5rl_exec(&s, NULL, NULL);
			done = true;
		} else {
			start = buffer;
			end = buffer + count;
			do
			{
				token = html5rl_exec(&s, start, end);
				start = s.p;
				print_token(token);
			}
			while (token.end != end);
		}
	}

	return 0;
}
Exemplo n.º 14
0
Arquivo: printing.c Projeto: fwum/fwum
void print_tokens(parse_source source) {
    optional op = get_token(&source);
    while(op_has(op)) {
        parse_token *token = op_get(op);
        print_token(token);
        op = get_token(&source);
    }
}
Exemplo n.º 15
0
/* Output generator printing */
void outgen_print(char *fmt, ...) {
  char buf[STRING_LENGTH];
  va_list argp;
  va_start(argp, fmt);
  vsprintf(buf, fmt, argp);
  va_end(argp);
  print_token(buf);
}
Exemplo n.º 16
0
Arquivo: lexer.c Projeto: mewo2/gertie
void print_tokenlist(tokenlist* tl) {
  while (tl) {
    print_token(tl->tok);
    if (tl->next) printf(" ");
    tl = tl->next;
  }
  printf("\n");
}
void draw_row_with_token(int x_position) {
	int remaining_line_width = SCREEN_WIDTH;
	remaining_line_width -= draw_left_border();
	remaining_line_width -= draw_empty_spaces(x_position);
	remaining_line_width -= print_token();
	draw_empty_spaces(REMAINING_LINE_WIDTH_WITHOUT_RIGHT_BORDER);
	draw_right_border();
}
Exemplo n.º 18
0
Arquivo: expr.c Projeto: thewhoo/ifj15
void after_infix()
{
	printf("expr: Unget token ");
	print_token(token);
	printf("\n");
	printf("expr: Postfix  ");
	stack_print(postfix_output_stack);
	printf("\n");
}
Exemplo n.º 19
0
Arquivo: input.c Projeto: thewml/wml
static void
lex_debug (void)
{
  token_type t;
  token_data td;

  while ((t = next_token (&td, READ_NORMAL, FALSE)) != TOKEN_EOF)
    print_token ("lex", t, &td);
}
Exemplo n.º 20
0
Arquivo: input.c Projeto: WndSks/msys
static void
lex_debug (void)
{
  token_type t;
  token_data td;

  while ((t = next_token (&td)) != NULL)
    print_token ("lex", t, &td);
}
Exemplo n.º 21
0
static void M4_GNUC_UNUSED
lex_debug (void)
{
  token_type t;
  token_data td;

  while ((t = next_token (&td, NULL)) != TOKEN_EOF)
    print_token ("lex", t, &td);
}
Exemplo n.º 22
0
void
print_elem(const struct elem *e) {
	const struct backptr *bp;

	if (e == 0) {
		printf("NULL");
		return;
	}
	
	printf(e->is_expanded ? "[" : "");
	print_token(e);
	printf(e->is_expanded ? "]" : "");
	
	bp = e->backptr;
	if (bp) {
		printf("{");
		while (bp) {
			print_token(bp->elem);
			if (bp->next) {
				printf(",");
			}
			if (	/* there is another node to print */
				bp->next
			&&	/* this one has already been printed */
				bp->elem->_print_count == print_count
			) {
				printf("...");
				break;
			}
			if (bp->elem->_print_count != print_count) {
				/* the backptr has not yet been printed;
				   make sure it does
				*/
				struct top *t = new(struct top);
				t->elem = bp->elem;
				t->next = loops;
				loops = t;
			}
			bp = bp->next;
		}
		printf("}");
	}
	printf(" ");
}
Exemplo n.º 23
0
Arquivo: expr.c Projeto: thewhoo/ifj15
void before_start()
{
	printf("expr: --START--\n");
	printf("expr: hint TYPE[VALUE]\n");
	token = get_token();
	printf("expr: First token ");
	print_token(token);
	printf("\n");
	unget_token(token);
}
Exemplo n.º 24
0
/*
5 * 2 / 3
*/
int factor(struct token_t **current_token, char* input, int* position) {
  struct token_t* next_t = eat(*current_token, INT, input, position);
  int ret_val = atoi((*current_token)->value);
  free_token(*current_token);
  printf("in factor next_token POINTER: %p\n", next_t);
  *current_token = next_t;
  print_token(*current_token);
  printf("in factor current_token POINTER: %p\n", *current_token);
  return ret_val;
}
Exemplo n.º 25
0
/*
 * Print all tokens from the start of the queue to tk (excluding tk).
 * - tk must be in the token queue
 */
static void flush_tokens(formatter_t *f, void *tk) {
  printer_t *p;
  void *x;

  p = f->printer;
  while (ptr_queue_first(&f->token_queue) != tk) {
    x = ptr_queue_pop(&f->token_queue);
    print_token(p, x);
  }
}
Exemplo n.º 26
0
Arquivo: scan.c Projeto: whc2uestc/OS
/*Print the tokens of the nodes one by one, from head to tail.*/
 void print_token_list(TokenList * lis){
	 /* !!!!!!!!!!! provide the missing code here !!!!!!!!!!!!!!!!!*/
	 TokenNode *cur = lis->head;
	 if(NULL == cur)
		 return ;
	 while(cur!=lis->tail){
		 printf("%d: ",cur->lineNum);
		 print_token(cur->token);
		 if(cur->token->string)
			printf("%s\n",cur->token->string);
		 else
			printf("\n");
		 cur = cur->next;
	 }
	 printf("%d: ",cur->lineNum);
	 print_token(cur->token);
	 if(cur->token->string)
		printf("%s\n",cur->token->string);
	 else
		printf("\n");
 }
Exemplo n.º 27
0
int expr(char* input) {
  printf("Entering expr\n");
  int position = 0;
  struct token_t* current_token = get_next_token(input, &position);
  print_token(current_token);
  int result = factor(&current_token, input, &position);
  printf("got result from factor: %d\n", result);
  print_token(current_token);
  enum token current_type = current_token->type;
  struct token_t* next_token;

  while (current_type == MUL || current_type == DIV) {
    printf("\nbeginning of while\n");
    if (current_type == MUL) {
      printf("GOT MUL\n");
      next_token = eat(current_token, MUL, input, &position);
      free_token(current_token);
      result *= factor(&next_token, input, &position);
      print_token(next_token);
      print_token_enum(next_token->type);
      current_type = next_token->type;
    } else if (current_type == DIV) {
      printf("GOT DIV\n");
      next_token = eat(current_token, DIV, input, &position);
      free_token(current_token);
      result /= factor(&next_token, input, &position);
      print_token(current_token);
      print_token_enum(next_token->type);
      current_type = next_token->type;
    }
    current_token = next_token;
  }
  printf("\n\nAfter while loop current position is: %d\n", position);
  printf("current_token 22222 POINTER: %p\n", current_token);
  if (current_token) {
    printf("Freeing\n");
    free_token(current_token);
  }
  return result;
}
Exemplo n.º 28
0
/*
 * Send all the tokens in the token queue to the printer
 */
static void flush_token_queue(formatter_t *f) {
  printer_t *p;
  void *tk;

  p = f->printer;
  while (! ptr_queue_is_empty(&f->token_queue)) {
    tk = ptr_queue_pop(&f->token_queue);
    print_token(p, tk);
  }

  f->last_atom = NULL;
  f->head_token = NULL;
  f->head_closed = false;
}
Exemplo n.º 29
0
int main(void) {
  while (1) {
    int token = yylex();
    if (token == 0) {
      break;
    }
    if (token < 0) {
      printf("error on line %d\n", yyget_lineno());
      break;
    }
    print_token(token);
  }
  return 0;
}
Exemplo n.º 30
0
void prefix()
{
	int top=0,n=0;
	char symbol;
	precedence token;
	stack[0]=eos;

	for(token=get_token(&symbol,&n);token!=eos;token=get_token(&symbol,&n))
	{
		if(token==operand)
		{
			expr1[i++]=symbol;
		}
		else if(token==lpara)
		{
			while(stack[top]!=rpara)
			{
				print_token(pop(&top));
			}
			pop(&top);

		}
		else
		{
			while(isp[stack[top]]>=icp[token])
			{
				print_token(pop(&top));
			}
			push(&top,token);
		}
	}

	while((token=pop(&top))!=eos)
	{
		print_token(token);
	}
}