fork download
  1. %{
  2.  
  3. #include <stdio.h>
  4.  
  5. %}
  6.  
  7. %%
  8.  
  9. (\"\%d\")|(\"\%c\")|(\"\%s\") {printf("%s is a FORMAT SPECIFIER.\n", yytext);}
  10. \"(\\.|[^\\"])*\" {printf("%s is a STRING LITERAL.\n", yytext);}
  11. "++"|"--" {printf("%s is a UNARY OPERATOR.\n", yytext);}
  12. ("|")|("&")|("~")|("^") {printf("%s is a BITWISE OPERATOR.\n", yytext);}
  13. ("=")|("+")|("-")|("/") {printf("%s is an ARITHMETIC OPERATOR.\n", yytext);}
  14. "<"|"<="|">="|">" {printf("%s is a RELATIONAL OPERATOR.\n", yytext);}
  15. "&&"|"||"|"!" {printf("%s is a LOGICAL OPERATOR.\n", yytext);}
  16. "{" {printf("%s is OPENING CURLY BRACE.\n", yytext);}
  17. "}" {printf("%s is CLOSING CURLY BRACE.\n", yytext);}
  18. "(" {printf("%s is OPENING BRACE.\n", yytext);}
  19. ")" {printf("%s is CLOSING BRACE.\n", yytext);}
  20. ";"|"," {printf("%s is a DELIMITER.\n", yytext);}
  21. "main"|"void"|"switch"|"if"|"else"|"for"|"while"|"break"|"continue"|"auto"|"static" {printf("%s is a RESERVED KEYWORD.\n", yytext);}
  22. ^#[a-z]+ {printf("%s is a PREPROCESSOR DIRECTIVE.\n", yytext);}
  23. "<stdio.h>"|"<string.h>"|"<math.h>" {printf("%s is a HEADER FILE.\n", yytext);}
  24. "int"|"char"|"float"|"long"|"long long"|"double" {printf("%s is a DATATYPE.\n", yytext);}
  25. [0-9]+ {printf("%s is an INTEGER NUMBER.\n", yytext);}
  26. [0-9]+"."[0-9]+ {printf("%s is a DECIMAL NUMBER.\n", yytext);}
  27. [a-zA-z_][a-zA-z_0-9]* {printf("%s is an IDENTIFIER.\n", yytext);}
  28. [ \n\t] {}
  29.  
  30. %%
  31.  
  32. int yywrap() {
  33. return 1;
  34. }
  35.  
  36. int main() {
  37. FILE *f = fopen("3input.txt", "r");
  38. yyin = f;
  39. yylex();
  40. }
  41.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
#include<stdio.h>
int main() {
	int x = 56;
	printf("%d", x);
	char ty;
	scanf("%c", &ty);
	float y = 0.454;
	printf("+this must work(()");
}
compilation info
prog.c:1:1: error: expected identifier or '(' before '%' token
 %{
 ^
prog.c:7:1: error: expected identifier or '(' before '%' token
 %%
 ^
prog.c:9:1: error: stray '\' in program
 (\"\%d\")|(\"\%c\")|(\"\%s\")    {printf("%s is a FORMAT SPECIFIER.\n", yytext);}
 ^
prog.c:9:1: error: stray '\' in program
prog.c:9:70: warning: missing terminating " character
 (\"\%d\")|(\"\%c\")|(\"\%s\")    {printf("%s is a FORMAT SPECIFIER.\n", yytext);}
                                                                      ^
prog.c:9:1: error: missing terminating " character
 (\"\%d\")|(\"\%c\")|(\"\%s\")    {printf("%s is a FORMAT SPECIFIER.\n", yytext);}
 ^
prog.c:10:1: error: stray '\' in program
 \"(\\.|[^\\"])*\"    {printf("%s is a STRING LITERAL.\n", yytext);}
 ^
prog.c:10:1: error: stray '\' in program
prog.c:10:1: error: stray '\' in program
prog.c:10:56: warning: missing terminating " character
 \"(\\.|[^\\"])*\"    {printf("%s is a STRING LITERAL.\n", yytext);}
                                                        ^
prog.c:10:1: error: missing terminating " character
 \"(\\.|[^\\"])*\"    {printf("%s is a STRING LITERAL.\n", yytext);}
 ^
prog.c:12:2: error: expected identifier or '(' before string constant
 ("|")|("&")|("~")|("^")    {printf("%s is a BITWISE OPERATOR.\n", yytext);}
  ^
prog.c:13:2: error: expected identifier or '(' before string constant
 ("=")|("+")|("-")|("/")    {printf("%s is an ARITHMETIC OPERATOR.\n", yytext);}
  ^
prog.c:14:1: error: expected identifier or '(' before string constant
 "<"|"<="|">="|">"    {printf("%s is a RELATIONAL OPERATOR.\n", yytext);}
 ^
prog.c:15:1: error: expected identifier or '(' before string constant
 "&&"|"||"|"!"    {printf("%s is a LOGICAL OPERATOR.\n", yytext);}
 ^
prog.c:16:1: error: expected identifier or '(' before string constant
 "{"    {printf("%s is OPENING CURLY BRACE.\n", yytext);}
 ^
prog.c:17:1: error: expected identifier or '(' before string constant
 "}"    {printf("%s is CLOSING CURLY BRACE.\n", yytext);}
 ^
prog.c:18:1: error: expected identifier or '(' before string constant
 "("    {printf("%s is OPENING BRACE.\n", yytext);}
 ^
prog.c:19:1: error: expected identifier or '(' before string constant
 ")"    {printf("%s is CLOSING BRACE.\n", yytext);}
 ^
prog.c:20:1: error: expected identifier or '(' before string constant
 ";"|","    {printf("%s is a DELIMITER.\n", yytext);}
 ^
prog.c:21:1: error: expected identifier or '(' before string constant
 "main"|"void"|"switch"|"if"|"else"|"for"|"while"|"break"|"continue"|"auto"|"static"    {printf("%s is a RESERVED KEYWORD.\n", yytext);}
 ^
prog.c:22:1: error: expected identifier or '(' before '^' token
 ^#[a-z]+    {printf("%s is a PREPROCESSOR DIRECTIVE.\n", yytext);}
 ^
prog.c:22:2: error: stray '#' in program
 ^#[a-z]+    {printf("%s is a PREPROCESSOR DIRECTIVE.\n", yytext);}
  ^
prog.c:23:1: error: expected identifier or '(' before string constant
 "<stdio.h>"|"<string.h>"|"<math.h>"    {printf("%s is a HEADER FILE.\n", yytext);}
 ^
prog.c:24:1: error: expected identifier or '(' before string constant
 "int"|"char"|"float"|"long"|"long long"|"double"    {printf("%s is a DATATYPE.\n", yytext);}
 ^
prog.c:25:1: error: expected identifier or '(' before '[' token
 [0-9]+    {printf("%s is an INTEGER NUMBER.\n", yytext);}
 ^
prog.c:26:1: error: expected identifier or '(' before '[' token
 [0-9]+"."[0-9]+    {printf("%s is a DECIMAL NUMBER.\n", yytext);}
 ^
prog.c:27:1: error: expected identifier or '(' before '[' token
 [a-zA-z_][a-zA-z_0-9]*    {printf("%s is an IDENTIFIER.\n", yytext);}
 ^
prog.c:28:1: error: expected identifier or '(' before '[' token
 [ \n\t]    {}
 ^
prog.c:28:1: error: stray '\' in program
prog.c:28:1: error: stray '\' in program
prog.c:30:1: error: expected identifier or '(' before '%' token
 %%
 ^
prog.c: In function 'main':
prog.c:37:2: error: unknown type name 'FILE'
  FILE *f = fopen("3input.txt", "r");
  ^
prog.c:37:12: warning: implicit declaration of function 'fopen' [-Wimplicit-function-declaration]
  FILE *f = fopen("3input.txt", "r");
            ^
prog.c:37:12: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
prog.c:38:2: error: 'yyin' undeclared (first use in this function)
  yyin = f;
  ^
prog.c:38:2: note: each undeclared identifier is reported only once for each function it appears in
prog.c:39:2: warning: implicit declaration of function 'yylex' [-Wimplicit-function-declaration]
  yylex();
  ^
stdout
Standard output is empty