Answer the question
In order to leave comments, you need to log in
How to encode it?
Suppose the data structure to represent a regular expression is as follows
reg_expr := { ‘key’ : ‘atm’, ‘val’ : token}
| {‘key’ : ‘|’, ‘val’ : {‘fst’ : reg_expr, ‘snd’ : reg_expr}}
| {‘key’ : ‘.’, ‘val’ : {‘fst’ : reg_expr, ‘snd’ : reg_expr}}
| {‘key’ : ‘*”, ‘val’ : reg_expr}
Priority of the key is following ‘*’ > ‘.’ > ‘|’
‘*’ is postfix
‘.’ and ‘|’ are left associative
Answer the question
In order to leave comments, you need to log in
reg_expr is not a dictionary, but a grammar that describes an expression.
In Russian, it reads something like:
Regexp - THIS: EITHER
Atom
OR OperatorOr (with two arguments: the first is Regexp; the second is also Regexp)
OR OperatorPoint (with two arguments: the first is Regexp; the second is also Regexp)
OR OperatorAsterisk (with one argument , which is regexp).
Below is an important addition:
Priority of the key is following '*' > '.' > '|'
'*' is postfix
'.' and '|' are left associated
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question