1 ;;; semantic-grammar.wy -- LALR grammar of Semantic input grammars
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 ;; 2011, 2012 Free Software Foundation, Inc.
6 ;; Author: David Ponce <david@dponce.com>
7 ;; Maintainer: David Ponce <david@dponce.com>
8 ;; Created: 26 Aug 2002
10 ;; X-RCS: $Id: semantic-grammar.wy,v 1.16 2005/09/30 20:20:27 zappo Exp $
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; Current parsed nonterminal name.
29 (defvar semantic-grammar-wy--nterm nil)
30 ;; Index of rule in a nonterminal clause.
31 (defvar semantic-grammar-wy--rindx nil)
34 %package semantic-grammar-wy
41 %start prologue epilogue declaration nonterminal rule
43 %start put_names put_values use_names
47 %keyword DEFAULT-PREC "%default-prec"
48 %keyword NO-DEFAULT-PREC "%no-default-prec"
49 %keyword KEYWORD "%keyword"
50 %keyword LANGUAGEMODE "%languagemode"
52 %keyword NONASSOC "%nonassoc"
53 %keyword PACKAGE "%package"
56 %keyword QUOTEMODE "%quotemode"
57 %keyword RIGHT "%right"
58 %keyword SCOPESTART "%scopestart"
59 %keyword START "%start"
60 %keyword TOKEN "%token"
62 %keyword USE-MACROS "%use-macros"
66 %token <string> STRING
68 %type <symbol> syntax ":?\\(\\sw\\|\\s_\\)+"
69 %token <symbol> SYMBOL
70 %token <symbol> PERCENT_PERCENT "\\`%%\\'"
72 %type <char> syntax semantic-grammar-lex-c-char-re
73 %token <char> CHARACTER
75 %type <qlist> matchdatatype sexp syntax "\\s'\\s-*("
76 %token <qlist> PREFIXED_LIST
78 %type <sexp> matchdatatype sexp syntax "\\="
81 ;; Don't generate these analyzers which needs special handling code.
82 %token <code> PROLOGUE "%{...%}"
83 %token <code> EPILOGUE "%%...EOF"
85 ;; Blocks & Parenthesis
87 %token <block> PAREN_BLOCK "(LPAREN RPAREN)"
88 %token <block> BRACE_BLOCK "(LBRACE RBRACE)"
89 %token <open-paren> LPAREN "("
90 %token <close-paren> RPAREN ")"
91 %token <open-paren> LBRACE "{"
92 %token <close-paren> RBRACE "}"
96 %token <punctuation> COLON ":"
97 %token <punctuation> SEMI ";"
98 %token <punctuation> OR "|"
99 %token <punctuation> LT "<"
100 %token <punctuation> GT ">"
112 ;;; Prologue/Epilogue
116 (CODE-TAG "prologue" nil)
121 (CODE-TAG "epilogue" nil)
133 | no_default_prec_decl
149 `(TAG "default-prec" 'assoc :value '("t"))
152 no_default_prec_decl:
154 `(TAG "default-prec" 'assoc :value '("nil"))
159 `(TAG ',(car $2) 'languagemode :rest ',(cdr $2))
164 `(PACKAGE-TAG ',$2 nil)
168 associativity token_type_opt items
169 `(TAG ',$1 'assoc :type ',$2 :value ',$3)
182 PUT put_name put_value
183 `(TAG ',$2 'put :value ',(list $3))
184 | PUT put_name put_value_list
185 `(TAG ',$2 'put :value ',$3)
186 | PUT put_name_list put_value
187 `(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',(list $3))
188 | PUT put_name_list put_value_list
189 `(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',$3)
194 (mapcar 'semantic-tag-name (EXPANDFULL $1 put_names))
203 ;; Must return a list of Semantic tags to EXPANDFULL!
214 (mapcar 'semantic-tag-code-detail (EXPANDFULL $1 put_values))
223 ;; Must return a list of Semantic tags to EXPANDFULL!
224 (CODE-TAG "put-value" $1)
234 `(TAG ',$2 'scopestart)
239 `(TAG ',$2 'quotemode)
244 `(TAG ',(car $2) 'start :rest ',(cdr $2))
248 KEYWORD SYMBOL string_value
249 `(TAG ',$2 'keyword :value ',$3)
253 TOKEN token_type_opt SYMBOL string_value
254 `(TAG ',$3 ',(if $2 'token 'keyword) :type ',$2 :value ',$4)
255 | TOKEN token_type_opt symbols
256 `(TAG ',(car $3) 'token :type ',$2 :rest ',(cdr $3))
270 TYPE token_type plist_opt
271 `(TAG ',$2 'type :value ',$3)
281 (append (list $2) $1)
288 (mapcar 'semantic-tag-name (EXPANDFULL $1 use_names))
297 ;; Must return a list of Semantic tags to EXPANDFULL!
302 USE-MACROS SYMBOL use_name_list
303 `(TAG "macro" 'macro :type ',$2 :value ',$3)
311 ;; Return a Lisp readable form
336 (setq semantic-grammar-wy--nterm $1
337 semantic-grammar-wy--rindx 0)
339 (TAG $1 'nonterminal :children $4)
344 (apply 'nconc (nreverse $1))
356 (let* ((nterm semantic-grammar-wy--nterm)
357 (rindx semantic-grammar-wy--rindx)
359 comps prec action elt)
360 (setq semantic-grammar-wy--rindx (1+ semantic-grammar-wy--rindx))
368 (error "Duplicate %%prec in `%s:%d' rule" nterm rindx))
369 (setq prec (aref elt 0)))
372 ;; don't forget that rhs items are in reverse order, so
373 ;; the end-of-rule semantic action is the first item.
374 (if (or action comps)
376 (setq comps (cons elt comps)
377 ;; keep rule and action index synchronized
378 semantic-grammar-wy--rindx
379 (1+ semantic-grammar-wy--rindx))
380 ;; the end-of-rule action
381 (setq action (car elt))))
384 (setq comps (cons elt comps)))))
386 (TAG (format "%s:%d" nterm rindx) 'rule
387 :type (if comps "group" "empty")
388 :value comps :prec prec :expr action)))
398 (cons (vector $3) $1)
405 (format "(progn\n%s)"
407 (if (string-match "^{[\r\n\t ]*" s)
408 (setq s (substring s (match-end 0))))
409 (if (string-match "[\r\n\t ]*}$" s)
410 (setq s (substring s 0 (match-beginning 0))))
433 ;;; grammar.wy ends here