Регистрация | Войти
Lisp — программируемый язык программирования
Автор: somequestions - 2011-07-08T15:56:23.000000+04:00
#+asdf(eval-when (:compile-toplevel :execute :load-toplevel)
        (asdf:oos 'asdf:load-op 'lispbuilder-regex)
)

#+asdf(eval-when (:compile-toplevel :execute :load-toplevel)
        (asdf:oos 'asdf:load-op 'lispbuilder-lexer)
)

#+asdf(eval-when (:compile-toplevel :execute :load-toplevel)
        (asdf:oos 'asdf:load-op :fucc-parser)
)

#+asdf(eval-when (:compile-toplevel :execute)
        (asdf:oos 'asdf:load-op :fucc-generator)
)



(require 'lispbuilder-lexer)
(require 'fucc-parser)

(defpackage :mypackage
  (:use :cl :lispbuilder-lexer :fucc )
)


(in-package :mypackage)


(defparameter *text* "CREATE [ GLOBAL TEMPORARY ] TABLE
   [ schema. ]table OF
   [ schema. ]object_type
   [ object_table_substitution ]
   [ (object_properties) ]
   [ ON COMMIT { DELETE | PRESERVE | SODEL } ROWS ]
   [ OID_clause ]
   [ OID_index_clause ]
   [ physical_properties ]
   [ table_properties ] ;"
)



(deflexer oracle-grm-lexer
    ("\\s+" (return  'ws ))
    (","    (return (values 'comma 'comma)))
    ("\\.\\.\\." (return (values 'mdot 'mdot)))
    ("\\."  (return (values 'dot 'dot)))
    ("\\[" (return 'sopen))
    ("\\]" (return 'sclose))
    ("\\(" (return 'oopen))
    ("\\)" (return 'oclose))
    ("\\{" (return 'fopen))
    ("\\|" (return (values 'mor 'or)))
    ("\\}" (return 'fclose))
    (";" (return (values 'semicolon 'semicolon)))
    ("[a-zA-Z_]+" (return (values (if (equal %0 (string-upcase %0))  'token 'atom) %0)))
)


(defparser *oracle-grammar-parse*
    grammar
    (token atom semicolon fclose fopen oclose oopen sopen sclose dot mdot mor  ws comma)

    ((grammar     > (CL:+ one-string  ))
                    
   (one-string    -> (:or atom token
                   s-string
                   o-string
                   f-string
                   comma
                   ws
                   mdot
                   dot
                   mor
                   semicolon
)
)

     (f-string   -> fopen grammar fclose
                   (:call (lambda (a b c) (declare (ignore a c)) (list :f-string  b)))
)

     (o-string     -> oopen grammar oclose
                   (:call (lambda (a b c) (declare (ignore a c)) (list :o-string  b)))
)

     (s-string     -> sopen grammar sclose
                   (:call (lambda (a b c) (declare (ignore a c))
                             (list :maybe  b)

                             
)
)
)
)
)

  
  

(defun test-parser (text)
  (parser-lr    (oracle-grm-lexer text) *oracle-grammar-parse*)
)

@2009-2013 lisper.ru