Changeset 14712 in project


Ignore:
Timestamp:
05/20/09 08:16:08 (10 years ago)
Author:
Ivan Raikov
Message:

lalr ported to Chicken 4

Location:
release/4/lalr
Files:
1 deleted
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • release/4/lalr/trunk/lalr-driver.scm

    r4334 r14712  
    77
    88; ---------- CHICKEN DEPENDENT SECTION -----------------
    9 (declare
    10    (uses extras)
    11    (usual-integrations)
    12    (fixnum)
    13    (not safe))
    14 
    15 (define-extension lalr-driver)
    16 
    17 (declare (export lr-driver glr-driver))
     9
     10(module lalr-driver
     11
     12        (lr-driver glr-driver)
    1813                 
     14        (import scheme chicken)
    1915
    2016; ---------- END CHICKEN DEPENDENT SECTION -----------------
     
    306302  (drop l (- (length l) n)))
    307303
     304)
  • release/4/lalr/trunk/lalr.meta

    r9305 r14712  
    44 (synopsis "An efficient LALR(1) parser generator")
    55 (author "Dominique Boucher")
     6 (maintainer "Ivan Raikov")
    67 (license "GPL-2")
    78 (needs eggdoc)
  • release/4/lalr/trunk/lalr.scm

    r4334 r14712  
    66; ---------- CHICKEN DEPENDENT SECTION -----------------
    77 
    8 (define-macro (def-macro form . body)
    9   `(define-macro ,form (let () ,@body)))
    10 
     8
     9(module lalr *
     10
     11   (import scheme chicken extras)
     12   
    1113(define pprint pretty-print)
    1214(define lalr-keyword? symbol?)
    13 (def-macro (BITS-PER-WORD) 30)
    14 (def-macro (logical-or x . y) `(bitwise-ior ,x ,@y))
    15 (def-macro (lalr-error msg obj) `(error ,msg ,obj))
     15
     16(define-syntax BITS-PER-WORD (lambda (x r c) 30))
     17(define-syntax logical-or
     18  (lambda (f r c)
     19    (let ((x (cadr f))
     20          (y (cddr f)))
     21      `(bitwise-ior ,x ,@y))))
     22
     23(define-syntax lalr-error
     24  (lambda (f r c)
     25    (let ((msg (cadr f))
     26          (obj (caddr f)))
     27      `(error ,msg ,obj))))
    1628
    1729(define (lr-driver action-table goto-table reduction-table) (void))
     
    130142
    131143(define driver-name     'lr-driver)
    132 
    133 (define (gen-tables! tokens gram )
    134   (initialize-all)
    135   (rewrite-grammar
    136    tokens
    137    gram
    138    (lambda (terms terms/prec vars gram gram/actions)
    139      (set! the-terminals/prec (list->vector terms/prec))
    140      (set! the-terminals (list->vector terms))
    141      (set! the-nonterminals (list->vector vars))
    142      (set! nterms (length terms))
    143      (set! nvars  (length vars))
    144      (set! nsyms  (+ nterms nvars))
    145      (let ((no-of-rules (length gram/actions))
    146            (no-of-items (let loop ((l gram/actions) (count 0))
    147                           (if (null? l)
    148                               count
    149                               (loop (cdr l) (+ count (length (caar l))))))))
    150        (pack-grammar no-of-rules no-of-items gram)
    151        (set-derives)
    152        (set-nullable)
    153        (generate-states)
    154        (lalr)
    155        (build-tables)
    156        (compact-action-table terms)
    157        gram/actions))))
    158 
    159144
    160145(define (initialize-all)
     
    199184  (set! token-set-size  #f)
    200185  (set! rule-precedences '()))
     186
     187(define (gen-tables! tokens gram )
     188  (initialize-all)
     189  (rewrite-grammar
     190   tokens
     191   gram
     192   (lambda (terms terms/prec vars gram gram/actions)
     193     (set! the-terminals/prec (list->vector terms/prec))
     194     (set! the-terminals (list->vector terms))
     195     (set! the-nonterminals (list->vector vars))
     196     (set! nterms (length terms))
     197     (set! nvars  (length vars))
     198     (set! nsyms  (+ nterms nvars))
     199     (let ((no-of-rules (length gram/actions))
     200           (no-of-items (let loop ((l gram/actions) (count 0))
     201                          (if (null? l)
     202                              count
     203                              (loop (cdr l) (+ count (length (caar l))))))))
     204       (pack-grammar no-of-rules no-of-items gram)
     205       (set-derives)
     206       (set-nullable)
     207       (generate-states)
     208       (lalr)
     209       (build-tables)
     210       (compact-action-table terms)
     211       gram/actions))))
     212
    201213
    202214
     
    16001612
    16011613
    1602 (define-macro (lalr-parser . arguments)
    1603   (extract-arguments arguments build-driver))
    1604 
     1614(define-syntax lalr-parser
     1615  (lambda (f r c)
     1616    (let ((arguments (cdr f)))
     1617      `(extract-arguments ',arguments build-driver))))
     1618
     1619)
  • release/4/lalr/trunk/lalr.setup

    r4334 r14712  
     1;; -*- Hen -*-
    12
    2 (define has-exports? (string>=? (chicken-version) "2.310"))
     3(define (dynld-name fn)         
     4  (make-pathname #f fn ##sys#load-dynamic-extension))   
    35
    4 (compile -O2 -d0 -s
    5          ,@(if has-exports? '(-check-imports -emit-exports lalr-driver.exports) '())
    6          lalr-driver.scm)
     6(compile -O2 -d0 -s lalr.scm -j lalr )
     7(compile -O2 -d0 -s lalr.import.scm)
    78
    8 (run (csi -qbs lalr-eggdoc.scm > lalr.html))
     9(compile -O2 -d0 -s lalr-driver.scm -j lalr-driver)
     10(compile -O2 -d0 -s lalr-driver.import.scm )
     11
     12(run (csi -s lalr-eggdoc.scm > lalr.html))
    913
    1014(install-extension
    1115 'lalr
    12  `("lalr.scm" "lalr-driver.so" "lalr.html"
    13    ,@(if has-exports? '("lalr-driver.exports") (list)) )
    14  `((syntax)
    15    (version 2.3.0)
    16    (exports "lalr-driver.exports")
    17    ,@(if has-exports? `((exports "lalr-driver.exports")) (list))
    18    (require-at-runtime lalr-driver)
     16
     17 `(,(dynld-name "lalr")          ,(dynld-name "lalr.import")
     18   ,(dynld-name "lalr-driver")   ,(dynld-name "lalr-driver.import") )
     19
     20 `((version 2.3.0)
    1921   (documentation "lalr.html")) )
     22
     23
Note: See TracChangeset for help on using the changeset viewer.