You are not logged in.

#1 2010-03-13 03:00:20

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Plisp: Lisp/S-expression parser library

Plisp is a C library for parsing Lisp/S-expressions. I wrote it because I got massively sick of writing the same code every time I wanted to parse a text file.

I'd like some testers/users for this. It suits *my* needs, but I'm not too good at accommodating other people's. Do give it a try.

Installation:

I decided to mix it up and use Mercurial instead of Git. I'm liking the change.

AUR package is here: http://aur.archlinux.org/packages.php?ID=35422
hg clone URI (also web view): http://peasantoid.org:1024/plisp

Manual installation:

$ root=/path/to/root_directory ./make install

Documentation:

Sorely lacking. I will attempt to write some of this later; in the meantime, look at the source (particularly header files) and everything in test/.

Technical details:

Text is processed in two stages. The first, tokenization, iterates through the text looking for 'simple' tokens (left/right parentheses, quotes, numbers, strings, symbols, etc.). The second, parsing, iterates through the token list and converts it to a parse tree.

POSIX ERE (extended regular expressions) are used for tokenization. Seriously, this is really handy. $(man 3 regex) for details.

Linked lists are heavily relied upon.

Note that numbers are just stored as strings. It's up to the programmer to change those to actual numbers (f.e. strtol(), strtod()).

Testing:

The distribution includes a simple syntax-dumper utility that takes data from stdin, parses it, and formats the resulting syntax tree to stdout. My terminal transcript follows:

narch plisp -> ./make test && build/test/dump
---[RUN test (lib)]
---[RUN lib (obj)]
---[RUN obj ()]
build/obj/error.o
build/obj/escape.o
build/obj/init.o
build/obj/list.o
build/obj/parser.o
build/obj/tokenizer.o
---[END obj]
build/libplisp.so
build/libplisp.a
build/include/*.h
---[END lib]
build/test/dump
---[END test]
(foo '("bar") `(3.456 ,(baz 4 5)))
^D
1:1 list: ...
    1:2 symbol: foo
    1:7 list (quoting: '): ...
        1:8 string: bar
    1:16 list (quoting: `): ...
        1:17 real: 3.456
        1:20 list (quoting: ,): ...
            1:21 symbol: baz
            1:25 integer: 4
            1:27 integer: 5

Tested by/on:

me: Arch 64-bit (x86_64 Intel Core 2 Duo (Apple MacBook3,1))
me: Arch 64-bit (x86_64 Intel Xeon (Xen))
me: ArchPPC (32-bit PowerPC processor (Apple Mac Mini G4))

If you test this, please post your architecture and processor type. I really hate those insidious system-specific bugs.

Last edited by Peasantoid (2010-03-13 05:31:46)

Offline

Board footer

Powered by FluxBB