Translates infix formulas into MathML and vice-versa.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 1024
char *translateInfix (const char *formula);
char *translateMathML (const char *xml);
int
main (int argc, char* argv[])
{
char line[BUFFER_SIZE];
char* trimmed;
char* result;
char* str;
size_t len;
StringBuffer_t* sb = StringBuffer_create(1024);
cout << endl
<< "This program translates infix formulas into MathML and" << endl
<< "vice-versa. Enter or return on an empty line triggers" << endl
<< "translation. Ctrl-C quits" << endl
<< endl;
while (1)
{
cout << "Enter infix formula or MathML expression (Ctrl-C to quit):"
<< endl << endl;
cout << "> " ;
cin.getline(line, BUFFER_SIZE, '\n');
while (line != 0)
{
trimmed = util_trim(line);
len = strlen(trimmed);
if (len > 0)
{
StringBuffer_append (sb, trimmed);
StringBuffer_appendChar(sb, '\n');
}
else
{
str = StringBuffer_getBuffer(sb);
result = (str[0] == '<') ? translateMathML(str) : translateInfix(str);
if (result==NULL) {
cout << "Unable to parse string." << endl;
}
else {
cout << "Result:" << endl << endl << result << endl << endl << endl;
}
StringBuffer_reset(sb);
break;
}
cin.getline(line, BUFFER_SIZE, '\n');
}
}
StringBuffer_free(sb);
return 0;
}
char *
translateInfix (const char* formula)
{
char* result;
ASTNode_free(math);
return result;
}
char *
translateMathML (const char* xml)
{
char* result;
ASTNode_free(math);
return result;
}