Example #1
0
static int scan_c_comment(Token *tok, Tokenizer *tokz)
{
    STRING_DECL_P(s, "/*");
    int c;
    int st=0;
    
    while(1){
        c=GETCH();
        
        if(c==EOF){
            STRING_FREE(s);
            return E_TOKZ_UNEXPECTED_EOF;
        }
        
        STRING_APPEND(s, c);
        
        if(c=='\n'){
            INC_LINE();
        }else if(st==0 && c=='*'){
            st=1;
        }else if(st==1){
            if(c=='/')
                break;
            st=0;
        }
    }

    STRING_FINISH(s);

    TOK_SET_COMMENT(tok, s);

    return 0;
}
Example #2
0
static int scan_string(Token *tok, Tokenizer *tokz, bool escapes)
{
    STRING_DECL(s);
    int c;

    while(1){    
        c=GETCH();
        
        if(c=='"')
            break;
        
        if(c=='\n'){
            UNGETCH(c);
            STRING_FREE(s);
            return E_TOKZ_UNEXPECTED_EOL;
        }
        
        if(c=='\\' && escapes){
            c=scan_char_escape(tokz);
            if(c==-2){
                STRING_FREE(s);
                return E_TOKZ_UNEXPECTED_EOL;
            }
        }
        
        if(c==EOF){
            STRING_FREE(s);
            return E_TOKZ_UNEXPECTED_EOF;
        }
        
        STRING_APPEND(s, c);
    }
    
    STRING_FINISH(s);
    
    TOK_SET_STRING(tok, s);

    return 0;
}
Example #3
0
File: ast.c Project: mdoug/FIAL
int FIAL_destroy_ast_node(struct FIAL_ast_node *n)
{
	if(!n)
		return 0;

	/* ok, I am just going to manual account for what to delete
	from different nodes. default will be to delete both left and
	right, as that is the typical case. */

	switch(n->type) {
/*
 *  these are list headers, only delete left side, right side contains
 *  a link to the last node, which is used to build the list.
 *
 *  obviously, fall through provides somewhat cleaner code, but
 *  seperate cases provides unique stack traces.
 */
	case AST_TOP:
		FIAL_destroy_ast_node(n->left);
		break;
	case AST_MAP_INITIALIZER:
		FIAL_destroy_ast_node(n->left);
		break;
	case AST_SEQ_INITIALIZER:
		FIAL_destroy_ast_node(n->left);
		break;
	case AST_STMTS:
		FIAL_destroy_ast_node(n->left);
		break;
	case AST_ARGLIST:
		FIAL_destroy_ast_node(n->left);
		break;
	case AST_VAR_DECL:
		FIAL_destroy_ast_node(n->left);
		break;
/*
 * These are lists that sneak in the last element as the left hand
 * side of the first element, only delete right side.
 *
 * These seem a bit hacky, I should probably switch to the header node
 * style for everything.  They have the advantage of being able to
 * store the length of the list in the header nodes's ->n field.
 */

	case AST_ARG_DECL:
		FIAL_destroy_ast_node(n->right);
		break;
	case AST_MAP_ACS:
		FIAL_destroy_ast_node(n->right);
		break;
	default:
		FIAL_destroy_ast_node(n->left);
		FIAL_destroy_ast_node(n->right);
		break;
	}

	if(n->type == AST_STRING)
	    STRING_FREE(n->str);

	FREE(n);

	return 0;
}