Mercurial > emacs
annotate lisp/cedet/semantic/wisent/comp.el @ 105966:1b85a4b6472f
(ffap-alternate-file-other-window, ffap-literally): New functions.
(find-file-literally-at-point): Alias of `ffap-literally'.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Thu, 12 Nov 2009 10:41:50 +0000 |
parents | 7f4c7f5c0eba |
children | 019d906c8f48 |
rev | line source |
---|---|
104478
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1 ;;; semantic/wisent/comp.el --- GNU Bison for Emacs - Grammar compiler |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3 ;; Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002, 2003, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
4 ;; 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
5 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
6 ;; Author: David Ponce <david@dponce.com> |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
7 ;; Maintainer: David Ponce <david@dponce.com> |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
8 ;; Created: 30 January 2002 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
9 ;; Keywords: syntax |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
10 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
11 ;; This file is part of GNU Emacs. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
12 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
16 ;; (at your option) any later version. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
17 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
21 ;; GNU General Public License for more details. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
22 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
25 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
26 ;;; Commentary: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
27 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
28 ;; Grammar compiler that produces Wisent's LALR automatons. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
29 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
30 ;; Wisent (the European Bison ;-) is an Elisp implementation of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
31 ;; GNU Compiler Compiler Bison. The Elisp code is a port of the C |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
32 ;; code of GNU Bison 1.28 & 1.31. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
33 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
34 ;; For more details on the basic concepts for understanding Wisent, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
35 ;; read the Bison manual ;) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
36 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
37 ;; For more details on Wisent itself read the Wisent manual. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
38 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
39 ;;; History: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
40 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
41 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
42 ;;; Code: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
43 (require 'semantic/wisent) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
44 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
45 ;;;; ------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
46 ;;;; Misc. useful things |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
47 ;;;; ------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
48 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
49 ;; As much as possible I would like to keep the name of global |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
50 ;; variables used in Bison without polluting too much the Elisp global |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
51 ;; name space. Elisp dynamic binding allows that ;-) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
52 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
53 ;; Here are simple macros to easily define and use set of variables |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
54 ;; binded locally, without all these "reference to free variable" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
55 ;; compiler warnings! |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
56 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
57 (defmacro wisent-context-name (name) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
58 "Return the context name from NAME." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
59 `(if (and ,name (symbolp ,name)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
60 (intern (format "wisent-context-%s" ,name)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
61 (error "Invalid context name: %S" ,name))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
62 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
63 (defmacro wisent-context-bindings (name) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
64 "Return the variables in context NAME." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
65 `(symbol-value (wisent-context-name ,name))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
66 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
67 (defmacro wisent-defcontext (name &rest vars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
68 "Define a context NAME that will bind variables VARS." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
69 (let* ((context (wisent-context-name name)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
70 (bindings (mapcar #'(lambda (v) (list 'defvar v)) vars))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
71 `(eval-when-compile |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
72 ,@bindings |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
73 (defvar ,context ',vars)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
74 (put 'wisent-defcontext 'lisp-indent-function 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
75 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
76 (defmacro wisent-with-context (name &rest body) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
77 "Bind variables in context NAME then eval BODY." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
78 `(let* ,(wisent-context-bindings name) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
79 ,@body)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
80 (put 'wisent-with-context 'lisp-indent-function 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
81 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
82 ;; A naive implementation of data structures! But it suffice here ;-) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
83 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
84 (defmacro wisent-struct (name &rest fields) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
85 "Define a simple data structure called NAME. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
86 Which contains data stored in FIELDS. FIELDS is a list of symbols |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
87 which are field names or pairs (FIELD INITIAL-VALUE) where |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
88 INITIAL-VALUE is a constant used as the initial value of FIELD when |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
89 the data structure is created. INITIAL-VALUE defaults to nil. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
90 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
91 This defines a `make-NAME' constructor, get-able `NAME-FIELD' and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
92 set-able `set-NAME-FIELD' accessors." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
93 (let ((size (length fields)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
94 (i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
95 accors field sufx fun ivals) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
96 (while (< i size) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
97 (setq field (car fields) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
98 fields (cdr fields)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
99 (if (consp field) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
100 (setq ivals (cons (cadr field) ivals) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
101 field (car field)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
102 (setq ivals (cons nil ivals))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
103 (setq sufx (format "%s-%s" name field) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 fun (intern (format "%s" sufx)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 accors (cons `(defmacro ,fun (s) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
106 (list 'aref s ,i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
107 accors) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
108 fun (intern (format "set-%s" sufx)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
109 accors (cons `(defmacro ,fun (s v) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
110 (list 'aset s ,i v)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
111 accors) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 `(progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 (defmacro ,(intern (format "make-%s" name)) () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
115 (cons 'vector ',(nreverse ivals))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
116 ,@accors))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
117 (put 'wisent-struct 'lisp-indent-function 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 ;; Other utilities |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
120 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
121 (defsubst wisent-pad-string (s n &optional left) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
122 "Fill string S with spaces. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 Return a new string of at least N characters. Insert spaces on right. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 If optional LEFT is non-nil insert spaces on left." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
125 (let ((i (length s))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 (if (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 (if left |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 (concat (make-string (- n i) ?\ ) s) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 (concat s (make-string (- n i) ?\ ))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 s))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
132 ;;;; ------------------------ |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 ;;;; Environment dependencies |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
134 ;;;; ------------------------ |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 (defconst wisent-BITS-PER-WORD |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 (let ((i 1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
138 (while (not (zerop (lsh 1 i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
139 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
140 i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
141 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
142 (defsubst wisent-WORDSIZE (n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 "(N + BITS-PER-WORD - 1) / BITS-PER-WORD." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 (/ (1- (+ n wisent-BITS-PER-WORD)) wisent-BITS-PER-WORD)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
145 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
146 (defsubst wisent-SETBIT (x i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 "X[I/BITS-PER-WORD] |= 1 << (I % BITS-PER-WORD)." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
148 (let ((k (/ i wisent-BITS-PER-WORD))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
149 (aset x k (logior (aref x k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
150 (lsh 1 (% i wisent-BITS-PER-WORD)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
151 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
152 (defsubst wisent-RESETBIT (x i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
153 "X[I/BITS-PER-WORD] &= ~(1 << (I % BITS-PER-WORD))." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
154 (let ((k (/ i wisent-BITS-PER-WORD))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 (aset x k (logand (aref x k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
156 (lognot (lsh 1 (% i wisent-BITS-PER-WORD))))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
157 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
158 (defsubst wisent-BITISSET (x i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
159 "(X[I/BITS-PER-WORD] & (1 << (I % BITS-PER-WORD))) != 0." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 (not (zerop (logand (aref x (/ i wisent-BITS-PER-WORD)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 (lsh 1 (% i wisent-BITS-PER-WORD)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 (eval-when-compile |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 (or (fboundp 'noninteractive) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 ;; Silence the Emacs byte compiler |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 (defun noninteractive nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
167 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
168 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 (defsubst wisent-noninteractive () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
170 "Return non-nil if running without interactive terminal." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
171 (if (featurep 'xemacs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
172 (noninteractive) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
173 noninteractive)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
174 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
175 (defvar wisent-debug-flag nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
176 "Non-nil means enable some debug stuff.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
177 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
178 ;;;; -------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
179 ;;;; Logging/Output |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
180 ;;;; -------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
181 (defconst wisent-log-buffer-name "*wisent-log*" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
182 "Name of the log buffer.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
183 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 (defvar wisent-new-log-flag nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 "Non-nil means to start a new report.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 (defvar wisent-verbose-flag nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 "*Non-nil means to report verbose information on generated parser.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 (defun wisent-toggle-verbose-flag () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 "Toggle whether to report verbose information on generated parser." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
192 (interactive) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
193 (setq wisent-verbose-flag (not wisent-verbose-flag)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
194 (when (interactive-p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
195 (message "Verbose report %sabled" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
196 (if wisent-verbose-flag "en" "dis")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
197 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
198 (defmacro wisent-log-buffer () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
199 "Return the log buffer. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
200 Its name is defined in constant `wisent-log-buffer-name'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
201 `(get-buffer-create wisent-log-buffer-name)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
202 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
203 (defmacro wisent-clear-log () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
204 "Delete the entire contents of the log buffer." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
205 `(with-current-buffer (wisent-log-buffer) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
206 (erase-buffer))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
207 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
208 (eval-when-compile (defvar byte-compile-current-file)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
209 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
210 (defun wisent-source () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
211 "Return the current source file name or nil." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
212 (let ((source (or (and (boundp 'byte-compile-current-file) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
213 byte-compile-current-file) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
214 load-file-name (buffer-file-name)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
215 (if source |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
216 (file-relative-name source)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
217 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
218 (defun wisent-new-log () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
219 "Start a new entry into the log buffer." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
220 (setq wisent-new-log-flag nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
221 (let ((text (format "\n\n*** Wisent %s - %s\n\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
222 (or (wisent-source) (buffer-name)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
223 (format-time-string "%Y-%m-%d %R")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
224 (with-current-buffer (wisent-log-buffer) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
225 (goto-char (point-max)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
226 (insert text)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
227 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
228 (defsubst wisent-log (&rest args) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
229 "Insert text into the log buffer. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
230 `format' is applied to ARGS and the result string is inserted into the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
231 log buffer returned by the function `wisent-log-buffer'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
232 (and wisent-new-log-flag (wisent-new-log)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
233 (with-current-buffer (wisent-log-buffer) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
234 (insert (apply 'format args)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
235 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
236 (defconst wisent-log-file "wisent.output" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
237 "The log file. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
238 Used when running without interactive terminal.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
239 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
240 (defun wisent-append-to-log-file () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
241 "Append contents of logging buffer to `wisent-log-file'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
242 (if (get-buffer wisent-log-buffer-name) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
243 (condition-case err |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
244 (with-current-buffer (wisent-log-buffer) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
245 (widen) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
246 (if (> (point-max) (point-min)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
247 (write-region (point-min) (point-max) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
248 wisent-log-file t))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
249 (error |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
250 (message "*** %s" (error-message-string err)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
251 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
252 ;;;; ----------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
253 ;;;; Representation of the grammar rules |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
254 ;;;; ----------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
255 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
256 ;; ntokens is the number of tokens, and nvars is the number of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
257 ;; variables (nonterminals). nsyms is the total number, ntokens + |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
258 ;; nvars. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
259 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
260 ;; Each symbol (either token or variable) receives a symbol number. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
261 ;; Numbers 0 to ntokens-1 are for tokens, and ntokens to nsyms-1 are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
262 ;; for variables. Symbol number zero is the end-of-input token. This |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
263 ;; token is counted in ntokens. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
264 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
265 ;; The rules receive rule numbers 1 to nrules in the order they are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
266 ;; written. Actions and guards are accessed via the rule number. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
267 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
268 ;; The rules themselves are described by three arrays: rrhs, rlhs and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
269 ;; ritem. rlhs[R] is the symbol number of the left hand side of rule |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
270 ;; R. The right hand side is stored as symbol numbers in a portion of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
271 ;; ritem. rrhs[R] contains the index in ritem of the beginning of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
272 ;; portion for rule R. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
273 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
274 ;; The length of the portion is one greater than the number of symbols |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
275 ;; in the rule's right hand side. The last element in the portion |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
276 ;; contains minus R, which identifies it as the end of a portion and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
277 ;; says which rule it is for. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
278 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
279 ;; The portions of ritem come in order of increasing rule number and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
280 ;; are followed by an element which is nil to mark the end. nitems is |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
281 ;; the total length of ritem, not counting the final nil. Each |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
282 ;; element of ritem is called an "item" and its index in ritem is an |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
283 ;; item number. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
284 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
285 ;; Item numbers are used in the finite state machine to represent |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
286 ;; places that parsing can get to. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
287 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
288 ;; The vector rprec contains for each rule, the item number of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
289 ;; symbol giving its precedence level to this rule. The precedence |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
290 ;; level and associativity of each symbol is recorded in respectively |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
291 ;; the properties 'wisent--prec and 'wisent--assoc. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
292 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
293 ;; Precedence levels are assigned in increasing order starting with 1 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
294 ;; so that numerically higher precedence values mean tighter binding |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
295 ;; as they ought to. nil as a symbol or rule's precedence means none |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
296 ;; is assigned. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
297 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
298 (defcustom wisent-state-table-size 1009 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
299 "The size of the state table." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
300 :type 'integer |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
301 :group 'wisent) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
302 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
303 ;; These variables only exist locally in the function |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
304 ;; `wisent-compile-grammar' and are shared by all other nested |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
305 ;; callees. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
306 (wisent-defcontext compile-grammar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
307 F LA LAruleno accessing-symbol conflicts consistent default-prec |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
308 derives err-table fderives final-state first-reduction first-shift |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
309 first-state firsts from-state goto-map includes itemset nitemset |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
310 kernel-base kernel-end kernel-items last-reduction last-shift |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
311 last-state lookaheads lookaheadset lookback maxrhs ngotos nitems |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
312 nrules nshifts nstates nsyms ntokens nullable nvars rassoc redset |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
313 reduction-table ritem rlhs rprec rrc-count rrc-total rrhs ruseful |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
314 rcode ruleset rulesetsize shift-symbol shift-table shiftset |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
315 src-count src-total start-table state-table tags this-state to-state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
316 tokensetsize ;; nb of words req. to hold a bit for each rule |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
317 varsetsize ;; nb of words req. to hold a bit for each variable |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
318 error-token-number start-symbol token-list var-list |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
319 N P V V1 nuseless-nonterminals nuseless-productions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
320 ptable ;; symbols & characters properties |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
321 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
322 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
323 (defmacro wisent-ISTOKEN (s) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
324 "Return non-nil if item number S defines a token (terminal). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
325 That is if S < `ntokens'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
326 `(< ,s ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
327 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
328 (defmacro wisent-ISVAR(s) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
329 "Return non-nil if item number S defines a nonterminal. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
330 That is if S >= `ntokens'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
331 `(>= ,s ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
332 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
333 (defsubst wisent-tag (s) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
334 "Return printable form of item number S." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
335 (wisent-item-to-string (aref tags s))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
336 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
337 ;; Symbol and character properties |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
338 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
339 (defsubst wisent-put (object propname value) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
340 "Store OBJECT's PROPNAME property with value VALUE. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
341 Use `eq' to locate OBJECT." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
342 (let ((entry (assq object ptable))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
343 (or entry (setq entry (list object) ptable (cons entry ptable))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
344 (setcdr entry (plist-put (cdr entry) propname value)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
345 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
346 (defsubst wisent-get (object propname) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
347 "Return the value of OBJECT's PROPNAME property. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
348 Use `eq' to locate OBJECT." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
349 (plist-get (cdr (assq object ptable)) propname)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
350 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
351 (defsubst wisent-item-number (x) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
352 "Return the item number of symbol X." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
353 (wisent-get x 'wisent--item-no)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
354 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
355 (defsubst wisent-set-item-number (x n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
356 "Set the item number of symbol X to N." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
357 (wisent-put x 'wisent--item-no n)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
358 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
359 (defsubst wisent-assoc (x) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
360 "Return the associativity of symbol X." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
361 (wisent-get x 'wisent--assoc)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
362 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
363 (defsubst wisent-set-assoc (x a) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
364 "Set the associativity of symbol X to A." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
365 (wisent-put x 'wisent--assoc a)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
366 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
367 (defsubst wisent-prec (x) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
368 "Return the precedence level of symbol X." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
369 (wisent-get x 'wisent--prec)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
370 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
371 (defsubst wisent-set-prec (x p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
372 "Set the precedence level of symbol X to P." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
373 (wisent-put x 'wisent--prec p)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
374 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
375 ;;;; ---------------------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
376 ;;;; Type definitions for nondeterministic finite state machine |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
377 ;;;; ---------------------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
378 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
379 ;; These type definitions are used to represent a nondeterministic |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
380 ;; finite state machine that parses the specified grammar. This |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
381 ;; information is generated by the function `wisent-generate-states'. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
382 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
383 ;; Each state of the machine is described by a set of items -- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
384 ;; particular positions in particular rules -- that are the possible |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
385 ;; places where parsing could continue when the machine is in this |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
386 ;; state. These symbols at these items are the allowable inputs that |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
387 ;; can follow now. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
388 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
389 ;; A core represents one state. States are numbered in the number |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
390 ;; field. When `wisent-generate-states' is finished, the starting |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
391 ;; state is state 0 and `nstates' is the number of states. (A |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
392 ;; transition to a state whose state number is `nstates' indicates |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
393 ;; termination.) All the cores are chained together and `first-state' |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
394 ;; points to the first one (state 0). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
395 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
396 ;; For each state there is a particular symbol which must have been |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
397 ;; the last thing accepted to reach that state. It is the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
398 ;; accessing-symbol of the core. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
399 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
400 ;; Each core contains a vector of `nitems' items which are the indices |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
401 ;; in the `ritems' vector of the items that are selected in this |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
402 ;; state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
403 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
404 ;; The link field is used for chaining buckets that hash states by |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
405 ;; their itemsets. This is for recognizing equivalent states and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
406 ;; combining them when the states are generated. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
407 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
408 ;; The two types of transitions are shifts (push the lookahead token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
409 ;; and read another) and reductions (combine the last n things on the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
410 ;; stack via a rule, replace them with the symbol that the rule |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
411 ;; derives, and leave the lookahead token alone). When the states are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
412 ;; generated, these transitions are represented in two other lists. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
413 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
414 ;; Each shifts structure describes the possible shift transitions out |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
415 ;; of one state, the state whose number is in the number field. The |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
416 ;; shifts structures are linked through next and first-shift points to |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
417 ;; them. Each contains a vector of numbers of the states that shift |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
418 ;; transitions can go to. The accessing-symbol fields of those |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
419 ;; states' cores say what kind of input leads to them. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
420 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
421 ;; A shift to state zero should be ignored. Conflict resolution |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
422 ;; deletes shifts by changing them to zero. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
423 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
424 ;; Each reductions structure describes the possible reductions at the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
425 ;; state whose number is in the number field. The data is a list of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
426 ;; nreds rules, represented by their rule numbers. `first-reduction' |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
427 ;; points to the list of these structures. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
428 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
429 ;; Conflict resolution can decide that certain tokens in certain |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
430 ;; states should explicitly be errors (for implementing %nonassoc). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
431 ;; For each state, the tokens that are errors for this reason are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
432 ;; recorded in an errs structure, which has the state number in its |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
433 ;; number field. The rest of the errs structure is full of token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
434 ;; numbers. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
435 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
436 ;; There is at least one shift transition present in state zero. It |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
437 ;; leads to a next-to-final state whose accessing-symbol is the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
438 ;; grammar's start symbol. The next-to-final state has one shift to |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
439 ;; the final state, whose accessing-symbol is zero (end of input). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
440 ;; The final state has one shift, which goes to the termination state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
441 ;; (whose number is `nstates'-1). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
442 ;; The reason for the extra state at the end is to placate the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
443 ;; parser's strategy of making all decisions one token ahead of its |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
444 ;; actions. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
445 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
446 (wisent-struct core |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
447 next ; -> core |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
448 link ; -> core |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
449 (number 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
450 (accessing-symbol 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
451 (nitems 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
452 (items [0])) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
453 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
454 (wisent-struct shifts |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
455 next ; -> shifts |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
456 (number 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
457 (nshifts 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
458 (shifts [0])) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
459 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
460 (wisent-struct reductions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
461 next ; -> reductions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
462 (number 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
463 (nreds 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
464 (rules [0])) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
465 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
466 (wisent-struct errs |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
467 (nerrs 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
468 (errs [0])) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
469 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
470 ;;;; -------------------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
471 ;;;; Find unreachable terminals, nonterminals and productions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
472 ;;;; -------------------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
473 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
474 (defun wisent-bits-equal (L R n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
475 "Visit L and R and return non-nil if their first N elements are `='. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
476 L and R must be vectors of integers." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
477 (let* ((i (1- n)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
478 (iseq t)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
479 (while (and iseq (natnump i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
480 (setq iseq (= (aref L i) (aref R i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
481 i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
482 iseq)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
483 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
484 (defun wisent-nbits (i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
485 "Return number of bits set in integer I." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
486 (let ((count 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
487 (while (not (zerop i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
488 ;; i ^= (i & ((unsigned) (-(int) i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
489 (setq i (logxor i (logand i (- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
490 count (1+ count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
491 count)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
492 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
493 (defun wisent-bits-size (S n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
494 "In vector S count the total of bits set in first N elements. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
495 S must be a vector of integers." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
496 (let* ((i (1- n)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
497 (count 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
498 (while (natnump i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
499 (setq count (+ count (wisent-nbits (aref S i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
500 i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
501 count)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
502 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
503 (defun wisent-useful-production (i N0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
504 "Return non-nil if production I is in useful set N0." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
505 (let* ((useful t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
506 (r (aref rrhs i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
507 n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
508 (while (and useful (> (setq n (aref ritem r)) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
509 (if (wisent-ISVAR n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
510 (setq useful (wisent-BITISSET N0 (- n ntokens)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
511 (setq r (1+ r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
512 useful)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
513 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
514 (defun wisent-useless-nonterminals () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
515 "Find out which nonterminals are used." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
516 (let (Np Ns i n break) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
517 ;; N is set as built. Np is set being built this iteration. P is |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
518 ;; set of all productions which have a RHS all in N. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
519 (setq n (wisent-WORDSIZE nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
520 Np (make-vector n 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
521 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
522 ;; The set being computed is a set of nonterminals which can |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
523 ;; derive the empty string or strings consisting of all |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
524 ;; terminals. At each iteration a nonterminal is added to the set |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
525 ;; if there is a production with that nonterminal as its LHS for |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
526 ;; which all the nonterminals in its RHS are already in the set. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
527 ;; Iterate until the set being computed remains unchanged. Any |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
528 ;; nonterminals not in the set at that point are useless in that |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
529 ;; they will never be used in deriving a sentence of the language. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
530 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
531 ;; This iteration doesn't use any special traversal over the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
532 ;; productions. A set is kept of all productions for which all |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
533 ;; the nonterminals in the RHS are in useful. Only productions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
534 ;; not in this set are scanned on each iteration. At the end, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
535 ;; this set is saved to be used when finding useful productions: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
536 ;; only productions in this set will appear in the final grammar. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
537 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
538 (while (not break) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
539 (setq i (1- n)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
540 (while (natnump i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
541 ;; Np[i] = N[i] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
542 (aset Np i (aref N i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
543 (setq i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
544 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
545 (setq i 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
546 (while (<= i nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
547 (if (not (wisent-BITISSET P i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
548 (when (wisent-useful-production i N) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
549 (wisent-SETBIT Np (- (aref rlhs i) ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
550 (wisent-SETBIT P i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
551 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
552 (if (wisent-bits-equal N Np n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
553 (setq break t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
554 (setq Ns Np |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
555 Np N |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
556 N Ns))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
557 (setq N Np))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
558 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
559 (defun wisent-inaccessable-symbols () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
560 "Find out which productions are reachable and which symbols are used." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
561 ;; Starting with an empty set of productions and a set of symbols |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
562 ;; which only has the start symbol in it, iterate over all |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
563 ;; productions until the set of productions remains unchanged for an |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
564 ;; iteration. For each production which has a LHS in the set of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
565 ;; reachable symbols, add the production to the set of reachable |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
566 ;; productions, and add all of the nonterminals in the RHS of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
567 ;; production to the set of reachable symbols. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
568 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
569 ;; Consider only the (partially) reduced grammar which has only |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
570 ;; nonterminals in N and productions in P. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
571 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
572 ;; The result is the set P of productions in the reduced grammar, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
573 ;; and the set V of symbols in the reduced grammar. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
574 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
575 ;; Although this algorithm also computes the set of terminals which |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
576 ;; are reachable, no terminal will be deleted from the grammar. Some |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
577 ;; terminals might not be in the grammar but might be generated by |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
578 ;; semantic routines, and so the user might want them available with |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
579 ;; specified numbers. (Is this true?) However, the non reachable |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
580 ;; terminals are printed (if running in verbose mode) so that the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
581 ;; user can know. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
582 (let (Vp Vs Pp i tt r n m break) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
583 (setq n (wisent-WORDSIZE nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
584 m (wisent-WORDSIZE (1+ nrules)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
585 Vp (make-vector n 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
586 Pp (make-vector m 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
587 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
588 ;; If the start symbol isn't useful, then nothing will be useful. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
589 (when (wisent-BITISSET N (- start-symbol ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
590 (wisent-SETBIT V start-symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
591 (while (not break) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
592 (setq i (1- n)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
593 (while (natnump i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
594 (aset Vp i (aref V i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
595 (setq i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
596 (setq i 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
597 (while (<= i nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
598 (when (and (not (wisent-BITISSET Pp i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
599 (wisent-BITISSET P i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
600 (wisent-BITISSET V (aref rlhs i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
601 (setq r (aref rrhs i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
602 (while (natnump (setq tt (aref ritem r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
603 (if (or (wisent-ISTOKEN tt) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
604 (wisent-BITISSET N (- tt ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
605 (wisent-SETBIT Vp tt)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
606 (setq r (1+ r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
607 (wisent-SETBIT Pp i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
608 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
609 (if (wisent-bits-equal V Vp n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
610 (setq break t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
611 (setq Vs Vp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
612 Vp V |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
613 V Vs)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
614 (setq V Vp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
615 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
616 ;; Tokens 0, 1 are internal to Wisent. Consider them useful. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
617 (wisent-SETBIT V 0) ;; end-of-input token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
618 (wisent-SETBIT V 1) ;; error token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
619 (setq P Pp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
620 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
621 (setq nuseless-productions (- nrules (wisent-bits-size P m)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
622 nuseless-nonterminals nvars |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
623 i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
624 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
625 (if (wisent-BITISSET V i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
626 (setq nuseless-nonterminals (1- nuseless-nonterminals))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
627 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
628 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
629 ;; A token that was used in %prec should not be warned about. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
630 (setq i 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
631 (while (<= i nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
632 (if (aref rprec i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
633 (wisent-SETBIT V1 (aref rprec i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
634 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
635 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
636 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
637 (defun wisent-reduce-grammar-tables () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
638 "Disable useless productions." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
639 (if (> nuseless-productions 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
640 (let ((pn 1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
641 (while (<= pn nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
642 (aset ruseful pn (wisent-BITISSET P pn)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
643 (setq pn (1+ pn)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
644 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
645 (defun wisent-nonterminals-reduce () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
646 "Remove useless nonterminals." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
647 (let (i n r item nontermmap tags-sorted) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
648 ;; Map the nonterminals to their new index: useful first, useless |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
649 ;; afterwards. Kept for later report. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
650 (setq nontermmap (make-vector nvars 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
651 n ntokens |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
652 i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
653 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
654 (when (wisent-BITISSET V i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
655 (aset nontermmap (- i ntokens) n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
656 (setq n (1+ n))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
657 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
658 (setq i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
659 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
660 (unless (wisent-BITISSET V i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
661 (aset nontermmap (- i ntokens) n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
662 (setq n (1+ n))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
663 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
664 ;; Shuffle elements of tables indexed by symbol number |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
665 (setq tags-sorted (make-vector nvars nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
666 i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
667 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
668 (setq n (aref nontermmap (- i ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
669 (aset tags-sorted (- n ntokens) (aref tags i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
670 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
671 (setq i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
672 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
673 (aset tags i (aref tags-sorted (- i ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
674 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
675 ;; Replace all symbol numbers in valid data structures. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
676 (setq i 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
677 (while (<= i nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
678 (aset rlhs i (aref nontermmap (- (aref rlhs i) ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
679 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
680 (setq r 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
681 (while (setq item (aref ritem r)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
682 (if (wisent-ISVAR item) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
683 (aset ritem r (aref nontermmap (- item ntokens)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
684 (setq r (1+ r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
685 (setq start-symbol (aref nontermmap (- start-symbol ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
686 nsyms (- nsyms nuseless-nonterminals) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
687 nvars (- nvars nuseless-nonterminals)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
688 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
689 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
690 (defun wisent-total-useless () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
691 "Report number of useless nonterminals and productions." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
692 (let* ((src (wisent-source)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
693 (src (if src (concat " in " src) "")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
694 (msg (format "Grammar%s contains" src))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
695 (if (> nuseless-nonterminals 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
696 (setq msg (format "%s %d useless nonterminal%s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
697 msg nuseless-nonterminals |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
698 (if (> nuseless-nonterminals 0) "s" "")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
699 (if (and (> nuseless-nonterminals 0) (> nuseless-productions 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
700 (setq msg (format "%s and" msg))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
701 (if (> nuseless-productions 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
702 (setq msg (format "%s %d useless rule%s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
703 msg nuseless-productions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
704 (if (> nuseless-productions 0) "s" "")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
705 (message msg))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
706 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
707 (defun wisent-reduce-grammar () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
708 "Find unreachable terminals, nonterminals and productions." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
709 ;; Allocate the global sets used to compute the reduced grammar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
710 (setq N (make-vector (wisent-WORDSIZE nvars) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
711 P (make-vector (wisent-WORDSIZE (1+ nrules)) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
712 V (make-vector (wisent-WORDSIZE nsyms) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
713 V1 (make-vector (wisent-WORDSIZE nsyms) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
714 nuseless-nonterminals 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
715 nuseless-productions 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
716 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
717 (wisent-useless-nonterminals) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
718 (wisent-inaccessable-symbols) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
719 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
720 (when (> (+ nuseless-nonterminals nuseless-productions) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
721 (wisent-total-useless) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
722 (or (wisent-BITISSET N (- start-symbol ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
723 (error "Start symbol `%s' does not derive any sentence" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
724 (wisent-tag start-symbol))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
725 (wisent-reduce-grammar-tables) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
726 (if (> nuseless-nonterminals 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
727 (wisent-nonterminals-reduce)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
728 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
729 (defun wisent-print-useless () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
730 "Output the detailed results of the reductions." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
731 (let (i b r) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
732 (when (> nuseless-nonterminals 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
733 ;; Useless nonterminals have been moved after useful ones. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
734 (wisent-log "\n\nUseless nonterminals:\n\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
735 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
736 (while (< i nuseless-nonterminals) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
737 (wisent-log " %s\n" (wisent-tag (+ nsyms i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
738 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
739 (setq b nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
740 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
741 (while (< i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
742 (unless (or (wisent-BITISSET V i) (wisent-BITISSET V1 i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
743 (or b |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
744 (wisent-log "\n\nTerminals which are not used:\n\n")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
745 (setq b t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
746 (wisent-log " %s\n" (wisent-tag i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
747 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
748 (when (> nuseless-productions 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
749 (wisent-log "\n\nUseless rules:\n\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
750 (setq i 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
751 (while (<= i nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
752 (unless (aref ruseful i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
753 (wisent-log "#%s " (wisent-pad-string (format "%d" i) 4)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
754 (wisent-log "%s:" (wisent-tag (aref rlhs i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
755 (setq r (aref rrhs i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
756 (while (natnump (aref ritem r)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
757 (wisent-log " %s" (wisent-tag (aref ritem r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
758 (setq r (1+ r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
759 (wisent-log ";\n")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
760 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
761 (if (or b (> nuseless-nonterminals 0) (> nuseless-productions 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
762 (wisent-log "\n\n")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
763 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
764 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
765 ;;;; ----------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
766 ;;;; Match rules with nonterminals |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
767 ;;;; ----------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
768 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
769 (defun wisent-set-derives () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
770 "Find, for each variable (nonterminal), which rules can derive it. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
771 It sets up the value of DERIVES so that DERIVES[i - NTOKENS] points to |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
772 a list of rule numbers, terminated with -1." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
773 (let (i lhs p q dset delts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
774 (setq dset (make-vector nvars nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
775 delts (make-vector (1+ nrules) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
776 (setq p 0 ;; p = delts |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
777 i nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
778 (while (> i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
779 (when (aref ruseful i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
780 (setq lhs (aref rlhs i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
781 ;; p->next = dset[lhs]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
782 ;; p->value = i; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
783 (aset delts p (cons i (aref dset (- lhs ntokens)))) ;; (value . next) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
784 (aset dset (- lhs ntokens) p) ;; dset[lhs] = p |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
785 (setq p (1+ p)) ;; p++ |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
786 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
787 (setq i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
788 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
789 (setq derives (make-vector nvars nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
790 i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
791 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
792 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
793 (setq q nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
794 p (aref dset (- i ntokens))) ;; p = dset[i] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
795 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
796 (while p |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
797 (setq p (aref delts p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
798 q (cons (car p) q) ;;q++ = p->value |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
799 p (cdr p))) ;; p = p->next |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
800 (setq q (nreverse (cons -1 q))) ;; *q++ = -1 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
801 (aset derives (- i ntokens) q) ;; derives[i] = q |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
802 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
803 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
804 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
805 ;;;; -------------------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
806 ;;;; Find which nonterminals can expand into the null string. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
807 ;;;; -------------------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
808 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
809 (defun wisent-print-nullable () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
810 "Print NULLABLE." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
811 (let (i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
812 (wisent-log "NULLABLE\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
813 (setq i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
814 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
815 (wisent-log "\t%s: %s\n" (wisent-tag i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
816 (if (aref nullable (- i ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
817 "yes" : "no")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
818 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
819 (wisent-log "\n\n"))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
820 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
821 (defun wisent-set-nullable () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
822 "Set up NULLABLE. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
823 A vector saying which nonterminals can expand into the null string. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
824 NULLABLE[i - NTOKENS] is nil if symbol I can do so." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
825 (let (ruleno s1 s2 p r squeue rcount rsets relts item any-tokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
826 (setq squeue (make-vector nvars 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
827 rcount (make-vector (1+ nrules) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
828 rsets (make-vector nvars nil) ;; - ntokens |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
829 relts (make-vector (+ nitems nvars 1) nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
830 nullable (make-vector nvars nil)) ;; - ntokens |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
831 (setq s1 0 s2 0 ;; s1 = s2 = squeue |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
832 p 0 ;; p = relts |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
833 ruleno 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
834 (while (<= ruleno nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
835 (when (aref ruseful ruleno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
836 (if (> (aref ritem (aref rrhs ruleno)) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
837 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
838 ;; This rule has a non empty RHS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
839 (setq any-tokens nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
840 r (aref rrhs ruleno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
841 (while (> (aref ritem r) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
842 (if (wisent-ISTOKEN (aref ritem r)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
843 (setq any-tokens t)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
844 (setq r (1+ r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
845 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
846 ;; This rule has only nonterminals: schedule it for the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
847 ;; second pass. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
848 (unless any-tokens |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
849 (setq r (aref rrhs ruleno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
850 (while (> (setq item (aref ritem r)) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
851 (aset rcount ruleno (1+ (aref rcount ruleno))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
852 ;; p->next = rsets[item]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
853 ;; p->value = ruleno; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
854 (aset relts p (cons ruleno (aref rsets (- item ntokens)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
855 ;; rsets[item] = p; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
856 (aset rsets (- item ntokens) p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
857 (setq p (1+ p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
858 r (1+ r))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
859 ;; This rule has an empty RHS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
860 ;; assert (ritem[rrhs[ruleno]] == -ruleno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
861 (when (and (aref ruseful ruleno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
862 (setq item (aref rlhs ruleno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
863 (not (aref nullable (- item ntokens)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
864 (aset nullable (- item ntokens) t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
865 (aset squeue s2 item) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
866 (setq s2 (1+ s2))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
867 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
868 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
869 (setq ruleno (1+ ruleno))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
870 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
871 (while (< s1 s2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
872 ;; p = rsets[*s1++] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
873 (setq p (aref rsets (- (aref squeue s1) ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
874 s1 (1+ s1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
875 (while p |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
876 (setq p (aref relts p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
877 ruleno (car p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
878 p (cdr p)) ;; p = p->next |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
879 ;; if (--rcount[ruleno] == 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
880 (when (zerop (aset rcount ruleno (1- (aref rcount ruleno)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
881 (setq item (aref rlhs ruleno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
882 (aset nullable (- item ntokens) t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
883 (aset squeue s2 item) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
884 (setq s2 (1+ s2))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
885 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
886 (if wisent-debug-flag |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
887 (wisent-print-nullable)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
888 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
889 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
890 ;;;; ----------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
891 ;;;; Subroutines |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
892 ;;;; ----------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
893 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
894 (defun wisent-print-fderives () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
895 "Print FDERIVES." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
896 (let (i j rp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
897 (wisent-log "\n\n\nFDERIVES\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
898 (setq i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
899 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
900 (wisent-log "\n\n%s derives\n\n" (wisent-tag i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
901 (setq rp (aref fderives (- i ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
902 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
903 (while (<= j nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
904 (if (wisent-BITISSET rp j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
905 (wisent-log " %d\n" j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
906 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
907 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
908 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
909 (defun wisent-set-fderives () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
910 "Set up FDERIVES. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
911 An NVARS by NRULES matrix of bits indicating which rules can help |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
912 derive the beginning of the data for each nonterminal. For example, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
913 if symbol 5 can be derived as the sequence of symbols 8 3 20, and one |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
914 of the rules for deriving symbol 8 is rule 4, then the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
915 \[5 - NTOKENS, 4] bit in FDERIVES is set." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
916 (let (i j k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
917 (setq fderives (make-vector nvars nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
918 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
919 (while (< i nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
920 (aset fderives i (make-vector rulesetsize 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
921 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
922 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
923 (wisent-set-firsts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
924 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
925 (setq i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
926 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
927 (setq j ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
928 (while (< j nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
929 ;; if (BITISSET (FIRSTS (i), j - ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
930 (when (wisent-BITISSET (aref firsts (- i ntokens)) (- j ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
931 (setq k (aref derives (- j ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
932 (while (> (car k) 0) ;; derives[j][k] > 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
933 ;; SETBIT (FDERIVES (i), derives[j][k]); |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
934 (wisent-SETBIT (aref fderives (- i ntokens)) (car k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
935 (setq k (cdr k)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
936 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
937 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
938 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
939 (if wisent-debug-flag |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
940 (wisent-print-fderives)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
941 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
942 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
943 (defun wisent-print-firsts () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
944 "Print FIRSTS." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
945 (let (i j v) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
946 (wisent-log "\n\n\nFIRSTS\n\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
947 (setq i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
948 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
949 (wisent-log "\n\n%s firsts\n\n" (wisent-tag i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
950 (setq v (aref firsts (- i ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
951 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
952 (while (< j nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
953 (if (wisent-BITISSET v j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
954 (wisent-log "\t\t%d (%s)\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
955 (+ j ntokens) (wisent-tag (+ j ntokens)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
956 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
957 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
958 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
959 (defun wisent-TC (R n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
960 "Transitive closure. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
961 Given R an N by N matrix of bits, modify its contents to be the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
962 transitive closure of what was given." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
963 (let (i j k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
964 ;; R (J, I) && R (I, K) => R (J, K). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
965 ;; I *must* be the outer loop. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
966 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
967 (while (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
968 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
969 (while (< j n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
970 (when (wisent-BITISSET (aref R j) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
971 (setq k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
972 (while (< k n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
973 (if (wisent-BITISSET (aref R i) k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
974 (wisent-SETBIT (aref R j) k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
975 (setq k (1+ k)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
976 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
977 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
978 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
979 (defun wisent-RTC (R n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
980 "Reflexive Transitive Closure. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
981 Same as `wisent-TC' and then set all the bits on the diagonal of R, an |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
982 N by N matrix of bits." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
983 (let (i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
984 (wisent-TC R n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
985 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
986 (while (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
987 (wisent-SETBIT (aref R i) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
988 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
989 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
990 (defun wisent-set-firsts () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
991 "Set up FIRSTS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
992 An NVARS by NVARS bit matrix indicating which items can represent the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
993 beginning of the input corresponding to which other items. For |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
994 example, if some rule expands symbol 5 into the sequence of symbols 8 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
995 3 20, the symbol 8 can be the beginning of the data for symbol 5, so |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
996 the bit [8 - NTOKENS, 5 - NTOKENS] in FIRSTS is set." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
997 (let (row symbol sp rowsize i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
998 (setq rowsize (wisent-WORDSIZE nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
999 varsetsize rowsize |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1000 firsts (make-vector nvars nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1001 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1002 (while (< i nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1003 (aset firsts i (make-vector rowsize 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1004 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1005 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1006 (setq row 0 ;; row = firsts |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1007 i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1008 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1009 (setq sp (aref derives (- i ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1010 (while (>= (car sp) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1011 (setq symbol (aref ritem (aref rrhs (car sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1012 sp (cdr sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1013 (when (wisent-ISVAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1014 (setq symbol (- symbol ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1015 (wisent-SETBIT (aref firsts row) symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1016 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1017 (setq row (1+ row) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1018 i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1019 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1020 (wisent-RTC firsts nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1021 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1022 (if wisent-debug-flag |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1023 (wisent-print-firsts)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1024 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1025 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1026 (defun wisent-initialize-closure (n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1027 "Allocate the ITEMSET and RULESET vectors. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1028 And precompute useful data so that `wisent-closure' can be called. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1029 N is the number of elements to allocate for ITEMSET." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1030 (setq itemset (make-vector n 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1031 rulesetsize (wisent-WORDSIZE (1+ nrules)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1032 ruleset (make-vector rulesetsize 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1033 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1034 (wisent-set-fderives)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1035 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1036 (defun wisent-print-closure () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1037 "Print ITEMSET." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1038 (let (i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1039 (wisent-log "\n\nclosure n = %d\n\n" nitemset) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1040 (setq i 0) ;; isp = itemset |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1041 (while (< i nitemset) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1042 (wisent-log " %d\n" (aref itemset i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1043 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1044 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1045 (defun wisent-closure (core n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1046 "Set up RULESET and ITEMSET for the transitions out of CORE state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1047 Given a vector of item numbers items, of length N, set up RULESET and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1048 ITEMSET to indicate what rules could be run and which items could be |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1049 accepted when those items are the active ones. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1050 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1051 RULESET contains a bit for each rule. `wisent-closure' sets the bits |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1052 for all rules which could potentially describe the next input to be |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1053 read. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1054 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1055 ITEMSET is a vector of item numbers; NITEMSET is the number of items |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1056 in ITEMSET. `wisent-closure' places there the indices of all items |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1057 which represent units of input that could arrive next." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1058 (let (c r v symbol ruleno itemno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1059 (if (zerop n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1060 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1061 (setq r 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1062 v (aref fderives (- start-symbol ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1063 (while (< r rulesetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1064 ;; ruleset[r] = FDERIVES (start-symbol)[r]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1065 (aset ruleset r (aref v r)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1066 (setq r (1+ r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1067 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1068 (fillarray ruleset 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1069 (setq c 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1070 (while (< c n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1071 (setq symbol (aref ritem (aref core c))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1072 (when (wisent-ISVAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1073 (setq r 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1074 v (aref fderives (- symbol ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1075 (while (< r rulesetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1076 ;; ruleset[r] |= FDERIVES (ritem[core[c]])[r]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1077 (aset ruleset r (logior (aref ruleset r) (aref v r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1078 (setq r (1+ r)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1079 (setq c (1+ c))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1080 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1081 (setq nitemset 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1082 c 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1083 ruleno 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1084 r (* rulesetsize wisent-BITS-PER-WORD)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1085 (while (< ruleno r) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1086 (when (wisent-BITISSET ruleset ruleno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1087 (setq itemno (aref rrhs ruleno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1088 (while (and (< c n) (< (aref core c) itemno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1089 (aset itemset nitemset (aref core c)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1090 (setq nitemset (1+ nitemset) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1091 c (1+ c))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1092 (aset itemset nitemset itemno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1093 (setq nitemset (1+ nitemset))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1094 (setq ruleno (1+ ruleno))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1095 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1096 (while (< c n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1097 (aset itemset nitemset (aref core c)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1098 (setq nitemset (1+ nitemset) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1099 c (1+ c))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1100 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1101 (if wisent-debug-flag |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1102 (wisent-print-closure)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1103 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1104 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1105 ;;;; -------------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1106 ;;;; Generate the nondeterministic finite state machine |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1107 ;;;; -------------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1108 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1109 (defun wisent-allocate-itemsets () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1110 "Allocate storage for itemsets." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1111 (let (symbol i count symbol-count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1112 ;; Count the number of occurrences of all the symbols in RITEMS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1113 ;; Note that useless productions (hence useless nonterminals) are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1114 ;; browsed too, hence we need to allocate room for _all_ the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1115 ;; symbols. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1116 (setq count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1117 symbol-count (make-vector (+ nsyms nuseless-nonterminals) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1118 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1119 (while (setq symbol (aref ritem i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1120 (when (> symbol 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1121 (setq count (1+ count)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1122 (aset symbol-count symbol (1+ (aref symbol-count symbol)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1123 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1124 ;; See comments before `wisent-new-itemsets'. All the vectors of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1125 ;; items live inside kernel-items. The number of active items |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1126 ;; after some symbol cannot be more than the number of times that |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1127 ;; symbol appears as an item, which is symbol-count[symbol]. We |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1128 ;; allocate that much space for each symbol. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1129 (setq kernel-base (make-vector nsyms nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1130 kernel-items (make-vector count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1131 count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1132 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1133 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1134 (aset kernel-base i count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1135 (setq count (+ count (aref symbol-count i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1136 i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1137 (setq shift-symbol symbol-count |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1138 kernel-end (make-vector nsyms nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1139 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1140 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1141 (defun wisent-allocate-storage () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1142 "Allocate storage for the state machine." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1143 (wisent-allocate-itemsets) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1144 (setq shiftset (make-vector nsyms 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1145 redset (make-vector (1+ nrules) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1146 state-table (make-vector wisent-state-table-size nil))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1147 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1148 (defun wisent-new-itemsets () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1149 "Find which symbols can be shifted in the current state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1150 And for each one record which items would be active after that shift. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1151 Uses the contents of ITEMSET. SHIFT-SYMBOL is set to a vector of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1152 symbols that can be shifted. For each symbol in the grammar, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1153 KERNEL-BASE[symbol] points to a vector of item numbers activated if |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1154 that symbol is shifted, and KERNEL-END[symbol] points after the end of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1155 that vector." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1156 (let (i shiftcount isp ksp symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1157 (fillarray kernel-end nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1158 (setq shiftcount 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1159 isp 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1160 (while (< isp nitemset) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1161 (setq i (aref itemset isp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1162 isp (1+ isp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1163 symbol (aref ritem i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1164 (when (> symbol 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1165 (setq ksp (aref kernel-end symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1166 (when (not ksp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1167 ;; shift-symbol[shiftcount++] = symbol; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1168 (aset shift-symbol shiftcount symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1169 (setq shiftcount (1+ shiftcount) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1170 ksp (aref kernel-base symbol))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1171 ;; *ksp++ = i + 1; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1172 (aset kernel-items ksp (1+ i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1173 (setq ksp (1+ ksp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1174 (aset kernel-end symbol ksp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1175 (setq nshifts shiftcount))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1176 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1177 (defun wisent-new-state (symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1178 "Create a new state for those items, if necessary. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1179 SYMBOL is the core accessing-symbol. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1180 Subroutine of `wisent-get-state'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1181 (let (n p isp1 isp2 iend items) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1182 (setq isp1 (aref kernel-base symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1183 iend (aref kernel-end symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1184 n (- iend isp1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1185 p (make-core) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1186 items (make-vector n 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1187 (set-core-accessing-symbol p symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1188 (set-core-number p nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1189 (set-core-nitems p n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1190 (set-core-items p items) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1191 (setq isp2 0) ;; isp2 = p->items |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1192 (while (< isp1 iend) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1193 ;; *isp2++ = *isp1++; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1194 (aset items isp2 (aref kernel-items isp1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1195 (setq isp1 (1+ isp1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1196 isp2 (1+ isp2))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1197 (set-core-next last-state p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1198 (setq last-state p |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1199 nstates (1+ nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1200 p)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1201 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1202 (defun wisent-get-state (symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1203 "Find the state we would get to by shifting SYMBOL. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1204 Return the state number for the state we would get to (from the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1205 current state) by shifting SYMBOL. Create a new state if no |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1206 equivalent one exists already. Used by `wisent-append-states'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1207 (let (key isp1 isp2 iend sp sp2 found n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1208 (setq isp1 (aref kernel-base symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1209 iend (aref kernel-end symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1210 n (- iend isp1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1211 key 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1212 ;; Add up the target state's active item numbers to get a hash key |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1213 (while (< isp1 iend) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1214 (setq key (+ key (aref kernel-items isp1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1215 isp1 (1+ isp1))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1216 (setq key (% key wisent-state-table-size) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1217 sp (aref state-table key)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1218 (if sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1219 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1220 (setq found nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1221 (while (not found) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1222 (when (= (core-nitems sp) n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1223 (setq found t |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1224 isp1 (aref kernel-base symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1225 ;; isp2 = sp->items; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1226 sp2 (core-items sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1227 isp2 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1228 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1229 (while (and found (< isp1 iend)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1230 ;; if (*isp1++ != *isp2++) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1231 (if (not (= (aref kernel-items isp1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1232 (aref sp2 isp2))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1233 (setq found nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1234 (setq isp1 (1+ isp1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1235 isp2 (1+ isp2)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1236 (if (not found) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1237 (if (core-link sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1238 (setq sp (core-link sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1239 ;; sp = sp->link = new-state(symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1240 (setq sp (set-core-link sp (wisent-new-state symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1241 found t))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1242 ;; bucket is empty |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1243 ;; state-table[key] = sp = new-state(symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1244 (setq sp (wisent-new-state symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1245 (aset state-table key sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1246 ;; return (sp->number); |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1247 (core-number sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1248 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1249 (defun wisent-append-states () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1250 "Find or create the core structures for states. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1251 Use the information computed by `wisent-new-itemsets' to find the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1252 state numbers reached by each shift transition from the current state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1253 SHIFTSET is set up as a vector of state numbers of those states." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1254 (let (i j symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1255 ;; First sort shift-symbol into increasing order |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1256 (setq i 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1257 (while (< i nshifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1258 (setq symbol (aref shift-symbol i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1259 j i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1260 (while (and (> j 0) (> (aref shift-symbol (1- j)) symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1261 (aset shift-symbol j (aref shift-symbol (1- j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1262 (setq j (1- j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1263 (aset shift-symbol j symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1264 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1265 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1266 (while (< i nshifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1267 (setq symbol (aref shift-symbol i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1268 (aset shiftset i (wisent-get-state symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1269 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1270 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1271 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1272 (defun wisent-initialize-states () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1273 "Initialize states." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1274 (let ((p (make-core))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1275 (setq first-state p |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1276 last-state p |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1277 this-state p |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1278 nstates 1))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1279 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1280 (defun wisent-save-shifts () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1281 "Save the NSHIFTS of SHIFTSET into the current linked list." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1282 (let (p i shifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1283 (setq p (make-shifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1284 shifts (make-vector nshifts 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1285 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1286 (set-shifts-number p (core-number this-state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1287 (set-shifts-nshifts p nshifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1288 (set-shifts-shifts p shifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1289 (while (< i nshifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1290 ;; (p->shifts)[i] = shiftset[i]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1291 (aset shifts i (aref shiftset i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1292 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1293 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1294 (if last-shift |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1295 (set-shifts-next last-shift p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1296 (setq first-shift p)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1297 (setq last-shift p))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1298 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1299 (defun wisent-insert-start-shift () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1300 "Create the next-to-final state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1301 That is the state to which a shift has already been made in the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1302 initial state. Subroutine of `wisent-augment-automaton'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1303 (let (statep sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1304 (setq statep (make-core)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1305 (set-core-number statep nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1306 (set-core-accessing-symbol statep start-symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1307 (set-core-next last-state statep) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1308 (setq last-state statep) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1309 ;; Make a shift from this state to (what will be) the final state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1310 (setq sp (make-shifts)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1311 (set-shifts-number sp nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1312 (setq nstates (1+ nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1313 (set-shifts-nshifts sp 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1314 (set-shifts-shifts sp (vector nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1315 (set-shifts-next last-shift sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1316 (setq last-shift sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1317 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1318 (defun wisent-augment-automaton () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1319 "Set up initial and final states as parser wants them. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1320 Make sure that the initial state has a shift that accepts the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1321 grammar's start symbol and goes to the next-to-final state, which has |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1322 a shift going to the final state, which has a shift to the termination |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1323 state. Create such states and shifts if they don't happen to exist |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1324 already." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1325 (let (i k statep sp sp2 sp1 shifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1326 (setq sp first-shift) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1327 (if sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1328 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1329 (if (zerop (shifts-number sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1330 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1331 (setq k (shifts-nshifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1332 statep (core-next first-state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1333 ;; The states reached by shifts from first-state are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1334 ;; numbered 1...K. Look for one reached by |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1335 ;; START-SYMBOL. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1336 (while (and (< (core-accessing-symbol statep) start-symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1337 (< (core-number statep) k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1338 (setq statep (core-next statep))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1339 (if (= (core-accessing-symbol statep) start-symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1340 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1341 ;; We already have a next-to-final state. Make |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1342 ;; sure it has a shift to what will be the final |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1343 ;; state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1344 (setq k (core-number statep)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1345 (while (and sp (< (shifts-number sp) k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1346 (setq sp1 sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1347 sp (shifts-next sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1348 (if (and sp (= (shifts-number sp) k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1349 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1350 (setq i (shifts-nshifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1351 sp2 (make-shifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1352 shifts (make-vector (1+ i) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1353 (set-shifts-number sp2 k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1354 (set-shifts-nshifts sp2 (1+ i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1355 (set-shifts-shifts sp2 shifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1356 (aset shifts 0 nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1357 (while (> i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1358 ;; sp2->shifts[i] = sp->shifts[i - 1]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1359 (aset shifts i (aref (shifts-shifts sp) (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1360 (setq i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1361 ;; Patch sp2 into the chain of shifts in |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1362 ;; place of sp, following sp1. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1363 (set-shifts-next sp2 (shifts-next sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1364 (set-shifts-next sp1 sp2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1365 (if (eq sp last-shift) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1366 (setq last-shift sp2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1367 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1368 (setq sp2 (make-shifts)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1369 (set-shifts-number sp2 k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1370 (set-shifts-nshifts sp2 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1371 (set-shifts-shifts sp2 (vector nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1372 ;; Patch sp2 into the chain of shifts between |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1373 ;; sp1 and sp. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1374 (set-shifts-next sp2 sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1375 (set-shifts-next sp1 sp2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1376 (if (not sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1377 (setq last-shift sp2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1378 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1379 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1380 ;; There is no next-to-final state as yet. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1381 ;; Add one more shift in FIRST-SHIFT, going to the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1382 ;; next-to-final state (yet to be made). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1383 (setq sp first-shift |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1384 sp2 (make-shifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1385 i (shifts-nshifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1386 shifts (make-vector (1+ i) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1387 (set-shifts-nshifts sp2 (1+ i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1388 (set-shifts-shifts sp2 shifts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1389 ;; Stick this shift into the vector at the proper place. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1390 (setq statep (core-next first-state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1391 k 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1392 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1393 (while (< i (shifts-nshifts sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1394 (when (and (> (core-accessing-symbol statep) start-symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1395 (= i k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1396 (aset shifts k nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1397 (setq k (1+ k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1398 (aset shifts k (aref (shifts-shifts sp) i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1399 (setq statep (core-next statep)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1400 (setq i (1+ i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1401 k (1+ k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1402 (when (= i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1403 (aset shifts k nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1404 (setq k (1+ k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1405 ;; Patch sp2 into the chain of shifts in place of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1406 ;; sp, at the beginning. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1407 (set-shifts-next sp2 (shifts-next sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1408 (setq first-shift sp2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1409 (if (eq last-shift sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1410 (setq last-shift sp2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1411 ;; Create the next-to-final state, with shift to |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1412 ;; what will be the final state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1413 (wisent-insert-start-shift))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1414 ;; The initial state didn't even have any shifts. Give it |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1415 ;; one shift, to the next-to-final state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1416 (setq sp (make-shifts)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1417 (set-shifts-nshifts sp 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1418 (set-shifts-shifts sp (vector nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1419 ;; Patch sp into the chain of shifts at the beginning. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1420 (set-shifts-next sp first-shift) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1421 (setq first-shift sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1422 ;; Create the next-to-final state, with shift to what will |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1423 ;; be the final state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1424 (wisent-insert-start-shift))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1425 ;; There are no shifts for any state. Make one shift, from the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1426 ;; initial state to the next-to-final state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1427 (setq sp (make-shifts)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1428 (set-shifts-nshifts sp 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1429 (set-shifts-shifts sp (vector nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1430 ;; Initialize the chain of shifts with sp. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1431 (setq first-shift sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1432 last-shift sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1433 ;; Create the next-to-final state, with shift to what will be |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1434 ;; the final state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1435 (wisent-insert-start-shift)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1436 ;; Make the final state--the one that follows a shift from the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1437 ;; next-to-final state. The symbol for that shift is 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1438 ;; (end-of-file). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1439 (setq statep (make-core)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1440 (set-core-number statep nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1441 (set-core-next last-state statep) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1442 (setq last-state statep) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1443 ;; Make the shift from the final state to the termination state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1444 (setq sp (make-shifts)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1445 (set-shifts-number sp nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1446 (setq nstates (1+ nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1447 (set-shifts-nshifts sp 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1448 (set-shifts-shifts sp (vector nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1449 (set-shifts-next last-shift sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1450 (setq last-shift sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1451 ;; Note that the variable FINAL-STATE refers to what we sometimes |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1452 ;; call the termination state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1453 (setq final-state nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1454 ;; Make the termination state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1455 (setq statep (make-core)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1456 (set-core-number statep nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1457 (setq nstates (1+ nstates)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1458 (set-core-next last-state statep) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1459 (setq last-state statep))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1460 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1461 (defun wisent-save-reductions () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1462 "Make a reductions structure. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1463 Find which rules can be used for reduction transitions from the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1464 current state and make a reductions structure for the state to record |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1465 their rule numbers." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1466 (let (i item count p rules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1467 ;; Find and count the active items that represent ends of rules. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1468 (setq count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1469 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1470 (while (< i nitemset) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1471 (setq item (aref ritem (aref itemset i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1472 (when (< item 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1473 (aset redset count (- item)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1474 (setq count (1+ count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1475 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1476 ;; Make a reductions structure and copy the data into it. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1477 (when (> count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1478 (setq p (make-reductions) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1479 rules (make-vector count 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1480 (set-reductions-number p (core-number this-state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1481 (set-reductions-nreds p count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1482 (set-reductions-rules p rules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1483 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1484 (while (< i count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1485 ;; (p->rules)[i] = redset[i] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1486 (aset rules i (aref redset i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1487 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1488 (if last-reduction |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1489 (set-reductions-next last-reduction p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1490 (setq first-reduction p)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1491 (setq last-reduction p)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1492 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1493 (defun wisent-generate-states () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1494 "Compute the nondeterministic finite state machine from the grammar." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1495 (wisent-allocate-storage) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1496 (wisent-initialize-closure nitems) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1497 (wisent-initialize-states) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1498 (while this-state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1499 ;; Set up RULESET and ITEMSET for the transitions out of this |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1500 ;; state. RULESET gets a 1 bit for each rule that could reduce |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1501 ;; now. ITEMSET gets a vector of all the items that could be |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1502 ;; accepted next. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1503 (wisent-closure (core-items this-state) (core-nitems this-state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1504 ;; Record the reductions allowed out of this state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1505 (wisent-save-reductions) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1506 ;; Find the itemsets of the states that shifts can reach. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1507 (wisent-new-itemsets) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1508 ;; Find or create the core structures for those states. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1509 (wisent-append-states) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1510 ;; Create the shifts structures for the shifts to those states, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1511 ;; now that the state numbers transitioning to are known. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1512 (if (> nshifts 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1513 (wisent-save-shifts)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1514 ;; States are queued when they are created; process them all. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1515 (setq this-state (core-next this-state))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1516 ;; Set up initial and final states as parser wants them. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1517 (wisent-augment-automaton)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1518 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1519 ;;;; --------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1520 ;;;; Compute look-ahead criteria |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1521 ;;;; --------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1522 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1523 ;; Compute how to make the finite state machine deterministic; find |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1524 ;; which rules need lookahead in each state, and which lookahead |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1525 ;; tokens they accept. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1526 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1527 ;; `wisent-lalr', the entry point, builds these data structures: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1528 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1529 ;; GOTO-MAP, FROM-STATE and TO-STATE record each shift transition |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1530 ;; which accepts a variable (a nonterminal). NGOTOS is the number of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1531 ;; such transitions. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1532 ;; FROM-STATE[t] is the state number which a transition leads from and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1533 ;; TO-STATE[t] is the state number it leads to. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1534 ;; All the transitions that accept a particular variable are grouped |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1535 ;; together and GOTO-MAP[i - NTOKENS] is the index in FROM-STATE and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1536 ;; TO-STATE of the first of them. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1537 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1538 ;; CONSISTENT[s] is non-nil if no lookahead is needed to decide what |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1539 ;; to do in state s. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1540 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1541 ;; LARULENO is a vector which records the rules that need lookahead in |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1542 ;; various states. The elements of LARULENO that apply to state s are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1543 ;; those from LOOKAHEADS[s] through LOOKAHEADS[s+1]-1. Each element |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1544 ;; of LARULENO is a rule number. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1545 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1546 ;; If LR is the length of LARULENO, then a number from 0 to LR-1 can |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1547 ;; specify both a rule and a state where the rule might be applied. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1548 ;; LA is a LR by NTOKENS matrix of bits. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1549 ;; LA[l, i] is 1 if the rule LARULENO[l] is applicable in the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1550 ;; appropriate state when the next token is symbol i. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1551 ;; If LA[l, i] and LA[l, j] are both 1 for i != j, it is a conflict. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1552 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1553 (wisent-defcontext digraph |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1554 INDEX R VERTICES |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1555 infinity top) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1556 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1557 (defun wisent-traverse (i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1558 "Traverse I." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1559 (let (j k height Ri Fi break) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1560 (setq top (1+ top) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1561 height top) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1562 (aset VERTICES top i) ;; VERTICES[++top] = i |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1563 (aset INDEX i top) ;; INDEX[i] = height = top |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1564 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1565 (setq Ri (aref R i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1566 (when Ri |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1567 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1568 (while (>= (aref Ri j) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1569 (if (zerop (aref INDEX (aref Ri j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1570 (wisent-traverse (aref Ri j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1571 ;; if (INDEX[i] > INDEX[R[i][j]]) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1572 (if (> (aref INDEX i) (aref INDEX (aref Ri j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1573 ;; INDEX[i] = INDEX[R[i][j]]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1574 (aset INDEX i (aref INDEX (aref Ri j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1575 (setq Fi (aref F i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1576 k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1577 (while (< k tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1578 ;; F (i)[k] |= F (R[i][j])[k]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1579 (aset Fi k (logior (aref Fi k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1580 (aref (aref F (aref Ri j)) k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1581 (setq k (1+ k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1582 (setq j (1+ j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1583 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1584 (when (= (aref INDEX i) height) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1585 (setq break nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1586 (while (not break) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1587 (setq j (aref VERTICES top) ;; j = VERTICES[top--] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1588 top (1- top)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1589 (aset INDEX j infinity) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1590 (if (= i j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1591 (setq break t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1592 (setq k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1593 (while (< k tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1594 ;; F (j)[k] = F (i)[k]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1595 (aset (aref F j) k (aref (aref F i) k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1596 (setq k (1+ k)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1597 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1598 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1599 (defun wisent-digraph (relation) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1600 "Digraph RELATION." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1601 (wisent-with-context digraph |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1602 (setq infinity (+ ngotos 2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1603 INDEX (make-vector (1+ ngotos) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1604 VERTICES (make-vector (1+ ngotos) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1605 top 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1606 R relation) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1607 (let ((i 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1608 (while (< i ngotos) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1609 (if (and (= (aref INDEX i) 0) (aref R i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1610 (wisent-traverse i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1611 (setq i (1+ i)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1612 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1613 (defun wisent-set-state-table () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1614 "Build state table." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1615 (let (sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1616 (setq state-table (make-vector nstates nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1617 sp first-state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1618 (while sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1619 (aset state-table (core-number sp) sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1620 (setq sp (core-next sp))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1621 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1622 (defun wisent-set-accessing-symbol () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1623 "Build accessing symbol table." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1624 (let (sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1625 (setq accessing-symbol (make-vector nstates 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1626 sp first-state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1627 (while sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1628 (aset accessing-symbol (core-number sp) (core-accessing-symbol sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1629 (setq sp (core-next sp))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1630 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1631 (defun wisent-set-shift-table () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1632 "Build shift table." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1633 (let (sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1634 (setq shift-table (make-vector nstates nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1635 sp first-shift) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1636 (while sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1637 (aset shift-table (shifts-number sp) sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1638 (setq sp (shifts-next sp))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1639 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1640 (defun wisent-set-reduction-table () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1641 "Build reduction table." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1642 (let (rp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1643 (setq reduction-table (make-vector nstates nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1644 rp first-reduction) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1645 (while rp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1646 (aset reduction-table (reductions-number rp) rp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1647 (setq rp (reductions-next rp))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1648 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1649 (defun wisent-set-maxrhs () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1650 "Setup MAXRHS length." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1651 (let (i len max) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1652 (setq len 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1653 max 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1654 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1655 (while (aref ritem i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1656 (if (> (aref ritem i) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1657 (setq len (1+ len)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1658 (if (> len max) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1659 (setq max len)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1660 (setq len 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1661 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1662 (setq maxrhs max))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1663 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1664 (defun wisent-initialize-LA () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1665 "Set up LA." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1666 (let (i j k count rp sp np v) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1667 (setq consistent (make-vector nstates nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1668 lookaheads (make-vector (1+ nstates) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1669 count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1670 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1671 (while (< i nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1672 (aset lookaheads i count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1673 (setq rp (aref reduction-table i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1674 sp (aref shift-table i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1675 ;; if (rp && |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1676 ;; (rp->nreds > 1 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1677 ;; || (sp && ! ISVAR(accessing-symbol[sp->shifts[0]])))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1678 (if (and rp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1679 (or (> (reductions-nreds rp) 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1680 (and sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1681 (not (wisent-ISVAR |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1682 (aref accessing-symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1683 (aref (shifts-shifts sp) 0))))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1684 (setq count (+ count (reductions-nreds rp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1685 (aset consistent i t)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1686 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1687 (when sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1688 (setq k 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1689 j (shifts-nshifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1690 v (shifts-shifts sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1691 (while (< k j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1692 (when (= (aref accessing-symbol (aref v k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1693 error-token-number) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1694 (aset consistent i nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1695 (setq k j)) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1696 (setq k (1+ k)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1697 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1698 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1699 (aset lookaheads nstates count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1700 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1701 (if (zerop count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1702 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1703 (setq LA (make-vector 1 nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1704 LAruleno (make-vector 1 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1705 lookback (make-vector 1 nil))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1706 (setq LA (make-vector count nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1707 LAruleno (make-vector count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1708 lookback (make-vector count nil))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1709 (setq i 0 j (length LA)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1710 (while (< i j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1711 (aset LA i (make-vector tokensetsize 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1712 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1713 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1714 (setq np 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1715 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1716 (while (< i nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1717 (when (not (aref consistent i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1718 (setq rp (aref reduction-table i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1719 (when rp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1720 (setq j 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1721 k (reductions-nreds rp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1722 v (reductions-rules rp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1723 (while (< j k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1724 (aset LAruleno np (aref v j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1725 (setq np (1+ np) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1726 j (1+ j))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1727 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1728 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1729 (defun wisent-set-goto-map () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1730 "Set up GOTO-MAP." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1731 (let (sp i j symbol k temp-map state1 state2 v) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1732 (setq goto-map (make-vector (1+ nvars) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1733 temp-map (make-vector (1+ nvars) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1734 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1735 (setq ngotos 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1736 sp first-shift) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1737 (while sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1738 (setq i (1- (shifts-nshifts sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1739 v (shifts-shifts sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1740 (while (>= i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1741 (setq symbol (aref accessing-symbol (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1742 (if (wisent-ISTOKEN symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1743 (setq i 0) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1744 (setq ngotos (1+ ngotos)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1745 ;; goto-map[symbol]++; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1746 (aset goto-map (- symbol ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1747 (1+ (aref goto-map (- symbol ntokens))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1748 (setq i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1749 (setq sp (shifts-next sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1750 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1751 (setq k 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1752 i ntokens |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1753 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1754 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1755 (aset temp-map j k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1756 (setq k (+ k (aref goto-map j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1757 i (1+ i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1758 j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1759 (setq i ntokens |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1760 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1761 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1762 (aset goto-map j (aref temp-map j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1763 (setq i (1+ i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1764 j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1765 ;; goto-map[nsyms] = ngotos; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1766 ;; temp-map[nsyms] = ngotos; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1767 (aset goto-map j ngotos) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1768 (aset temp-map j ngotos) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1769 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1770 (setq from-state (make-vector ngotos 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1771 to-state (make-vector ngotos 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1772 sp first-shift) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1773 (while sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1774 (setq state1 (shifts-number sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1775 v (shifts-shifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1776 i (1- (shifts-nshifts sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1777 (while (>= i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1778 (setq state2 (aref v i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1779 symbol (aref accessing-symbol state2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1780 (if (wisent-ISTOKEN symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1781 (setq i 0) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1782 ;; k = temp-map[symbol]++; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1783 (setq k (aref temp-map (- symbol ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1784 (aset temp-map (- symbol ntokens) (1+ k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1785 (aset from-state k state1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1786 (aset to-state k state2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1787 (setq i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1788 (setq sp (shifts-next sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1789 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1790 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1791 (defun wisent-map-goto (state symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1792 "Map a STATE/SYMBOL pair into its numeric representation." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1793 (let (high low middle s result) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1794 ;; low = goto-map[symbol]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1795 ;; high = goto-map[symbol + 1] - 1; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1796 (setq low (aref goto-map (- symbol ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1797 high (1- (aref goto-map (- (1+ symbol) ntokens)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1798 (while (and (not result) (<= low high)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1799 (setq middle (/ (+ low high) 2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1800 s (aref from-state middle)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1801 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1802 ((= s state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1803 (setq result middle)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1804 ((< s state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1805 (setq low (1+ middle))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1806 (t |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1807 (setq high (1- middle))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1808 (or result |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1809 (error "Internal error in `wisent-map-goto'")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1810 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1811 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1812 (defun wisent-initialize-F () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1813 "Set up F." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1814 (let (i j k sp edge rowp rp reads nedges stateno symbol v break) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1815 (setq F (make-vector ngotos nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1816 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1817 (while (< i ngotos) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1818 (aset F i (make-vector tokensetsize 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1819 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1820 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1821 (setq reads (make-vector ngotos nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1822 edge (make-vector (1+ ngotos) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1823 nedges 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1824 rowp 0 ;; rowp = F |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1825 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1826 (while (< i ngotos) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1827 (setq stateno (aref to-state i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1828 sp (aref shift-table stateno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1829 (when sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1830 (setq k (shifts-nshifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1831 v (shifts-shifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1832 j 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1833 break nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1834 (while (and (not break) (< j k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1835 ;; symbol = accessing-symbol[sp->shifts[j]]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1836 (setq symbol (aref accessing-symbol (aref v j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1837 (if (wisent-ISVAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1838 (setq break t) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1839 (wisent-SETBIT (aref F rowp) symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1840 (setq j (1+ j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1841 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1842 (while (< j k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1843 ;; symbol = accessing-symbol[sp->shifts[j]]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1844 (setq symbol (aref accessing-symbol (aref v j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1845 (when (aref nullable (- symbol ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1846 (aset edge nedges (wisent-map-goto stateno symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1847 (setq nedges (1+ nedges))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1848 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1849 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1850 (when (> nedges 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1851 ;; reads[i] = rp = NEW2(nedges + 1, short); |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1852 (setq rp (make-vector (1+ nedges) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1853 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1854 (aset reads i rp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1855 (while (< j nedges) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1856 ;; rp[j] = edge[j]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1857 (aset rp j (aref edge j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1858 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1859 (aset rp nedges -1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1860 (setq nedges 0))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1861 (setq rowp (1+ rowp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1862 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1863 (wisent-digraph reads) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1864 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1865 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1866 (defun wisent-add-lookback-edge (stateno ruleno gotono) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1867 "Add a lookback edge. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1868 STATENO, RULENO, GOTONO are self-explanatory." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1869 (let (i k found) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1870 (setq i (aref lookaheads stateno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1871 k (aref lookaheads (1+ stateno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1872 found nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1873 (while (and (not found) (< i k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1874 (if (= (aref LAruleno i) ruleno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1875 (setq found t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1876 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1877 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1878 (or found |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1879 (error "Internal error in `wisent-add-lookback-edge'")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1880 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1881 ;; value . next |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1882 ;; lookback[i] = (gotono . lookback[i]) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1883 (aset lookback i (cons gotono (aref lookback i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1884 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1885 (defun wisent-transpose (R-arg n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1886 "Return the transpose of R-ARG, of size N. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1887 Destroy R-ARG, as it is replaced with the result. R-ARG[I] is nil or |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1888 a -1 terminated list of numbers. RESULT[NUM] is nil or the -1 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1889 terminated list of the I such as NUM is in R-ARG[I]." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1890 (let (i j new-R end-R nedges v sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1891 (setq new-R (make-vector n nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1892 end-R (make-vector n nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1893 nedges (make-vector n 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1894 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1895 ;; Count. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1896 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1897 (while (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1898 (setq v (aref R-arg i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1899 (when v |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1900 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1901 (while (>= (aref v j) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1902 (aset nedges (aref v j) (1+ (aref nedges (aref v j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1903 (setq j (1+ j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1904 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1905 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1906 ;; Allocate. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1907 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1908 (while (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1909 (when (> (aref nedges i) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1910 (setq sp (make-vector (1+ (aref nedges i)) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1911 (aset sp (aref nedges i) -1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1912 (aset new-R i sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1913 (aset end-R i 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1914 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1915 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1916 ;; Store. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1917 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1918 (while (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1919 (setq v (aref R-arg i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1920 (when v |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1921 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1922 (while (>= (aref v j) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1923 (aset (aref new-R (aref v j)) (aref end-R (aref v j)) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1924 (aset end-R (aref v j) (1+ (aref end-R (aref v j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1925 (setq j (1+ j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1926 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1927 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1928 new-R)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1929 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1930 (defun wisent-build-relations () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1931 "Build relations." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1932 (let (i j k rulep rp sp length nedges done state1 stateno |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1933 symbol1 symbol2 edge states v) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1934 (setq includes (make-vector ngotos nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1935 edge (make-vector (1+ ngotos) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1936 states (make-vector (1+ maxrhs) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1937 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1938 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1939 (while (< i ngotos) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1940 (setq nedges 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1941 state1 (aref from-state i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1942 symbol1 (aref accessing-symbol (aref to-state i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1943 rulep (aref derives (- symbol1 ntokens))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1944 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1945 (while (> (car rulep) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1946 (aset states 0 state1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1947 (setq length 1 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1948 stateno state1 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1949 rp (aref rrhs (car rulep))) ;; rp = ritem + rrhs[*rulep] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1950 (while (> (aref ritem rp) 0) ;; *rp > 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1951 (setq symbol2 (aref ritem rp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1952 sp (aref shift-table stateno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1953 k (shifts-nshifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1954 v (shifts-shifts sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1955 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1956 (while (< j k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1957 (setq stateno (aref v j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1958 (if (= (aref accessing-symbol stateno) symbol2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1959 (setq j k) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1960 (setq j (1+ j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1961 ;; states[length++] = stateno; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1962 (aset states length stateno) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1963 (setq length (1+ length)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1964 (setq rp (1+ rp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1965 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1966 (if (not (aref consistent stateno)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1967 (wisent-add-lookback-edge stateno (car rulep) i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1968 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1969 (setq length (1- length) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1970 done nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1971 (while (not done) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1972 (setq done t |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1973 rp (1- rp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1974 (when (and (>= rp 0) (wisent-ISVAR (aref ritem rp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1975 ;; stateno = states[--length]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1976 (setq length (1- length) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1977 stateno (aref states length)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1978 (aset edge nedges (wisent-map-goto stateno (aref ritem rp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1979 (setq nedges (1+ nedges)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1980 (if (aref nullable (- (aref ritem rp) ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1981 (setq done nil)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1982 (setq rulep (cdr rulep))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1983 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1984 (when (> nedges 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1985 (setq v (make-vector (1+ nedges) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1986 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1987 (aset includes i v) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1988 (while (< j nedges) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1989 (aset v j (aref edge j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1990 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1991 (aset v nedges -1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1992 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1993 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1994 (setq includes (wisent-transpose includes ngotos)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1995 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1996 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1997 (defun wisent-compute-FOLLOWS () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1998 "Compute follows." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1999 (wisent-digraph includes)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2000 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2001 (defun wisent-compute-lookaheads () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2002 "Compute lookaheads." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2003 (let (i j n v1 v2 sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2004 (setq n (aref lookaheads nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2005 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2006 (while (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2007 (setq sp (aref lookback i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2008 (while sp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2009 (setq v1 (aref LA i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2010 v2 (aref F (car sp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2011 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2012 (while (< j tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2013 ;; LA (i)[j] |= F (sp->value)[j] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2014 (aset v1 j (logior (aref v1 j) (aref v2 j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2015 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2016 (setq sp (cdr sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2017 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2018 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2019 (defun wisent-lalr () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2020 "Make the nondeterministic finite state machine deterministic." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2021 (setq tokensetsize (wisent-WORDSIZE ntokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2022 (wisent-set-state-table) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2023 (wisent-set-accessing-symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2024 (wisent-set-shift-table) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2025 (wisent-set-reduction-table) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2026 (wisent-set-maxrhs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2027 (wisent-initialize-LA) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2028 (wisent-set-goto-map) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2029 (wisent-initialize-F) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2030 (wisent-build-relations) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2031 (wisent-compute-FOLLOWS) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2032 (wisent-compute-lookaheads)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2033 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2034 ;;;; ----------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2035 ;;;; Find and resolve or report look-ahead conflicts |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2036 ;;;; ----------------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2037 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2038 (defsubst wisent-log-resolution (state LAno token resolution) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2039 "Log a shift-reduce conflict resolution. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2040 In specified STATE between rule pointed by lookahead number LANO and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2041 TOKEN, resolved as RESOLUTION." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2042 (if (or wisent-verbose-flag wisent-debug-flag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2043 (wisent-log |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2044 "Conflict in state %d between rule %d and token %s resolved as %s.\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2045 state (aref LAruleno LAno) (wisent-tag token) resolution))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2046 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2047 (defun wisent-flush-shift (state token) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2048 "Turn off the shift recorded in the specified STATE for TOKEN. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2049 Used when we resolve a shift-reduce conflict in favor of the reduction." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2050 (let (shiftp i k v) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2051 (when (setq shiftp (aref shift-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2052 (setq k (shifts-nshifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2053 v (shifts-shifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2054 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2055 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2056 (if (and (not (zerop (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2057 (= token (aref accessing-symbol (aref v i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2058 (aset v i 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2059 (setq i (1+ i)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2060 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2061 (defun wisent-resolve-sr-conflict (state lookaheadnum) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2062 "Attempt to resolve shift-reduce conflict for one rule. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2063 Resolve by means of precedence declarations. The conflict occurred in |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2064 specified STATE for the rule pointed by the lookahead symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2065 LOOKAHEADNUM. It has already been checked that the rule has a |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2066 precedence. A conflict is resolved by modifying the shift or reduce |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2067 tables so that there is no longer a conflict." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2068 (let (i redprec errp errs nerrs token sprec sassoc) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2069 ;; Find the rule to reduce by to get precedence of reduction |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2070 (setq token (aref tags (aref rprec (aref LAruleno lookaheadnum))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2071 redprec (wisent-prec token) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2072 errp (make-errs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2073 errs (make-vector ntokens 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2074 nerrs 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2075 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2076 (set-errs-errs errp errs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2077 (while (< i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2078 (setq token (aref tags i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2079 (when (and (wisent-BITISSET (aref LA lookaheadnum) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2080 (wisent-BITISSET lookaheadset i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2081 (setq sprec (wisent-prec token))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2082 ;; Shift-reduce conflict occurs for token number I and it has |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2083 ;; a precedence. The precedence of shifting is that of token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2084 ;; I. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2085 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2086 ((< sprec redprec) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2087 (wisent-log-resolution state lookaheadnum i "reduce") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2088 ;; Flush the shift for this token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2089 (wisent-RESETBIT lookaheadset i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2090 (wisent-flush-shift state i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2091 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2092 ((> sprec redprec) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2093 (wisent-log-resolution state lookaheadnum i "shift") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2094 ;; Flush the reduce for this token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2095 (wisent-RESETBIT (aref LA lookaheadnum) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2096 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2097 (t |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2098 ;; Matching precedence levels. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2099 ;; For left association, keep only the reduction. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2100 ;; For right association, keep only the shift. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2101 ;; For nonassociation, keep neither. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2102 (setq sassoc (wisent-assoc token)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2103 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2104 ((eq sassoc 'right) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2105 (wisent-log-resolution state lookaheadnum i "shift")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2106 ((eq sassoc 'left) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2107 (wisent-log-resolution state lookaheadnum i "reduce")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2108 ((eq sassoc 'nonassoc) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2109 (wisent-log-resolution state lookaheadnum i "an error")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2110 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2111 (when (not (eq sassoc 'right)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2112 ;; Flush the shift for this token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2113 (wisent-RESETBIT lookaheadset i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2114 (wisent-flush-shift state i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2115 (when (not (eq sassoc 'left)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2116 ;; Flush the reduce for this token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2117 (wisent-RESETBIT (aref LA lookaheadnum) i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2118 (when (eq sassoc 'nonassoc) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2119 ;; Record an explicit error for this token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2120 (aset errs nerrs i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2121 (setq nerrs (1+ nerrs))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2122 ))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2123 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2124 (when (> nerrs 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2125 (set-errs-nerrs errp nerrs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2126 (aset err-table state errp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2127 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2128 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2129 (defun wisent-set-conflicts (state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2130 "Find and attempt to resolve conflicts in specified STATE." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2131 (let (i j k v shiftp symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2132 (unless (aref consistent state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2133 (fillarray lookaheadset 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2134 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2135 (when (setq shiftp (aref shift-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2136 (setq k (shifts-nshifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2137 v (shifts-shifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2138 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2139 (while (and (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2140 (wisent-ISTOKEN |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2141 (setq symbol (aref accessing-symbol (aref v i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2142 (or (zerop (aref v i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2143 (wisent-SETBIT lookaheadset symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2144 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2145 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2146 ;; Loop over all rules which require lookahead in this state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2147 ;; first check for shift-reduce conflict, and try to resolve |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2148 ;; using precedence |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2149 (setq i (aref lookaheads state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2150 k (aref lookaheads (1+ state))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2151 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2152 (when (aref rprec (aref LAruleno i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2153 (setq v (aref LA i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2154 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2155 (while (< j tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2156 (if (zerop (logand (aref v j) (aref lookaheadset j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2157 (setq j (1+ j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2158 ;; if (LA (i)[j] & lookaheadset[j]) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2159 (wisent-resolve-sr-conflict state i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2160 (setq j tokensetsize)))) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2161 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2162 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2163 ;; Loop over all rules which require lookahead in this state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2164 ;; Check for conflicts not resolved above. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2165 (setq i (aref lookaheads state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2166 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2167 (setq v (aref LA i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2168 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2169 (while (< j tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2170 ;; if (LA (i)[j] & lookaheadset[j]) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2171 (if (not (zerop (logand (aref v j) (aref lookaheadset j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2172 (aset conflicts state t)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2173 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2174 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2175 (while (< j tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2176 ;; lookaheadset[j] |= LA (i)[j]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2177 (aset lookaheadset j (logior (aref lookaheadset j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2178 (aref v j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2179 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2180 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2181 ))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2182 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2183 (defun wisent-resolve-conflicts () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2184 "Find and resolve conflicts." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2185 (let (i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2186 (setq conflicts (make-vector nstates nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2187 shiftset (make-vector tokensetsize 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2188 lookaheadset (make-vector tokensetsize 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2189 err-table (make-vector nstates nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2190 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2191 (while (< i nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2192 (wisent-set-conflicts i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2193 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2194 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2195 (defun wisent-count-sr-conflicts (state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2196 "Count the number of shift/reduce conflicts in specified STATE." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2197 (let (i j k shiftp symbol v) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2198 (setq src-count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2199 shiftp (aref shift-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2200 (when shiftp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2201 (fillarray shiftset 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2202 (fillarray lookaheadset 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2203 (setq k (shifts-nshifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2204 v (shifts-shifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2205 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2206 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2207 (when (not (zerop (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2208 (setq symbol (aref accessing-symbol (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2209 (if (wisent-ISVAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2210 (setq i k) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2211 (wisent-SETBIT shiftset symbol))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2212 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2213 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2214 (setq k (aref lookaheads (1+ state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2215 i (aref lookaheads state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2216 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2217 (setq v (aref LA i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2218 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2219 (while (< j tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2220 ;; lookaheadset[j] |= LA (i)[j] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2221 (aset lookaheadset j (logior (aref lookaheadset j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2222 (aref v j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2223 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2224 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2225 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2226 (setq k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2227 (while (< k tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2228 ;; lookaheadset[k] &= shiftset[k]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2229 (aset lookaheadset k (logand (aref lookaheadset k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2230 (aref shiftset k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2231 (setq k (1+ k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2232 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2233 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2234 (while (< i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2235 (if (wisent-BITISSET lookaheadset i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2236 (setq src-count (1+ src-count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2237 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2238 src-count)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2239 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2240 (defun wisent-count-rr-conflicts (state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2241 "Count the number of reduce/reduce conflicts in specified STATE." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2242 (let (i j count n m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2243 (setq rrc-count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2244 m (aref lookaheads state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2245 n (aref lookaheads (1+ state))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2246 (when (>= (- n m) 2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2247 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2248 (while (< i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2249 (setq count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2250 j m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2251 (while (< j n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2252 (if (wisent-BITISSET (aref LA j) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2253 (setq count (1+ count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2254 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2255 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2256 (if (>= count 2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2257 (setq rrc-count (1+ rrc-count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2258 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2259 rrc-count)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2260 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2261 (defvar wisent-expected-conflicts nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2262 "*If non-nil suppress the warning about shift/reduce conflicts. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2263 It is a decimal integer N that says there should be no warning if |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2264 there are N shift/reduce conflicts and no reduce/reduce conflicts. A |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2265 warning is given if there are either more or fewer conflicts, or if |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2266 there are any reduce/reduce conflicts.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2267 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2268 (defun wisent-total-conflicts () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2269 "Report the total number of conflicts." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2270 (unless (and (zerop rrc-total) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2271 (or (zerop src-total) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2272 (= src-total (or wisent-expected-conflicts 0)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2273 (let* ((src (wisent-source)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2274 (src (if src (concat " in " src) "")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2275 (msg (format "Grammar%s contains" src))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2276 (if (> src-total 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2277 (setq msg (format "%s %d shift/reduce conflict%s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2278 msg src-total (if (> src-total 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2279 "s" "")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2280 (if (and (> src-total 0) (> rrc-total 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2281 (setq msg (format "%s and" msg))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2282 (if (> rrc-total 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2283 (setq msg (format "%s %d reduce/reduce conflict%s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2284 msg rrc-total (if (> rrc-total 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2285 "s" "")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2286 (message msg)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2287 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2288 (defun wisent-print-conflicts () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2289 "Report conflicts." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2290 (let (i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2291 (setq src-total 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2292 rrc-total 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2293 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2294 (while (< i nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2295 (when (aref conflicts i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2296 (wisent-count-sr-conflicts i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2297 (wisent-count-rr-conflicts i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2298 (setq src-total (+ src-total src-count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2299 rrc-total (+ rrc-total rrc-count)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2300 (when (or wisent-verbose-flag wisent-debug-flag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2301 (wisent-log "State %d contains" i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2302 (if (> src-count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2303 (wisent-log " %d shift/reduce conflict%s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2304 src-count (if (> src-count 1) "s" ""))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2305 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2306 (if (and (> src-count 0) (> rrc-count 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2307 (wisent-log " and")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2308 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2309 (if (> rrc-count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2310 (wisent-log " %d reduce/reduce conflict%s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2311 rrc-count (if (> rrc-count 1) "s" ""))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2312 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2313 (wisent-log ".\n"))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2314 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2315 (wisent-total-conflicts))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2316 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2317 ;;;; -------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2318 ;;;; Report information on generated parser |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2319 ;;;; -------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2320 (defun wisent-print-grammar () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2321 "Print grammar." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2322 (let (i j r break left-count right-count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2323 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2324 (wisent-log "\n\nGrammar\n\n Number, Rule\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2325 (setq i 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2326 (while (<= i nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2327 ;; Don't print rules disabled in `wisent-reduce-grammar-tables'. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2328 (when (aref ruseful i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2329 (wisent-log " %s %s ->" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2330 (wisent-pad-string (number-to-string i) 6) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2331 (wisent-tag (aref rlhs i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2332 (setq r (aref rrhs i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2333 (if (> (aref ritem r) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2334 (while (> (aref ritem r) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2335 (wisent-log " %s" (wisent-tag (aref ritem r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2336 (setq r (1+ r))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2337 (wisent-log " /* empty */")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2338 (wisent-log "\n")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2339 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2340 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2341 (wisent-log "\n\nTerminals, with rules where they appear\n\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2342 (wisent-log "%s (-1)\n" (wisent-tag 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2343 (setq i 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2344 (while (< i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2345 (wisent-log "%s (%d)" (wisent-tag i) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2346 (setq j 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2347 (while (<= j nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2348 (setq r (aref rrhs j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2349 break nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2350 (while (and (not break) (> (aref ritem r) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2351 (if (setq break (= (aref ritem r) i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2352 (wisent-log " %d" j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2353 (setq r (1+ r)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2354 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2355 (wisent-log "\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2356 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2357 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2358 (wisent-log "\n\nNonterminals, with rules where they appear\n\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2359 (setq i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2360 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2361 (setq left-count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2362 right-count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2363 j 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2364 (while (<= j nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2365 (if (= (aref rlhs j) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2366 (setq left-count (1+ left-count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2367 (setq r (aref rrhs j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2368 break nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2369 (while (and (not break) (> (aref ritem r) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2370 (if (= (aref ritem r) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2371 (setq right-count (1+ right-count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2372 break t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2373 (setq r (1+ r)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2374 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2375 (wisent-log "%s (%d)\n " (wisent-tag i) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2376 (when (> left-count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2377 (wisent-log " on left:") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2378 (setq j 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2379 (while (<= j nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2380 (if (= (aref rlhs j) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2381 (wisent-log " %d" j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2382 (setq j (1+ j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2383 (when (> right-count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2384 (if (> left-count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2385 (wisent-log ",")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2386 (wisent-log " on right:") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2387 (setq j 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2388 (while (<= j nrules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2389 (setq r (aref rrhs j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2390 break nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2391 (while (and (not break) (> (aref ritem r) 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2392 (if (setq break (= (aref ritem r) i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2393 (wisent-log " %d" j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2394 (setq r (1+ r)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2395 (setq j (1+ j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2396 (wisent-log "\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2397 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2398 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2399 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2400 (defun wisent-print-reductions (state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2401 "Print reductions on STATE." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2402 (let (i j k v symbol m n defaulted |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2403 default-LA default-rule cmax count shiftp errp nodefault) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2404 (setq nodefault nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2405 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2406 (fillarray shiftset 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2407 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2408 (setq shiftp (aref shift-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2409 (when shiftp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2410 (setq k (shifts-nshifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2411 v (shifts-shifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2412 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2413 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2414 (when (not (zerop (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2415 (setq symbol (aref accessing-symbol (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2416 (if (wisent-ISVAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2417 (setq i k) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2418 ;; If this state has a shift for the error token, don't |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2419 ;; use a default rule. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2420 (if (= symbol error-token-number) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2421 (setq nodefault t)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2422 (wisent-SETBIT shiftset symbol))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2423 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2424 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2425 (setq errp (aref err-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2426 (when errp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2427 (setq k (errs-nerrs errp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2428 v (errs-errs errp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2429 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2430 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2431 (if (not (zerop (setq symbol (aref v i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2432 (wisent-SETBIT shiftset symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2433 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2434 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2435 (setq m (aref lookaheads state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2436 n (aref lookaheads (1+ state))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2437 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2438 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2439 ((and (= (- n m) 1) (not nodefault)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2440 (setq default-rule (aref LAruleno m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2441 v (aref LA m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2442 k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2443 (while (< k tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2444 (aset lookaheadset k (logand (aref v k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2445 (aref shiftset k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2446 (setq k (1+ k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2447 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2448 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2449 (while (< i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2450 (if (wisent-BITISSET lookaheadset i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2451 (wisent-log " %s\t[reduce using rule %d (%s)]\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2452 (wisent-tag i) default-rule |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2453 (wisent-tag (aref rlhs default-rule)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2454 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2455 (wisent-log " $default\treduce using rule %d (%s)\n\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2456 default-rule |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2457 (wisent-tag (aref rlhs default-rule))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2458 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2459 ((>= (- n m) 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2460 (setq cmax 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2461 default-LA -1 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2462 default-rule 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2463 (when (not nodefault) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2464 (setq i m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2465 (while (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2466 (setq v (aref LA i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2467 count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2468 k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2469 (while (< k tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2470 ;; lookaheadset[k] = LA (i)[k] & ~shiftset[k] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2471 (aset lookaheadset k |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2472 (logand (aref v k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2473 (lognot (aref shiftset k)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2474 (setq k (1+ k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2475 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2476 (while (< j ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2477 (if (wisent-BITISSET lookaheadset j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2478 (setq count (1+ count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2479 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2480 (if (> count cmax) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2481 (setq cmax count |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2482 default-LA i |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2483 default-rule (aref LAruleno i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2484 (setq k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2485 (while (< k tokensetsize) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2486 (aset shiftset k (logior (aref shiftset k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2487 (aref lookaheadset k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2488 (setq k (1+ k))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2489 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2490 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2491 (fillarray shiftset 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2492 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2493 (when shiftp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2494 (setq k (shifts-nshifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2495 v (shifts-shifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2496 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2497 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2498 (when (not (zerop (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2499 (setq symbol (aref accessing-symbol (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2500 (if (wisent-ISVAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2501 (setq i k) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2502 (wisent-SETBIT shiftset symbol))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2503 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2504 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2505 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2506 (while (< i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2507 (setq defaulted nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2508 count (if (wisent-BITISSET shiftset i) 1 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2509 j m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2510 (while (< j n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2511 (when (wisent-BITISSET (aref LA j) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2512 (if (zerop count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2513 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2514 (if (not (= j default-LA)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2515 (wisent-log |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2516 " %s\treduce using rule %d (%s)\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2517 (wisent-tag i) (aref LAruleno j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2518 (wisent-tag (aref rlhs (aref LAruleno j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2519 (setq defaulted t)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2520 (setq count (1+ count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2521 (if defaulted |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2522 (wisent-log |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2523 " %s\treduce using rule %d (%s)\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2524 (wisent-tag i) (aref LAruleno default-LA) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2525 (wisent-tag (aref rlhs (aref LAruleno default-LA))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2526 (setq defaulted nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2527 (wisent-log |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2528 " %s\t[reduce using rule %d (%s)]\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2529 (wisent-tag i) (aref LAruleno j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2530 (wisent-tag (aref rlhs (aref LAruleno j)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2531 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2532 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2533 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2534 (if (>= default-LA 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2535 (wisent-log |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2536 " $default\treduce using rule %d (%s)\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2537 default-rule |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2538 (wisent-tag (aref rlhs default-rule)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2539 )))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2540 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2541 (defun wisent-print-actions (state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2542 "Print actions on STATE." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2543 (let (i j k v state1 symbol shiftp errp redp rule nerrs break) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2544 (setq shiftp (aref shift-table state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2545 redp (aref reduction-table state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2546 errp (aref err-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2547 (if (and (not shiftp) (not redp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2548 (if (= final-state state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2549 (wisent-log " $default\taccept\n") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2550 (wisent-log " NO ACTIONS\n")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2551 (if (not shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2552 (setq i 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2553 k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2554 (setq k (shifts-nshifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2555 v (shifts-shifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2556 i 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2557 break nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2558 (while (and (not break) (< i k)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2559 (if (zerop (setq state1 (aref v i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2560 (setq i (1+ i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2561 (setq symbol (aref accessing-symbol state1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2562 ;; The following line used to be turned off. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2563 (if (wisent-ISVAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2564 (setq break t) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2565 (wisent-log " %s\tshift, and go to state %d\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2566 (wisent-tag symbol) state1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2567 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2568 (if (> i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2569 (wisent-log "\n"))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2570 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2571 (when errp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2572 (setq nerrs (errs-nerrs errp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2573 v (errs-errs errp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2574 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2575 (while (< j nerrs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2576 (if (aref v j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2577 (wisent-log " %s\terror (nonassociative)\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2578 (wisent-tag (aref v j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2579 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2580 (if (> j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2581 (wisent-log "\n"))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2582 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2583 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2584 ((and (aref consistent state) redp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2585 (setq rule (aref (reductions-rules redp) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2586 symbol (aref rlhs rule)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2587 (wisent-log " $default\treduce using rule %d (%s)\n\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2588 rule (wisent-tag symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2589 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2590 (redp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2591 (wisent-print-reductions state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2592 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2593 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2594 (when (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2595 (setq v (shifts-shifts shiftp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2596 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2597 (when (setq state1 (aref v i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2598 (setq symbol (aref accessing-symbol state1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2599 (wisent-log " %s\tgo to state %d\n" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2600 (wisent-tag symbol) state1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2601 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2602 (wisent-log "\n")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2603 ))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2604 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2605 (defun wisent-print-core (state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2606 "Print STATE core." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2607 (let (i k rule statep sp sp1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2608 (setq statep (aref state-table state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2609 k (core-nitems statep)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2610 (when (> k 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2611 (setq i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2612 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2613 ;; sp1 = sp = ritem + statep->items[i]; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2614 (setq sp1 (aref (core-items statep) i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2615 sp sp1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2616 (while (> (aref ritem sp) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2617 (setq sp (1+ sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2618 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2619 (setq rule (- (aref ritem sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2620 (wisent-log " %s -> " (wisent-tag (aref rlhs rule))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2621 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2622 (setq sp (aref rrhs rule)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2623 (while (< sp sp1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2624 (wisent-log "%s " (wisent-tag (aref ritem sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2625 (setq sp (1+ sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2626 (wisent-log ".") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2627 (while (> (aref ritem sp) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2628 (wisent-log " %s" (wisent-tag (aref ritem sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2629 (setq sp (1+ sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2630 (wisent-log " (rule %d)\n" rule) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2631 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2632 (wisent-log "\n")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2633 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2634 (defun wisent-print-state (state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2635 "Print information on STATE." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2636 (wisent-log "\n\nstate %d\n\n" state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2637 (wisent-print-core state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2638 (wisent-print-actions state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2639 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2640 (defun wisent-print-states () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2641 "Print information on states." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2642 (let ((i 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2643 (while (< i nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2644 (wisent-print-state i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2645 (setq i (1+ i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2646 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2647 (defun wisent-print-results () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2648 "Print information on generated parser. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2649 Report detailed informations if `wisent-verbose-flag' or |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2650 `wisent-debug-flag' are non-nil." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2651 (when (or wisent-verbose-flag wisent-debug-flag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2652 (wisent-print-useless)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2653 (wisent-print-conflicts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2654 (when (or wisent-verbose-flag wisent-debug-flag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2655 (wisent-print-grammar) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2656 (wisent-print-states)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2657 ;; Append output to log file when running in batch mode |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2658 (when (wisent-noninteractive) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2659 (wisent-append-to-log-file) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2660 (wisent-clear-log))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2661 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2662 ;;;; --------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2663 ;;;; Build the generated parser tables |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2664 ;;;; --------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2665 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2666 (defun wisent-action-row (state actrow) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2667 "Figure out the actions for the specified STATE. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2668 Decide what to do for each type of token if seen as the lookahead |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2669 token in specified state. The value returned is used as the default |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2670 action for the state. In addition, ACTROW is filled with what to do |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2671 for each kind of token, index by symbol number, with nil meaning do |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2672 the default action. The value 'error, means this situation is an |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2673 error. The parser recognizes this value specially. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2674 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2675 This is where conflicts are resolved. The loop over lookahead rules |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2676 considered lower-numbered rules last, and the last rule considered |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2677 that likes a token gets to handle it." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2678 (let (i j k m n v default-rule nreds rule max count |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2679 shift-state symbol redp shiftp errp nodefault) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2680 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2681 (fillarray actrow nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2682 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2683 (setq default-rule 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2684 nodefault nil ;; nil inhibit having any default reduction |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2685 nreds 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2686 m 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2687 n 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2688 redp (aref reduction-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2689 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2690 (when redp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2691 (setq nreds (reductions-nreds redp)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2692 (when (>= nreds 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2693 ;; loop over all the rules available here which require |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2694 ;; lookahead |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2695 (setq m (aref lookaheads state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2696 n (aref lookaheads (1+ state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2697 i (1- n)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2698 (while (>= i m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2699 ;; and find each token which the rule finds acceptable to |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2700 ;; come next |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2701 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2702 (while (< j ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2703 ;; and record this rule as the rule to use if that token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2704 ;; follows. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2705 (if (wisent-BITISSET (aref LA i) j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2706 (aset actrow j (- (aref LAruleno i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2707 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2708 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2709 (setq i (1- i))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2710 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2711 ;; Now see which tokens are allowed for shifts in this state. For |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2712 ;; them, record the shift as the thing to do. So shift is |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2713 ;; preferred to reduce. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2714 (setq shiftp (aref shift-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2715 (when shiftp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2716 (setq k (shifts-nshifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2717 v (shifts-shifts shiftp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2718 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2719 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2720 (setq shift-state (aref v i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2721 (if (zerop shift-state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2722 nil ;; continue |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2723 (setq symbol (aref accessing-symbol shift-state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2724 (if (wisent-ISVAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2725 (setq i k) ;; break |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2726 (aset actrow symbol shift-state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2727 ;; Do not use any default reduction if there is a shift |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2728 ;; for error |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2729 (if (= symbol error-token-number) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2730 (setq nodefault t)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2731 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2732 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2733 ;; See which tokens are an explicit error in this state (due to |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2734 ;; %nonassoc). For them, record error as the action. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2735 (setq errp (aref err-table state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2736 (when errp |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2737 (setq k (errs-nerrs errp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2738 v (errs-errs errp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2739 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2740 (while (< i k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2741 (aset actrow (aref v i) wisent-error-tag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2742 (setq i (1+ i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2743 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2744 ;; Now find the most common reduction and make it the default |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2745 ;; action for this state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2746 (when (and (>= nreds 1) (not nodefault)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2747 (if (aref consistent state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2748 (setq default-rule (- (aref (reductions-rules redp) 0))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2749 (setq max 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2750 i m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2751 (while (< i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2752 (setq count 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2753 rule (- (aref LAruleno i)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2754 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2755 (while (< j ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2756 (if (and (numberp (aref actrow j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2757 (= (aref actrow j) rule)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2758 (setq count (1+ count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2759 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2760 (if (> count max) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2761 (setq max count |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2762 default-rule rule)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2763 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2764 ;; actions which match the default are replaced with zero, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2765 ;; which means "use the default" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2766 (when (> max 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2767 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2768 (while (< j ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2769 (if (and (numberp (aref actrow j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2770 (= (aref actrow j) default-rule)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2771 (aset actrow j nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2772 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2773 ))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2774 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2775 ;; If have no default rule, if this is the final state the default |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2776 ;; is accept else it is an error. So replace any action which |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2777 ;; says "error" with "use default". |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2778 (when (zerop default-rule) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2779 (if (= final-state state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2780 (setq default-rule wisent-accept-tag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2781 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2782 (while (< j ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2783 (if (eq (aref actrow j) wisent-error-tag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2784 (aset actrow j nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2785 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2786 (setq default-rule wisent-error-tag))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2787 default-rule)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2788 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2789 (defconst wisent-default-tag 'default |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2790 "Tag used in an action table to indicate a default action.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2791 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2792 ;; These variables only exist locally in the function |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2793 ;; `wisent-state-actions' and are shared by all other nested callees. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2794 (wisent-defcontext semantic-actions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2795 ;; Uninterned symbols used in code generation. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2796 stack sp gotos state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2797 ;; Name of the current semantic action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2798 NAME) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2799 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2800 (defun wisent-state-actions () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2801 "Figure out the actions for every state. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2802 Return the action table." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2803 ;; Store the semantic action obarray in (unused) RCODE[0]. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2804 (aset rcode 0 (make-vector 13 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2805 (let (i j action-table actrow action) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2806 (setq action-table (make-vector nstates nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2807 actrow (make-vector ntokens nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2808 i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2809 (wisent-with-context semantic-actions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2810 (setq stack (make-symbol "stack") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2811 sp (make-symbol "sp") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2812 gotos (make-symbol "gotos") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2813 state (make-symbol "state")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2814 (while (< i nstates) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2815 (setq action (wisent-action-row i actrow)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2816 ;; Translate a reduction into semantic action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2817 (and (integerp action) (< action 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2818 (setq action (wisent-semantic-action (- action)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2819 (aset action-table i (list (cons wisent-default-tag action))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2820 (setq j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2821 (while (< j ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2822 (when (setq action (aref actrow j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2823 ;; Translate a reduction into semantic action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2824 (and (integerp action) (< action 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2825 (setq action (wisent-semantic-action (- action)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2826 (aset action-table i (cons (cons (aref tags j) action) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2827 (aref action-table i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2828 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2829 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2830 (aset action-table i (nreverse (aref action-table i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2831 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2832 action-table))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2833 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2834 (defun wisent-goto-actions () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2835 "Figure out what to do after reducing with each rule. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2836 Depending on the saved state from before the beginning of parsing the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2837 data that matched this rule. Return the goto table." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2838 (let (i j m n symbol state goto-table) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2839 (setq goto-table (make-vector nstates nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2840 i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2841 (while (< i nsyms) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2842 (setq symbol (- i ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2843 m (aref goto-map symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2844 n (aref goto-map (1+ symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2845 j m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2846 (while (< j n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2847 (setq state (aref from-state j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2848 (aset goto-table state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2849 (cons (cons (aref tags i) (aref to-state j)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2850 (aref goto-table state))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2851 (setq j (1+ j))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2852 (setq i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2853 goto-table)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2854 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2855 (defsubst wisent-quote-p (sym) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2856 "Return non-nil if SYM is bound to the `quote' function." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2857 (condition-case nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2858 (eq (indirect-function sym) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2859 (indirect-function 'quote)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2860 (error nil))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2861 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2862 (defsubst wisent-backquote-p (sym) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2863 "Return non-nil if SYM is bound to the `backquote' function." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2864 (condition-case nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2865 (eq (indirect-function sym) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2866 (indirect-function 'backquote)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2867 (error nil))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2868 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2869 (defun wisent-check-$N (x m) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2870 "Return non-nil if X is a valid $N or $regionN symbol. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2871 That is if X is a $N or $regionN symbol with N >= 1 and N <= M. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2872 Also warn if X is a $N or $regionN symbol with N < 1 or N > M." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2873 (when (symbolp x) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2874 (let* ((n (symbol-name x)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2875 (i (and (string-match "\\`\\$\\(region\\)?\\([0-9]+\\)\\'" n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2876 (string-to-number (match-string 2 n))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2877 (when i |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2878 (if (and (>= i 1) (<= i m)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2879 t |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2880 (message |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2881 "*** In %s, %s might be a free variable (rule has %s)" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2882 NAME x (format (cond ((< m 1) "no component") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2883 ((= m 1) "%d component") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2884 ("%d components")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2885 m)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2886 nil))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2887 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2888 (defun wisent-semantic-action-expand-body (body n &optional found) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2889 "Parse BODY of semantic action. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2890 N is the maximum number of $N variables that can be referenced in |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2891 BODY. Warn on references out of permitted range. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2892 Optional argument FOUND is the accumulated list of '$N' references |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2893 encountered so far. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2894 Return a cons (FOUND . XBODY), where FOUND is the list of $N |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2895 references found in BODY, and XBODY is BODY expression with |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2896 `backquote' forms expanded." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2897 (if (not (listp body)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2898 ;; BODY is an atom, no expansion needed |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2899 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2900 (if (wisent-check-$N body n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2901 ;; Accumulate $i symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2902 (add-to-list 'found body)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2903 (cons found body)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2904 ;; BODY is a list, expand inside it |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2905 (let (xbody sexpr) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2906 ;; If backquote expand it first |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2907 (if (wisent-backquote-p (car body)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2908 (setq body (macroexpand body))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2909 (while body |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2910 (setq sexpr (car body) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2911 body (cdr body)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2912 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2913 ;; Function call excepted quote expression |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2914 ((and (consp sexpr) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2915 (not (wisent-quote-p (car sexpr)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2916 (setq sexpr (wisent-semantic-action-expand-body sexpr n found) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2917 found (car sexpr) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2918 sexpr (cdr sexpr))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2919 ;; $i symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2920 ((wisent-check-$N sexpr n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2921 ;; Accumulate $i symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2922 (add-to-list 'found sexpr)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2923 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2924 ;; Accumulate expanded forms |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2925 (setq xbody (nconc xbody (list sexpr)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2926 (cons found xbody)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2927 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2928 (defun wisent-semantic-action (r) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2929 "Set up the Elisp function for semantic action at rule R. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2930 On entry RCODE[R] contains a vector [BODY N (NTERM I)] where BODY is the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2931 body of the semantic action, N is the maximum number of values |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2932 available in the parser's stack, NTERM is the nonterminal the semantic |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2933 action belongs to, and I is the index of the semantic action inside |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2934 NTERM definition. Return the semantic action symbol. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2935 The semantic action function accepts three arguments: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2936 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2937 - the state/value stack |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2938 - the top-of-stack index |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2939 - the goto table |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2940 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2941 And returns the updated top-of-stack index." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2942 (if (not (aref ruseful r)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2943 (aset rcode r nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2944 (let* ((actn (aref rcode r)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2945 (n (aref actn 1)) ; nb of val avail. in stack |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2946 (NAME (apply 'format "%s:%d" (aref actn 2))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2947 (form (wisent-semantic-action-expand-body (aref actn 0) n)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2948 ($l (car form)) ; list of $vars used in body |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2949 (form (cdr form)) ; expanded form of body |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2950 (nt (aref rlhs r)) ; nonterminal item no. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2951 (bl nil) ; `let*' binding list |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2952 $v i j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2953 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2954 ;; Compute $N and $regionN bindings |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2955 (setq i n) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2956 (while (> i 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2957 (setq j (1+ (* 2 (- n i)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2958 ;; Only bind $regionI if used in action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2959 (setq $v (intern (format "$region%d" i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2960 (if (memq $v $l) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2961 (setq bl (cons `(,$v (cdr (aref ,stack (- ,sp ,j)))) bl))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2962 ;; Only bind $I if used in action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2963 (setq $v (intern (format "$%d" i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2964 (if (memq $v $l) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2965 (setq bl (cons `(,$v (car (aref ,stack (- ,sp ,j)))) bl))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2966 (setq i (1- i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2967 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2968 ;; Compute J, the length of rule's RHS. It will give the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2969 ;; current parser state at STACK[SP - 2*J], and where to push |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2970 ;; the new semantic value and the next state, respectively at: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2971 ;; STACK[SP - 2*J + 1] and STACK[SP - 2*J + 2]. Generally N, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2972 ;; the maximum number of values available in the stack, is equal |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2973 ;; to J. But, for mid-rule actions, N is the number of rule |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2974 ;; elements before the action and J is always 0 (empty rule). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2975 (setq i (aref rrhs r) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2976 j 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2977 (while (> (aref ritem i) 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2978 (setq j (1+ j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2979 i (1+ i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2980 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2981 ;; Create the semantic action symbol. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2982 (setq actn (intern NAME (aref rcode 0))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2983 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2984 ;; Store source code in function cell of the semantic action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2985 ;; symbol. It will be byte-compiled at automaton's compilation |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2986 ;; time. Using a byte-compiled automaton can significantly |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2987 ;; speed up parsing! |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2988 (fset actn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2989 `(lambda (,stack ,sp ,gotos) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2990 (let* (,@bl |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2991 ($region |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2992 ,(cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2993 ((= n 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2994 (if (assq '$region1 bl) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2995 '$region1 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2996 `(cdr (aref ,stack (1- ,sp))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2997 ((> n 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2998 `(wisent-production-bounds |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2999 ,stack (- ,sp ,(1- (* 2 n))) (1- ,sp))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3000 ($action ,NAME) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3001 ($nterm ',(aref tags nt)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3002 ,@(and (> j 0) `((,sp (- ,sp ,(* j 2))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3003 (,state (cdr (assq $nterm |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3004 (aref ,gotos |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3005 (aref ,stack ,sp)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3006 (setq ,sp (+ ,sp 2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3007 ;; push semantic value |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3008 (aset ,stack (1- ,sp) (cons ,form $region)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3009 ;; push next state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3010 (aset ,stack ,sp ,state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3011 ;; return new top of stack |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3012 ,sp))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3013 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3014 ;; Return the semantic action symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3015 actn))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3016 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3017 ;;;; ---------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3018 ;;;; Build parser LALR automaton. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3019 ;;;; ---------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3020 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3021 (defun wisent-parser-automaton () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3022 "Compute and return LALR(1) automaton from GRAMMAR. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3023 GRAMMAR is in internal format. GRAM/ACTS are grammar rules |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3024 in internal format. STARTS defines the start symbols." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3025 ;; Check for useless stuff |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3026 (wisent-reduce-grammar) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3027 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3028 (wisent-set-derives) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3029 (wisent-set-nullable) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3030 ;; convert to nondeterministic finite state machine. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3031 (wisent-generate-states) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3032 ;; make it deterministic. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3033 (wisent-lalr) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3034 ;; Find and record any conflicts: places where one token of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3035 ;; lookahead is not enough to disambiguate the parsing. Also |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3036 ;; resolve s/r conflicts based on precedence declarations. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3037 (wisent-resolve-conflicts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3038 (wisent-print-results) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3039 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3040 (vector (wisent-state-actions) ; action table |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3041 (wisent-goto-actions) ; goto table |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3042 start-table ; start symbols |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3043 (aref rcode 0) ; sem. action symbol obarray |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3044 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3045 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3046 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3047 ;;;; ------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3048 ;;;; Parse input grammar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3049 ;;;; ------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3050 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3051 (defconst wisent-reserved-symbols (list wisent-error-term) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3052 "The list of reserved symbols. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3053 Also all symbols starting with a character defined in |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3054 `wisent-reserved-capitals' are reserved for internal use.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3055 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3056 (defconst wisent-reserved-capitals '(?\$ ?\@) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3057 "The list of reserved capital letters. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3058 All symbol starting with one of these letters are reserved for |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3059 internal use.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3060 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3061 (defconst wisent-starts-nonterm '$STARTS |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3062 "Main start symbol. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3063 It gives the rules for start symbols.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3064 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3065 (defvar wisent-single-start-flag nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3066 "Non-nil means allows only one start symbol like in Bison. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3067 That is don't add extra start rules to the grammar. This is |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3068 useful to compare the Wisent's generated automaton with the Bison's |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3069 one.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3070 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3071 (defsubst wisent-ISVALID-VAR (x) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3072 "Return non-nil if X is a character or an allowed symbol." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3073 (and x (symbolp x) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3074 (not (memq (aref (symbol-name x) 0) wisent-reserved-capitals)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3075 (not (memq x wisent-reserved-symbols)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3076 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3077 (defsubst wisent-ISVALID-TOKEN (x) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3078 "Return non-nil if X is a character or an allowed symbol." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3079 (or (wisent-char-p x) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3080 (wisent-ISVALID-VAR x))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3081 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3082 (defun wisent-push-token (symbol &optional nocheck) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3083 "Push a new SYMBOL in the list of tokens. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3084 Bypass checking if NOCHECK is non-nil." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3085 ;; Check |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3086 (or nocheck (wisent-ISVALID-TOKEN symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3087 (error "Invalid terminal symbol: %S" symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3088 (if (memq symbol token-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3089 (message "*** duplicate terminal `%s' ignored" symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3090 ;; Set up properties |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3091 (wisent-set-prec symbol nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3092 (wisent-set-assoc symbol nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3093 (wisent-set-item-number symbol ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3094 ;; Add |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3095 (setq ntokens (1+ ntokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3096 token-list (cons symbol token-list)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3097 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3098 (defun wisent-push-var (symbol &optional nocheck) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3099 "Push a new SYMBOL in the list of nonterminals. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3100 Bypass checking if NOCHECK is non-nil." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3101 ;; Check |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3102 (unless nocheck |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3103 (or (wisent-ISVALID-VAR symbol) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3104 (error "Invalid nonterminal symbol: %S" symbol)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3105 (if (memq symbol var-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3106 (error "Nonterminal `%s' already defined" symbol))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3107 ;; Set up properties |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3108 (wisent-set-item-number symbol nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3109 ;; Add |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3110 (setq nvars (1+ nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3111 var-list (cons symbol var-list))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3112 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3113 (defun wisent-parse-nonterminals (defs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3114 "Parse nonterminal definitions in DEFS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3115 Fill in each element of the global arrays RPREC, RCODE, RUSEFUL with |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3116 respectively rule precedence level, semantic action code and |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3117 usefulness flag. Return a list of rules of the form (LHS . RHS) where |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3118 LHS and RHS are respectively the Left Hand Side and Right Hand Side of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3119 the rule." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3120 (setq rprec nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3121 rcode nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3122 nitems 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3123 nrules 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3124 (let (def nonterm rlist rule rules rhs rest item items |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3125 rhl plevel semact @n @count iactn) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3126 (setq @count 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3127 (while defs |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3128 (setq def (car defs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3129 defs (cdr defs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3130 nonterm (car def) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3131 rlist (cdr def) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3132 iactn 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3133 (or (consp rlist) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3134 (error "Invalid nonterminal definition syntax: %S" def)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3135 (while rlist |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3136 (setq rule (car rlist) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3137 rlist (cdr rlist) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3138 items (car rule) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3139 rest (cdr rule) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3140 rhl 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3141 rhs nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3142 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3143 ;; Check & count items |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3144 (setq nitems (1+ nitems)) ;; LHS item |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3145 (while items |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3146 (setq item (car items) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3147 items (cdr items) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3148 nitems (1+ nitems)) ;; RHS items |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3149 (if (listp item) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3150 ;; Mid-rule action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3151 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3152 (setq @count (1+ @count) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3153 @n (intern (format "@%d" @count))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3154 (wisent-push-var @n t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3155 ;; Push a new empty rule with the mid-rule action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3156 (setq semact (vector item rhl (list nonterm iactn)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3157 iactn (1+ iactn) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3158 plevel nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3159 rcode (cons semact rcode) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3160 rprec (cons plevel rprec) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3161 item @n ;; Replace action by @N nonterminal |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3162 rules (cons (list item) rules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3163 nitems (1+ nitems) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3164 nrules (1+ nrules))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3165 ;; Check terminal or nonterminal symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3166 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3167 ((or (memq item token-list) (memq item var-list))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3168 ;; Create new literal character token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3169 ((wisent-char-p item) (wisent-push-token item t)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3170 ((error "Symbol `%s' is used, but is not defined as a token and has no rules" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3171 item)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3172 (setq rhl (1+ rhl) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3173 rhs (cons item rhs))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3174 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3175 ;; Check & collect rule precedence level |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3176 (setq plevel (when (vectorp (car rest)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3177 (setq item (car rest) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3178 rest (cdr rest)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3179 (if (and (= (length item) 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3180 (memq (aref item 0) token-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3181 (wisent-prec (aref item 0))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3182 (wisent-item-number (aref item 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3183 (error "Invalid rule precedence level syntax: %S" item))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3184 rprec (cons plevel rprec)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3185 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3186 ;; Check & collect semantic action body |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3187 (setq semact (vector |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3188 (if rest |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3189 (if (cdr rest) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3190 (error "Invalid semantic action syntax: %S" rest) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3191 (car rest)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3192 ;; Give a default semantic action body: nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3193 ;; for an empty rule or $1, the value of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3194 ;; first symbol in the rule, otherwise. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3195 (if (> rhl 0) '$1 '())) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3196 rhl |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3197 (list nonterm iactn)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3198 iactn (1+ iactn) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3199 rcode (cons semact rcode)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3200 (setq rules (cons (cons nonterm (nreverse rhs)) rules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3201 nrules (1+ nrules)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3202 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3203 (setq ruseful (make-vector (1+ nrules) t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3204 rprec (vconcat (cons nil (nreverse rprec))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3205 rcode (vconcat (cons nil (nreverse rcode)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3206 (nreverse rules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3207 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3208 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3209 (defun wisent-parse-grammar (grammar &optional start-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3210 "Parse GRAMMAR and build a suitable internal representation. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3211 Optional argument START-LIST defines the start symbols. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3212 GRAMMAR is a list of form: (TOKENS ASSOCS . NONTERMS) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3213 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3214 TOKENS is a list of terminal symbols (tokens). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3215 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3216 ASSOCS is nil or an alist of (ASSOC-TYPE . ASSOC-VALUE) elements |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3217 describing the associativity of TOKENS. ASSOC-TYPE must be one of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3218 `default-prec' `nonassoc', `left' or `right' symbols. When ASSOC-TYPE |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3219 is `default-prec', ASSOC-VALUE must be nil or t (the default). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3220 Otherwise it is a list of tokens which must have been previously |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3221 declared in TOKENS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3222 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3223 NONTERMS is the list of non terminal definitions (see function |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3224 `wisent-parse-nonterminals')." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3225 (or (and (consp grammar) (> (length grammar) 2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3226 (error "Bad input grammar")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3227 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3228 (let (i r rhs pre dpre lst start-var assoc rules item |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3229 token var def tokens defs ep-token ep-var ep-def) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3230 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3231 ;; Built-in tokens |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3232 (setq ntokens 0 nvars 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3233 (wisent-push-token wisent-eoi-term t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3234 (wisent-push-token wisent-error-term t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3235 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3236 ;; Check/collect terminals |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3237 (setq lst (car grammar)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3238 (while lst |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3239 (wisent-push-token (car lst)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3240 (setq lst (cdr lst))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3241 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3242 ;; Check/Set up tokens precedence & associativity |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3243 (setq lst (nth 1 grammar) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3244 pre 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3245 defs nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3246 dpre nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3247 default-prec t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3248 (while lst |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3249 (setq def (car lst) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3250 assoc (car def) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3251 tokens (cdr def) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3252 lst (cdr lst)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3253 (if (eq assoc 'default-prec) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3254 (progn |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3255 (or (null (cdr tokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3256 (memq (car tokens) '(t nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3257 (error "Invalid default-prec value: %S" tokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3258 (setq default-prec (car tokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3259 (if dpre |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3260 (message "*** redefining default-prec to %s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3261 default-prec)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3262 (setq dpre t)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3263 (or (memq assoc '(left right nonassoc)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3264 (error "Invalid associativity syntax: %S" assoc)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3265 (setq pre (1+ pre)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3266 (while tokens |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3267 (setq token (car tokens) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3268 tokens (cdr tokens)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3269 (if (memq token defs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3270 (message "*** redefining precedence of `%s'" token)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3271 (or (memq token token-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3272 ;; Define token not previously declared. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3273 (wisent-push-token token)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3274 (setq defs (cons token defs)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3275 ;; Record the precedence and associativity of the terminal. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3276 (wisent-set-prec token pre) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3277 (wisent-set-assoc token assoc)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3278 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3279 ;; Check/Collect nonterminals |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3280 (setq lst (nthcdr 2 grammar) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3281 defs nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3282 (while lst |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3283 (setq def (car lst) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3284 lst (cdr lst)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3285 (or (consp def) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3286 (error "Invalid nonterminal definition: %S" def)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3287 (if (memq (car def) token-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3288 (error "Nonterminal `%s' already defined as token" (car def))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3289 (wisent-push-var (car def)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3290 (setq defs (cons def defs))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3291 (or defs |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3292 (error "No input grammar")) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3293 (setq defs (nreverse defs)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3294 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3295 ;; Set up the start symbol. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3296 (setq start-table nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3297 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3298 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3299 ;; 1. START-LIST is nil, the start symbol is the first |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3300 ;; nonterminal defined in the grammar (Bison like). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3301 ((null start-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3302 (setq start-var (caar defs))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3303 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3304 ;; 2. START-LIST contains only one element, it is the start |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3305 ;; symbol (Bison like). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3306 ((or wisent-single-start-flag (null (cdr start-list))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3307 (setq start-var (car start-list)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3308 (or (assq start-var defs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3309 (error "Start symbol `%s' has no rule" start-var))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3310 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3311 ;; 3. START-LIST contains more than one element. All defines |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3312 ;; potential start symbols. One of them (the first one by |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3313 ;; default) will be given at parse time to be the parser goal. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3314 ;; If `wisent-single-start-flag' is non-nil that feature is |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3315 ;; disabled and the first nonterminal in START-LIST defines |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3316 ;; the start symbol, like in case 2 above. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3317 ((not wisent-single-start-flag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3318 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3319 ;; START-LIST is a list of nonterminals '(nt0 ... ntN). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3320 ;; Build and push ad hoc start rules in the grammar: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3321 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3322 ;; ($STARTS ((nt0) $1) ((nt1) $1) ... ((ntN) $1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3323 ;; ($nt1 (($$nt1 nt1) $2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3324 ;; ... |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3325 ;; ($ntN (($$ntN ntN) $2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3326 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3327 ;; Where internal symbols $ntI and $$ntI are respectively |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3328 ;; nonterminals and terminals. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3329 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3330 ;; The internal start symbol $STARTS is used to build the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3331 ;; LALR(1) automaton. The true default start symbol used by the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3332 ;; parser is the first nonterminal in START-LIST (nt0). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3333 (setq start-var wisent-starts-nonterm |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3334 lst (nreverse start-list)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3335 (while lst |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3336 (setq var (car lst) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3337 lst (cdr lst)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3338 (or (memq var var-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3339 (error "Start symbol `%s' has no rule" var)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3340 (unless (assq var start-table) ;; Ignore duplicates |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3341 ;; For each nt start symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3342 (setq ep-var (intern (format "$%s" var)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3343 ep-token (intern (format "$$%s" var))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3344 (wisent-push-token ep-token t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3345 (wisent-push-var ep-var t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3346 (setq |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3347 ;; Add entry (nt . $$nt) to start-table |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3348 start-table (cons (cons var ep-token) start-table) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3349 ;; Add rule ($nt (($$nt nt) $2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3350 defs (cons (list ep-var (list (list ep-token var) '$2)) defs) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3351 ;; Add start rule (($nt) $1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3352 ep-def (cons (list (list ep-var) '$1) ep-def)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3353 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3354 (wisent-push-var start-var t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3355 (setq defs (cons (cons start-var ep-def) defs)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3356 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3357 ;; Set up rules main data structure & RPREC, RCODE, RUSEFUL |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3358 (setq rules (wisent-parse-nonterminals defs)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3359 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3360 ;; Set up the terminal & nonterminal lists. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3361 (setq nsyms (+ ntokens nvars) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3362 token-list (nreverse token-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3363 lst var-list |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3364 var-list nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3365 (while lst |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3366 (setq var (car lst) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3367 lst (cdr lst) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3368 var-list (cons var var-list)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3369 (wisent-set-item-number ;; adjust nonterminal item number to |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3370 var (+ ntokens (wisent-item-number var)))) ;; I += NTOKENS |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3371 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3372 ;; Store special item numbers |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3373 (setq error-token-number (wisent-item-number wisent-error-term) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3374 start-symbol (wisent-item-number start-var)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3375 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3376 ;; Keep symbols in the TAGS vector so that TAGS[I] is the symbol |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3377 ;; associated to item number I. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3378 (setq tags (vconcat token-list var-list)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3379 ;; Set up RLHS RRHS & RITEM data structures from list of rules |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3380 ;; (LHS . RHS) received from `wisent-parse-nonterminals'. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3381 (setq rlhs (make-vector (1+ nrules) nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3382 rrhs (make-vector (1+ nrules) nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3383 ritem (make-vector (1+ nitems) nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3384 i 0 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3385 r 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3386 (while rules |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3387 (aset rlhs r (wisent-item-number (caar rules))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3388 (aset rrhs r i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3389 (setq rhs (cdar rules) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3390 pre nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3391 (while rhs |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3392 (setq item (wisent-item-number (car rhs))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3393 ;; Get default precedence level of rule, that is the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3394 ;; precedence of the last terminal in it. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3395 (and (wisent-ISTOKEN item) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3396 default-prec |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3397 (setq pre item)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3398 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3399 (aset ritem i item) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3400 (setq i (1+ i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3401 rhs (cdr rhs))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3402 ;; Setup the precedence level of the rule, that is the one |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3403 ;; specified by %prec or the default one. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3404 (and (not (aref rprec r)) ;; Already set by %prec |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3405 pre |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3406 (wisent-prec (aref tags pre)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3407 (aset rprec r pre)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3408 (aset ritem i (- r)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3409 (setq i (1+ i) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3410 r (1+ r)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3411 (setq rules (cdr rules))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3412 )) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3413 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3414 ;;;; --------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3415 ;;;; Compile input grammar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3416 ;;;; --------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3417 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3418 (defun wisent-compile-grammar (grammar &optional start-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3419 "Compile the LALR(1) GRAMMAR. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3420 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3421 GRAMMAR is a list (TOKENS ASSOCS . NONTERMS) where: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3422 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3423 - TOKENS is a list of terminal symbols (tokens). |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3424 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3425 - ASSOCS is nil, or an alist of (ASSOC-TYPE . ASSOC-VALUE) elements |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3426 describing the associativity of TOKENS. ASSOC-TYPE must be one of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3427 the `default-prec' `nonassoc', `left' or `right' symbols. When |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3428 ASSOC-TYPE is `default-prec', ASSOC-VALUE must be nil or t (the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3429 default). Otherwise it is a list of tokens which must have been |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3430 previously declared in TOKENS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3431 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3432 - NONTERMS is a list of nonterminal definitions. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3433 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3434 Optional argument START-LIST specify the possible grammar start |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3435 symbols. This is a list of nonterminals which must have been |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3436 previously declared in GRAMMAR's NONTERMS form. By default, the start |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3437 symbol is the first nonterminal defined. When START-LIST contains |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3438 only one element, it is the start symbol. Otherwise, all elements are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3439 possible start symbols, unless `wisent-single-start-flag' is non-nil. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3440 In that case, the first element is the start symbol, and others are |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3441 ignored. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3442 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3443 Return an automaton as a vector: [ACTIONS GOTOS STARTS FUNCTIONS] |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3444 where: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3445 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3446 - ACTIONS is a state/token matrix telling the parser what to do at |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3447 every state based on the current lookahead token. That is shift, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3448 reduce, accept or error. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3449 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3450 - GOTOS is a state/nonterminal matrix telling the parser the next |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3451 state to go to after reducing with each rule. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3452 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3453 - STARTS is an alist which maps the allowed start nonterminal symbols |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3454 to tokens that will be first shifted into the parser stack. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3455 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3456 - FUNCTIONS is an obarray of semantic action symbols. Each symbol's |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3457 function definition is the semantic action lambda expression." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3458 (if (wisent-automaton-p grammar) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3459 grammar ;; Grammar already compiled just return it |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3460 (wisent-with-context compile-grammar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3461 (let* ((gc-cons-threshold 1000000) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3462 automaton) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3463 (garbage-collect) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3464 (setq wisent-new-log-flag t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3465 ;; Parse input grammar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3466 (wisent-parse-grammar grammar start-list) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3467 ;; Generate the LALR(1) automaton |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3468 (setq automaton (wisent-parser-automaton)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3469 automaton)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3470 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3471 ;;;; -------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3472 ;;;; Byte compile input grammar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3473 ;;;; -------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3474 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3475 (require 'bytecomp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3476 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3477 (defun wisent-byte-compile-grammar (form) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3478 "Byte compile the `wisent-compile-grammar' FORM. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3479 Automatically called by the Emacs Lisp byte compiler as a |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3480 `byte-compile' handler." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3481 ;; Eval the `wisent-compile-grammar' form to obtain an LALR |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3482 ;; automaton internal data structure. Then, because the internal |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3483 ;; data structure contains an obarray, convert it to a lisp form so |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3484 ;; it can be byte-compiled. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3485 (byte-compile-form (wisent-automaton-lisp-form (eval form)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3486 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3487 (put 'wisent-compile-grammar 'byte-compile 'wisent-byte-compile-grammar) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3488 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3489 (defun wisent-automaton-lisp-form (automaton) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3490 "Return a Lisp form that produces AUTOMATON. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3491 See also `wisent-compile-grammar' for more details on AUTOMATON." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3492 (or (wisent-automaton-p automaton) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3493 (signal 'wrong-type-argument |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3494 (list 'wisent-automaton-p automaton))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3495 (let ((obn (make-symbol "ob")) ; Generated obarray name |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3496 (obv (aref automaton 3)) ; Semantic actions obarray |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3497 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3498 `(let ((,obn (make-vector 13 0))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3499 ;; Generate code to initialize the semantic actions obarray, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3500 ;; in local variable OBN. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3501 ,@(let (obcode) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3502 (mapatoms |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3503 #'(lambda (s) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3504 (setq obcode |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3505 (cons `(fset (intern ,(symbol-name s) ,obn) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3506 #',(symbol-function s)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3507 obcode))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3508 obv) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3509 obcode) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3510 ;; Generate code to create the automaton. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3511 (vector |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3512 ;; In code generated to initialize the action table, take |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3513 ;; care of symbols that are interned in the semantic actions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3514 ;; obarray. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3515 (vector |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3516 ,@(mapcar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3517 #'(lambda (state) ;; for each state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3518 `(list |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3519 ,@(mapcar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3520 #'(lambda (tr) ;; for each transition |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3521 (let ((k (car tr)) ; token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3522 (a (cdr tr))) ; action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3523 (if (and (symbolp a) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3524 (intern-soft (symbol-name a) obv)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3525 `(cons ,(if (symbolp k) `(quote ,k) k) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3526 (intern-soft ,(symbol-name a) ,obn)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3527 `(quote ,tr)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3528 state))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3529 (aref automaton 0))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3530 ;; The code of the goto table is unchanged. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3531 ,(aref automaton 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3532 ;; The code of the alist of start symbols is unchanged. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3533 ',(aref automaton 2) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3534 ;; The semantic actions obarray is in the local variable OBN. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3535 ,obn)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3536 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3537 (provide 'semantic/wisent/comp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3538 |
105377 | 3539 ;; arch-tag: 758ea04c-ea97-466b-9b35-aea0861033c9 |
104478
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3540 ;;; semantic/wisent/comp.el ends here |