csssaz / compilers_project

0 stars 0 forks source link

regex matcher #6

Closed csssaz closed 7 years ago

csssaz commented 7 years ago

This adds a class that matches regular expressions constructing an NFA and simulating it.

The basic idea is to transform the regex to "postfix" form which is equivalent to parsing and constructing the syntax tree for it. Once it's on postfix, you can process it left to right keeping a stack with the current NFAs built and when encountering an operator, proceed with the corresponding construction popping the needed operands from the stack (maybe just one in the case of kleene star, for example). To simplify stuff I just maintained a list of states and the stack contains the index of the initial and accepting state.

The simulation is then pretty simple just following the algorithm in the book.

Stuff missing: