Hello everybody,
I am trying to make a translater-compiler. What it does is translate from my language called
Fexa(F++)(c) to C++ then it is compiled. I created this class for translating but I can't find what's wrong. It stores the word, but then it can't do the if's and there's a bug that it can't jump to the next word in GetWord().
Header File:
#include <stdio.h>
#include <system.hpp>
class Compiler
{
public:
int a; // buffer1's "oponent" index
int b; // CheckCommand exit variable
int c; // buffer3 index
int d; // buffer3 2nd index
int f; // GetBetweenQuotes exit variable
int buffer3[99]; // Place to put the type of word
int return_value1; // CheckWordSequence return value
int return_value2; // CheckCommand return value
FILE *file_handle; // Open file
char buffer1; // Place to put a character
char command[99]; // Command using
char word[99]; // Word using
char between_quotes[99]; // Text between quotes
char return_value3[99]; // CheckCommand return value.
AnsiString sequence; // Word sequence
AnsiString e; // buffer1 2nd index
void GetCommand(AnsiString file_name); // Get a command from the file.
void GetWord(); // Get a word from the command
void GetBetweenQuotes(); // Get text between quotes
void CheckWord(); // Set world type
int CheckCommand(AnsiString file_name); // Function for doing most of the work(the one that the user calls.
int CheckWordSequence(); // Verify word sequence
AnsiString RemoveExt(AnsiString FileName, AnsiString extension); // Takeout file extension(is my spelling right?)
};
Source File(please ignore portuguese comments, they're the same as the header file):
#include "Compiler.h"
//--------------------------------------------------------------------------
int Compiler::CheckCommand(AnsiString file_name) // Função para o usuário fazer tudo
{
GetCommand(file_name);
while(b == 0)
{
GetWord();
CheckWord();
return_value2 = CheckWordSequence();
if(buffer3[c] == 0)
{
b++;
}
}
b = 0;
return (return_value2);
}
//--------------------------------------------------------------------------
void Compiler::GetCommand(AnsiString file_name) // Pegar uma frase de comando
{
file_handle = fopen(file_name.c_str(), "r"
;
while((buffer1 != '.') && (buffer1 != EOF))
{
buffer1 = fgetc(file_handle);
if((buffer1 != '.') || (buffer1 != EOF))
{
command[a] = buffer1;
a++;
}
else
{
break;
}
}
fclose(file_handle);
buffer1 = NULL;
}
//--------------------------------------------------------------------------
void Compiler::GetWord() // Pegar uma palavra de um comando
{
sscanf(command, "%s", word);
}
//--------------------------------------------------------------------------
void Compiler::GetBetweenQuotes() // Pegar texto entre aspas
{
a = 0;
while(f != 1)
{
sscanf(command, "%c", buffer1);
if(buffer1 == '"')
{
while(f != 1)
{
sscanf(command, "%c", buffer1);
if(buffer1 == '"')
{
break;
}
else
{
between_quotes[a] = buffer1;
}
}
break;
}
}
}
//--------------------------------------------------------------------------
void Compiler::CheckWord() // Setar o tipo de palavra
{
/***********************************
1 = Write
2 = on
3 = screen:
***********************************/
if(word == "Write"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
{
buffer3[c] = 1;
}
if(word == "on"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
{
buffer3[c] = 2;
}
if(word == "screen:"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
{
buffer3[c] = 3;
}
while(c > d)
{
e = sequence;
sequence = e + buffer3[d];
d++;
}
c++;
}
//--------------------------------------------------------------------------
int Compiler::CheckWordSequence() // Verificar a sequência de tipo das palavras
{
/**********************
123 = Write on screen:
**********************/
if(sequence == "123"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
{
return_value1 = 1;
}
else
{
return_value1 = 0;
}
return (return_value1);
}
//--------------------------------------------------------------------------
AnsiString Compiler::RemoveExt(AnsiString FileName, AnsiString extension) // Retirar a extensão de arquivo
{
int index = FileName.Pos(extension);
int count = index + 4;
AnsiString Extension = FileName.SubString(index, count);
if(Extension == extension)
{
FileName.Delete(index, count);
}
return (FileName);
}
//--------------------------------------------------------------------------
I am trying to make a translater-compiler. What it does is translate from my language called
Fexa(F++)(c) to C++ then it is compiled. I created this class for translating but I can't find what's wrong. It stores the word, but then it can't do the if's and there's a bug that it can't jump to the next word in GetWord().
Header File:
#include <stdio.h>
#include <system.hpp>
class Compiler
{
public:
int a; // buffer1's "oponent" index
int b; // CheckCommand exit variable
int c; // buffer3 index
int d; // buffer3 2nd index
int f; // GetBetweenQuotes exit variable
int buffer3[99]; // Place to put the type of word
int return_value1; // CheckWordSequence return value
int return_value2; // CheckCommand return value
FILE *file_handle; // Open file
char buffer1; // Place to put a character
char command[99]; // Command using
char word[99]; // Word using
char between_quotes[99]; // Text between quotes
char return_value3[99]; // CheckCommand return value.
AnsiString sequence; // Word sequence
AnsiString e; // buffer1 2nd index
void GetCommand(AnsiString file_name); // Get a command from the file.
void GetWord(); // Get a word from the command
void GetBetweenQuotes(); // Get text between quotes
void CheckWord(); // Set world type
int CheckCommand(AnsiString file_name); // Function for doing most of the work(the one that the user calls.
int CheckWordSequence(); // Verify word sequence
AnsiString RemoveExt(AnsiString FileName, AnsiString extension); // Takeout file extension(is my spelling right?)
};
Source File(please ignore portuguese comments, they're the same as the header file):
#include "Compiler.h"
//--------------------------------------------------------------------------
int Compiler::CheckCommand(AnsiString file_name) // Função para o usuário fazer tudo
{
GetCommand(file_name);
while(b == 0)
{
GetWord();
CheckWord();
return_value2 = CheckWordSequence();
if(buffer3[c] == 0)
{
b++;
}
}
b = 0;
return (return_value2);
}
//--------------------------------------------------------------------------
void Compiler::GetCommand(AnsiString file_name) // Pegar uma frase de comando
{
file_handle = fopen(file_name.c_str(), "r"
while((buffer1 != '.') && (buffer1 != EOF))
{
buffer1 = fgetc(file_handle);
if((buffer1 != '.') || (buffer1 != EOF))
{
command[a] = buffer1;
a++;
}
else
{
break;
}
}
fclose(file_handle);
buffer1 = NULL;
}
//--------------------------------------------------------------------------
void Compiler::GetWord() // Pegar uma palavra de um comando
{
sscanf(command, "%s", word);
}
//--------------------------------------------------------------------------
void Compiler::GetBetweenQuotes() // Pegar texto entre aspas
{
a = 0;
while(f != 1)
{
sscanf(command, "%c", buffer1);
if(buffer1 == '"')
{
while(f != 1)
{
sscanf(command, "%c", buffer1);
if(buffer1 == '"')
{
break;
}
else
{
between_quotes[a] = buffer1;
}
}
break;
}
}
}
//--------------------------------------------------------------------------
void Compiler::CheckWord() // Setar o tipo de palavra
{
/***********************************
1 = Write
2 = on
3 = screen:
***********************************/
if(word == "Write"
{
buffer3[c] = 1;
}
if(word == "on"
{
buffer3[c] = 2;
}
if(word == "screen:"
{
buffer3[c] = 3;
}
while(c > d)
{
e = sequence;
sequence = e + buffer3[d];
d++;
}
c++;
}
//--------------------------------------------------------------------------
int Compiler::CheckWordSequence() // Verificar a sequência de tipo das palavras
{
/**********************
123 = Write on screen:
**********************/
if(sequence == "123"
{
return_value1 = 1;
}
else
{
return_value1 = 0;
}
return (return_value1);
}
//--------------------------------------------------------------------------
AnsiString Compiler::RemoveExt(AnsiString FileName, AnsiString extension) // Retirar a extensão de arquivo
{
int index = FileName.Pos(extension);
int count = index + 4;
AnsiString Extension = FileName.SubString(index, count);
if(Extension == extension)
{
FileName.Delete(index, count);
}
return (FileName);
}
//--------------------------------------------------------------------------