-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.l
55 lines (52 loc) · 1.43 KB
/
parser.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
51
52
53
54
55
%{
#include <stdio.h>
#include "y.tab.h"
#define PRINTDEBUG(x, y) fprintf(stderr, "\nDBG: %s, lineno: %d\n", x,y);
%}
%option yylineno
letter [A-Za-z]
digit [0-9]
NoStar [^*]
NoStarDash [^*/]
NoQuoteDashNl [^\"\\\n]
id {letter}({letter}|{digit}|_)*
INTEGER_LITERAL ({digit})*{digit}
STRING_LITERAL \"(\\.|{NoQuoteDashNl})*\"
op (&&)|(\|\|)|(<=)|(>=)|(==)|(!=)
single_char [+\-!{}[\]();,=.<>*/]
sl_comment (\/\/.*)
ml_comment (\/\*)({NoStar}|\*+{NoStarDash})*\*+\/
SYNTAX_ERR (\+\+)|(--)
%%
"for" { return FOR; }
"class" { return CLASS; }
"public" { return PUBLIC; }
"static" { return STATIC; }
"void" { return VOID; }
"main" { return MAIN; }
"String" { return STRING; }
"int" { return INT; }
"boolean" { return BOOLEAN; }
"extends" { return EXTENDS; }
"return" { return RETURN; }
"if" { return IF; }
"else" { return ELSE; }
"while" { return WHILE; }
"System.out.println" { return PRINT; }
"length" { return LENGTH; }
"true" { return TRUE; }
"false" { return FALSE; }
"this" { return THIS; }
"new" { return NEW; }
{id} { return id; }
{INTEGER_LITERAL} { return INTEGER_LITERAL; }
{STRING_LITERAL} { return STRING_LITERAL; }
{op} { return op; }
{single_char} { return *yytext; }
{sl_comment} { }
{ml_comment} { }
{SYNTAX_ERR} { printf("Syntax errors in %d\n", yylineno); }
[ \n\t\r] { }
. { printf("Syntax errors in %d\n", yylineno); }
%%
int yywrap(void) { return 1; }