WONKY



LOG | FILES | OVERVIEW


F diff --git a/src/semantics/program/translation_unit.c b/src/semantics/program/translation_unit.c --- a/src/semantics/program/translation_unit.c +++ b/src/semantics/program/translation_unit.c
struct token* token_ptr_get_token_under_pointer(struct Token_Pointer *token_pointer)
{
struct token *hold_token;
- if(token_pointer->current_token_node==NULL)
+ if(!token_ptr_has_remaining_tokens(token_pointer))
return get_eof_token();
+ if(token_ptr_has_buffered_tokens(token_pointer))
+ return token_ptr_get_buffered_token(token_pointer);
+
token_ptr_goto_next_normal_token(token_pointer);
hold_token=(struct token*)token_pointer->current_token_node->data;
void token_ptr_goto_next_normal_token(struct Token_Pointer *token_pointer)
{
struct token *hold_token;
- if(token_pointer->current_token_node==NULL)
+ if(token_ptr_has_buffered_tokens(token_pointer))
return;
while(1)
{
+ if(token_pointer->current_token_node==NULL)
+ return;
+
hold_token=(struct token*)token_pointer->current_token_node->data;
if(hold_token==NULL)
return;
struct token* token_ptr_check_next_normal_token(struct Token_Pointer *token_pointer)
{
struct token *ret;
- if(token_pointer->current_token_node==NULL)
+
+ if(token_ptr_has_buffered_tokens(token_pointer))
+ return token_ptr_check_buffered_token(token_pointer);
+
+ if(!token_ptr_has_remaining_tokens(token_pointer))
return get_eof_token();
else
return (struct token*)token_pointer->current_token_node->data;
}
void token_ptr_goto_next_token(struct Token_Pointer *token_pointer)
{
- if(token_pointer->current_token_node!=NULL)
+ if(token_ptr_has_remaining_tokens(token_pointer) && !token_ptr_has_buffered_tokens(token_pointer))
token_pointer->current_token_node=token_pointer->current_token_node->prev;
}
ret=wonky_malloc(sizeof(struct Token_Pointer));
ret->current_token_node=unit->tokens->first;
ret->call_stack=wonky_malloc(sizeof(struct Stack));
+ ret->ungeted_tokens=wonky_malloc(sizeof(struct Queue));
+
Stack_Init(ret->call_stack);
+ Queue_Init(ret->ungeted_tokens);
ret->current_location=NULL;/*todo*/
+ ret->program=NULL;/*todo*/
+
+ return ret;
}
void token_ptr_execute_include_directive(struct Token_Pointer *ptr,struct token_include_directive *include_directive)
}
_Bool token_ptr_has_remaining_tokens(struct Token_Pointer *ptr)
{
- token_ptr_goto_next_normal_token(ptr);
+ if(token_ptr_has_buffered_tokens(ptr))
+ {
+ return 1;
+ }else
+ {
+ token_ptr_goto_next_normal_token(ptr);
- return ptr->current_token_node!=NULL;
+ return ptr->current_token_node!=NULL;
+ }
}
void token_ptr_unget_token(struct Token_Pointer *ptr,struct token *token)
{
{
ptr->current_location=token->location;
}
+ _Bool token_ptr_has_buffered_tokens(struct Token_Pointer *ptr)
+ {
+ return ptr->ungeted_tokens->size!=0;
+ }
+ struct token* token_ptr_get_buffered_token(struct Token_Pointer *ptr)
+ {
+ if(token_ptr_has_buffered_tokens(ptr))
+ return (struct token*)Queue_Pop(ptr->ungeted_tokens);
+ else
+ return NULL;
+ }
+ struct token* token_ptr_check_buffered_token(struct Token_Pointer *ptr)
+ {
+ if(token_ptr_has_buffered_tokens(ptr))
+ return (struct token*)ptr->ungeted_tokens->first->data;
+ else
+ return NULL;
+ }
#endif
F diff --git a/src/semantics/program/translation_unit.h b/src/semantics/program/translation_unit.h --- a/src/semantics/program/translation_unit.h +++ b/src/semantics/program/translation_unit.h
void token_ptr_assume_location_of_token(struct Token_Pointer *ptr,struct token *token);
+ _Bool token_ptr_has_buffered_tokens(struct Token_Pointer *ptr);
+ struct token* token_ptr_get_buffered_token(struct Token_Pointer *ptr);
+ struct token* token_ptr_check_buffered_token(struct Token_Pointer *ptr);
+
#endif