fork download
  1. lex_by_file( FileName ) :-
  2. get_input_from_file( FileName, TokenList ),
  3. lex( TokenList, OutputList ),
  4. %write_output( OutputList ), !.
  5. maplist(writeln,OutputList),!.
  6.  
  7. %% atom_number(atom, number)
  8. lex([],[]).
  9. lex(['int' | T], ['TYPE: int' | R]) :- lex(T, R).
  10. lex(['bool' | T], ['TYPE: bool'] | R) :- lex(T, R).
  11. lex([',' | T], ['COMMA: ,'] | R) :- lex(T, R).
  12. lex([X | T], [X | R]) :- lex(T, R).
  13.  
Success #stdin #stdout #stderr 0.12s 7424KB
stdin
LETTER [a-zA-Z]
DIGIT [0-9]
%%
begin {printf("Recognized KeyWORD:%s\n",yytext);}
if    {printf("Recognized KeyWORD:%s\n",yytext);}
{LETTER}({LETTER}|{DIGIT})*{
           printf("Recognized ID:%s\n",yytext);}
%%
main()
{
yylex();
}
stdout

	
stderr
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: toplevel: procedure `program' does not exist (DWIM could not correct goal)
   Exception: (3) program ?    Exception: (3)  ? ERROR: program/0: stream `debugger_write_options' does not exist
   Exception: (3)  ? % Break level 1

ERROR: Stream user_input:15:0 Syntax error: Unexpected end of file
% Exit break level 1
   Exception: (3)  ? EOF: exit