Book a Demo

Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Prev Next

Regular Expression Parser

StateMachine for Regular Expression Parser

The Class RegularExpressionParser is defined with one attribute: bMatch.

An Example Regular Expression Parser Class in Sparx Systems Enterprise Architect

A StateMachine is used to describe the regular expression (a|b)*abb

Example Regular Expression in StateMachine in Sparx Systems Enterprise Architect.

  • The transition triggers are specified as events a, b, x and reset
  • On entry to State4, bMatch is set to True; on exit from State4, bMatch is set to False
  • On entry to State5, bMatch is set to False
  • On self transition of State6, bMatch is set to False

Customize index.html and statemachineGUI.js

Make these changes to the generated files:

  • Create an HTML input field and an image to indicate the result
  • Create JavaScript as the field's oninput event handler
  • Create the function 'SetResult' to toggle the pass/fail image
  • Create the function 'getEventStr', which will return 'a' on 'a' and 'b' on 'b', but will return 'x' on any other character
  • On initialize, broadcast 'reset'
  • On the broadcast event, request the runtime variable 'regxParser.bMatch'

In statemachineGUI.js, find the function 'onRuntimeValueResponse'.

  • In 'regxParser.bMatch', we will receive 'True' or 'False' and pass it into 'SetResult' to update the image

The Complete Example

The example can be accessed from the 'Resources' page of the Sparx Systems website, by clicking on this link:

Regular Expression Parser Simulation