From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jan Nieuwenhuizen Newsgroups: gmane.lisp.guile.devel Subject: [PATCH 1/2] LALR-parser: provide bison-like location constructs @1 ... @n. Date: Sat, 2 Aug 2014 09:58:30 +0200 Message-ID: <1406966311-19014-2-git-send-email-janneke@gnu.org> References: <1406966311-19014-1-git-send-email-janneke@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1406966391 7147 80.91.229.3 (2 Aug 2014 07:59:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 2 Aug 2014 07:59:51 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Aug 02 09:59:47 2014 Return-path: Envelope-to: guile-devel@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 1XDUED-0001yu-On for guile-devel@m.gmane.org; Sat, 02 Aug 2014 09:59:45 +0200 Original-Received: from localhost ([::1]:43330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDUED-0000hP-F2 for guile-devel@m.gmane.org; Sat, 02 Aug 2014 03:59:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDUE4-0000bI-5f for guile-devel@gnu.org; Sat, 02 Aug 2014 03:59:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDUDw-0001jg-D3 for guile-devel@gnu.org; Sat, 02 Aug 2014 03:59:36 -0400 Original-Received: from smtp-vbr8.xs4all.nl ([194.109.24.28]:4168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDUDr-0001iJ-4x; Sat, 02 Aug 2014 03:59:23 -0400 Original-Received: from drakenvlieg.verum.local ([62.140.132.76]) (authenticated bits=0) by smtp-vbr8.xs4all.nl (8.13.8/8.13.8) with ESMTP id s727x1gk003341 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Sat, 2 Aug 2014 09:59:16 +0200 (CEST) (envelope-from janneke@gnu.org) X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406966311-19014-1-git-send-email-janneke@gnu.org> X-Virus-Scanned: by XS4ALL Virus Scanner X-MIME-Autoconverted: from 8bit to quoted-printable by smtp-vbr8.xs4all.nl id s727x1gk003341 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 194.109.24.28 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17301 Archived-At: * module/system/base/lalr.upstream.scm (lalr-parser): Provide bison-like positional location constructs: @1 ... @n. (*lalr-scm-version*): Bump to 2.5.0. --- module/system/base/lalr.upstream.scm | 40 ++++++++++++++++--------------= ------ 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/module/system/base/lalr.upstream.scm b/module/system/base/la= lr.upstream.scm index 217c439..b250c23 100755 --- a/module/system/base/lalr.upstream.scm +++ b/module/system/base/lalr.upstream.scm @@ -1,6 +1,7 @@ ;;; ;;;; An Efficient and Portable LALR(1) Parser Generator for Scheme ;;; +;; Copyright 2014 Jan Nieuwenhuizen ;; Copyright 1993, 2010 Dominique Boucher ;; ;; This program is free software: you can redistribute it and/or @@ -17,7 +18,7 @@ ;; along with this program. If not, see . =20 =20 -(define *lalr-scm-version* "2.4.1") +(define *lalr-scm-version* "2.5.0") =20 =20 (cond-expand=20 @@ -1591,17 +1592,19 @@ `(let* (,@(if act (let loop ((i 1) (l rhs)) (if (pair? l) - (let ((rest (cdr l))) - (cons=20 - `(,(string->symbol - (string-append - "$" - (number->string=20 - (+ (- n i) 1)))) - ,(if (eq? driver-name 'lr-driver) - `(vector-ref ___stack (- ___sp ,(- (* i 2) 1))) - `(list-ref ___sp ,(+ (* (- i 1) 2) 1)))) - (loop (+ i 1) rest))) + (let ((rest (cdr l)) + (ns (number->string (+ (-= n i) 1)))) + (cons + `(tok ,(if (eq? driver-name = 'lr-driver) + `(vector-ref ___s= tack (- ___sp ,(- (* i 2) 1))) + `(list-ref ___sp = ,(+ (* (- i 1) 2) 1)))) + (cons + `(,(string->symbol (string-= append "$" ns)) + (if (lexical-token? tok) = (lexical-token-value tok) tok)) + (cons + `(,(string->symbol (string= -append "@" ns)) + (if (lexical-token? tok)= (lexical-token-source tok) tok)) + (loop (+ i 1) rest))))) '())) '())) ,(if (=3D nt 0) @@ -1879,17 +1882,11 @@ (lexical-token-category tok) tok)) =20 - (define (___value tok) - (if (lexical-token? tok) - (lexical-token-value tok) - tok)) - =20 (define (___run) (let loop () (if ___input (let* ((state (vector-ref ___stack ___sp)) (i (___category ___input)) - (attr (___value ___input)) (act (___action i (vector-ref ___atable state)))) =20 (cond ((not (symbol? i)) @@ -1918,7 +1915,7 @@ =20 ;; Shift current token on top of the stack ((>=3D act 0) - (___shift act attr) + (___shift act ___input) (set! ___input (if (eq? i '*eoi*) '*eoi* #f)) (loop)) =20 @@ -2025,8 +2022,7 @@ (define (run) (let loop-tokens () (consume) - (let ((symbol (token-category *input*)) - (attr (token-attribute *input*))) + (let ((symbol (token-category *input*))) (for-all-processes (lambda (process) (let loop ((stacks (list process)) (active-stacks '())) @@ -2044,7 +2040,7 @@ (add-parse (car (take-right stack 2= ))) (actions-loop other-actions active-= stacks)) ((>=3D action 0) - (let ((new-stack (shift action attr= stack))) + (let ((new-stack (shift action *inp= ut* stack))) (add-process new-stack)) (actions-loop other-actions active-= stacks)) (else --=20 Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar=C2=AE http://AvatarAcademy.= nl =20