lex_by_file( FileName ) :-
get_input_from_file( FileName, TokenList ),
lex( TokenList, OutputList ),
%write_output( OutputList ), !.
maplist(writeln,OutputList),!.
%% atom_number(atom, number)
lex([],[]).
lex(['int' | T], ['TYPE: int' | R]) :- lex(T, R).
lex(['bool' | T], ['TYPE: bool'] | R) :- lex(T, R).
lex([',' | T], ['COMMA: ,'] | R) :- lex(T, R).
lex([X | T], [X | R]) :- lex(T, R).
bGV4X2J5X2ZpbGUoIEZpbGVOYW1lICkgOi0KCWdldF9pbnB1dF9mcm9tX2ZpbGUoIEZpbGVOYW1lLCBUb2tlbkxpc3QgKSwKCWxleCggVG9rZW5MaXN0LCBPdXRwdXRMaXN0ICksCgkld3JpdGVfb3V0cHV0KCBPdXRwdXRMaXN0ICksICEuCgltYXBsaXN0KHdyaXRlbG4sT3V0cHV0TGlzdCksIS4KCiUlIGF0b21fbnVtYmVyKGF0b20sIG51bWJlcikKbGV4KFtdLFtdKS4KbGV4KFsnaW50JyB8IFRdLCBbJ1RZUEU6IGludCcgfCBSXSkgOi0gIGxleChULCBSKS4KbGV4KFsnYm9vbCcgfCBUXSwgWydUWVBFOiBib29sJ10gfCBSKSA6LSBsZXgoVCwgUikuCmxleChbJywnIHwgVF0sIFsnQ09NTUE6ICwnXSB8IFIpIDotIGxleChULCBSKS4KbGV4KFtYIHwgVF0sIFtYIHwgUl0pIDotIGxleChULCBSKS4K
CiV7IAojaW5jbHVkZSAmbHQ7c3RkaW8uaCZndDsgCiNpbmNsdWRlICZsdDtjdHlwZS5oJmd0OyAKdm9pZCBwcmludF90b2tlbihjb25zdCBjaGFyICp0b2tlbl90eXBlLCBjb25zdCBjaGFyICp2YWx1ZSk7IAolfSAKJSUgCiZxdW90O2ludCZxdW90O3wmcXVvdDtmbG9hdCZxdW90O3wmcXVvdDtyZXR1cm4mcXVvdDsge3ByaW50X3Rva2VuKCZxdW90O0tFWVdPUkQmcXVvdDssIHl5dGV4dCk7fSAKW2EtekEtWl9dW2EtekEtWjAtOV9dKiB7cHJpbnRfdG9rZW4oJnF1b3Q7SURFTlRJRklFUiZxdW90OywgeXl0ZXh0KTt9IApbMC05XSsge3ByaW50X3Rva2VuKCZxdW90O05VTUJFUiZxdW90OywgeXl0ZXh0KTt9IAomcXVvdDsrJnF1b3Q7fCZxdW90Oy0mcXVvdDt8JnF1b3Q7KiZxdW90O3wmcXVvdDsvJnF1b3Q7IHtwcmludF90b2tlbigmcXVvdDtPUEVSQVRPUiZxdW90OywgeXl0ZXh0KTt9IAomcXVvdDsoJnF1b3Q7IHtwcmludF90b2tlbigmcXVvdDtMRUZUX1BBUkVOJnF1b3Q7LCB5eXRleHQpO30gCiZxdW90OykmcXVvdDsge3ByaW50X3Rva2VuKCZxdW90O1JJR0hUX1BBUkVOJnF1b3Q7LCB5eXRleHQpO30gCiZxdW90OzsmcXVvdDsge3ByaW50X3Rva2VuKCZxdW90O1NFTUlDT0xPTiZxdW90OywgeXl0ZXh0KTt9IApbIFx0XG5dKzsgCi57cHJpbnRfdG9rZW4oJnF1b3Q7VU5LTk9XTiZxdW90OywgeXl0ZXh0KTt9IAolJSAKdm9pZCBwcmludF90b2tlbihjb25zdCBjaGFyICp0b2tlbl90eXBlLCBjb25zdCBjaGFyICp2YWx1ZSkgeyAKcHJpbnRmKCZxdW90O1Rva2VuOiAlLTEycyBWYWx1ZTogJXNcbiZxdW90OywgdG9rZW5fdHlwZSwgdmFsdWUpOyAKfSAKaW50IG1haW4oKSB7IAp5eWxleCgpOw==
%{
#include <stdio.h>
#include <ctype.h>
void print_token(const char *token_type, const char *value);
%}
%%
"int"|"float"|"return" {print_token("KEYWORD", yytext);}
[a-zA-Z_][a-zA-Z0-9_]* {print_token("IDENTIFIER", yytext);}
[0-9]+ {print_token("NUMBER", yytext);}
"+"|"-"|"*"|"/" {print_token("OPERATOR", yytext);}
"(" {print_token("LEFT_PAREN", yytext);}
")" {print_token("RIGHT_PAREN", yytext);}
";" {print_token("SEMICOLON", yytext);}
[ \t\n]+;
.{print_token("UNKNOWN", yytext);}
%%
void print_token(const char *token_type, const char *value) {
printf("Token: %-12s Value: %s\n", token_type, value);
}
int main() {
yylex();