fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. float a=0.0, b=0.0, c=0.0;
  5. %}
  6.  
  7. %%
  8.  
  9. "int"|"void"|"float" { printf("Data Type: %s\n", yytext); } /* Identifies data types */
  10. [a-zA-Z][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); } /* Identifies identifiers */
  11. [0-9]+ { printf("Constant: %s\n", yytext); } /* Identifies integer constants */
  12. [0-9]+"."[0-9]+ { printf("Constant: %s\n", yytext); } /* Identifies float constants */
  13. "+" { printf("Addition Operator\n"); } /* Identifies addition operator */
  14. "=" { printf("Assignment Operator\n"); } /* Identifies assignment operator */
  15. "printf" { printf("Print Statement\n"); } /* Identifies printf statement */
  16. "return" { printf("Return Statement\n"); } /* Identifies return statement */
  17. "(" { printf("Opening Parenthesis\n"); } /* Identifies opening parenthesis */
  18. ")" { printf("Closing Parenthesis\n"); } /* Identifies closing parenthesis */
  19. ";" { printf("Semicolon\n"); } /* Identifies semicolon */
  20.  
  21. . {} /* Ignores characters not matched by any rule */
  22.  
  23. %%
  24.  
  25. int main (void) {
  26. yylex();
  27. return (0);
  28. }
Success #stdin #stdout #stderr 0.02s 6852KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/CF6SGG/prog:2:1: Syntax error: Operator expected
ERROR: /home/CF6SGG/prog:28:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit