From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: my current project: new lalr module Date: Fri, 26 Jun 2015 13:43:21 -0700 Message-ID: <11C48931-416C-46B1-AA4B-9BA8FA936010@verizon.net> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_00772F9E-BF64-44AB-8E9A-58D457A94237" X-Trace: ger.gmane.org 1435351452 14783 80.91.229.3 (26 Jun 2015 20:44:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Jun 2015 20:44:12 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jun 26 22:44:03 2015 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z8aTi-0000Ww-Ji for guile-user@m.gmane.org; Fri, 26 Jun 2015 22:44:02 +0200 Original-Received: from localhost ([::1]:33734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8aTi-0003fA-0i for guile-user@m.gmane.org; Fri, 26 Jun 2015 16:44:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8aTW-0003cF-TQ for guile-user@gnu.org; Fri, 26 Jun 2015 16:43:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8aTS-00021D-LG for guile-user@gnu.org; Fri, 26 Jun 2015 16:43:50 -0400 Original-Received: from vms173023pub.verizon.net ([206.46.173.23]:55212) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8aTS-0001za-EF for guile-user@gnu.org; Fri, 26 Jun 2015 16:43:46 -0400 Original-Received: from [192.168.2.127] ([71.108.227.241]) by vms173023.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0NQK00DAJK8A5NO0@vms173023.mailsrvcs.net> for guile-user@gnu.org; Fri, 26 Jun 2015 15:43:28 -0500 (CDT) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=Za3gTZhA c=1 sm=1 tr=0 a=C7TgS9Pb229lFodQust5qw==:117 a=o1OHuDzbAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=XAFQembCKUMA:10 a=mSCpSBZQZBVd1H-tGNUA:9 a=CjuIK1q_8ugA:10 a=1GWXaEYdf4CKvvJ0ifIA:9 a=68BjnS49aD3cob01:21 a=_W_S_7VecoQA:10 In-reply-to: X-Mailer: Apple Mail (2.1878.6) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.46.173.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:11881 Archived-At: --Apple-Mail=_00772F9E-BF64-44AB-8E9A-58D457A94237 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Jun 3, 2015, at 8:40 PM, Matt Wette = wrote: > My current project is a lalr module.=20 Here is a slight update on my parser generator.=20 1) I have added a "hashify" procedure that allows one to set up the = parser and lex'er to use integers instead of symbols. 2) I have updated the specification parser and processor to allow use of = strings. My C-parser is using "++" and "+=3D" now. 3) I have updated the lexical analyzer tools to allow (I hope) easier = construction of lexical analyzers. The idea is that the user generates readers for identifiers, numbers, other character = sequences, comments, etc and then throws those, along with a match-table provided by the parser-generator, to a procedure to make = a lexical analyzer. Still thinking about a name. I may call it NYACC: "Not yet another = compiler compiler!" Here is the lexer: (lambda () (let iter ((ch (read-char))) (cond ((eof-object? ch) (mapval (cons '$end ch))) ((char-set-contains? c:ws ch) (iter (read-char))) ((read-ident ch) =3D> (lambda (s) (or (assq (string->symbol s) = symtab) (cons '$ident s)))) ((read-num ch) =3D> mapval) ((read-chseq ch) =3D> identity) ((read-string ch) =3D> mapval) ((read-comm ch) =3D> identity) ((skip-comm ch) =3D> (iter (read-char))) ((assq-ref chrtab ch) =3D> (lambda (t) (cons t ch))) (else (cons ch ch))))))) And here is the parser when using the hashified interface: (lambda (lexr) (let iter ((state (list 0)) ; state stack (stack (list '$dummy)) ; sval stack (nval #f) ; prev reduce to non-terminal value (lval (lexr))) ; lexical value (from lex'er) (let* ((tval (if nval (car nval) (car lval))) ; token = (syntax value) (sval (if nval (cdr nval) (cdr lval))) ; semantic = value (stxl (vector-ref pat-v (car state))) ; state = transition list (stx (or (assq-ref stxl tval) ; trans action (e.g. = shift 32) (assq-ref stxl 0) ; default action=20 (cons 'error 0)))) ; else error (when pdbug (dmsg (car state) tval stx)) (cond ((positive? stx) (iter (cons stx state) (cons sval stack) #f (if nval lval (lexr)))) ((negative? stx) (let* ((gx (abs stx)) (gl (vector-ref len-v gx)) ($$ (apply (vector-ref act-v gx) stack))) (iter (list-tail state gl) (list-tail stack gl) (cons (vector-ref rto-v gx) $$) lval))) ((zero? stx) ;; accept (car stack)))))) Matt =20= --Apple-Mail=_00772F9E-BF64-44AB-8E9A-58D457A94237 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
On Jun 3, 2015, at 8:40 PM, Matt Wette <matthew.wette@verizon.net>= ; wrote:
My current project is a lalr = module. 

Here is a slight = update on my parser generator. 
1) I have added a = "hashify" procedure that allows one to set up the parser and lex'er to = use integers instead of symbols.
2) I have updated the = specification parser and processor to allow use of strings.  My = C-parser is using "++" and "+=3D" now.
3) I have updated = the lexical analyzer tools to allow (I hope) easier construction of = lexical analyzers.   The idea is that the user
  =   generates readers for identifiers, numbers, other character = sequences, comments, etc and then throws those, along with = a
   match-table provided by the parser-generator, = to a procedure to make a lexical = analyzer.

Still thinking about a name.  I = may call it NYACC: "Not yet another compiler = compiler!"

Here is the lexer:
  =   (lambda ()
      (let iter ((ch = (read-char)))
        (cond
   =       ((eof-object? ch) (mapval (cons '$end = ch)))
         ((char-set-contains? c:ws ch) = (iter (read-char)))
         ((read-ident ch) = =3D> (lambda (s) (or (assq (string->symbol s) symtab)
   =                     =                     =   (cons '$ident s))))
         ((read-num = ch) =3D> mapval)
         ((read-chseq ch) = =3D> identity)
         ((read-string ch) = =3D> mapval)
         ((read-comm ch) = =3D> identity)
         ((skip-comm ch) = =3D> (iter (read-char)))
         ((assq-ref = chrtab ch) =3D> (lambda (t) (cons t ch)))
       =   (else (cons ch ch)))))))

And here is the parser when = using the hashified interface:
       (lambda = (lexr)
          (let iter ((state (list 0)) =           ; state stack
   =                   (stack = (list '$dummy))     ; sval stack
       =               (nval #f)     = ; prev reduce to non-terminal value
         =             (lval (lexr)))    =     ; lexical value (from lex'er)
        =     (let* ((tval (if nval (car nval) (car lval))) ; token = (syntax value)
             =       (sval (if nval (cdr nval) (cdr lval))) ; semantic = value
                 =   (stxl (vector-ref pat-v (car state))) ; state transition = list
                 =   (stx (or (assq-ref stxl tval) ; trans action (e.g. shift = 32)
                  =           (assq-ref stxl 0) ; default = action 
              =               (cons 'error = 0))))    ; else error
          =     (when pdbug (dmsg (car state) tval stx))
  =             (cond
        =         ((positive? stx)
       =           (iter (cons stx state) (cons sval = stack)
                 =       #f (if nval lval (lexr))))
        =         ((negative? stx)
       =           (let* ((gx (abs stx)) (gl (vector-ref = len-v gx))
                  =       ($$ (apply (vector-ref act-v gx) stack)))
   =                 (iter (list-tail = state gl)
                 =         (list-tail stack gl)
   =                     =   (cons (vector-ref rto-v gx) $$)
         =                 = lval)))
                ((zero? = stx) ;; accept
             =     (car stack))))))
Matt

          =  
= --Apple-Mail=_00772F9E-BF64-44AB-8E9A-58D457A94237--