2

I wrote a CYK parser, and I use it to parse math expressions like (1+2)/3-4^5. I also wrote a code that builds parse-tree from the table (left triangular matrix) that CYK algorithm provides, using the grammar below. My question would be that is it possible to build an expression tree (which inner nodes are operations and leafs are numbers) directly from my parse tree? The grammar (CYK requires Chomsky normal form) I used for parsing is the following:

start symbol: A

A -> [N(,B], B -> [A,N)], A -> [A,C]

C -> [N+,A], C -> [N-,A], C -> [N/,A]

C -> [N*,A], C -> [N^,A], N+ -> +

N- -> - , N/ -> / , N* -> *

N^ -> ^ , N( -> ( , N) -> ) 

A -> number
PaulMcG
  • 62,419
  • 16
  • 94
  • 130
losleon
  • 21
  • 2

0 Answers0