Posts

Showing posts from December, 2023

tape_t.h

  #pragma once #include <stdlib.h> #include <stdio.h> enum Bool { FALSE, TRUE }; char getch(char *Tape, int current_ptr) { return Tape[current_ptr]; } char getchIncr(char *Tape, int current_ptr) { return Tape[current_ptr++]; } int tapeIncr(int current_ptr, int i) { current_ptr += i; return current_ptr; } void necessary_expect(char *Tape, int current_ptr, char expected_symbol) { if (getch(Tape, current_ptr) != expected_symbol) { printf("Missing char is %c but input char is (%c)%d\n", expected_symbol, getch(Tape, current_ptr), getch(Tape, current_ptr)); exit(0); } current_ptr++; } Bool optional_expect(char *Tape, int current_ptr, char expected_symbol) { if (getch(Tape, current_ptr) != expected_symbol) { return FALSE; } current_ptr++; return TRUE; } void jumpline(char *Tape, int current_ptr) { if (getch(Tape, current_ptr) == '\n') { current_ptr++; return; } while (getch(Tape, current_ptr) != '\n') ...

string_t.h

 #pragma once #include <stdio.h> #include <stdlib.h> #include <cstring> #undef empty #define STR_LEN_CHECK(str,pos)  str->len <= pos #define IS_SPACE(str,pos) at(str,pos) == ' ' ||  \ at(str, pos) == '\n' || \ at(str, pos) == '\v' || \ at(str, pos) == '\t' struct string_struct { int len; char *str; char *back; char empty; }; typedef struct string_struct struct_var; typedef struct_var* string_t; typedef struct mem { string_t str; int string_size; int index; } memrecord; string_t string_file(char *s,int *len); string_t string(char *s); void push(string_t st, char s); char pop(string_t st); char *con(string_t a); int length(string_t a); char at(string_t a, int i); string_t copy(string_t a, string_t b); string_t getlines(string_t a); int locate(string_t s, string_t find_str); string_t partOfstring(string_t s, int start, int length); char* c_string(string_t s); void manipulate(string_t s, const char *str, int start)...

string_t.c

  #include "stdafx.h" #include "string_t.h" int string_file_len(char *s) { int i = 0; while (s[i] != EOF) { i++; } return i; } string_t string_file(char *s,int *file_length) { int len = string_file_len(s); char *content = (char *)malloc(len + 1); memcpy(content, s, len); content[len] = EOF; string_t st = (string_t)malloc(sizeof(struct_var)); st->len = len + 1; st->str = content; st->back = content + len - 1; if (strcmp(s, "\0")) st->empty = 1;     *file_length = len; return st; }  string_t string(char *s) { int len = strlen(s); char *content = (char *)malloc(len + 1); memcpy(content, s, len); content[len] = '\0'; string_t st = (string_t)malloc(sizeof(struct_var)); st->len = len + 1; st->str = content; st->back = content + len - 1; if (strcmp(s, "\0")) st->empty = 1; return st; } #define empty_str(st)   if(st->len == 0)              ...

function_t.c

 /********** Standard Predefined Macros **********/ class Func {     string function_name;     int line_numb; }; bool function_parse(string line_str,int line) {         bool flag = false;         int i=0;         string return_type,funct_name;         while(i< line_str.length() && (line_str.at(i) != ' ' || line_str.at(i) != '\t' || line_str.at(i) != '\0'))         {             return_type += line_str.at(i);             i++;         }         if(line_str.at(i) == '\0')             return false;         if(return_type == "int" || return_type == "void" || return_type == "float" || return_type == "unsigned" || return_type == "double" || return_type == "long")             flag = t...

VECPP.c

 /* Written for Embedded C++ */ /* Follow TR.18015 Standard Specs */ /* VECPP version 1.0 */ /* Designed by Daipayan Bhowal */ #include <iostream>  #include "datastructure.h" #include <fstream> #include <string> #include <unistd.h> #include <stdio.h> #include <cstdlib> #include <bits/stdc++.h>  #define UTX 0 #define FWK 0 #define DEBUG 0 #define PARSE 0 #define LEVEL_INC 1 #define NO_OF_MAX_FILES 5 using namespace std; #undef stack bool is_id(string token,string term,const int term_char_option); /**************  Defination ****************/ enum MacroType {     define_t,     include_t,     line_t,     undef_t,     error_tt,     pragma_t,     defined_t,     if_t,     ifdef_t,     ifndef_t,     elif_t,     else_t,     endif_t, UNDEFINED,     MAX_TYPE }; MacroType getIndexFromStr(string_t ...