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).
%{
#include<stdio.h>
%}
%%
if|
else|
printf{printf("%s is a keyword",yytext);}
[0-9]+{printf("%s is a number",yytext);}
[a-zA-Z]+{printf("%s is a word",yytext);}
.|\n {ECHO;}
%%
int main(){
printf("Enter the string ");
yylex();
}
int yywrap(){
return 1
}
bGV4X2J5X2ZpbGUoIEZpbGVOYW1lICkgOi0KCWdldF9pbnB1dF9mcm9tX2ZpbGUoIEZpbGVOYW1lLCBUb2tlbkxpc3QgKSwKCWxleCggVG9rZW5MaXN0LCBPdXRwdXRMaXN0ICksCgkld3JpdGVfb3V0cHV0KCBPdXRwdXRMaXN0ICksICEuCgltYXBsaXN0KHdyaXRlbG4sT3V0cHV0TGlzdCksIS4KCiUlIGF0b21fbnVtYmVyKGF0b20sIG51bWJlcikKbGV4KFtdLFtdKS4KbGV4KFsnaW50JyB8IFRdLCBbJ1RZUEU6IGludCcgfCBSXSkgOi0gIGxleChULCBSKS4KbGV4KFsnYm9vbCcgfCBUXSwgWydUWVBFOiBib29sJ10gfCBSKSA6LSBsZXgoVCwgUikuCmxleChbJywnIHwgVF0sIFsnQ09NTUE6ICwnXSB8IFIpIDotIGxleChULCBSKS4KbGV4KFtYIHwgVF0sIFtYIHwgUl0pIDotIGxleChULCBSKS4KJXsKICAjaW5jbHVkZTxzdGRpby5oPgolfQoKJSUKaWZ8CmVsc2V8CnByaW50ZntwcmludGYoIiVzIGlzIGEga2V5d29yZCIseXl0ZXh0KTt9CgpbMC05XSt7cHJpbnRmKCIlcyBpcyBhIG51bWJlciIseXl0ZXh0KTt9ClthLXpBLVpdK3twcmludGYoIiVzIGlzIGEgd29yZCIseXl0ZXh0KTt9Ci58XG4ge0VDSE87fQolJQoKaW50IG1haW4oKXsKICBwcmludGYoIkVudGVyIHRoZSBzdHJpbmcgIik7CiAgeXlsZXgoKTsKfQoKaW50IHl5d3JhcCgpewogIHJldHVybiAxCn0=