%{
#include <stdio.h>
#include <stdlib.h>
// Declare functions
int yylex(void);
void yyerror(const char *s);
%}
%option noyywrap // Disable the default wrapping behavior for LEX
// Definitions section
DIGIT [0-9]
LETTER [a-zA-Z]
// Rules section
%%
"+" { printf("Operator: +\n"); }
"-" { printf("Operator: -\n"); }
"*" { printf("Operator: *\n"); }
"/" { printf("Operator: /\n"); }
"(" { printf("Parenthesis: (\n"); }
")" { printf("Parenthesis: )\n"); }
[ \t\n]+ { /* Skip whitespace */ }
. { printf("Unknown: %s\n", yytext); }
%%
// User Code section
int main() {
yylex(); // Start lexical analysis
return 0;
}
void yyerror(const char *s) {
fprintf(stderr, "Error: %s\n", s);
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCi8vIERlY2xhcmUgZnVuY3Rpb25zCmludCB5eWxleCh2b2lkKTsKdm9pZCB5eWVycm9yKGNvbnN0IGNoYXIgKnMpOwolfQoKJW9wdGlvbiBub3l5d3JhcCAgIC8vIERpc2FibGUgdGhlIGRlZmF1bHQgd3JhcHBpbmcgYmVoYXZpb3IgZm9yIExFWAoKLy8gRGVmaW5pdGlvbnMgc2VjdGlvbgpESUdJVCBbMC05XQpMRVRURVIgW2EtekEtWl0KTlVNQkVSIHtESUdJVH0rICAvLyBNYXRjaGVzIGFueSBpbnRlZ2VyIG51bWJlcgoKLy8gUnVsZXMgc2VjdGlvbgolJQoiKyIgICAgICAgICAgICAgeyBwcmludGYoIk9wZXJhdG9yOiArXG4iKTsgfQoiLSIgICAgICAgICAgICAgeyBwcmludGYoIk9wZXJhdG9yOiAtXG4iKTsgfQoiKiIgICAgICAgICAgICAgeyBwcmludGYoIk9wZXJhdG9yOiAqXG4iKTsgfQoiLyIgICAgICAgICAgICAgeyBwcmludGYoIk9wZXJhdG9yOiAvXG4iKTsgfQoiKCIgICAgICAgICAgICAgeyBwcmludGYoIlBhcmVudGhlc2lzOiAoXG4iKTsgfQoiKSIgICAgICAgICAgICAg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