Posts

Showing posts from December, 2023

commons_old.h

 #include <stdlib.h> #include <stdio.h> #include <string.h> enum keywords {   TYPEDEF,   EXTERN,   STATIC,   AUTO,   REGISTER,   CONST,   VOLATILE,   VOID,   CHAR,   SHORT,   INT,   LONG,   FLOAT,   DOUBLE,   SIGNED,   UNSIGNED,   STRUCT,   UNION,   ID,   ICONST,   FCONST }; int arr[15]; //char* arr[15]; int tok; int block_level = 0; static int i =0; void nextToken() {    tok = arr[i];    i++; } int lookupToken() {    return arr[i+1]; } int getTokenNumber() {    return i; } typedef enum boolean {   FALSE,   TRUE }_bool; typedef enum error_type {   _FATAL_ERR,   _WARN_ERR,   _CONTINUE_ERR } errtype; struct err {    char *err_msg;    errtype type;    int token_number;     int line;    char *func; }; /**** error is not for logs, but for crashing ...

Function and globaks with expr calling

 #include <stdio.h> #include "commons.h" #include <stdlib.h> void array_decl(_bool* is_arraydecl) {   static _bool is_open_sqbr = FALSE;   static int count =0;     if(tok == '[')     {       count++;       if(count > 1)       {          make_error("unexpected [ \n",_FATAL_ERR, getTokenNumber(), __LINE__,__func__);          return;       }       is_open_sqbr = TRUE;       nextToken();     } else if(tok == ID || tok == ICONST || tok == FCONST) {  _bool is_expr; if(is_expr(&expr)) { } else if(tok == ID && lookupToken() == '(') {   function_caller(); } else { } // need to check whether it's an expression nextToken(); }     else if(tok == ']')     {         count--;   ...

Statement

 #include <stdio.h> #include "commons.h" void statement_list(_bool* is_stmt) { switch(tok) { case FOR: { nextToken(); if(tok == '(') {                nextToken();    is_expr(&isexpr);    if(isexpr == TRUE)    {   nextToken();   while(tok == ';')   {     is_expr(&isexpr);         if(isexpr == TRUE)         {           nextToken();     }   }   if(tok == ')')   { *is_stmt = TRUE; nextToken();   }   else   { printf("error! wrong usage of 'for' keyword\n"); exit(0);     }    } } else  {    *is_stmt = FALSE; }     } break; case IF:...

Function and globals

#include <stdio.h> #include "commons.h" #include <stdlib.h> void array_decl(_bool* is_arraydecl) {   static _bool is_open_sqbr = FALSE;   static int count =0;     if(tok == '[')     {       count++;       if(count > 1)       {          make_error("unexpected [ \n",_FATAL_ERR, getTokenNumber(), __LINE__,__func__);          return;       }       is_open_sqbr = TRUE;       nextToken();     }     else if(tok == ']')     {         count--;         if(is_open_sqbr == FALSE)         {            make_error("expected [ \n", _FATAL_ERR, getTokenNumber(), __LINE__, __func__);            return;         }         *is_arraydecl = ...

Functions common utility

 enum keywords {   TYPEDEF,   EXTERN,   STATIC,   AUTO,   REGISTER,   CONST,   VOLATILE,   VOID,   CHAR,   SHORT,   INT,   LONG,   FLOAT,   DOUBLE,   SIGNED,   UNSIGNED,   STRUCT,   UNION,   ID }; int arr[15]; //char* arr[15]; int tok; int block_level = 0; void nextToken() {    static int i =0;    tok = arr[i];    i++; } enum _bool {   FALSE,   TRUE };

Functions

#include <stdio.h> #include "commons.h" void array_decl(_bool* is_arraydecl) {   static bool is_open_sqbr = FALSE;     if(tok == '[')     {       is_open_sqbr = TRUE;       nextToken();     }     else if(tok == ']')     {         if(is_open_sqbr == FALSE)         {            printf("expected [ \n");            exit(0);         }         *is_arraydecl = TRUE;         is_open_sqbr = FALSE;         nextToken();         return;     }     else if(is_open_sqbr == TRUE) // expression     {         nextToken();     }     if(tok == EOF)       return;     else if(tok != ID || tok != ';')       array_de...