Wednesday, November 08, 2006

Post-Fix Procedure

Well, First : For each number, we have to stack in a temp numeric-stack variable, the same procedure is performed in the operator-stack variable.

If the length of operator-stack variable exceeds numbe ones, we can infer is bad formed he post-fix expression.

Finally for Evaluating both stacks, we get First and second -node on stack-number variable and we evaluate with the first node operator-stack.

Voila!


Este es el primer protitpo para el diseño de gramaticas Evolutivas, mas adelante estaré publicando la parte inicial del articulo, para que me revisen, una vez desarrollado el articulo, lo publicare en mis lexemas y lo intentare enviar como papper a una revista.

En la grafica se muestra una gramatica sesgada por las condiciones iniciales de la evolucion que genera la palabra 'fabio'.

la aplicacion esta disponible aqui (relased 1)

Tuesday, November 07, 2006

 Posted by Picasa

Evaluador Post Fijo

// Fabio Andres Palmieri Villa
// fabioandresp.blogspot.com
// Puede ser usado solamente con fines academicos
// si es respetado este encabezado
 
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>

#define TRUE 1
#define FALSE 0


#include "function.h"

#include "nodeInt.h"
#include "nodeOp.h"




int main(){
clrscr();

char * expr = "1111+++";

nodeInt* number = 0;
nodeChar* operators = 0;

int n = strlen(expr);
int i = 0;
int correct = TRUE;

while( (i<n) && (correct==TRUE) ) {
cout<<endl<<"Current Symbol : "<<expr[i]<<endl;

if ( isNumeric(expr[i]) ){
// stack each number
number = stack(number,Convert(expr[i])) ;
}else{
if ( isOperator(expr[i])) {
// stack each operator
operators = stack(operators,expr[i]);
}else{
cout<<"Error!";
}
}

cout<<"Stack Numbers: ";
View(number);
cout<<"Stack Operators: ";
View(operators);

cout<<endl<<"Size
#op="<<size(operators)<<"\t#nums="<<size(number)<<endl;

if ( (size(operators)>=size(number)) ){
correct = FALSE;
};

i = i + 1;
}

if (correct==TRUE && ( size(number)-size(operators)==1 ) ){
if (size(number)==1){
cout<<"Resultado=="<<number->n;
getch();
exit(0);
}

cout<<"Expression is formed correctly"<<endl<<endl<<endl;
int a = 0;
int b = 0;
char c = 0;
int resp = 0;
int TODO = TRUE;

while( TODO ){
cout<<"Stack Numbers: ";
View(number);
cout<<"Stack Operators: ";
View(operators);

if (size(number)==2 && size(operators)==1){
TODO = FALSE;
//has been found the terminal expression numb,numb,op
}

a = gethead(number);
b = gethead(number);
c = gethead(operators);
resp = calc(a,b,c);

cout<<a<<c<<b<<endl;
addlast(number, resp );
getch();
};

cout<<endl<<"Resultado = "<<resp;

}else{
cout<<"Incorrect Expression";
}

getch();
return 0;
}