diff --git a/cinc/main.c b/cinc/main.c index ab7ff94..6e912f6 100644 --- a/cinc/main.c +++ b/cinc/main.c @@ -11,8 +11,6 @@ #include #include "tokenize.h" -Token* tokenfunc(void); - int main(int argc, const char * argv[]) { char* prgstr="int main() {\nreturn 0;\n}"; Token* tokens=tokenize(prgstr); diff --git a/cinc/token.c b/cinc/token.c index 5183a94..edc0190 100644 --- a/cinc/token.c +++ b/cinc/token.c @@ -59,6 +59,12 @@ void print_tok(Token* token) { case TYPE_NUM: printf("NUM"); break; + case TYPE_RETURN: + printf("RETURN"); + break; + case TYPE_TYPE: + printf("TYPE"); + break; default: break; } diff --git a/cinc/tokenize.c b/cinc/tokenize.c index 3b69ebe..ea6e360 100644 --- a/cinc/tokenize.c +++ b/cinc/tokenize.c @@ -12,6 +12,7 @@ #include #include #include +#include #define ID_MAX_SIZE 31 @@ -36,6 +37,11 @@ Token* next_token(int* strpos, char* prg, Token* prev) { } } id[length]=0; + if (strcmp("return",id)==0) { + return new_token(TYPE_RETURN, NULL, prev); + } else if (strcmp("int",id)==0) { + return new_token(TYPE_TYPE, val_from_const_str("int"), prev); + } return new_token(TYPE_IDENT, val_from_str(id), prev); } else if (isdigit(current)) { char* id=malloc(sizeof(char)*ID_MAX_SIZE+1);