Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can somebody help me with this code?

Status
Not open for further replies.

jvff

Programmer
Apr 1, 2001
64
BR
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 &quot;oponent&quot; 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 &quot;Compiler.h&quot;
//--------------------------------------------------------------------------
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(), &quot;r&quot;);
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, &quot;%s&quot;, word);
}
//--------------------------------------------------------------------------
void Compiler::GetBetweenQuotes() // Pegar texto entre aspas
{
a = 0;
while(f != 1)
{
sscanf(command, &quot;%c&quot;, buffer1);
if(buffer1 == '&quot;')
{
while(f != 1)
{
sscanf(command, &quot;%c&quot;, buffer1);
if(buffer1 == '&quot;')
{
break;
}
else
{
between_quotes[a] = buffer1;
}
}
break;
}
}
}
//--------------------------------------------------------------------------
void Compiler::CheckWord() // Setar o tipo de palavra
{
/***********************************
1 = Write
2 = on
3 = screen:
***********************************/
if(word == &quot;Write&quot;)
{
buffer3[c] = 1;
}
if(word == &quot;on&quot;)
{
buffer3[c] = 2;
}
if(word == &quot;screen:&quot;)
{
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 == &quot;123&quot;)
{
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);
}
//--------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top