micro-scheme reverse lexer's stack and allocate the list in the heap. Very messy.
Very messy due to multiple characters in symbols, multiple spaces in a row and the lack of propper array in POSIX sh.
This commit is contained in:
parent
d5b3158ded
commit
5fa2baa4b7
|
@ -49,6 +49,21 @@ value() {
|
||||||
eval 'printf %s "$heap_value_'$1'"'
|
eval 'printf %s "$heap_value_'$1'"'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug_print() {
|
||||||
|
eval 'tmpdebug=$heap_type_'"$1"
|
||||||
|
if test $tmpdebug = C; then
|
||||||
|
printf '('
|
||||||
|
eval 'tmpdebugb=$heap_car_'$1
|
||||||
|
(debug_print $tmpdebugb)
|
||||||
|
printf ' . '
|
||||||
|
eval 'tmpdebugb=$heap_cdr_'$1
|
||||||
|
(debug_print $tmpdebugb)
|
||||||
|
printf ')'
|
||||||
|
else
|
||||||
|
eval 'printf "[%s]" "$heap_value_'$1'"'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
stack_init_name_unit() {
|
stack_init_name_unit() {
|
||||||
eval "stacklast_${1}=0"
|
eval "stacklast_${1}=0"
|
||||||
}
|
}
|
||||||
|
@ -113,15 +128,31 @@ od -v -A n -t x1 | sed -e 's/^ //' | tr ' ' \\n | (while read c; do
|
||||||
28) if test "x$(stack_peek_name_hex parse)" = 'x'; then
|
28) if test "x$(stack_peek_name_hex parse)" = 'x'; then
|
||||||
stack_pop_name_result_unit parse current
|
stack_pop_name_result_unit parse current
|
||||||
fi
|
fi
|
||||||
stack_push_name_hex_unit parse 28
|
stack_push_name_hex_unit parse 2028
|
||||||
stack_push_name_hex_unit parse '';;
|
stack_push_name_hex_unit parse '';;
|
||||||
# Close paren
|
# Close paren
|
||||||
29) if test "x$(stack_peek_name_hex parse)" = 'x'; then
|
29) if test "x$(stack_peek_name_hex parse)" = 'x'; then
|
||||||
stack_pop_name_result_unit parse current
|
stack_pop_name_result_unit parse current
|
||||||
|
else
|
||||||
|
stack_pop_name_result_unit parse current
|
||||||
|
alloc_primitive_hex_unit "Sym $current"
|
||||||
|
stack_push_name_hex_unit parse $heap_max
|
||||||
fi
|
fi
|
||||||
stack_push_name_hex_unit parse 29;;
|
alloc_primitive_hex_unit "Nil"
|
||||||
|
cdr=$heap_max
|
||||||
|
while test "x$(stack_peek_name_hex parse)" != 'x2028'; do
|
||||||
|
stack_pop_name_result_unit parse current
|
||||||
|
car=$current
|
||||||
|
alloc_cons_ptr_ptr_unit $car $cdr
|
||||||
|
cdr=$heap_max
|
||||||
|
done
|
||||||
|
stack_pop_name_result_unit parse current
|
||||||
|
stack_push_name_hex_unit parse $cdr;;
|
||||||
# Space
|
# Space
|
||||||
20) if test "x$(stack_peek_name_hex parse)" != 'x'; then
|
20) if test "x$(stack_peek_name_hex parse)" != 'x'; then
|
||||||
|
stack_pop_name_result_unit parse current
|
||||||
|
alloc_primitive_hex_unit "Sym $current"
|
||||||
|
stack_push_name_hex_unit parse $heap_max
|
||||||
stack_push_name_hex_unit parse ''
|
stack_push_name_hex_unit parse ''
|
||||||
fi;;
|
fi;;
|
||||||
# identifier character
|
# identifier character
|
||||||
|
@ -134,8 +165,8 @@ echo stack:
|
||||||
|
|
||||||
while test "x$(stack_len_name_int parse)" != 'x0'; do
|
while test "x$(stack_len_name_int parse)" != 'x0'; do
|
||||||
stack_pop_name_result_unit parse tmp
|
stack_pop_name_result_unit parse tmp
|
||||||
echo "$tmp 0a"
|
echo "$tmp"
|
||||||
done | tac | xxd -ps -r
|
done | tac
|
||||||
|
|
||||||
echo heap:
|
echo heap:
|
||||||
|
|
||||||
|
@ -143,5 +174,8 @@ for i in `seq $heap_max`; do
|
||||||
eval "echo $i \$heap_type_$i \$heap_car_$i \$heap_cdr_$i \$heap_value_$i"
|
eval "echo $i \$heap_type_$i \$heap_car_$i \$heap_cdr_$i \$heap_value_$i"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo $(value $(cdr $heap_max))
|
#echo $(value $(cdr $heap_max))
|
||||||
|
|
||||||
|
debug_print $heap_max
|
||||||
|
echo
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user