Am 11.03.2012 05:27, schrieb Bharath M R:
@Sergiu I was looking at top down operator precedence parsing for the task

That's the technique where the grammar requires the least contortions.
It also composes well: you can define sublanguages (such as arithmetic and boolean logic), and as long as their operator sets do not overlap, you can combine them without any problems.

It is a bit restricted in what classes of languages it can handle.
Parsing a*-b is not possible but can be enabled using a hack.
I don't know how to parse http://en.wikipedia.org/wiki/Bra-ket_notation using operator precedence.

(http://javascript.crockford.com/tdop/tdop.html) .

Crockford is very wrong that operator-precedence parsing is in any way connected to dynamic languages.

In general, he's not exposing principles but presenting a recipe. I don't think that's easy to transfer to Python code.

> One of the important task is to
come up with the grammar.

Not for operator-precedence grammars!
You need:
- a list of precedence levels,
- for each level:
  - the list of operators
  - whether it's left, right, or non-associative
- a list of left and right parentheses

The problem with unary minus is that it has a different precedence than binary minus. The standard approach is to let the tokenizer detect multiple operator symbols in a row, and emit a different pseudo-minus token whenever it isn't the first. I'm pretty sure I could whip up a systematic approach that would cover more operators and hold up in the presence of postfix operators, but I don't know whether that's even relevant in SymPy. (The only postfix operator in widespread use I know about is !, and that isn't used as an infix operator.)

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

Reply via email to