X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fparser_proc.y;h=d82a90f6f9d2986a03d4e161d1e962544f34f234;hp=5713c85d2481b41f4db1b5590afeb6dc3c62ca36;hb=5abcb8724ac7046d62203ea643e9ce69f63a6a8a;hpb=63fa6c00c541b9462784337e15955d7c3027f2f3 diff --git a/src/parser_proc.y b/src/parser_proc.y index 5713c85..d82a90f 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -2,6 +2,7 @@ #include #include #include +#include #include "parser.h" @@ -27,7 +28,7 @@ void psi_error(int, const char *, int, const char *, ...); %nonassoc NAME. %left PLUS MINUS. %left SLASH ASTERISK. -%fallback NAME TEMP FREE SET LET RETURN LIB INT UNSIGNED. +%fallback NAME TEMP FREE SET LET RETURN LIB INT LONG SIGNED UNSIGNED. file ::= blocks. @@ -244,20 +245,31 @@ decl_type(type_) ::= decl_type_token(T). { type_->token = T; } /* unsigned, urgh */ -decl_type(type_) ::= UNSIGNED NAME(T). { +decl_type(type_) ::= UNSIGNED(U) NAME(N). { + PSI_Token *T = PSI_TokenCat(2, U, N); type_ = init_decl_type(T->type, T->text); type_->token = T; - type_->name = realloc(type_->name, T->size + sizeof("unsigned")); - memmove(type_->name + sizeof("unsigned"), type_->name, T->size); - memcpy(type_->name, "unsigned", sizeof("unsigned")-1); - type_->name[sizeof("unsigned")] = ' '; - type_->name[T->size + sizeof("unsigned")] = 0; + free(U); + free(N); +} +decl_type(type_) ::= SIGNED NAME(T). { + type_ = init_decl_type(T->type, T->text); + type_->token = T; + type_->name = realloc(type_->name, T->size + sizeof("signed")); + memmove(type_->name + sizeof("signed"), type_->name, T->size); + memcpy(type_->name, "signed", sizeof("signed")-1); + type_->name[sizeof("signed")] = ' '; + type_->name[T->size + sizeof("signed")] = 0; } -/* we have to support plain int here because we have it in our lexer rules */ +/* we have to support plain int, long here because we have it in our lexer rules */ decl_type(type_) ::= INT(T). { type_ = init_decl_type(PSI_T_NAME, T->text); type_->token = T; } +decl_type(type_) ::= LONG INT(T). { + type_ = init_decl_type(PSI_T_NAME, T->text); + type_->token = T; +} /* structs ! */ decl_type(type_) ::= STRUCT(S) NAME(T). { type_ = init_decl_type(S->type, T->text);