How to control reading txt file

Asked

Viewed 37 times

0

I have the following entry in a file .txt:

var a;
var b; var c;
a = (10+2)/2;
b = a*2;
c = a*b;
print a; print b; print c;

Where the getToken() function will return me the current token, containing the type and its value. For example:

1st call of the method getToken(): will return an object of the type Token, containing cuss and var

2nd call of the method getToken(): will return an object of the type Token, containing ID and to

3rd call of the method getToken(): will return an object of the type Token, containing delimiter and ;

and so on.

That is, I need to analyze the file in such a way that it is possible to control where I took the last token. The code below is unviable, because I can’t control which part of the file I captured the last symbol:

if(entrada.is_open()){
    while(getline(entrada, linha)){
        int tam_linha = linha.size();
        for(int i=0; i<=tam_linha-1; i++){
        }
    }
}

So, how do I call the function getToken(), the file is read in a "interrupt" way and return me the next symbol?

Appendix:

inserir a descrição da imagem aqui

  • Don’t do this. Read the file and analyze later.

  • How would this reading be done? Would I have to store all input in some vector or something? @Maniero

  • It may be in vector one string even.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.