⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arquivofonte.cpp

📁 "tiny" language interpreter written in java
💻 CPP
字号:
/*
TP2 LP INTERPRETADOR TINY
ALUNO : ANDRE LUIS DURAO ABDO
MATRICULA : 283999
DATA DA ENTREGA : 10/05/2007
*/ 

//ArquivoFonte.cpp
#include "ArquivoFonte.h"
ifstream is;
bool em_string=false;
ArquivoFonte::ArquivoFonte(const string & str){
    is.open(str.data());
    getline(is,linha);
    st=new StringTokenizer(linha,":+-*/()=<>' ");
    //teste para ver se arquivo esta abrindo
    //e gerando as tokens corretamente
    /*cout << linha;    
    while (st->hasMoreTokens())
        cout << "\ntoken == [" << st->nextToken()<<"]";*/
}

//implementar proximaPalavra
string ArquivoFonte::proximaPalavra(){


    if (st->hasMoreTokens()) {
        //caso esteja dentro de uma string
        if (em_string){
            string s="";
            string tmp=st->nextToken();
            //caso nao seja apostrofo para terminar a string
            if (tmp!="'"){
                while (tmp!="'"){
                    s+=tmp;                
                    tmp=st->nextToken();
                }//while
                st->previousToken();//alterado para voltar uma posicao de modo que nao perca os caracteres
                return s;
            }//if (tmp!="'")
            else{//caso apostrofo apareca para terminar a string
                em_string= !em_string;                    
                return tmp;
            }
        }//if
        else{
            string s= st->nextToken();
            //caso apostrofo        
            if (s=="'"){
                em_string= !em_string;        
                return s;
            }//if
            else{
                if (s==" ")
                    return proximaPalavra();
                else
                    return s;            
            }
        }//else
    }//if (st->hasMoreTokens())
    else{
        if (!is.eof()){
            getline(is,linha);
            if (linha!="")
                st=new StringTokenizer(linha,":+-*/()=<>' ");            
            return proximaPalavra();
        }//if
        else
            return "EOF";
    }//else    
}
//implementar saltaPalavra
void ArquivoFonte::saltaPalavra(){
    string saida =  ArquivoFonte::proximaPalavra();
}
//lista todas as palavras chave do arq
void ArquivoFonte::listaPalavras(){
    string s = proximaPalavra();
    while(s!="EOF"){
        cout <<"\n["<<s<<"]";
        s = proximaPalavra();
    }    
}
//lista arquivo
void ArquivoFonte::listaArquivo(){
    while(!is.eof()){
        cout <<"\n"<<linha;
        getline(is,linha);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -