(F)lex provides the possibility to define what are, in effect, macros. The definitions go in the definitions section (before the first %%
) and the simple syntax is described in the flex manual, with eχamples.
So you could write
number [0-9]+|[0-9]+.[0-9]+
sign [+*/-]
%%
{number}{sign}{number}={number} { /* do something */ }
But that would rarely be a good idea, and it is certainly not the intended use of (f)lex. Normally, you would use flex to decompose the input into a sequence of five tokens: a number, an operator, another number, an =
, and a final number. You would use a parser, which repeatedly calls the flex-generated scanner, to construct an object representing the equation (or to verify the equation, if that was the intent.)
If you use the regex proposed in your question, you will almosrt certainly end up rescanning the matched equation in order to extract its components; it is almst always better to avoid the rescan.