Skip to content

Commit c0200f7

Browse files
authored
Create Compiler.l
0 parents  commit c0200f7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Compiler.l

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
%{
2+
#include <stdio.h>
3+
%}
4+
5+
DIGIT [0-9]
6+
NUMBER {DIGIT}+
7+
IDENTIFIER [a-zA-Z_][a-zA-Z0-9_]*
8+
OPERATOR "+"|"-"|"*"|"/"
9+
LPAREN "("
10+
RPAREN ")"
11+
WS [ \t\n]
12+
13+
%%
14+
{NUMBER} { printf("NUMBER(%s)\n", yytext); }
15+
{IDENTIFIER}{ printf("IDENTIFIER(%s)\n", yytext); }
16+
{OPERATOR} { printf("OPERATOR(%s)\n", yytext); }
17+
{LPAREN} { printf("LPAREN\n"); }
18+
{RPAREN} { printf("RPAREN\n"); }
19+
{WS} { /* Ignore whitespace */ }
20+
. { printf("UNKNOWN(%s)\n", yytext); }
21+
22+
%%
23+
24+
int main() {
25+
yylex();
26+
return 0;
27+
}

0 commit comments

Comments
 (0)