Translates infix formulas into MathML and vice-versa.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 1024
using namespace std;
LIBSBML_CPP_NAMESPACE_USE
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;
do
{
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');
}
} while (line != 0);
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;
}
ASTNode_t * readMathMLFromString(const char *xml)
Reads the MathML from the given XML string, constructs a corresponding abstract syntax tree,...
Definition: MathML.cpp:2273
char * writeMathMLToString(const ASTNode *node)
Definition: MathML.cpp:2428
Include all SBML types in a single header file.
Definition: ASTNode.h:221
class ASTNode ASTNode_t
Definition: sbmlfwd.h:269