mkpro118 / Regex-Engine

Regex Engine in C
MIT License
0 stars 0 forks source link

Develop the Parser #6

Closed mkpro118 closed 2 months ago

mkpro118 commented 3 months ago

The parser will convert the tokens into an abstract syntax tree (AST). The AST represents the hierarchical structure of the regular expression.

We will define the grammar for the parser as

terminal ::  CHAR := Any printable ASCII character except the terminals below.
terminal ::  OR := |
terminal ::  STAR := *
terminal ::  PLUS := +
terminal ::  QUESTION := ?
terminal ::  LPAREN := (
terminal ::  RPAREN := )

non terminal  ::  op ->   STAR  |  PLUS  |  QUESTION | epsilon (ε)

non terminal  ::  expr -> term | term OR term

non terminal  ::  term -> factor factor

non terminal  ::  factor ->   base op  | epsilon (ε)

non terminal  ::  base ->   CHAR  |  LPAREN expr RPAREN