summaryrefslogtreecommitdiff
path: root/src/lisp/ao_lisp_read.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-11-16 17:49:47 -0800
committerKeith Packard <keithp@keithp.com>2017-11-16 18:40:31 -0800
commitb3b4731fcb89cb404433f37a7704a503567c43bd (patch)
tree74f0a214725905c7556a735127f01a4b4b0926be /src/lisp/ao_lisp_read.c
parentbd881a5b85d7cd4fb82127f92f32e089499b50cb (diff)
altos/lisp: Add scheme-style bools (#t and #f)
Cond and while compare against #f, just like scheme says to. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_read.c')
-rw-r--r--src/lisp/ao_lisp_read.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/lisp/ao_lisp_read.c b/src/lisp/ao_lisp_read.c
index 550f62c2..508d16b4 100644
--- a/src/lisp/ao_lisp_read.c
+++ b/src/lisp/ao_lisp_read.c
@@ -51,18 +51,18 @@ static const uint16_t lex_classes[128] = {
PRINTABLE|WHITE, /* */
PRINTABLE, /* ! */
PRINTABLE|STRINGC, /* " */
- PRINTABLE|COMMENT, /* # */
+ PRINTABLE|POUND, /* # */
PRINTABLE, /* $ */
PRINTABLE, /* % */
PRINTABLE, /* & */
- PRINTABLE|QUOTEC, /* ' */
- PRINTABLE|BRA, /* ( */
- PRINTABLE|KET, /* ) */
+ PRINTABLE|SPECIAL, /* ' */
+ PRINTABLE|SPECIAL, /* ( */
+ PRINTABLE|SPECIAL, /* ) */
PRINTABLE, /* * */
PRINTABLE|SIGN, /* + */
PRINTABLE, /* , */
PRINTABLE|SIGN, /* - */
- PRINTABLE|DOTC, /* . */
+ PRINTABLE|SPECIAL, /* . */
PRINTABLE, /* / */
PRINTABLE|DIGIT, /* 0 */
PRINTABLE|DIGIT, /* 1 */
@@ -283,27 +283,38 @@ _lex(void)
continue;
}
- if (lex_class & (BRA|KET|QUOTEC)) {
+ if (lex_class & SPECIAL) {
add_token(c);
end_token();
switch (c) {
case '(':
+ case '[':
return OPEN;
case ')':
+ case ']':
return CLOSE;
case '\'':
return QUOTE;
+ case '.':
+ return DOT;
}
}
- if (lex_class & (DOTC)) {
- add_token(c);
- end_token();
- return DOT;
- }
if (lex_class & TWIDDLE) {
token_int = lexc();
return NUM;
}
+ if (lex_class & POUND) {
+ for (;;) {
+ c = lexc();
+ add_token(c);
+ switch (c) {
+ case 't':
+ return BOOL;
+ case 'f':
+ return BOOL;
+ }
+ }
+ }
if (lex_class & STRINGC) {
for (;;) {
c = lexc();
@@ -457,6 +468,12 @@ ao_lisp_read(void)
case NUM:
v = ao_lisp_int_poly(token_int);
break;
+ case BOOL:
+ if (token_string[0] == 't')
+ v = _ao_lisp_bool_true;
+ else
+ v = _ao_lisp_bool_false;
+ break;
case STRING:
string = ao_lisp_string_copy(token_string);
if (string)