%{
/* definitions of manifest constants */
#include <stdio.h>

/* Replacing the "..." with actual definitions for the tokens */
#define LT 256
#define LE 257
#define EQ 258
#define GT 259
#define IF 260
#define THEN 261
#define ELSE 262
#define ID 263
#define NUMBER 264
#define RELOP 265

/* Declare yylval so the lexer can compile without YACC/Bison */
int yylval;

/* Function prototypes */
int install_id(void);
int install_num(void);
%}

delim     [ \t\n]
ws        {delim}+
letter    [A-Za-z]
digit     [0-9]
id        {letter}({letter}|{digit})*
number    {digit}+(\.{digit}+)?(E[+\-]?{digit}+)?

%%

{ws}      { /* no action, ignore whitespace */ }
if        { return IF; }
then      { return THEN; }
else      { return ELSE; }
{id}      { yylval = install_id(); return ID; }
{number}  { yylval = install_num(); return NUMBER; }
"<"       { yylval = LT; return RELOP; }
"<="      { yylval = LE; return RELOP; }
"="       { yylval = EQ; return RELOP; }
">"       { yylval = GT; return RELOP; }

%%

/* Stub for install_id */
int install_id(void) {
    /* Normally, this would install the lexeme into a symbol table 
       and return an index or pointer. We return a dummy value for now. */
    return 1;
}

/* Stub for install_num */
int install_num(void) {
    return 2;
}

/* The wrapper function */
int yywrap(void) {
    return 1;
}

/* Added a main function to test the lexer */
int main(void) {
    int token;
    printf("Ready for input. Type your text (Ctrl+D to exit):\n");
    
    while ((token = yylex())) {
        printf("Token ID: %d", token);
        if (token == RELOP || token == ID || token == NUMBER) {
            printf(" | yylval: %d", yylval);
        }
        printf("\n");
    }
    return 0;
}