-
Notifications
You must be signed in to change notification settings - Fork 0
/
pjlisp.l
35 lines (28 loc) · 885 Bytes
/
pjlisp.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
/* -*- mode: c; -*- */
%{
#include "pjlisp.tab.h"
static int offset = 0;
#define YY_USER_ACTION { offset += yyleng; }
%}
FIXNUM [-]?[0-9]+
ID [!#$%&*+,-/0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz|]+
WHITESPACE [[:space:]\n]+
STRING \"(\\.|[^\"\\])*\"
COMMENT ;[^\n;]*$
%%
\. {return DOT;}
{FIXNUM} {yylval = make_fixnum(atoi(yytext)); return FIXNUM;}
nil {return NIL;}
{ID} {yylval = intern(yytext); return ID;}
[\'] {return QUOTE;}
[(] {return LPAREN;}
[)] {return RPAREN;}
{STRING} {yylval = make_string(yytext+1, yyleng-2); return STRING;}
{WHITESPACE}+ /* no-op */
{COMMENT} /* no-op */
. {
fprintf(stderr,
"lexer: illegal character at byte position %d: %#x\n",
offset - 1, (int)yytext[0] & 0xff);
abort();
}