Skip to content

The repository contains a Flutter application allows parse an arithmetic expression into tokens. The parser is based on the use of HSM - hierarchical state machine.

Notifications You must be signed in to change notification settings

mk590901/parser-hsm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parser-HSM

The application demonstrates the work of a lexical parser based on a hierarchical state machine.

Introduction

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.

State Machine

Below is the parser's hierarchical state machine, implement the processing of the source arithmetic expression and extract lexemes (tokens).

hsm

Implementation HSM

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.

Description of application

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

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.

Movie

parser_hsm.mp4

Updates

The application has been modified and supplemented

Asynchronous processing of events.

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.

Transformation of an infix expression into a postfix one

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.

Latest Movie

parser.mp4

About

The repository contains a Flutter application allows parse an arithmetic expression into tokens. The parser is based on the use of HSM - hierarchical state machine.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages