-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax_analysis.l
53 lines (46 loc) · 1.03 KB
/
syntax_analysis.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
%{
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "syntax_analysis.tab.h"
%}
delim [ \t \n]
ws {delim}+
letter [A-Za-z]
digit [0-9]
id {letter}({letter}|{digit})*
number {digit}+
%%
"int"|"float"|"char*"|"char"|"double" {return(TYPE);}
"void" {return(VOID);}
"while" {return(WHILE);}
"if" {return(IF);}
"break" {return(BREAK);}
"continue" {return(CONTINUE);}
"for" {return(FOR);}
"else" {return(ELSE);}
"return" {return(RETURN);}
"main" {return(MAIN);}
"while" {return(WHILE);}
"<"|">"|"=="|">="|"<="|"<>" {return(COMPAREOP);}
"+"|"-"|"*"|"/"|"*" {return(CALCULOP);}
"++"|"--" {return(AUTOCHANGEOP);}
"=" {return(EQUALOP);}
"(" {return(LB);}
"[" {return(LBB);}
"{" {return(LBBB);}
")" {return(RB);}
"]" {return(RBB);}
"}" {return(RBBB);}
";" {return(SEMI);}
"," {return(COMMA);}
{id} {return (ID);}
{number} {return (NUMBER);}
{ws} {;}
%%
int yywrap(){
return 1;
/*
%token TYPE VOID WHILE IF BREAK CONTINUE FOR ELSE RETURN MAIN WHILE COMPAREOP CALCULOP EQUALOP LB LBB LBBB RB RBB RBBB SEMI COMMA ID NUMBER
*/
}