unrecognized rule in lex when using ‘|’ (or) regex

I’m making a program that identifies keywords, identifiers, int, float and operators with Lex, but I keep getting errors even though there’s nothing wrong with it. below is my code. (file name is d.l)

In the 6th line, if it is one of several keywords, the keyword is output, so | is used as a regular expression for or.

[_a-zA-Z][_a-zA-Z0-9]{0,30} printf("identifiern");
(if|then|else|end|repeat|read|until|write)  printf("keywordn");
^[-+]?[0-9]*    printf("integern");
^[-+]?[0-9]*[.][0-9]*   printf("floatn");
(+|-|*|/) printf("operator");

when I execute lex d.l , the result is error message:

d.l:6: unrecognized rule

I am learning lex and regular expressions for the first time. Any help would be appreciated.

Read more here: Source link