%{
#include <stdio.h>
#include "y.tab.h" // Include the header generated by YACC
#include <stdlib.h> // For atof
%}

%%

// Match numbers and return DIGIT token
[0-9]+ {
    yylval.dval = atof(yytext); // Convert string to double
    return DIGIT; // Return DIGIT token
}

// Match newline character
\n {
    return '\n'; // Return newline character
}

// Match any other character and return it
. {
    return yytext[0]; // Return the character itself
}

%%

// Main function to call the parser
int main() {
    return yyparse(); // Start parsing
}

// Error handling function
void yyerror(char *s) {
    fprintf(stderr, "Error: %s\n", s); // Print error message
}