The application demonstrates the work of a lexical parser based on a hierarchical state machine.
A hierarchical state machine allows one to simplify the number of operations on text during lexical parsing of an arithmetic expression and replace the logic of lexeme detection by transitions from state to state under the action of events.
Below is the parser's hierarchical state machine, implement the processing of the source arithmetic expression and extract lexemes (tokens).
ParserHelper is a set of transfer functions of the hierarchical state machine shown in the diagram above. This class is generated automatically by the HSM editor and developer only needs to comment out unnecessary transitions and add links to the parser functions inside the significant functions. By the way, the parser used is a copy of the parser controller from the (https://github.com/mk590901/parser-fsm) project.
The application is a Flutter app with a predefined set of arithmetic expressions. They can be selected using a combo box and parsed by pressing the parse button. The result of parsing is a list of tokens indicating the type and classification.
Note. The two applications Parser HSM and Parser FSM (https://github.com/mk590901/parser-fsm) are made in the same style and from the GUI point of view are twin brothers. That is, they completely coincide except for the engine used. In fact, the main goal of these projects was the idea to show that the same tasks can be solved with both FSM and HSM. What exactly to choose is a matter of taste and sympathy of the developer.
parser_hsm.mp4
The application has been modified and supplemented
The previous method synchronous processing of threaded code was replaced by of asynchronous processing inside Runner class. This allowed solving the problem of hidden recursion when calling functions. The StreamController class implements the mechanism of posting of events via the add event operation and processing this event in the listener, which listens for changes of StreamController.
Actually, parsing, implemented using HSM, represented by threaded code, was the purpose of the application. But now I decided to supplement parsing with the operation of transforming an infix expression into a postfix one, or into "Polish" notation. This is not the pure Shunting Yard Algorithm [https://en.m.wikipedia.org/wiki/Shunting_yard_algorithm#:~:text=In%20computer%20science%2C%20the%20shunting,abstract%20syntax%20tree%20(AST)], but some modified version of it that allows detecting some errors.
