LALR Parser problem

"D. O'Keeffe" <[email protected]> 20 Feb 2009 00:39:22 +0000
Newsgroups gmane.comp.java.sisc.user
Message-ID <[email protected]>
Hello again all,
I'm having a small problem porting over my parser from plt's parser tools 
to dominique boucher's LALR(1) parser for Sisc (suggested by Nikita below).

Basically, I keep getting a fairly cryptic error relating to some of the 
rules I have defined in the parser. An example is given below for the 
(conj) rule. However, about a quarter of the rules in the parser give this 
error, and the one that causes evaluation to fail depends on the order in 
which they are specified. I'm finding it hard to debug what the parser is 
doing, does anyone have any suggestions as to what's going on, or how to 
get more information about what is causing the failure? I've included the 
parser definition below too, everything works up until the comment saying 
;; Problematic rules.

Thanks for any suggestions! Dan Error: unused arguments (conj) ?:?:?: <from 
call to apply> ?:?:?: <from call to/argument of cons> ?:?:?: <from call to 
cons> ?:?:?: <indeterminate call> ?:?:?: <from call to apply> 
file:/auto/homes/do244/devel/workspace/KawaCEP/lalr.scm:1688:26: 
<indeterminate call> ?:?:?: <from call to/argument of datum->syntax-object> 
?:?:?: <indeterminate call> [Repeated 4 times] ?:?:?: <from call 
to/argument of list> [Repeated 3 times] ?:?:?: <indeterminate call> 
[Repeated twice] ?:?:?: <from call to/argument of cons> [Repeated 4 times] 
?:?:?: <indeterminate call> [Repeated 4 times]

I've included the code defining the parser below:

;;
;; parser 
;;
;; Takes a lex function with no parameters as a parameter
;; Expects that tokens are pairs, with a number in 
;; the CAR, the token number, and any value in the CDR,
;; the token attribute.
(define sisc-cep-parser
   (lalr-parser
    
    ;; --- Options 
    ;; output a parser, called sisc-cep-parser, in a separate file - 
sisc-cep-parser.yy.scm,
    (output:    sisc-cep-parser "sisc-cep-parser.yy.scm")
    ;; output the LALR table to sisc-cep.out
    (out-table: "sisc-cep.out")
    ;; there should be no conflict
    (expect:    0)

    ;; --- token definitions
    (CEP-STRING CEP-NUM CEP-BOOL INTERVAL-STRING TIME-STRING ;;Value tokens
                CREATE SELECT EVENT INIT INIT-LIST TERM TERM-LIST WHERE 
;;Empty tokens
                LKEY LKEYS GKEY GKEYS START ADD IGNORE DISCARD AS STRICT 
CONJ
                SEQ PAR DISJ NTH ATMOST ATLEAST UNLESS AT EVERY AFTER
                REPLACE ALL ANY NEW OLD MAX CONSUME ROWS RANGE LP RP LCB 
                RCB < > = GE LE NE DOT COMMA AND OR EXCLAMATION-NOT NOT 
TODO EOF
       (left: + -)
       (left: * /))
      
    ;; --- rules
    
      (ce-def
       (CREATE CEP-STRING select-clause) : (make-ce-syntax-obj $2 (first 
$3) (cadr $3) (caddr $3)))
      

      (select-clause 
       (SELECT map-expr init-clause) : (list $2 (car $3) (cadr $3)))
      
 
      (init-clause
       (INIT-LIST init-expr-list event-clause) :
        (list (cadr $3) (make-ice-syntax-obj (first $3) 
(make-ctx-tmp-schema $2 (cadr (caddr $3))) (caddr (caddr $3)) (first (caddr 
$3))))
       (INIT init-expr event-clause) :
        (list (cadr $3) (make-ice-syntax-obj (first $3) 
(make-ctx-tmp-schema $2 (cadr (caddr $3))) (caddr (caddr $3)) (first (caddr 
$3))))
       (event-clause) :
        (list (cadr $1) (make-ice-syntax-obj (first $1) 
                                             (make-ctx-tmp-schema '() (cadr 
(caddr $1)))
                                             (caddr (caddr $1)) 
                                             (first (caddr $1)))))
      
    
      (event-clause 
       (EVENT event-expr where-clause) : (list $2 (first $3) (cadr $3)))
      
      
      (where-clause
       (WHERE where-expr lkeyby-clause) : (list $2 $3)
       (lkeyby-clause) : (list '() $1))
      
    
      (lkeyby-clause
       (LKEYS LP key RP keylist term-clause) : (list (list $3 $5) (first 
$6) (cadr $6))
       (LKEYS key term-clause) : (list $2 (first $3) (cadr $3))
       (term-clause) : (list '() (first $1) (cadr $1)))
      
    
      (term-clause
       (TERM-LIST term-expr-list gkeyby-clause) : (list $2 $3)
       (TERM term-expr gkeyby-clause) : (list $2 $3)
       (gkeyby-clause) : (list '() $1))
      
    
      (gkeyby-clause
       (GKEYS LP key RP keylist) : (list $3 $5)      
       (GKEYS key) : (list $2)
       () : '())
      
      (internal-init-clause
       (INIT-LIST init-expr-list internal-event-clause) : (cons $2 $3)
       (INIT init-expr internal-event-clause) : (cons $2 $3)
       (internal-event-clause) : (cons '() $1))
      
      (internal-event-clause 
       (event-expr lkeyby-clause) : (cons $1 $2))
       
      (map-expr
       (*) : (list 'all))
      
      (init-expr-list
       (init-expr COMMA init-expr-list) : (list $1 $3)
       (init-expr) : (list $1))
      
      (init-expr
       (START) : (list 'start)
       (CEP-STRING rename icc threshold) : (list $1 $2 $3 $4)
       () : (list 'start))  
      
      (rename
       (AS CEP-STRING) : (list $2)
       () : '()) 
      
      ;; icc = init correlation code
      (icc
       (< ADD >) : (list 'add)
       (< IGNORE >) :  (list 'ignore)
       () : (list 'ignore)) 
     
      (term-expr-list
       (term-expr COMMA term-expr-list) : (list $1 $3)
       (term-expr) : (list $1))  
      
      ;; tcc = term correlation code
      (term-expr
       (time-span tcc) : (list $1 $2)
       (CEP-STRING rename term-opts threshold) : (list $1 $2 $3 $4)
       () : '())
      
      (term-opts
       (< tquant COMMA tcc >) : (list $2 $4)
       (< tquant >) : (list $2 'discard)
       (< tcc >) : (list '+ $2)
       () : (list 'discard '+))
      
      (tquant
       (NEW) : (list 'new)
       (OLD) : (list 'old)
       (+) : (list '+))
      
      (tcc
       (TERM ) : (list 'term)
       (DISCARD) : (list 'discard)
       () : (list 'discard))
      
      (event-expr
       (seq) : $1
       (par) : $1
       (disj) : $1
       (conj) : $1
       (no-way) : $1
       (unless) : $1
       (nth) : $1
       (atmost) : $1
       (atleast) : $1
       (at) : $1
       (every) : $1
       (after) : $1)
      
  
      (operand-list
       (join-operand rest-operand-list) : (list $1 $2))
      
      (rest-operand-list 
       (COMMA join-operand rest-operand-list) : (list $2 $3)
       () '())
      
      (counting-operand-list
       (counting-operand rest-counting-operand-list) : (list $1 $2))
      
      (rest-counting-operand-list 
       (COMMA counting-operand rest-counting-operand-list) : (list $2 $3)
       () : '())
      
      (join-operand
       (CEP-STRING rename < join-operand-cfg > threshold) :
        (make-operand $1 $2 $6 '() '() (list-ref $4 2) (list-ref $4 0) 
(list-ref $4 1) '() '() '() '())
       (CEP-STRING rename threshold) : (make-default-operand $1 $2 $3)
       (LP internal-init-clause RP) : (make-operand '() '() '() '() '() '() 
'() '() '() '() $2 '() '())) ;; internal operand
      
      (counting-operand
       (CEP-STRING rename < counting-operand-cfg > threshold) : 
        (make-operand $1 $2 $6 '() '() (list-ref $4 2) (list-ref $4 0) 
(list-ref $4 1) '() '() '() '())
       (CEP-STRING rename threshold) : (make-default-counting-operand $1 $2 
$3)
       (LP internal-init-clause RP) : (make-operand '() '() '() '() '() '() 
'() '() '() '() $2 '() '()))
      
      (not-operand
       (CEP-STRING rename threshold) : (make-default-not-operand $1 $2 $3)
       (LP internal-init-clause RP) : (make-operand '() '() '() '() '() '() 
'() '() '() '() $2 '() '()))
      
      (join-operand-cfg
       (select COMMA consume COMMA rows COMMA range) : (list $1 $3 $5 $7)
       (select COMMA consume COMMA rows ) : (list $1 $3 $5 'unbounded)
       (select COMMA consume COMMA range) : (list $1 $3 'unbounded $5)
       (select COMMA consume ) : (list $1 $3 'unbounded 'unbounded)
       (select COMMA rows COMMA range) : (list $1 #f $3  $5)
       (select COMMA rows) : (list $1 #f $3 'unbounded)
       (select COMMA range) : (list $1 #f 'unbounded $3)
       (select) : (list $1 #f 'unbounded 'unbounded)
       (consume COMMA rows COMMA range) : (list (list 'any 'new 1) $1 $3 $5)
       (consume COMMA rows) : (list (list 'any 'new 1) $1 $3 'unbounded )
       (consume COMMA range) : (list (list 'any 'new 1) $1 'unbounded $3)
       (consume) : (list (list 'any 'new 1) $1 'unbounded 'unbounded)
       (rows COMMA range) : (list (list 'any 'new 1) #f $1 $3)
       (rows) : (list (list 'any 'new 1) #f $1 'unbounded)
       (range) : (list (list 'any 'new 1) #f 'unbounded $1))
      
      (counting-operand-cfg
       (CEP-NUM COMMA join-operand-cfg) : (list $1 $3) 
       (join-operand-cfg) : $1)
      
      (strictness
       (STRICT) : 'strict
       (ANY) : 'any)
      
      (order
       (NEW) : 'new
       (OLD) : 'old)
            
      (keylist
       (COMMA LP key RP keylist) : (cons $3 $5)
       () : '())
      
      (key
       (event-key event-keylist) : '())
      
      (event-keylist
       (COMMA event-key event-keylist) : (cons $2 $3)
       () : '())
      
      (event-key
       (CEP-STRING DOT CEP-STRING) : (cons $1 $3))
      
      (where-expr
       (TODO) : '()
       () : '())
      
      (cond-expr
       (TODO) : '()
       () : '())
      
      (threshold
       (LCB tcond RCB) : (list $2) 
       () : '())
      
      (tcond
       (TODO) : '()
       () : '())
      
      (aggfn-expr
       (TODO) : '()
       () : '())
      
      (time-span
       (INTERVAL-STRING) : $1)
      
      (time-expr
       (TIME-STRING) : $1)
      
      (acc
       (ADD) : (list 'add)
       (IGNORE) : (list 'ignore)
       (REPLACE) : (list 'replace)
       () : (list 'add))
      
      (internal-acc
       (ADD) : (list 'add)
       () : (list 'add))
    
      
      ;;
      ;; PROBLEMATIC PATTERNS
      ;; All of the following patterns cause problems with the Sisc LALR(1) 
parser
      ;; Whichever pattern is first causes an error (i.e. interchanging 
their
      ;; order gives the same error, but with different values.
      ;; e.g. running (include "sisc-cep-parser.scm") with conj before seq 
      ;; gives:
      ;; Error: unused arguments (conj)
      ;; ?:?:?: <from call to apply>
      ;; ?:?:?: <from call to/argument of cons>
      ;; ?:?:?: <from call to cons>
      ;; ?:?:?: <indeterminate call>
      ;; ?:?:?: <from call to apply>
      ;; file:/auto/homes/do244/devel/workspace/KawaCEP/lalr.scm:1688:26: 
<indeterminate call>
      ;; ?:?:?: <from call to/argument of datum->syntax-object>
      ;; ?:?:?: <indeterminate call> [Repeated 4 times]
      ;; ?:?:?: <from call to/argument of list> [Repeated 3 times]
      ;; ?:?:?: <indeterminate call> [Repeated twice]
      ;; ?:?:?: <from call to/argument of cons> [Repeated 4 times]
      ;; ?:?:?: <indeterminate call> [Repeated 4 times]
      ;;
      ;;
      ;; If instead they are rearranged so that seq comes before 
      ;; conj we get:
      ;;
      ;; Error: unused arguments (seq)
      ;; ?:?:?: <from call to apply>
      ;; ?:?:?: <from call to/argument of cons>
      ;; ?:?:?: <from call to cons>
      ;; etc..
      
      (conj 
       (AND LP operand-list RP) : (make-operator 'and $3 '() '()))
      
      (seq  
       (SEQ LP operand-list RP) : (make-operator 'seq $3 '() '()))
            
      (par  
       (PAR LP operand-list RP) : (make-operator 'sim $3 '() '()))
      
      (disj  
       (DISJ LP operand-list RP) : (make-operator 'or $3 '() '()))
      
      (no-way  
       (NOT LP not-operand RP) : (make-operator 'not $3 '() '()))
      
      (unless  
       (UNLESS LP join-operand not-operand RP) : (make-operator 'unless 
(list $3 $4) '() '()))
      
      (nth  
       (NTH LP CEP-NUM COMMA counting-operand-list RP) : (make-operator 
'nth (list $5) (make-op-params '() $3) '()))
      
      (atmost  
       (ATMOST LP CEP-NUM COMMA counting-operand-list RP) : (make-operator 
'atmost (list $5) (make-op-params '() $3 '()) '()))
      
      (atleast  
       (ATLEAST LP CEP-NUM COMMA counting-operand-list RP) : (make-operator 
'atleast (list $5) (make-op-params '() $3 '()) '()))
      
      (at  
       (AT time-expr) : (make-operator 'at '() (make-op-params '() '() $2) 
'()))
      
      (every  
       (EVERY time-span) : (make-operator 'every '() (make-op-params '() 
'() $2)))
      
      (after  
       (AFTER join-operand COMMA time-span COMMA acc) : (make-op-params 
'after (list $2) (make-op-params '() '() $4 $6) '()))
      
      (select
       (strictness order max) : (list $1 $2 $3)
       (strictness order) : (list $1 $2 1)
       (strictness max) : (list $1 'new $2)
       (strictness) : (list $1 'new 1)
       (order max) : (list 'any $1 $2)
       (order) : (list 'any $1 1)
       (max) : (list 'any 'new $1)
       (ALL) : (list 'all))
       
      (max 
       (MAX CEP-NUM) : $2
       (+) : '+)
       
      (consume
       (EXCLAMATION-NOT CONSUME) : (list #f)
       (CONSUME) : (list #t))
        
      (rows
       (ROWS CEP-NUM) : $2)
      
      (range
       (RANGE INTERVAL-STRING) : $2)
      
      ;; END PROBLEMATIC PATTERNS
))

>Message: 1
>Date: Mon, 09 Feb 2009 22:52:36 +0200
>From: "Nikita Sidorov" <[email protected]>
>Subject: Re: [Sisc-users] Question about porting mzscheme code
>To: [email protected]
>Cc: "D. O'Keeffe" <[email protected]>
>Message-ID: <[email protected]>
>Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8
>
>Hi Dan,
>
> Once I was also looking for a parser for sisc. I ended up using 
> Dominique Boucher's LALR(1) parser generator that could be found here: 
> http://www.iro.umontreal.ca/~boucherd/Lalr/documentation/lalr.html#A-portable-and-efficient-LALR(1)-parser-generator-for-Scheme 
> http://code.google.com/p/lalr-scm/ (seems to be more recent)
>
>As for the lexer I had to write it myself.
>
>I hope it will help you.
>
>Nikita
>
>



------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H