0

I’m trying to make a lexical parser to compute all solutions given a EBNF term. For example:

Grammar:

T::= nil | A.T | (T+T) | (T*T)

A::= a | b | c | d | e

Operators:

* Exclusive OR

. Sequence

+ Parallel

Symbols:

a b c d e

Example term:

a.(b+c).(d*e)

Computed term:

Computed term

Expected tree output:

Solution tree

The solution should be all tree branches.

My question is that which will a optimal approach for doing this?

For now i want to user ANTRL to build the grammar parse tree.

But im not very sure on how to make the refactor approach to compute the term.

Thanks!

ccamacho
  • 707
  • 8
  • 22

1 Answers1

0

After a lot of reading and researching on how to solve this problem, I realized that this situation is pretty much similar to a finite state machine, and there are a lot of software design patterns to deal with the solution.

So forth the update will be. Define the algorithm as a finite state machine using one of these models

Python finite state machine

Now, the next step will be on how to process each state as a parse tree (Ill try to use ANTLR), to get the next possible states.

So forth, does anyone know which would be an optimal solution to parse and process a term like a EBNF expression? i.e. using ANTLR?

Cheers.

ccamacho
  • 707
  • 8
  • 22