-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.l
33 lines (26 loc) · 922 Bytes
/
lexer.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
%{
#include "parser.tab.h"
#include <string.h>
%}
%option noyywrap
%%
[0-9]+ { yylval.num = atoi(yytext); return NUMBER; }
"int"|"float"|"string"|"waypoint"|"flight_level" { yylval.str = strdup(yytext); return TYPE; }
[a-zA-Z_][a-zA-Z0-9_]* { yylval.str = strdup(yytext); return IDENTIFIER; }
"->" { return ARROW; }
"=" { return EQUALS; }
"{" { return LBRACE; }
"}" { return RBRACE; }
"(" { return LPAREN; }
")" { return RPAREN; }
"," { return COMMA; }
"function" { return FUNCTION; }
"if" { return IF; }
"while" { return WHILE; }
"return" { return RETURN; }
";" { return SEMICOLON; }
"\n" { return NEWLINE; }
"//" { /* ignore single-line comments */ }
[ \t\n]+ { /* ignore whitespace */ }
. { /* catch-all for other characters */ }
%%