The Definition section consists of a sequence of Names, each
followed by an Expression to be given that name.
Definitions (Gives names to sequences of characters)
%%
Rules (Defines tokens. Class may be returned as a #)
%%
User-Written Procedures (In C)
The Rules consist of a sequence of regular expressions, each followed by an (optional) action which returns a number for that regular expression and performs other actions if desired, such as installing the characters in the token into a name table.
The User-Written Procedures are the code for the C functions invokes as actions in the rules. Thus, the form for each section is:
C function1
A section may be empty, but the "%%" is still needed.
Name1 Expression1
Name1 Expression1
...
%%
RegExp1 {Action1}
RegExp2 {Action2}
...
%%
C function2
...
Like UNIX itself, the metalanguage is case-sensitive, that is, "A" and "a" are read as different characters.
Example 4 shows a LEX description for our language consisting of assignment statements. There are other ways of expressing the tokens described here.