Commit bdc65568 authored by Lartu's avatar Lartu 🐕
Browse files

Cambios en el print, agregado el comando println, arreglada la igualación...

Cambios en el print, agregado el comando println, arreglada la igualación entre strings y comentados los prints de debug
parent ad55471b
No preview for this file type
......@@ -14,6 +14,10 @@ void print(string texto){
cout << texto << endl;
}
void printCont(string texto){
cout << texto;
}
//Convierte de Int a String
string intStr(long long numero){
string neg="";
......@@ -162,9 +166,13 @@ void evaluar(string linea){
if(!comandos.size() > 0) return;
long long pointer = 0;
//Muestra el codigo a evaluar
print("Ready to evaluate:");
/*print("Ready to evaluate:");
while (pointer < comandos.size()){
print("["+intStr(pointer) + "] " + comandos[pointer]);
pointer++;
}*/
//Recupera las tags
while (pointer < comandos.size()){
if(comandos[pointer].substr(0, 4)=="tag:"){
tags.push_back(make_pair(comandos[pointer].substr(4),pointer));
comandos[pointer] = "pass";
......@@ -172,31 +180,46 @@ void evaluar(string linea){
pointer++;
}
//Muestra la lista de tags
if(tags.size()>0){
/*if(tags.size()>0){
print("\nTag list:");
for(int a = 0; a<tags.size();a++){
print("[" + intStr(a) + "] Tag: '"+ tags[a].first + "' -> " + intStr(tags[a].second));
}
}
print("\nEvaluation:");
}*/
//print("\nEvaluation:");
//Aca se realiza la evaluacion
pointer = 0;
while (pointer < comandos.size()){
string com = comandos[pointer];
string arg = "";
bool tieneArg = false;
for(int a=0; a<comandos[pointer].size(); a++){
if(comandos[pointer][a]==':'){
tieneArg = true;
com=comandos[pointer].substr(0, a);
arg=comandos[pointer].substr(a+1);
break;
}
}
if(com == "println"){
if(tieneArg){
print(/*"=> "+*/arg);
}else{
if(stack.size()>0){
print(/*"=> "+*/stack[stack.size()-1]);
stack.pop_back();
}else{
print("Error: Empty Stack on command "+intStr(pointer));
return;
}
}
}
if(com == "print"){
if(arg != ""){
print("=> "+arg);
if(tieneArg){
printCont(/*"=> "+*/arg);
}else{
if(stack.size()>0){
print("=> "+stack[stack.size()-1]);
printCont(/*"=> "+*/stack[stack.size()-1]);
stack.pop_back();
}else{
print("Error: Empty Stack on command "+intStr(pointer));
......@@ -213,7 +236,7 @@ void evaluar(string linea){
}
}
else if(com == "push"){
if(arg!=""){
if(tieneArg){
stack.push_back(arg);
}else{
print("Warning: empty push");
......@@ -345,8 +368,8 @@ void evaluar(string linea){
}
else if(com == "if"){
if(stack.size()>=2){
long long b = strInt(stack[stack.size()-1]);
long long a = strInt(stack[stack.size()-2]);
string b = stack[stack.size()-1];
string a = stack[stack.size()-2];
stack.pop_back();
stack.pop_back();
if(arg=="="){
......@@ -355,36 +378,37 @@ void evaluar(string linea){
else
stack.push_back("0");
}
else if(arg=="!="){
if(a!=b)
stack.push_back("1");
else
stack.push_back("0");
}
else if(arg==">"){
if(a>b)
if(strInt(a)>strInt(b))
stack.push_back("1");
else
stack.push_back("0");
}
else if(arg=="<"){
if(a<b)
if(strInt(a)<strInt(b))
stack.push_back("1");
else
stack.push_back("0");
}
else if(arg==">="){
if(a>=b)
if(strInt(a)>=strInt(b))
stack.push_back("1");
else
stack.push_back("0");
}
else if(arg=="<="){
if(a<=b)
if(strInt(a)<=strInt(b))
stack.push_back("1");
else
stack.push_back("0");
}
else if(arg=="!="){
if(a!=b)
stack.push_back("1");
else
stack.push_back("0");
}else{
else{
print("Error: unknown comparison" + arg+ " on command "+intStr(pointer));
return;
}
......@@ -467,8 +491,7 @@ void evaluar(string linea){
}
else if(com == "input"){
string input;
cout << "? ";
cin >> input;
getline(cin, input);
stack.push_back(input);
}
else if(com == "aux"){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment