Search code examples
flex-lexerlex

Assign a regular expression a variable name and use it in another regular expression


So in flex, I'm trying to assign these:

ID     letterletter*
NUM    digitdigit*
letter [a-zA-Z]
digit  [0-9]

But flex is telling me that the ID and NUM are unrecognized rules. One way to bypass this would be setting ID to [0-9][0-9]*, but I want to use letter and digit.

Is this be possible?


Solution

  • Try this:

    ID     {letter}{letter}*
    NUM    {digit}{digit}*
    letter [a-zA-Z]
    digit  [0-9]
    

    The same goes for ID and NUM, anywhere you use them.