Add example files.
[cl-opossum.git] / example.lisp
blob59a62dac92da3e7a4207981ef8e9efb8ad928ad0
1 ;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; -*-
2 ;;;
3 ;;; example.lisp --- Sample code showing use of cl-opossum.
5 ;; Copyright (C) 2008 Utz-Uwe Haus <lisp@uuhaus.de>
6 ;; $Id$
7 ;; This code is free software; you can redistribute it and/or modify
8 ;; it under the terms of the version 3 of the GNU General
9 ;; Public License as published by the Free Software Foundation, as
10 ;; clarified by the prequel found in LICENSE.Lisp-GPL-Preface.
12 ;; This code is distributed in the hope that it will be useful, but
13 ;; without any warranty; without even the implied warranty of
14 ;; merchantability or fitness for a particular purpose. See the GNU
15 ;; Lesser General Public License for more details.
17 ;; Version 3 of the GNU General Public License is in the file
18 ;; LICENSE.GPL that was distributed with this file. If it is not
19 ;; present, you can access it from
20 ;; http://www.gnu.org/copyleft/gpl.txt (until superseded by a
21 ;; newer version) or write to the Free Software Foundation, Inc., 59
22 ;; Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ;; Commentary:
26 ;; Load this file into your lisp to see how cl-opossum can be utilized
27 ;; in your own programs.
29 ;;; Code:
33 (in-package #:CL-USER)
35 ;; load the opossum package
36 (asdf:operate 'asdf:load-op :opossum)
38 ;; Create a parser for the grammar defined in example.peg, in a fresh package
39 (setq *p* (opossum:make-string-parser "example.peg"))
40 ;; => ...
42 ;; use the parser to parse a string
43 (setq *t* (funcall *p* "14+7*(1+1)^2"))
44 ;; => ...
46 ;; and try out the code generated by the grammar
47 (eval *t*)
48 ;; => 42