test-reader.qi

1 view
Skip to first unread message

snorgers

unread,
Nov 5, 2009, 6:16:45 PM11/5/09
to Qilang
I've now been running same tests and made a couple of examples where
the focus have been in the Yacc part and the segment part of the code
as well as a General Streaming method.

as an example I did a parser for a toy lang. and then created a
modified list stream that
added the capabilities to let the line column and depth be kept in
sync with the cdr of a list.

I did this code,
(def cons-stat?
[[X|L] A B C] -> true
X -> false)
(def null-stat X -> [= (head X) []])
(def head-stat [[X|L]|U] -> X)
(def tail-stat
[[#\Newline|L] Col Row Dep] -> [L 0 (+ Row 1) Dep]
[[X |L] Col Row Dep] -> [L (+ Col 1) Row Dep])

And registered and made the stream come true

(cons-streamer lis cons-stat cons-stat? head-stat tail-stat null-stat)

Then there is a dynamic variable, e.g. *li* that can be used according
to
(let *li* lis Code) and the defines in the code will expand lists
acording to the lis
stream. Then I just modified the code slightly and voila the example
in test.reader.qi
worked. I got,

from evaluating

parse "
f(x) - b(a) + h(y)
g[y + w{a(1)}]
")

I got (the statistics is Col Row Depth)

[-list- [#\f] [[#\x]] [0 1 1]] [#\-] [-list- [#\b] [[#\a]] [7 1 1]] [#\
+]
[-list- [#\h] [[#\y]] [14 1 1]]
[-brck- [#\g]
[[#\y] [#\+] [-curl- [#\w] [[-list- [#\a] [[#\1]] [8 2 3]]] [6 2
2]]]
[0 2 1]]]

I will now stop this testing and concentrate to generating the qi code
to Lisp or Clojure or ...

Regards
Stefan


Reply all
Reply to author
Forward
0 new messages