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.  
  14. %{
  15. #include<stdio.h>
  16. int cnt = 0;
  17. %}
  18. %%
  19. [aA] {cnt++;}
  20. [\n] {/* ignore new line */}
  21. . {/* ignore all other characters */}
  22. %%
  23. int yywrap() {
  24. return 1;
  25. }
  26. int main() {
  27. printf("Enter text : ");
  28. yylex();
  29. printf("Number of a or A : %d\n",cnt);
  30. return 0;
  31. }
  32.  
Success #stdin #stdout #stderr 0.03s 6936KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/gyxomJ/prog:15:1: Syntax error: Operator expected
ERROR: /home/gyxomJ/prog:31:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit