I am working on a lexer. I need to identify patterns in BNF and specify them using Regular expressions. I know there are TOKENS e.g. keywords, identifiers, operators etc. So far I have defined Regular expressions:
digit=[0-9]
integer={digit}+
letter=[a-zA-Z]
But the given BNF rule for Identifier is:
< id > ::= < letter >
| "_"
| < id > < digit >
| < id > < letter >
Since the <id> is defined by Recursive pattern, how can I express this pattern using Regular expression.
I tried this Regular expression: id={letter}+|"_"|{id}{digit}+
for the above BNF rule but it is giving me error that Regular expression contains cycle.