Parser Parser_Obj = new Parser();
Parser_Obj.Parse("Example.cpp");
Console.Write("\n OS\n\n\n");
public void Parse(string Src)
DBG.ENTER("Parse(Srs = \"" + Src + "\")");
void Generate_Tokens_List()
DBG.ENTER("Generate_Tokens_List()");
Tokenizer T = new Tokenizer();
Token[] Token_List = T.Create_Token_List(Src);
string Src = "int main()" +
" Print(\"Hello world!\");"+
DBG.ENTER("Parse_Glb_Scope()");
Token T = Get_Next_Token();
DBG.ENTER("Get_Next_Token()");
DBG.ENTER("Parse_Sentence()");
Token T = Get_Next_Token();
if (T.Type == "Type") Parse_Sentence_Type();
else if(T.Value == "class") Parse_Sentence_Class();
else if(T.Value == "struct") Parse_Sentence_Struct();
DBG.ENTER("ERROR_TRAP()");
void Parse_Sentence_Type()
DBG.ENTER("Parse_Type()");
Token T = Get_Next_Token();
case ";": Parse_Var(); break;
case "=": Parse_Var_w_Init(); break;
case "(": Parse_Definite_Function(); break;
default: ERROR_TRAP(); break;
void Parse_Sentence_Class()
DBG.ENTER("Parse_Class()");
void Parse_Sentence_Struct()
DBG.ENTER("Parse_Struct()");
DBG.ENTER("Parse_Var()");
DBG.ENTER("Parse_Var_w_Init()");
void Parse_Definite_Function()
DBG.ENTER("Parse_Definite_Function()");
DBG.ENTER("Parse_Arg_List()");
void Parse_Function_Body()
DBG.ENTER("Parse_Function_Body()");
static int Enter_Cnt = 0;
public static void ENTER(string Msg)
for(int i=0; i<Level; i++)
for(int i=0; i<Level; i++)
Console.Write("· " + Msg + " " + Enter_Cnt);
public static void RETURN()
public static void RETURN(string Msg)
for(int i=0; i<Level; i++)
Console.Write("╭──╯ " + Msg);
static bool Visibled = true;
public static void Print_ON()
public static void Print_OFF()
public static void Print(string Str)
public static void Print(string[] Str)
public static void Print(Token[] TknList)
for(int i = 0; i < TknList.Length-2; i++)
Token Current_Token = TknList[i];
int TypeStr_Lenght = Current_Token.Type.Length;
int Spacer_Len = 16 - TypeStr_Lenght;
for(int j = 0; j < Spacer_Len; j++)
DBG.Print(Current_Token.Type + Spacer + Current_Token.Value + "\n");
public Token[] Create_Token_List(string Src)
DBG.ENTER("Create_Token_List()");
Src = Clear_Space_Pack(Src);
DBG.Print("\n\n\n------------------\n\n\n");
int Str_Len = Src.Length;
for(int i = 0; i < Str_Len; i++)
string c = Src[i].ToString();
if(c == "(") c = "\n(\n";
if(c == ")") c = "\n)\n";
if(c == "{") c = "\n{\n";
if(c == "}") c = "\n}\n";
if(c == ";") c = "\n;\n";
Out_Text = Clear_NewLine_Pack(Out_Text);
string[] Lexems = Out_Text.Split('\n', StringSplitOptions.RemoveEmptyEntries);
int How_Lexems = Lexems.Length;
for(int i = 0; i < How_Lexems; i++)
string Lexem = Lexems[i];
if (Is_Punctuator (Lexem) == true) Token_List += "Punctuator " + Lexem;
else if(Is_BuildInType (Lexem) == true) Token_List += "BuildInType " + Lexem;
else if(Is_Number (Lexem) == true) Token_List += "Number " + Lexem;
else if(Is_ControlKeyWord(Lexem) == true) Token_List += "ControlKeyWord " + Lexem;
else if(Is_Operation (Lexem) == true) Token_List += "Operation " + Lexem;
else if(Is_String (Lexem) == true) Token_List += "Literal_String " + Lexem;
else if(Is_Identifier (Lexem) == true) Token_List += "Identifier " + Lexem;
string[] Token_Array_Srtings = Token_List.Split('\n', StringSplitOptions.RemoveEmptyEntries);
int How_Tokens = Token_Array_Srtings.Length;
Token[] Token_Array_Sructs = new Token[How_Tokens+2];
for(int i = 0; i < How_Tokens; i++)
string[] TMP = Token_Array_Srtings[i].Split(' ', StringSplitOptions.RemoveEmptyEntries);
Token_Array_Sructs[i] = new Token();
Token_Array_Sructs[i].Type = TMP[0];
Token_Array_Sructs[i].Value = TMP[1];
return Token_Array_Sructs;
string Clear_Space_Pack(string Str)
DBG.ENTER("Clear_Space_Pack()");
int Str_Len = Str.Length;
char Prev_Symbol = (char)0;
for(int i = 0; i < Str_Len; i++)
string Clear_NewLine_Pack(string Str)
DBG.ENTER("Clear_NewLine_Pack()");
int Str_Len = Str.Length;
char Prev_Symbol = (char)0;
for(int i = 0; i < Str_Len; i++)
bool Is_Punctuator(string Str)
DBG.ENTER("Is_Punctuator()");
static bool Is_BuildInType(string Str)
DBG.ENTER("Is_BuildInType()");
if(Str == "int") return true;
if(Str == "float") return true;
if(Str == "double") return true;
if(Str == "char") return true;
if(Str == "void") return true;
bool Is_ControlKeyWord(string Str)
DBG.ENTER("Is_ControlKeyWord()");
if(Str == "if") return true;
if(Str == "else") return true;
if(Str == "while") return true;
if(Str == "for") return true;
if(Str == "do") return true;
bool Is_Operation(string Str)
DBG.ENTER("Is_Operation()");
if(Str == "+") return true;
if(Str == "-") return true;
if(Str == "*") return true;
if(Str == "/") return true;
if(Str == "=") return true;
if(Str == "==") return true;
if(Str == "!=") return true;
if(Str == ">" ) return true;
if(Str == "<" ) return true;
if(Str == ">=") return true;
if(Str == "<=") return true;
bool Is_Identifier(string Str)
DBG.ENTER("Is_Identifier()");
int Str_Len = Str.Length;
for(int i = 0; i < Str_Len; i++)
if(c != '_' && Char.IsLetter(c) == false && Char.IsDigit(c) == false)
bool Is_Number(string Str)
DBG.ENTER("Is_Number()");
bool Is_String(string Str)
DBG.ENTER("Is_String()");