Ejemplo n.º 1
0
Type Parser::parse_y_symbol(char& c, std::string& str)
{
    Type token = lexer->get_token(c, str);
    if(token == HASH)
    {
        token = lexer->get_token(c, str);
        if(token == MINUS)
        {
            token = lexer->get_token(c, str);
        }
        if(token != DEC && token != HEX)
            print_fatal("Syntax error: expected hex or dec but got %s\n", str.c_str());    
    }
    else if(token == REGISTER)
    {
        token = lexer->get_token(c, str);
        if(token == RIGHT_SQ_BRACKET)
            return token;
        if(token == COMMA)
        {
            check_next_token(INSTRUCTION, c, str);
            check_next_token(WHITESPACE, c, str);
            check_next_token(HASH, c, str);
            check_next_token(DEC, c, str);
        }
        else
            print_fatal("Syntax error: expected ']' or ',' but got %s\n", str.c_str());
    }
    else
        print_fatal("Syntax error: expected hash or register but got %s\n", str.c_str());
    return lexer->get_token(c, str);
}
Ejemplo n.º 2
0
void Parser::parse_x_symbol(Type token, char& c, std::string& str)
{
    if(token != STRING)
        print_fatal("Syntax error: expected string but got %s\n", str.c_str());
    token = lexer->get_token(c, str);
    if(token == MINUS || token == PLUS)
    {
        check_next_token(HEX, c, str);
        check_next_token(MORE_THAN, c, str);
    }
    else if(token != MORE_THAN)
    {
        print_fatal("Syntax error: expected '>' but got %s which is %s\n", str.c_str(), type_to_string(token));
    }
}
Ejemplo n.º 3
0
static int
do_bfrange (CMap *cmap, ifreader *input, int count)
{
  pst_obj *tok; 
  unsigned char   codeLo[TOKEN_LEN_MAX], codeHi[TOKEN_LEN_MAX];
  int      srcdim;

  while (count-- > 0) { 
    if (ifreader_need(input, TOKEN_LEN_MAX*3) == 0)
      return -1;
    if (get_coderange(input, codeLo, codeHi, &srcdim, TOKEN_LEN_MAX) < 0    ||
	(tok = pst_get_token(&(input->cursor), input->endptr)) == NULL)
      return -1;
    if (PST_STRINGTYPE(tok)) {
      CMap_add_bfrange(cmap, codeLo, codeHi, srcdim,
		       (unsigned char *) pst_data_ptr(tok), (int) pst_length_of(tok));
    } else if (PST_MARKTYPE(tok)) {
      if (handle_codearray(cmap, input, codeLo, srcdim,
			   codeHi[srcdim-1] - codeLo[srcdim-1] + 1) < 0) {
	pst_release_obj(tok);
	return -1;
      }
    } else
      WARN("%s: Invalid CMap mapping record. (ignored)", CMAP_PARSE_DEBUG_STR);
    pst_release_obj(tok);
  }
  
  return check_next_token(input, "endbfrange");
}
Ejemplo n.º 4
0
static int
do_cidrange (CMap *cmap, ifreader *input, int count)
{
  pst_obj *tok;
  unsigned char   codeLo[TOKEN_LEN_MAX], codeHi[TOKEN_LEN_MAX];
  long     dstCID;
  int      dim;

  while (count-- > 0) { 
    if (ifreader_need(input, TOKEN_LEN_MAX*3) == 0)
      return -1;
    if (get_coderange(input, codeLo, codeHi, &dim, TOKEN_LEN_MAX) < 0 ||
	(tok = pst_get_token(&(input->cursor), input->endptr)) == NULL)
      return -1;
    if (PST_INTEGERTYPE(tok)) {
      dstCID = pst_getIV(tok);
      if (dstCID >= 0 && dstCID <= CID_MAX)
	CMap_add_cidrange(cmap, codeLo, codeHi, dim, (CID) dstCID);
    } else
      WARN("%s: Invalid CMap mapping record. (ignored)", CMAP_PARSE_DEBUG_STR);
    pst_release_obj(tok);
  }

  return check_next_token(input, "endcidrange");
}
Ejemplo n.º 5
0
static int
do_bfchar (CMap *cmap, ifreader *input, int count)
{
  pst_obj *tok1, *tok2;

  while (count-- > 0) { 
    if (ifreader_need(input, TOKEN_LEN_MAX*2) == 0)
      return -1;
    if ((tok1 = pst_get_token(&(input->cursor), input->endptr)) == NULL)
      return -1;
    if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) == NULL) {
      pst_release_obj(tok1);
      return -1;
    }
    /* We only support single CID font as descendant font, charName should not come here. */
    if (PST_STRINGTYPE(tok1) && PST_STRINGTYPE(tok2)) {
      CMap_add_bfchar(cmap,
		      (unsigned char *) pst_data_ptr(tok1), (int) pst_length_of(tok1),
		      (unsigned char *) pst_data_ptr(tok2), (int) pst_length_of(tok2));
    } else if (PST_NAMETYPE(tok2))
      ERROR("%s: Mapping to charName not supported.", CMAP_PARSE_DEBUG_STR);
    else
      WARN("%s: Invalid CMap mapping record. (ignored)", CMAP_PARSE_DEBUG_STR);
    pst_release_obj(tok1);
    pst_release_obj(tok2);
  }

  return check_next_token(input, "endbfchar");
}
Ejemplo n.º 6
0
static int
do_cidchar (CMap *cmap, ifreader *input, int count)
{
  pst_obj *tok1, *tok2;
  long     dstCID;

  while (count-- > 0) { 
    if (ifreader_need(input, TOKEN_LEN_MAX*2) == 0)
      return -1;
    if ((tok1 = pst_get_token(&(input->cursor), input->endptr)) == NULL)
      return -1;
    if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) == NULL) {
      pst_release_obj(tok1);
      return -1;
    }
    if (PST_STRINGTYPE(tok1) && PST_INTEGERTYPE(tok2)) {
      dstCID = pst_getIV(tok2);
      if (dstCID >= 0 && dstCID <= CID_MAX)
	CMap_add_cidchar(cmap, pst_data_ptr(tok1), pst_length_of(tok1), (CID) dstCID);
    } else
      WARN("%s: Invalid CMap mapping record. (ignored)", CMAP_PARSE_DEBUG_STR);
    pst_release_obj(tok1);
    pst_release_obj(tok2);
  }

  return check_next_token(input, "endcidchar");
}
Ejemplo n.º 7
0
t_token		*check_minus(t_token *tok)
{
	t_token	*tmp;
	char	*tmp1;

	tmp = tok;
	if (!tok)
		return (NULL);
	while (tmp->next)
	{
		if (tmp->type == MINUS && check_next_token(tmp) == WORDS)
		{
			tmp1 = tmp->next->content;
			tmp->next->content = ft_strjoin(tmp->content, tmp->next->content);
			tmp->type = WORDS;
			free(tmp1);
			if (tmp == tok)
				tok = tok->next;
			tmp = pop_middle_token(tmp);
		}
		else
			tmp = tmp->next;
	}
	return (tok);
}
Ejemplo n.º 8
0
Archivo: undcl.c Proyecto: teirm/K-R_C
/* undcl: convert word description to declaration */
int main()
{
	int type;
	char temp[MAXTOKEN];

	while (gettoken() != EOF) {
		strcpy(out, token);
		while ((type = gettoken()) != '\n') {
			printf("%c\n",type);
			if (type == PARENS || type == BRACKETS)
				strcat(out, token);
			else if (type == '*') {
				if (check_next_token() == NAME) {
					sprintf(temp, "*%s", out);
				}
				else {
					sprintf(temp, "(*%s)", out);
				}
				strcpy(out, temp);
			} else if (type == NAME) {
				sprintf(temp, "%s %s", token, out);
				strcpy(out, temp);
			} else
				printf("invalid input at %s\n", token);
		}
		printf("%s\n", out);
	}
	return 0;
}
Ejemplo n.º 9
0
int			rules_for_and_great(t_token *tok)
{
	t_sym sym;

	sym = check_next_token(tok);
	if (sym == WORDS || sym == BACK_QUOTES)
		return (1);
	return (0);
}
Ejemplo n.º 10
0
int			rules_for_less_and(t_token *tok)
{
	t_sym sym;

	sym = check_next_token(tok);
	if (sym == MINUS || sym == NUMBERS)
		return (1);
	return (0);
}
Ejemplo n.º 11
0
Type Parser::parse_instruction_symbol(char& c, std::string& str, Instruction& instruction)
{
    check_next_token(INSTRUCTION, c, str);
    instruction.name = str;
    Type token = lexer->get_token(c, str);
    if(token == WHITESPACE)
        return parse_operands_symbol(c, str);
    else
        return token;
}
Ejemplo n.º 12
0
void Parser::parse_z_symbol(char& c, std::string& str)
{
    check_next_token(WHITESPACE, c, str);
    Type token = lexer->get_token(c, str);
    if(token == LESS_THAN)
    {
        check_next_token(STRING, c, str);
        check_next_token(AT, c, str);
        token = lexer->get_token(c, str);
        if(token == AT)
        {
            token = lexer->get_token(c, str);
        }
        parse_x_symbol(token, c, str);
    }
    else if(token == SEMICOLON)
    {
        check_next_token(WHITESPACE, c, str);
        check_next_token(STRING, c, str);
    }
}
Ejemplo n.º 13
0
static int
do_codespacerange (CMap *cmap, ifreader *input, int count)
{
  unsigned char codeLo[TOKEN_LEN_MAX], codeHi[TOKEN_LEN_MAX];
  int dim;

  while (count-- > 0) { 
    if (get_coderange(input, codeLo, codeHi, &dim, TOKEN_LEN_MAX) < 0)
      return -1;
    CMap_add_codespacerange(cmap, codeLo, codeHi, dim);
  }

  return check_next_token(input, "endcodespacerange");
}
Ejemplo n.º 14
0
int			rules_for_less(t_token *tok)
{
	t_sym sym;

	sym = check_next_token(tok);
	if (sym == WORDS)
	{
		tok->next->type = FILENAME;
		return (1);
	}
	if (sym == BACK_QUOTES)
		return (1);
	return (0);
}
Ejemplo n.º 15
0
void Parser::parse_comment_symbol(char& c, std::string& str)
{
    Type token = lexer->get_token(c, str);
    if(token == DOUBLE_SLASH)
    {
        check_next_token(WHITESPACE, c, str);
        check_next_token(HASH, c, str);
        token = lexer->get_token(c, str);
        if(token == MINUS)
            check_next_token(DEC, c, str);
        else if(token != DEC)
            print_fatal("Syntax error: expected DEC in comment but got %s\n", str.c_str());
    }
    else if(token == SEMICOLON)
    {
        check_next_token(WHITESPACE, c, str);
        check_next_token(STRING, c, str);
    }
    else
    {
        print_fatal("Syntax error: expected comment but got %s\n", str.c_str());
    }
}
Ejemplo n.º 16
0
void		ft_token_for_num(t_token *tok)
{
	while (tok)
	{
		if (tok->type == NUMBERS)
		{
			if (check_next_token(tok) == DIPLE_R || check_prev_token(tok) == AMPERSAND)
				tok = tok->next;
			else
				tok->type = WORDS;
		}
		else
			tok = tok->next;
	}
}
Ejemplo n.º 17
0
void		return_type_quoted(t_token *tok)
{
	int	is_quoted;

	is_quoted = 0;
	while (tok)
	{
		if (tok->type == QUOTES)
			is_quoted = is_quoted == 1 ? 0: 1;
		if (is_quoted && tok->type != QUOTES)
			tok->type = WORDS;
		if (tok->type == BACKSLASH)
		{
			if (check_next_token(tok) != -1)
			{
				pop_middle_token(tok);
				tok->next->type = WORDS;
			}
		}
		tok = tok->next;
	}
}
Ejemplo n.º 18
0
/*
 * bfrange
 *  <codeLo> <codeHi> [destCode1 destCode2 ...]
 */
static int
handle_codearray (CMap *cmap, ifreader *input, unsigned char *codeLo, int dim, int count)
{
  pst_obj *tok = NULL;

  if (dim < 1)
    ERROR("Invalid code range.");
  while (count-- > 0) {
    if ((tok = pst_get_token(&(input->cursor), input->endptr)) == NULL)
      return -1;
    else if (PST_STRINGTYPE(tok)) {
      CMap_add_bfchar(cmap, codeLo, dim, (unsigned char *) pst_data_ptr(tok), (int) pst_length_of(tok));
    } else if (PST_MARKTYPE(tok) || !PST_NAMETYPE(tok))
      ERROR("%s: Invalid CMap mapping record.", CMAP_PARSE_DEBUG_STR);
    else
      ERROR("%s: Mapping to charName not supported.", CMAP_PARSE_DEBUG_STR);
    pst_release_obj(tok);
    codeLo[dim-1] += 1;
  }

  return check_next_token(input, "]");
}
Ejemplo n.º 19
0
int
CMap_parse (CMap *cmap, FILE *fp)
{
  pst_obj  *tok1, *tok2;
  ifreader *input;
  int       status = 0, tmpint = -1;

  ASSERT(cmap && fp);

  input = ifreader_create(fp, file_size(fp), INPUT_BUF_SIZE-1);

  while (status >= 0) {
    tok1 = tok2 = NULL;
    ifreader_read(input, INPUT_BUF_SIZE/2);
    tok1 = pst_get_token(&(input->cursor), input->endptr);
    if (tok1 == NULL)
      break;
    else if (MATCH_NAME(tok1, "CMapName")) {
      if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) == NULL ||
	  !(PST_NAMETYPE(tok2) || PST_STRINGTYPE(tok2)) ||
	  check_next_token(input, "def") < 0)
	status = -1;
      else
	CMap_set_name(cmap, pst_data_ptr(tok2));
    } else if (MATCH_NAME(tok1, "CMapType")) {
      if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) == NULL ||
	  !PST_INTEGERTYPE(tok2) ||
	  check_next_token(input, "def") < 0)
	status = -1;
      else
	CMap_set_type(cmap, pst_getIV(tok2));
    } else if (MATCH_NAME(tok1, "WMode")) {
      if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) == NULL ||
	  !PST_INTEGERTYPE(tok2) ||
	  check_next_token(input, "def") < 0)
	status = -1;
      else
	CMap_set_wmode(cmap, pst_getIV(tok2));
    } else if (MATCH_NAME(tok1, "CIDSystemInfo")) {
      status = do_cidsysteminfo(cmap, input);
    } else if (MATCH_NAME(tok1, "Version") ||
	       MATCH_NAME(tok1, "UIDOffset") ||
	       MATCH_NAME(tok1, "XUID")) {
	/* Ignore */
    } else if (PST_NAMETYPE(tok1)) {
      /* Possibly usecmap comes next */
      if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) != NULL &&
	  MATCH_OP(tok2, "usecmap")) {
	int   id;
	CMap *ucmap;
	id = texpdf_CMap_cache_find(pst_data_ptr(tok1));
	if (id < 0)
	  status = -1;
	else {
	  ucmap = texpdf_CMap_cache_get(id);
	  CMap_set_usecmap(cmap, ucmap);
	}
      }
    } else if (MATCH_OP(tok1, "begincodespacerange")) {
      status = do_codespacerange(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "beginnotdefrange")) {
      status = do_notdefrange(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "beginnotdefchar")) {
      status = do_notdefchar(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "beginbfrange")) {
      status = do_bfrange(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "beginbfchar")) {
      status =  do_bfchar(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "begincidrange")) {
      status = do_cidrange(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "begincidchar")) {
      status =  do_cidchar(cmap, input, tmpint);
    } else if (PST_INTEGERTYPE(tok1)) {
      tmpint = pst_getIV(tok1);
    } /* else Simply ignore */
    if (tok1)
      pst_release_obj(tok1);
    if (tok2)
      pst_release_obj(tok2);
  }

  ifreader_destroy(input);

  return (status < 0) ? -1 : CMap_is_valid(cmap);
}
Ejemplo n.º 20
0
static int
do_cidsysteminfo (CMap *cmap, ifreader *input)
{
  pst_obj   *tok1, *tok2;
  CIDSysInfo csi = {NULL, NULL, -1};
  int        simpledict = 0;
  int        error = 0;

  ifreader_need(input, TOKEN_LEN_MAX*2);
  /*
   * Assuming /CIDSystemInfo 3 dict dup begin .... end def
   * or /CIDSystemInfo << ... >> def
   */
  while ((tok1 = pst_get_token(&(input->cursor), input->endptr)) != NULL) {
    if (PST_MARKTYPE(tok1)) {
      simpledict = 1;
      pst_release_obj(tok1);
      break;
    } else if (MATCH_OP(tok1, "begin")) {
      simpledict = 0;
      pst_release_obj(tok1);
      break;
    } else {
      pst_release_obj(tok1);
      /* continue */
    }
  }
  tok1 = tok2 = NULL;
  while (!error &&
         (tok1 = pst_get_token(&(input->cursor), input->endptr)) != NULL) {
    if (MATCH_OP(tok1, ">>") && simpledict) {
      pst_release_obj(tok1);
      break;
    } else if (MATCH_OP(tok1, "end") && !simpledict) {
      pst_release_obj(tok1);
      break;
    } else if (MATCH_NAME(tok1, "Registry") &&
               (tok2 = pst_get_token(&(input->cursor), input->endptr)) != NULL) {
      if (!PST_STRINGTYPE(tok2))
        error = -1;
      else if (!simpledict &&
                check_next_token(input, "def"))
        error = -1;
      if (!error)
        csi.registry = (char *) pst_getSV(tok2);
    } else if (MATCH_NAME(tok1, "Ordering") &&
               (tok2 = pst_get_token(&(input->cursor), input->endptr)) != NULL) {
      if (!PST_STRINGTYPE(tok2))
        error = -1;
      else if (!simpledict &&
                check_next_token(input, "def"))
        error = -1;
      if (!error)
        csi.ordering = (char *) pst_getSV(tok2);
    } else if (MATCH_NAME(tok1, "Supplement") &&
               (tok2 = pst_get_token(&(input->cursor), input->endptr)) != NULL) {
      if (!PST_INTEGERTYPE(tok2))
        error = -1;
      else if (!simpledict &&
                check_next_token(input, "def"))
        error = -1;
      if (!error)
        csi.supplement = pst_getIV(tok2);
    }
    if (tok2)
      pst_release_obj(tok2);
    if (tok1)
      pst_release_obj(tok1);
    tok1 = tok2 = NULL;
  }
  if (!error &&
       check_next_token(input, "def"))
    error = -1;

  if (!error &&
       csi.registry && csi.ordering &&
       csi.supplement >= 0) {
    CMap_set_CIDSysInfo(cmap, &csi);
  }

  if (csi.registry)
    RELEASE(csi.registry);
  if (csi.ordering)
    RELEASE(csi.ordering);

  return  error;
}
Ejemplo n.º 21
0
Instruction* Parser::parse_start_symbol(Type token, char& c, std::string& str)
{
    Instruction* instruction = new Instruction();
    if(token == HEX || token == DEC)
    {
        check_next_token(WHITESPACE, c, str);
        check_next_token(LESS_THAN, c, str);
        check_next_token(STRING, c, str);
        check_next_token(AT, c, str);
        token = lexer->get_token(c, str);
        if(token == AT)
        {
            token = lexer->get_token(c, str);
        }
        parse_x_symbol(token, c, str);
        check_next_token(COLON, c, str);
        check_next_token(NEWLINE, c, str);
        return NULL;
    }
    else if(token == WHITESPACE)
    {
        check_next_token(HEX, c, str);
        sscanf(str.c_str(), " %x", &instruction->address);
        check_next_token(COLON, c, str);
        check_next_token(WHITESPACE, c, str);
        check_next_token(HEX, c, str);
        sscanf(str.c_str(), " %x", &instruction->opcode);
        check_next_token(WHITESPACE, c, str);
        token = parse_instruction_symbol(c, str, *instruction);
        if(token == WHITESPACE)
        {
            parse_comment_symbol(c, str);
            check_next_token(NEWLINE, c, str);
        }
        else if(token != NEWLINE)
        {
            print_fatal("Syntax error: expected newline after instruction, got: %s\n", str.c_str());       
        }
        print_log("Got instruction, addr: %x \t opcode: %x \t %s\n", instruction->address, instruction->opcode, instruction->name.c_str());
        return instruction;
    }
    else if(token != NEWLINE)
    {
        print_fatal("Syntax error: expected starting symbol, got: %s\n", str.c_str());
        return NULL;
    }
    return NULL;
    //print_log("Syntax accepted, back to starting symbol\n");
}
Ejemplo n.º 22
0
Type Parser::parse_operands_symbol(char& c, std::string& str)
{
    Type token = lexer->get_token(c, str);
    for(int i = 0; i < 4; ++i)
    {
        if(token == REGISTER)
        {
            token = lexer->get_token(c, str);
        }
        else if(token == HASH)
        {
            token = lexer->get_token(c, str);
            if(token == MINUS)
                token = lexer->get_token(c, str);
            if(token != DEC && token != HEX)
                print_fatal("Syntax error: expected hex or dec but got %s\n", str.c_str());
            token = lexer->get_token(c, str);
        }
        else if(token == LEFT_SQ_BRACKET)
        {
            check_next_token(REGISTER, c, str);
            token = lexer->get_token(c, str);
            if(token == COMMA)
            {
                token = parse_y_symbol(c, str);
            }
            if(token != RIGHT_SQ_BRACKET)
                print_fatal("Syntax error: expected ',' or ']' but got %s\n", str.c_str());
            token = lexer->get_token(c, str);
            if(token == EXCLAMATION)
                token = lexer->get_token(c, str);
        }
        else if(token == HEX || token == DEC)
        {
            parse_z_symbol(c, str);
            token = lexer->get_token(c, str);
        }
        else if(token == STRING || token == CONDITION)
        {
            token = lexer->get_token(c, str);
        }
        else if(token == INSTRUCTION)
        {
            token = lexer->get_token(c, str);
            if(token == NEWLINE)
                return token;
            if(token != WHITESPACE)
                print_fatal("Syntax error: expected WHITESPACE but got %s\n", str.c_str());
            check_next_token(HASH, c, str);
            check_next_token(DEC, c, str);
            token = lexer->get_token(c, str);   
        }
        else
            break;
        if(token == COMMA)
        {
            token = lexer->get_token(c, str);
            if(token == WHITESPACE)
                token = lexer->get_token(c, str);
        }
    }
    return token;
}