예제 #1
0
/**
 * Allocate and initialize a new xQSearchExpr object from an expression
 * string.
 *
 * Returns a pointer to the new instance or 0 on error
 */
xQStatusCode xQSearchExpr_alloc_init(xQSearchExpr** self, const xmlChar* expr) {
  const xmlChar* ptr = expr;
  xQStatusCode status = XQ_OK;
  xQToken tok;
  
  initToken(&tok);

  tok.strPtr = expr;
  nextToken(&tok);
  
  status = xQSearchExpr_parseSelector(self, &tok);
  
  if (status == XQ_NO_MATCH) {
    if (tok.lastStatus != XQ_OK && tok.lastStatus != XQ_NO_TOKEN)
      status = tok.lastStatus;
    else if (tok.type != XQ_TT_NONE)
      status = XQ_INVALID_SEL_UNEXPECTED_TOKEN;
    else
      status = XQ_OK;
  }

  destroyToken(&tok);
  
  if (status == XQ_OK && (!*self))
    status = xQSearchExpr_alloc_init_copy(self);
  
  if (status != XQ_OK) {
    xQSearchExpr_free(*self);
    *self = 0;
  }
  
  return status;
}
예제 #2
0
파일: lexer.c 프로젝트: 8l/ark-c
void destroyLexer(Lexer *self) {
	if (self->tokenStream != NULL) {
		for (int i = 0; i < self->tokenStream->size; i++) {
			Token *tok = getVectorItem(self->tokenStream, i);
			// eof's content isnt malloc'd so free would give us some errors
			if (tok->type != TOKEN_END_OF_FILE) {
				verboseModeMessage("Freed `%s` token", tok->content);
				sdsfree(tok->content);
			}
			destroyToken(tok);
		}
	}

	verboseModeMessage("Destroyed lexer");
	free(self);
}
예제 #3
0
/*
 * main will have a string argument (in argv[1]).
 * The string argument contains the tokens.
 * Print out the tokens in the second string in left-to-right order.
 * Each token should be printed on a separate line.
 */
int main(int argc, char **argv) {
    // make sure theres exactly 1 argument
    if(argc != 2) {
        printf("Invalid number of arguments. \n");
        printf("Usage: \n    ./tokenizer <C-code string>\n");
        exit(1);
    }

    TokenizerT *tokenizer = TKCreate(argv[1]);

    TokenT *token;
    while((token = TKGetNextToken(tokenizer)) != NULL) {
        printToken(token);
        destroyToken(token);
    }

    TKDestroy(tokenizer);

    return 0;
}
예제 #4
0
/**
 * Allocate and initialize a new xQSearchExpr object from an expression
 * string. The created expression can be used for filtering a node list,
 * as opposted to searching (searching self instead of descendants).
 *
 * Returns a pointer to the new instance or 0 on error
 */
xQStatusCode xQSearchExpr_alloc_initFilter(xQSearchExpr** self, const xmlChar* expr) {
  const xmlChar* ptr = expr;
  xQStatusCode status = XQ_OK;
  xQToken tok;
  
  initToken(&tok);

  tok.strPtr = expr;
  nextToken(&tok);
  
  status = xQSearchExpr_parseSelector(self, &tok);
  
  if (status == XQ_NO_MATCH) {
    if (tok.lastStatus != XQ_OK && tok.lastStatus != XQ_NO_TOKEN)
      status = tok.lastStatus;
    else if (tok.type != XQ_TT_NONE)
      status = XQ_INVALID_SEL_UNEXPECTED_TOKEN;
    else
      status = XQ_OK;
  }

  destroyToken(&tok);

  if (status == XQ_OK && (!*self))
    status = xQSearchExpr_alloc_init_copy(self);
  else if (status == XQ_OK) {
    // convert to self-search
    if ((*self)->operation == _xQ_findDescendants)
      (*self)->operation = _xQ_addToOutput;
    else if ((*self)->operation == _xQ_findDescendantsByName)
      (*self)->operation = _xQ_filterByName;
  }
  
  if (status != XQ_OK)
    xQSearchExpr_free(*self);
  
  return status;
}
예제 #5
0
int main(){

	tSymTablePtr symTable;


	symtableInit(&symTable);


	tData symTableData = symtableInsert(&symTable,"c");

	printf("%s\n",symTable->key);



	symtableInsert(&symTable,"a");
	symtableInsert(&symTable,"e");

	printf("%s\n",symTable->LPtr->key);
	printf("%s\n",symTable->RPtr->key);
	


	//tData symTableData = symtableSearch(symTable,"c");


	symTableData->value->i=0;
	printf("%d\n",symTable->data->value->i);


	symTableData->type=INT;
	printf("%d\n",symTable->data->type);


	symTableData->scope=(char*) malloc(sizeof(5));
	strcpy(symTableData->scope,"main");
	printf("%s\n",symTable->data->scope);




	symTableData = symtableSearch(symTable,"a");

	symTableData->value->f=1.54;
	printf("%f\n",symTableData->value->f);


	symTableData->type=DBL;
	printf("%d\n",symTableData->type);


	symtableScopeInsert(symtableSearch(symTable,"a"),"globalna");
	printf("%s\n",symTable->LPtr->data->scope);



	symtableDispose(&symTable);

	printf("-----------------------------\n");


	loadSourceFile("test.txt");

	Ttoken* token = getNextToken();

	while(!(token->type==END_OF_FILE)){
	
		if ((token->type==1)||(token->type==2)||(token->type==3)||(token->type==4)){
			printf("LINE%d: %s\n",token->lineNum,token->attr->str);
		}
		else{
			printf("LINE%d: %d\n",token->lineNum,token->type);
		}

		destroyToken(token);
		token=getNextToken();
	}
	
	destroyToken(token);
	closeSourceFile();

return 0;
}