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. %{
  8. #include <stdio.h>
  9. %}
  10.  
  11. %%
  12. if|else|while|int|switch|for|char { printf("%s : keyword\n", yytext); }
  13. [0-9]+ { printf("%s : number\n", yytext); }
  14. [a-zA-Z_][a-zA-Z0-9_]* { printf("%s : identifier\n", yytext); }
  15. [ \t\n]+ { /* Ignore whitespace */ }
  16. . { printf("%s : invalid\n", yytext); }
  17. %%
  18.  
  19. int main() {
  20. yylex();
  21. return 0;
  22. }
  23.  
  24. int yywrap() {
  25. return 1;
  26. }
  27.  
  28.  
Success #stdin #stdout #stderr 0.02s 6908KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/tXeSv2/prog:8:1: Syntax error: Operator expected
ERROR: /home/tXeSv2/prog:27:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit