Complete the code to specify the section where definitions are placed in a Lex/Flex file.
%[1]%The definitions section in a Lex/Flex file is where you define macros and patterns used later in the rules section.
Complete the code to write a rule that matches the word 'if' in Lex/Flex.
"[1]" { return IF; }
In Lex/Flex, rules are written as patterns in quotes. To match the keyword if, you write it as "if".
Fix the error in the Lex/Flex rule to correctly match an identifier (a letter followed by letters or digits).
[1] { return IDENTIFIER; }
The correct pattern for an identifier is a letter followed by zero or more letters or digits, written as [a-zA-Z][a-zA-Z0-9]*.
Fill both blanks to create a rule that matches whitespace characters and ignores them.
[1] { [2]; }
The pattern [ \t\n]+ matches one or more whitespace characters (space, tab, newline). The action /* skip */ indicates to ignore these characters.
Fill all three blanks to define a Lex/Flex rule that matches a number and converts it to an integer.
"[1]" { yylval = atoi(yytext); return [2]; [3] }
The pattern [0-9]+ matches one or more digits. The action converts the matched text to an integer using atoi, returns the token NUMBER, and includes a comment for clarity.