-
Notifications
You must be signed in to change notification settings - Fork 0
/
C_compiler.l
50 lines (50 loc) · 1.16 KB
/
C_compiler.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%{
#include "C_compiler.tab.h"
%}
letter [a-zA-Z]
num [0-9]
underscore [_]
vname ({letter}|{underscore})({letter}|{num})*
%%
void {return VOID;}
int {return INT;}
main {return MAIN;}
float {return FLOAT;}
char {return CHAR;}
for {return FOR;}
while {return WHILE;}
if {return IF;}
else {return ELSE;}
switch {return SWITCH;}
case {return CASE;}
break {return BREAK;}
default {return DEFAULT;}
"scanf" {return SCANF;}
"printf" {return PRINTF;}
"<="|">="|"<"|">"|"!="|"==" {return OPERATOR;}
"=" {return ASSIGNMENT;}
"++" {return INC;}
"--" {return DEC;}
"{" { return OPENCURLY;}
"}" { return CLOSECURLY;}
"(" { return OPENBRACES;}
")" { return CLOSEBRACES;}
"[" {return OPENBIGBRACES;}
"]" {return CLOSEBIGBRACES;}
";" {return SEMICOLON;}
":" {return COLON;}
"," {return COMMA;}
letter {return LETTER;}
"+"|"-"|"*"|"/"|"^" {return ARITHMETIC;}
"%" {return MOD;}
{vname} {return VNAME;}
{num}+ {return NUMBER;}
{num}+.({num}+) {return DECIMAL;}
" " { return SPACE;}
\"[^\"\n]*\" {return STR;}
"&" {return AND;}
[.] {ECHO; yyerror("unexpected character");}
\n {return NL;}
"#include<stdio.h>"|"#include<stdlib.h>"|"#include<math.h>" {return LIBRARY;}
"#define" {return DEFINE;}
%%