Am 14.03.2012 09:43, schrieb Bharath M R:
I am a complete noob here. But if we are trying to implement wide array of
syntaxes,
can't we write separate parsers for each of them and combine them with a
try exception statements
Say we have a latex input .
Then
try:
     sympify(input)
except InterpretationError:
     try:
         mathematica(input)
except InterpretationError:
    try:
          latex(input)
  except InterpretationError:
       throw Exception("Not interpreted")

Something like the above. This might help us to divide the task of writing
a parser and also the need make the parser universal and hence can
reduce the complexity of the parser.

Technical detail: Parsers don't necessarily throw an exception if the fail to parse, they might return Null instead of a parse tree if there is an error, or return a data structure with a status flag set.

But, yes, it would be possible to try each syntax and see which of them gives a useful result.

Maybe it's even useless to assume that a LaTex formula may contain a Maple-syntax subformula. What's the use cases that we want to support here? (We could be in for serious trouble anyway if we allow mixing syntaxes within the same formula. For example, square brackets might have different interpretations depending on whether it's interpreted as LaTeX, SymPy, or Mathematica.)

However, I would not stick with the first syntax that gives a match. It's entirely possible that two different syntaxes give a valid parse. So: try all syntaxes. Check if they give the same abstract syntax (logical structure, if you will). If they give different interpretations, alert the user to the fact and ask which interpretation is what he meant.

Just food for thought.

--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to