From b43380c8d8df98f3666ac5df01a8b6abbaf5ba56 Mon Sep 17 00:00:00 2001 From: Matt Wette Date: Sun, 5 Mar 2017 13:22:51 -0800 Subject: [PATCH] nyacc: removed start from lalr-spec -- not needed --- module/nyacc/export.scm | 6 +++--- module/nyacc/lalr.scm | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/module/nyacc/export.scm b/module/nyacc/export.scm index 23584bde..64efb8b1 100644 --- a/module/nyacc/export.scm +++ b/module/nyacc/export.scm @@ -1,6 +1,6 @@ ;;; nyacc/export.scm ;;; -;;; Copyright (C) 2015 Matthew R. Wette +;;; Copyright (C) 2015,2017 Matthew R. Wette ;;; ;;; This library is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU Lesser General Public @@ -20,7 +20,7 @@ lalr->guile c-char token->bison elt->bison ) - #:use-module ((nyacc lalr) #:select (find-terminal pp-rule)) + #:use-module ((nyacc lalr) #:select (find-terminal pp-rule lalr-start)) #:use-module (nyacc lex) #:use-module (nyacc util) #:use-module ((srfi srfi-1) #:select (fold)) @@ -130,7 +130,7 @@ ;; Don't compact tables. (fmt port "%define lr.default-reduction accepting\n") ;; Provide start symbol. - (fmt port "%start ~A\n%%\n" (elt->bison (assq-ref spec 'start) terms)) + (fmt port "%start ~A\n%%\n" (elt->bison (lalr-start spec) terms)) ;; (do ((i 1 (1+ i))) ((= i nrule)) (let* ((lhs (vector-ref lhs-v i)) (rhs (vector-ref rhs-v i))) diff --git a/module/nyacc/lalr.scm b/module/nyacc/lalr.scm index fcdeb4e5..6b032f53 100644 --- a/module/nyacc/lalr.scm +++ b/module/nyacc/lalr.scm @@ -29,7 +29,7 @@ #:export-syntax (lalr-spec) #:export (*nyacc-version* make-lalr-machine compact-machine hashify-machine - lalr-match-table + lalr-start lalr-match-table restart-spec add-recovery-logic! pp-lalr-notice pp-lalr-grammar pp-lalr-machine write-lalr-actions write-lalr-tables @@ -508,12 +508,12 @@ ;; Put most referenced items first, but keep start and rhs-v at ;; top so that if we want to restart (see restart-spec) we can ;; reuse the tail here. - (cons 'start start-symbol) + ;;(cons 'start start-symbol) ; use lalr-start, aka rhs-v[0][0] (cons 'rhs-v (map-attr->vector al 'rhs)) ;; (cons 'restart-tail #t) ; see @code{restart-spec} below - (cons 'non-terms nl) (cons 'lhs-v (list->vector (reverse ll))) + (cons 'non-terms nl) (cons 'terminals tl) (cons 'attr (list (cons 'expect (or (assq-ref tree 'expect) 0)) @@ -522,7 +522,7 @@ (cons 'assc (assq-ref pna 'assc)) (cons 'prp-v (map-attr->vector al 'prec)) ; per-rule precedence (cons 'act-v (map-attr->vector al 'act)) - (cons 'ref-v (map-attr->vector al 'ref)) + (cons 'ref-v (map-attr->vector al 'ref)) ; action references (cons 'err-l err-l) )))))))) @@ -535,14 +535,20 @@ ;; vector of vector of right-hand side symbols. (define *lalr-core* (make-fluid #f)) +;; @deffn {Procedure} lalr-start spec => symbol +;; Return the start symbol for the grammar. +;; @end deffn +(define (lalr-start spec) + (vector-ref (vector-ref (assq-ref spec 'rhs-v) 0) 0)) + ;; This record holds the minimum data from the grammar needed to build the ;; machine from the grammar specification. (define-record-type lalr-core-type - (make-lalr-core non-terms terminals start lhs-v rhs-v eps-l) + ;;(make-lalr-core non-terms terminals start lhs-v rhs-v eps-l) + (make-lalr-core non-terms terminals lhs-v rhs-v eps-l) lalr-core-type? (non-terms core-non-terms) ; list of non-terminals (terminals core-terminals) ; list of non-terminals - (start core-start) ; start non-terminal (lhs-v core-lhs-v) ; vec of left hand sides (rhs-v core-rhs-v) ; vec of right hand sides (eps-l core-eps-l)) ; non-terms w/ eps prod's @@ -551,7 +557,6 @@ (define (make-core spec) (make-lalr-core (assq-ref spec 'non-terms) (assq-ref spec 'terminals) - (assq-ref spec 'start) (assq-ref spec 'lhs-v) (assq-ref spec 'rhs-v) '())) @@ -561,10 +566,9 @@ (define (make-core/extras spec) (let ((non-terms (assq-ref spec 'non-terms)) (terminals (assq-ref spec 'terminals)) - (start (assq-ref spec 'start)) (lhs-v (assq-ref spec 'lhs-v)) (rhs-v (assq-ref spec 'rhs-v))) - (make-lalr-core non-terms terminals start lhs-v rhs-v + (make-lalr-core non-terms terminals lhs-v rhs-v (find-eps non-terms lhs-v rhs-v)))) @@ -1532,9 +1536,9 @@ ;; len-v - rule lengths ;; rto-v - hashed lhs symbols (rto = reduce to) ;; to print itemsets need: -;; kis-v - itemsets ;; lhs-v - left hand sides ;; rhs-v - right hand sides +;; kis-v - itemsets ;; pat-v - action table ;; @deffn restart-spec [spec|mach] start => spec @@ -1545,8 +1549,7 @@ (define (restart-spec spec start) (let* ((rhs-v (vector-copy (assq-ref spec 'rhs-v)))) (vector-set! rhs-v 0 (vector start)) - (cons* (cons 'start start) - (cons 'rhs-v rhs-v) + (cons* (cons 'rhs-v rhs-v) (member '(restart-tail . #t) spec)))) ;; @deffn make-lalr-machine spec => pgen