Example #1
0
int lpostfix_expression(struct token *token)
{
    if (token->type == ID_KW){
        struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
        if (ifkw != NULL){ //is a keyword
            log_error(LPOSTFIX_EXPRESSION);
            return -1;
        }
        else{
            struct hashentry *entry = hash_retrieve(symboltable, token->lexeme);
            if (entry == NULL){ //not defined
                log_error(POSTFIX_EXPRESSION);
                printf("%s has not been defined!\n", token->lexeme);
            }
            else{
                tree_mknode(LPOSTFIX_EXPRESSION);
                tree_add_attr(entry->data, 1);
                input_consume();
                free_token(token);
                stack_pop();
                stack_push(PRIMARY_EXPRESSION_MODS);
                return 0;
            }
        }

    }
    else{
        log_error(LPOSTFIX_EXPRESSION);
        return -1;
    }
    return -1;
}
Example #2
0
int postfix_expression(struct token *token)
{

    if ((token->type >= ID_KW) && (token->type <= S_C)){
        if(token->type == ID_KW){ 
            struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
            if (ifkw != NULL){ //is a keyword
                log_error(POSTFIX_EXPRESSION);
                return -1;
            }
        }
        
        //if identifier
        if (token->type == ID_KW){ //already checked if kw
            struct hashentry *entry = hash_retrieve(symboltable, token->lexeme);
            if (entry == NULL){ //not defined
                log_error(POSTFIX_EXPRESSION);
                printf("%s has not been defined!\n", token->lexeme);
                return -1;
            }
            else{
                tree_mknode(POSTFIX_EXPRESSION);
                tree_add_attr(entry->data, 1);
                input_consume();
                free_token(token);
                stack_pop();
                stack_push(PRIMARY_EXPRESSION_MODS);
                return 0;
            }
        }
        else{ //should be some sort of constant
            struct identifier *c = malloc(sizeof(struct identifier));
            type_const(c->type);
            c->lexeme = token->lexeme;

            tree_mknode(POSTFIX_EXPRESSION);
            tree_add_attr(c, 1);
            input_consume();
            free(token);
            stack_pop();
            return 0;
        }
    }
    else{
        log_error(POSTFIX_EXPRESSION);
        return -1;
    }

}
Example #3
0
int assignment_operator(struct token *token)
{
    printf("Hello from assignment operator!\n");//DEBUG
    if(token->op_type == ASSIGN){
        printf("found the assignment!\n");//DEBUG
        tree_mknode(ASSIGNMENT_OPERATOR);
        stack_pop();
 
        struct hashentry *he = hash_retrieve(kwtable, token->lexeme);
        if (he == NULL){
            log_error(ASSIGNMENT_OPERATOR);
            printf("disconnect between scanner's %s and parser!\n", token->lexeme);
            return -1;
        }


        tree_add_attr(he->data, 1);
        input_consume();


        free_token(token);
        return 0;
    }
    return -1;
}
Example #4
0
int statement(struct token *token)
{
    printf("Hello from statement\n");//DEBUG

    struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
    if (ifkw != NULL){ //is a keyword
        if (strncmp("goto", token->lexeme, 4) == 0){
            tree_mknode(STATEMENT);
            stack_pop();
            stack_push(JUMP_STATEMENT);
        }
        if (strncmp("begin", token->lexeme, 5) == 0){
            tree_mknode(STATEMENT);
            stack_pop();
            stack_push(LABELED_STATEMENT);
        }
    }
    else if (token->op_type == CLOSESCOPE){
        stack_pop(); //not a statement
    }
    else{
        tree_mknode(STATEMENT);
        stack_pop();
        stack_push(EXPRESSION_STATEMENT);
    }
    return 0;
}
Example #5
0
int reference_operator(struct token *token)
{
    if ((token->op_type == STAR) ||
        (token->op_type == AND) ||
        (token->op_type == MULTIPLY) ||
        (token->op_type == BWAND)){
        tree_mknode(REFERENCE_OPERATOR);

        struct hashentry *he = hash_retrieve(kwtable, token->lexeme);
        if (he == NULL){
            log_error(ASSIGNMENT_OPERATOR);
            printf("disconnect between scanner's %s and parser!\n", token->lexeme);
            return -1;
        }


        tree_add_attr(he->data, 0);
        input_consume();


        stack_pop();
        free_token(token);
        return 0;
    }
    else {
        log_error(REFERENCE_OPERATOR);
        return -1;
    }
}
Example #6
0
int type_specifier(struct token *token)
{
    printf("Hello from type_specifier\n");//DEBUG
    
    struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
    if (ifkw == NULL){ //not a keyword
        printf("%s, not a keyword\n", token->lexeme);//DEBUG
        log_error(TYPE_SPECIFIER);
        return -1;
    }
    else{ //check if right kind of keyword
        if( ifkw->data->id == KW_TYPESPECIFIER){
            tree_mknode(TYPE_SPECIFIER);
            stack_pop();
            tree_add_attr(ifkw->data, 1);//TODO
            input_consume();
            free(token);
            return 0;
        }
        else{
            log_error(TYPE_SPECIFIER);
            return -1;
        }
    }

    return 0;
}
Example #7
0
int declaration(struct token *token)
{ 
    printf("Hello from declaration\n");//DEBUG
    
    struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
    if (ifkw == NULL){ //not a keyword
        printf("%s, not a keyword\n", token->lexeme);//DEBUG
        log_error(DECLARATION);
        return -1;
    }
    else{ //check if right kind of keyword
        if( (ifkw->data->id == KW_TYPEQUALIFIER) ||
            (ifkw->data->id == KW_TYPESPECIFIER)){

            tree_mknode(DECLARATION);
            stack_pop();
            stack_push(TOKEN_ENDSTATEMENT);// ';' 
            stack_push(TYPEDEF_NAME);
            stack_push(DECLARATION_SPECIFIERS);
        }
        else{
            log_error(DECLARATION);
            return -1;
        }
    }
    return 0;
}
Example #8
0
int declaration_specifiers(struct token *token)
{ 
    printf("Hello from declaration speficiers\n");//DEBUG
    
    struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
    if (ifkw == NULL){ //not a keyword
        printf("%s, not a keyword\n", token->lexeme);//DEBUG
        log_error(DECLARATION);
        return -1;
    }
    else{ //check if right kind of keyword
        if( ifkw->data->id == KW_TYPEQUALIFIER){
            tree_mknode(DECLARATION_SPECIFIERS);
            stack_pop();
            stack_push(POINTER_QUALIFIER);
            stack_push(TYPE_SPECIFIER);
            stack_push(TYPE_QUALIFIER);
        }
        else if( ifkw->data->id == KW_TYPESPECIFIER){
            tree_mknode(DECLARATION_SPECIFIERS);
            stack_pop();
            stack_push(POINTER_QUALIFIER);
            stack_push(TYPE_SPECIFIER);
        }
        else{
            log_error(DECLARATION_SPECIFIERS);
            return -1;
        }
    }
    return 0; 
}
Example #9
0
static METACACHE_RECORD* _cache_lookup(METACACHE_FS_PRIV* fspriv, const char* filename)
{
    METACACHE_RECORD* rec;
    
    // FIXME: do a lookup
    if ((hash_retrieve(&(fspriv->cache), (char*)filename, (void**)&rec)) && (rec!=NULL))
    {
	if ((rec->mtime+CACHE_TIMEOUT) > _curtime()) 
	{
	    DEBUGMSG("cached: %s", filename);
	    return rec;
	}
	
	DEBUGMSG("purging old cache record for %s", filename);
	mvfs_stat_free(rec->stat);
	rec->stat = NULL;
	return rec;
    }

    // ... lookup failed - no record yet
    rec = calloc(1,sizeof(METACACHE_RECORD));
    rec->filename = strdup(filename);
    
    // now insert
    hash_insert(&(fspriv->cache),rec->filename,rec);
    return rec;
}
Example #10
0
int lvalue(struct token *token)
{
    // & operator not allowed on lhs
    printf("Hello from lvalue\n");//DEBUG
    if ((token->op_type == STAR) ||
        (token->op_type == MULTIPLY)){ //must be interpreted as star
        token->op_type = STAR;
        tree_mknode(LVALUE);
        stack_pop();

 
        struct hashentry *he = hash_retrieve(kwtable, token->lexeme);
        if (he == NULL){
            log_error(LVALUE);
            printf("disconnect between scanner's %s and parser!\n", token->lexeme);
            return -1;
        }


        tree_add_attr(he->data, 0);
        input_consume();
        stack_push(LPOSTFIX_EXPRESSION);
        free_token(token);
        return 0;
    }
    else if (token->type == ID_KW){
        //check if keyword
        struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
        if (ifkw == NULL){ // identifier
            tree_mknode(LVALUE);
            stack_pop();
            stack_push(LPOSTFIX_EXPRESSION);
            return 0;
        }
        else{
            log_error(LVALUE);
            return -1;
        }
    }
    else{
        log_error(LVALUE);
        return -1;
    }
}
Example #11
0
//TODO
int labeled_statement(struct token *token)
{
    printf("hello from labeled statement\n");//DEBUG
    //need to make node
    //consume the "begin" kw (check for it first)
    //consume and add the next identifier token (check)
    //check and consume the final ':'
    input_consume(); // "begin"
    free_token(token);
    struct token *t = input_consume(); // the identifier
    struct hashentry *label = hash_retrieve(kwtable, t->lexeme);
    struct token *colon = input_consume(); //should be ':'

    if(label == NULL && colon->op_type == TERNC){ //good, not a keyword
        tree_mknode(LABELED_STATEMENT);

        struct hashentry *predefined;
        struct identifier *labelsym = malloc(sizeof(struct identifier));
        labelsym->lexeme = t->lexeme;

        predefined = hash_insert(symboltable, labelsym);
        if(predefined == NULL || predefined == (void *)1){
            log_error(LABELED_STATEMENT);
            printf("Symbol: %s has previously been defined\n", t->lexeme);
            return -1;
        }
        type_id(labelsym->type);
        labelsym->op_type = 0;

        struct hashentry *beginkw = hash_retrieve(kwtable, "begin");

        tree_add_attr(beginkw->data, 0);
        tree_add_attr(labelsym, 1);
        free(t);
        free(colon);
        stack_pop();
        return 0;
    }
    else{
        log_error(LABELED_STATEMENT);
        return -1;
    }
}
Example #12
0
int typedef_name(struct token *token)
{
    printf("Hello from typedef_name\n");//DEBUG
    
    if (token->type != ID_KW){
        printf("Not an identifier!\n");//DEBUG
        log_error(TYPEDEF_NAME);
        return -1;
    }

    struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
    if (ifkw != NULL){ //not a keyword
        printf("%s, not an identifier\n", token->lexeme);//DEBUG
        log_error(TYPEDEF_NAME);
        return -1;
    }
    else{ //add to symboltable
        //create a new identifier for symbol table
        struct identifier *newid = malloc(sizeof(struct identifier *));
        type_id(newid->type);
        newid->op_type = 0;
        newid->kw_name = 0;
        newid->lexeme = token->lexeme;

        //ensure not already in the symbol table
        struct hashentry *entry = hash_insert(symboltable, newid);
        if (entry == NULL){
            log_error(TYPEDEF_NAME);
            printf("Error inserting into symbol table!\n");
            return -1;
        }
        else if (entry == (void *)1){
            log_error(TYPEDEF_NAME);
            printf("%s is already defined!\n", newid->lexeme);
            return -1;
        }

        //make the tree node, and add the attribute
        tree_mknode(TYPEDEF_NAME);
        stack_pop();
        tree_add_attr(newid, 3);//TODO
        input_consume(); //consume the identifier

        struct token *t = input_peek();
        if (t->op_type == OPENBRACKET){
            input_consume();
            stack_push(DEFINE_ARRAY);
        }
        free(token);
    }
    printf("leaving typedef_name\n");//DEBUG;

    return 0;
}
Example #13
0
static void *get_record(t_symtab *symtab, const char *s)
{
   t_symrec *symrec;
   if (symtab->lookup_table) {
      symrec = hash_retrieve(symtab->lookup_table, s);
   } else {
      symtab->symrec = NULL;
      llist_iterate(symtab->list, symtab_find, (char*)s);
      symrec = symtab->symrec;
   }
   return symrec;
}
Example #14
0
void test_kwtable(){
    int i;
    for(i = 0; i < NUMKEYWORDS; i++){
        struct hashentry *temp = hash_retrieve(kwtable, keywords[i]);
        if( temp == NULL ){
            printf("ERROR, not all keywords entered into table!\n");
        }
        else{
            printf("%s keyword found in table.\n", temp->data->lexeme);
        }
    }
}
Example #15
0
/**
 * Link Detached Handler
 */
static int router_link_detach_handler(void* context, dx_link_t *link, int closed)
{
    dx_router_t    *router  = (dx_router_t*) context;
    pn_link_t      *pn_link = dx_link_pn(link);
    const char     *r_tgt   = pn_terminus_get_address(pn_link_remote_target(pn_link));
    dx_link_item_t *item;

    sys_mutex_lock(router->lock);
    if (pn_link_is_sender(pn_link)) {
        item = DEQ_HEAD(router->out_links);

        dx_field_iterator_t *iter = dx_field_iterator_string(r_tgt, ITER_VIEW_NO_HOST);
        dx_router_link_t    *rlink;
        if (iter) {
            int result = hash_retrieve(router->out_hash, iter, (void*) &rlink);
            if (result == 0) {
                dx_field_iterator_reset(iter, ITER_VIEW_NO_HOST);
                hash_remove(router->out_hash, iter);
                free_dx_router_link_t(rlink);
                dx_log(module, LOG_TRACE, "Removed local address: %s", r_tgt);
            }
            dx_field_iterator_free(iter);
        }
    }
    else
        item = DEQ_HEAD(router->in_links);

    while (item) {
        if (item->link == link) {
            if (pn_link_is_sender(pn_link))
                DEQ_REMOVE(router->out_links, item);
            else
                DEQ_REMOVE(router->in_links, item);
            free_dx_link_item_t(item);
            break;
        }
        item = item->next;
    }

    sys_mutex_unlock(router->lock);
    return 0;
}
Example #16
0
int pointer_qualifier(struct token *token)
{
    printf("Hello from pointer qualifier\n");
    if (token->op_type == STAR || token->op_type == MULTIPLY){
        
        struct hashentry *he = hash_retrieve(kwtable, token->lexeme);
        if (he == NULL){
            log_error(POINTER_QUALIFIER);
            printf("disconnect between scanner's %s and parser!\n", token->lexeme);
            return -1;
        }
        tree_add_attr(he->data, 2);
        input_consume();
        free_token(token);
    }
    else{
        stack_pop();
    }
    return 0;
}
Example #17
0
int cast_expression(struct token *token)
{
    printf("hello from cast_expression\n");//DEBUG
    //need to get 'type' ')' 'lrvalue'
    struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
    
    if (ifkw == NULL){ //not a keyword, error
        log_error(CAST_EXPRESSION);
        return -1;
    }
    else {
        //TODO implement actual check
        tree_mknode(CAST_EXPRESSION);
        tree_add_attr(ifkw->data, 0);
        input_consume();
        stack_pop();
        free_token(token);
        stack_push(LRVALUE);
        stack_push(TOKEN_CLOSEPAREN);
        return 0;
    }
}
Example #18
0
int declaration_list(struct token *token)
{
    printf("Hello from declaration list\n");//DEBUG
    
    struct hashentry *ifkw = hash_retrieve(kwtable, token->lexeme);
    if (ifkw == NULL){ //not a keyword
        printf("%s, not a keyword\n", token->lexeme);//DEBUG
        stack_pop();
    }
    else{ //check if right kind of keyword
        if( (ifkw->data->id == KW_TYPEQUALIFIER) ||
            (ifkw->data->id == KW_TYPESPECIFIER)){
            stack_push(DECLARATION);
            printf("%s, IS a keyword\n", token->lexeme);//DEBUG
        }
        else{
            stack_pop();
        }
    }

    return 0;
}
Example #19
0
int main(int argc, char **argv)
{
  hash *h=hash_retrieve(argv[1]);
  hash_dump(h);
  return 0;
}
Example #20
0
int primary_expression_mods(struct token *token)
{
    printf("Hello from primary_expression_mods\n");
    if (token->op_type == OPENPAREN){
        tree_mknode(-1); //TODO implement '('
        input_consume();
        free_token(token);
        stack_pop();
        stack_push(TOKEN_CLOSEPAREN); //')'
        stack_push(PRIMARY_EXPRESSION_LIST);
        return -1;
    }
    else if (token->op_type == OPENBRACKET){
        tree_mknode(PRIMARY_EXPRESSION_MODS);
        input_consume(); //get the [
        free_token(token);
        stack_pop();
        struct token *t = input_consume(); //the inner part of the [x]

        struct identifier *nid = malloc(sizeof(struct identifier));
        nid->lexeme = t->lexeme;
        if (t->type == ID_KW){
            struct hashentry *he = hash_retrieve(kwtable, nid->lexeme);
            if (he != NULL){ //is a keyword (an error)
                log_error(PRIMARY_EXPRESSION_MODS);
                return -1;
            }
            else{
                he = hash_retrieve(symboltable, nid->lexeme);
                if (he == NULL){ //symbol not defined
                    log_error(PRIMARY_EXPRESSION_MODS);
                    printf("%s has not been initialized\n", nid->lexeme);
                    return -1;
                }
                else{
                    tree_add_attr(he->data, 4);
                    free_token(t);
                    input_consume();    //the last ]
                    return 0;
                }
            }
        }
        else if (t->type >= C_NUM && t->type <= C_F){
            struct identifier *id = malloc(sizeof(struct identifier));
            id->lexeme = t->lexeme;
            type_const(id->type);
            tree_add_attr(id, 4); //add it as attribute
            free(t);
            input_consume(); // the last ]
            return 0;
        }
        else{
            log_error(PRIMARY_EXPRESSION_MODS);
            printf("%s has not been initialized\n", nid->lexeme);
            return -1;
        }
    }
    else if (token->op_type == VALUEAT){
        input_consume(); // throw away '.'
        struct token *tmp = input_consume(); //get the identifier
        struct hashentry *ifkw = hash_retrieve(kwtable, tmp->lexeme);
        if (ifkw != NULL){ //error is a keyword
            log_error(PRIMARY_EXPRESSION_MODS);
            return -1;
        }
        else{
            tree_mknode(-1); //TODO implement '.'
            free_token(token);
            stack_pop();
            stack_push(PRIMARY_EXPRESSION);
            return -1;
        }
    }
    else{ //not a mod of a primary expression
        stack_pop();
        return 0;
    }
}
Example #21
0
/**
 * Inbound Delivery Handler
 */
static void router_rx_handler(void* context, dx_link_t *link, pn_delivery_t *delivery)
{
    dx_router_t  *router  = (dx_router_t*) context;
    pn_link_t    *pn_link = pn_delivery_link(delivery);
    dx_message_t *msg;
    int           valid_message = 0;

    //
    // Receive the message into a local representation.  If the returned message
    // pointer is NULL, we have not yet received a complete message.
    //
    sys_mutex_lock(router->lock);
    msg = dx_message_receive(delivery);
    sys_mutex_unlock(router->lock);

    if (!msg)
        return;

    //
    // Validate the message through the Properties section
    //
    valid_message = dx_message_check(msg, DX_DEPTH_PROPERTIES);

    pn_link_advance(pn_link);
    pn_link_flow(pn_link, 1);

    if (valid_message) {
        dx_field_iterator_t *iter = dx_message_field_iterator(msg, DX_FIELD_TO);
        dx_router_link_t    *rlink;
        if (iter) {
            dx_field_iterator_reset(iter, ITER_VIEW_NO_HOST);
            sys_mutex_lock(router->lock);
            int result = hash_retrieve(router->out_hash, iter, (void*) &rlink);
            dx_field_iterator_free(iter);

            if (result == 0) {
                //
                // To field is valid and contains a known destination.  Enqueue on
                // the output fifo for the next-hop-to-destination.
                //
                pn_link_t* pn_outlink = dx_link_pn(rlink->link);
                DEQ_INSERT_TAIL(rlink->out_fifo, msg);
                pn_link_offered(pn_outlink, DEQ_SIZE(rlink->out_fifo));
                dx_link_activate(rlink->link);
            } else {
                //
                // To field contains an unknown address.  Release the message.
                //
                pn_delivery_update(delivery, PN_RELEASED);
                pn_delivery_settle(delivery);
            }

            sys_mutex_unlock(router->lock);
        }
    } else {
        //
        // Message is invalid.  Reject the message.
        //
        pn_delivery_update(delivery, PN_REJECTED);
        pn_delivery_settle(delivery);
        pn_delivery_set_context(delivery, 0);
        dx_free_message(msg);
    }
}
Example #22
0
int jump_statement(struct token *token)
{
    printf("Hello from jump_statement\n");//DEBUG
    // goto label conditional
    if( strncmp("goto", token->lexeme, 4) == 0){
        tree_mknode(JUMP_STATEMENT);
        input_consume(); //consume the goto
        free_token(token);
        struct token *label = input_consume();
        struct token *conditional = input_consume();
        if (label->type == ID_KW){
            struct hashentry *ifkw = hash_retrieve(kwtable, label->lexeme);
            if (ifkw == NULL){//not a keyword, an identifier

                struct hashentry *predefined;
                struct hashentry *predefined2;

                //get symboltable entry for label
                predefined = hash_retrieve(symboltable, label->lexeme);
                if(predefined == NULL){
                    predefined = malloc(sizeof(struct hashentry));
                    predefined->data = malloc(sizeof(struct identifier));
                    predefined->data->lexeme = label->lexeme;
                    type_id(predefined->data->type);
                    //log_error(LABELED_STATEMENT);
                    //printf("Symbol: %s has not been defined!\n", label->lexeme);
                    //return -1;
                }
                //get symboltable entry for conditional
                predefined2 = hash_retrieve(symboltable, conditional->lexeme);
                if(predefined2 == NULL){
                    log_error(LABELED_STATEMENT);
                    printf("Symbol: %s has not been defined!\n", conditional->lexeme);
                    return -1;
                }

                struct hashentry *gokw = hash_retrieve(kwtable, "goto");

                tree_add_attr(gokw->data, 0);
                tree_add_attr(predefined->data, 1);
                tree_add_attr(predefined2->data, 2);

                printf("Consumed: goto %s %s\n", 
                    label->lexeme, conditional->lexeme);//DEBUG
                stack_pop();
                stack_push(TOKEN_ENDSTATEMENT);
                free(label);
                free(conditional);
                return 0;
            }
            else{
                log_error(JUMP_STATEMENT);
                free_token(label);
                free_token(conditional);
                return -1;
            }
        }
        else{
            printf("Incorrect goto label: %s\n", label->lexeme);//DEBUG
            free_token(label);
            free_token(conditional);
            log_error(JUMP_STATEMENT);
            return -1;
        }
    }
    else{
        log_error(JUMP_STATEMENT);
        return -1;
    }
}