I'm learning Automaton Theory and facing some difficulties for converting a RE directly to DFA. This method requires to create syntax tree from the RE. But i am not able to generate.
I am given a regular expression e.g a*b*(a|b)abc
Now i want to generate a syntax tree from this. I don't want program for it but i want to do it manually. Can anyone help me?
You need to figure out what are the operations represented by this expression, in which order they apply, and what are their operands.
For instance
a*
means: "apply the*
operator toa
". In the expression tree, you'd get a node for the star operator, and ana
node for the symbol the operator acts upon.Similarly, the
|
denotes an alternation, so it would be a node in the tree, and the child nodes would be the subexpressions of the alternation.The top-level operation is simply a concatenation, that would be your root node.
Here's the full AST derived from these rules:
EDIT: You asked for a binary tree, the transformation should be straightforward. I'll leave both trees so you can figure it out:
Note that the above tree uses a left-associative concatenation operator.