%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Token definitions
#define LT 256
#define LE 257
#define EQ 258
#define NE 259
#define GT 260
#define GE 261
#define RELOP 262
#define ID 263
#define NUM 264
#define IF 265
#define THEN 266
#define ELSE 267
int attribute; // To store relational operator attribute
%}
delim [\t\n ]
ws {delim}+
letter [A-Za-z]
digit [0-9]
id {letter}({letter}|{digit})*
num {digit}+(\.{digit}+)?(E[+-]?{digit}+)?
%%
{ws} { /* Ignore whitespace */ }
if { return(IF); }
then { return(THEN); }
else { return(ELSE); }
{id} { return(ID); }
{num} { return(NUM); }
"<" { attribute = LT; return(RELOP); }
"<=" { attribute = LE; return(RELOP); }
"<>" { attribute = NE; return(RELOP); }
"=" { attribute = EQ; return(RELOP); }
">" { attribute = GT; return(RELOP); }
">=" { attribute = GE; return(RELOP); }
%%
// Default wrap function
int yywrap() {
return 1;
}
// Main function to test the lexer
int main() {
int token;
while ((token = yylex())) {
printf("<%d,", token);
switch (token) {
case ID:
case NUM:
printf("%s>\n", yytext); // Print lexeme for ID and NUM tokens
break;
case RELOP:
printf("%d>\n", attribute); // Print attribute for RELOP tokens
break;
default:
printf(")\n");
break;
}
}
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKLy8gVG9rZW4gZGVmaW5pdGlvbnMKI2RlZmluZSBMVCAyNTYKI2RlZmluZSBMRSAyNTcKI2RlZmluZSBFUSAyNTgKI2RlZmluZSBORSAyNTkKI2RlZmluZSBHVCAyNjAKI2RlZmluZSBHRSAyNjEKI2RlZmluZSBSRUxPUCAyNjIKI2RlZmluZSBJRCAyNjMKI2RlZmluZSBOVU0gMjY0CiNkZWZpbmUgSUYgMjY1CiNkZWZpbmUgVEhFTiAyNjYKI2RlZmluZSBFTFNFIDI2NwoKaW50IGF0dHJpYnV0ZTsgLy8gVG8gc3RvcmUgcmVsYXRpb25hbCBvcGVyYX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