2 * Copyright (c) 2015-2016 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 %lex
-param
{void *scanner
}
25 %parse
-param
{struct sexpr_parser_state
*data
}
28 #include <jeffpc/error.h>
30 #include "sexpr_impl.h"
32 #define scanner data->scanner
34 extern
int sexpr_reader_lex
(void *, void *);
36 void yyerror(void *scan
, char *e
)
38 cmn_err
(CE_ERROR
, "Error: %s", e
);
41 void sexpr_error2
(char *e
, char *yytext
)
43 cmn_err
(CE_ERROR
, "Error: %s (%s)", e
, yytext
);
55 %token
<s
> SYMBOL STRING
59 %type
<lv
> document tok list toklist
62 document
: tok
{ data
->output
= $1; }
65 tok
: SYMBOL
{ $$
= VAL_ALLOC_SYM
($1); }
66 | STRING
{ $$
= VAL_ALLOC_STR
($1); }
67 | NUMBER
{ $$
= VAL_ALLOC_INT
($1); }
68 | BOOL
{ $$
= VAL_ALLOC_BOOL
($1); }
70 |
'\'' tok
{ $$
= VAL_ALLOC_CONS
(
71 VAL_ALLOC_SYM_CSTR
("quote"),
72 VAL_ALLOC_CONS
($2, NULL
)); }
76 * We are not left-recursive because we want to make cons cells right
79 toklist
: tok toklist
{ $$
= VAL_ALLOC_CONS
($1, $2); }
80 | tok
{ $$
= VAL_ALLOC_CONS
($1, NULL
); }
83 list
: '(' ')' { $$
= NULL
; }
84 |
'(' toklist
')' { $$
= $2; }
85 |
'(' tok
'.' tok
')' { $$
= VAL_ALLOC_CONS
($2, $4); }