1 This is grammar-fw.info, produced by makeinfo version 5.2 from
4 This manual documents Grammar Development with Semantic.
6 Copyright (C) 2004 Eric M. Ludlam Copyright (C) 2004 David Ponce
7 Copyright (C) 2004 Richard Y. Kim
9 Permission is granted to copy, distribute and/or modify this
10 document under the terms of the GNU Free Documentation License,
11 Version 1.1 or any later version published by the Free Software
12 Foundation; with the Invariant Sections being list their titles,
13 with the Front-Cover Texts being list, and with the Back-Cover
14 Texts being list. A copy of the license is included in the section
15 entitled "GNU Free Documentation License".
16 INFO-DIR-SECTION Emacs
18 * Semantic Grammar Framework: (grammar-fw).
21 This file documents Grammar Development with Semantic.
23 Copyright (C) 2004 Eric M. Ludlam, David Ponce, and Richard Y. Kim
26 File: grammar-fw.info, Node: Top, Next: Overview, Up: (dir)
28 Semantic Grammar Framework Manual
29 *********************************
31 The Semantic Grammar Framework provides a consistent way to write rule
32 based grammars for use in Emacs. This document describes how to use the
33 grammar writing environment, and how to write in the rule based
40 * Working with grammars::
41 * Adding a new grammar mode::
42 * GNU Free Documentation License::
46 File: grammar-fw.info, Node: Overview, Next: Grammar File, Prev: Top, Up: Top
51 semantic version 2 introduced a new grammar framework to provide a clean
52 and consistent view into parser writing.
54 All grammars are specified in a common rule based language derived from
55 the input grammar language used by the GNU parser generator Bison. The
56 main differences are that:
58 - The C-like syntax is replaced by Emacs Lisp syntax.
59 - Percent declarations are specific to semantic.
61 Nevertheless, for those who are a familiar with Bison grammar syntax,
62 and have some knowledge of Emacs Lisp, writing semantic grammars won't
63 hard. Moreover, the grammar framework provides Emacs goodies
64 (indentation, syntax coloring, etc.) to help edit grammars.
66 Grammars written in the common rule based language must be translated
67 into Emacs Lisp code so a semantic parser can use it. The framework
68 defines a reusable and flexible API that simplifies the implementation
69 of grammar-to-lisp translators.
71 The _abstract_ major mode 'semantic-grammar-mode' provides the core
72 functionalities to edit and translate input grammars.
74 _Concrete_ grammar modes, derived from 'semantic-grammar-mode',
75 implement the common API that translates the input grammar format into
76 Emacs Lisp code understandable by a particular parser. An unique file
77 extension associates input grammars to a _concrete_ grammar mode, that
78 is to a particular translator and parser.
80 semantic provides these _concrete_ grammar modes:
82 - 'bovine-grammar-mode', *Note BY grammars::.
83 - 'wisent-grammar-mode', *Note WY grammars::.
85 The following diagram presents a global view of the framework:
87 \0\b[image src="grammar-fw-ov.png" text="
89 `Bovine' parser ! `Wisent' parser ! Other parser
91 /! + - - - - - - - - -!- - - - - - - - - -!- - - - - - - - - +
92 || ! Common Semantic Grammar Mode !
93 || ! ,,,,,,,,,,,,,,,, ! ,,,,,,,,,,,,,,,, ! ,,,,,,,,,,,,,,,, !
94 Grammar ! ; `BY' Grammar ; ! ; `WY' Grammar ; ! ; `??' Grammar ; !
95 Framework! ; ; ! ; ; ! ; ; !
96 || ! ; Elisp Gen. ; ! ; Elisp Gen. ; ! ; Elisp Gen. ; !
97 || ! '''''''!'''''''' ! '''''''!'''''''' ! '''''''!'''''''' !
98 !/ + - - - -|- - - - -!- - - - | - - - - -!- - - - | - - - - +
100 /! ,-----V------, ! ,-----V------, ! ,-----V------,
101 || . Language . ! . Language . ! . Language .
102 || ` Support Lib. ' ! ` Support Lib. ' ! ` Support Lib. '
103 || `--!------!--' ! `--!------!--' ! `--!------!--'
105 || +---V---+ | ! +---V---+ | ! +---V---+ |
106 || | Lexer | | ! | Lexer | | ! | Lexer | |
107 Parser +-------+ | ! +-------+ | ! +-------+ |
109 || +- -- -- --! --+ ! +- -- -- --V --+ ! +- -- -- --V --+
110 || ! No Compiler ! ! !LALR Compiler ! ! !Optional Comp.!
111 || +- -- -- --! --+ ! +- -- -- --! --+ ! +- -- -- --! --+
113 || +----------V---+ ! +----------V---+ ! +----------V---+
114 || | LL Parser | ! | LR Parser | ! | Parser Engine|
115 !/ +--------------+ ! +--------------+ ! +--------------+
119 File: grammar-fw.info, Node: Grammar File, Next: Working with grammars, Prev: Overview, Up: Top
124 A semantic grammar file has four main sections, and looks like this:
138 Comments are like Emacs Lisp ones but start with two consecutive
139 semicolons (';;') instead of a single one. The single semicolon (';')
140 is the end of rule delimiter.
144 * Terminal and Nonterminal Symbols::
151 File: grammar-fw.info, Node: Terminal and Nonterminal Symbols, Next: Prologue, Up: Grammar File
153 2.1 Terminal and Nonterminal Symbols
154 ====================================
156 "Symbols" in semantic grammars represent the grammatical classifications
157 of the language. They are valid Emacs Lisp symbols without special
158 punctuations that require escaping.
160 A "terminal symbol" (also known as a "lexical token class") represents a
161 class of syntactically equivalent tokens. You use the symbol in grammar
162 rules to mean that a token in that class is allowed. Bison's convention
163 recommends it should be all upper case.
165 Terminal symbols are part of the lexical tokens returned by the function
166 'semantic-lex-analyzer'. They indicate what kind of token has been
167 read. For more on lexical analysis, *note (semantic-langdev)Writing
170 Terminal symbols are declared using '%keyword' (*note keyword Decl::) or
171 '%token' (*note token Decl::) statements.
174 Terminal symbols can be "literal characters" which have the same
175 syntax used in C for character constants; for example, ''+'' is a
176 "literal character token class". A character token class doesn't
177 need to be declared, and can be used in precedence declarations
178 like other terminal symbols (*note precedence Decl::).
179 For now semantic lexers don't handle literal characters terminals.
181 A "nonterminal symbol" stands for a class of syntactically equivalent
182 groupings. The symbol name is used in writing grammar rules. Bison's
183 convention recommends it should be all lower case.
185 The symbol 'error' is a terminal symbol reserved for error recovery; you
186 shouldn't use it for any other purpose.
189 File: grammar-fw.info, Node: Prologue, Next: Declarations, Prev: Terminal and Nonterminal Symbols, Up: Grammar File
194 The PROLOGUE section contains definitions of Emacs Lisp variables,
195 function and macros that are used in the actions in the grammar rules.
197 These are copied to the beginning of the generated parser file so that
198 they precede the definition of the grammar rules actions. You can use
199 'require' to get the declarations from other libraries. If you don't
200 need any Emacs Lisp declarations, you may omit this section.
202 You may have more than one PROLOGUE section, intermixed with other
203 DECLARATIONS. All PROLOGUE sections are copied to the generated parser
204 file in the order they appear in the grammar.
207 File: grammar-fw.info, Node: Declarations, Next: Grammar Rules, Prev: Prologue, Up: Grammar File
212 The DECLARATIONS section contains declarations that define terminal
213 symbols, specify precedence, and so on. In some simple grammars you may
214 not need any declarations.
216 Declarations of terminal symbols defines the symbols used in formulating
217 the grammar and the type associated to categories of tokens (*note
218 Terminal and Nonterminal Symbols::).
223 * languagemode Decl::
229 * default-prec Decl::
236 File: grammar-fw.info, Node: package Decl, Next: languagemode Decl, Up: Declarations
241 -- %-Decl: %package library-name
242 Declare the Emacs Lisp library created from the grammar.
244 This will generate an Emacs Lisp file named 'LIBRARY-NAME.el', and
245 provide the LIBRARY-NAME feature at the end of the generated file
248 (provide 'LIBRARY-NAME)
250 All variable and function names generated from the DECLARATIONS
251 section will be prefixed by 'LIBRARY-NAME-', following Emacs
252 standard coding conventions.
254 If there is no '%package' statement, a default LIBRARY-NAME is
257 GRAMMAR_FILENAME_SANS_EXTENTION-GRAMMAR_FILENAME_EXTENTION
259 For instance, the default library name for the grammar in the
260 'foo.wy' file is 'foo-wy'.
263 File: grammar-fw.info, Node: languagemode Decl, Next: keyword Decl, Prev: package Decl, Up: Declarations
265 2.3.2 languagemode Decl
266 -----------------------
268 -- %-Decl: %languagemode MODE1...
269 Declare in which major modes Emacs edits the sources that semantic
270 parses using this grammar.
272 For instance, the following declares that the grammar will be used
273 to parse files edited in 'c-mode' or 'c++-mode' by Emacs.
275 %languagemode c-mode c++-mode
277 Typically, when a parser file is re-generated from a modified
278 grammar, language modes are used to refresh local parser settings
279 in buffers currently edited in those major modes.
282 File: grammar-fw.info, Node: keyword Decl, Next: put Decl, Prev: languagemode Decl, Up: Declarations
287 -- %-Decl: %keyword KEYWORD-NAME KEYWORD-VALUE
288 Declare a language keyword (a reserved word).
291 Is the terminal symbol used in grammar rules to represent this
294 Is the actual value of the keyword as a string.
296 Here is how the 'if', 'else', 'endif' keywords might be declared:
300 %keyword ENDIF "endif"
302 Keywords have the implicit reserved type 'keyword' (*note type
305 In the generated library, keyword declarations are defined in the
306 constant 'LIBRARY-NAME--keyword-table'. The keyword table value is an
307 Emacs Lisp obarray, available at run time in the parsed buffer, in the
308 buffer local variable 'semantic-flex-keywords-obarray'.
310 However you shouldn't use that variable directly. semantic provides the
311 following API to use with language keywords at run time.
313 -- Function: semantic-lex-keyword-symbol name
314 Return keyword symbol with NAME or 'nil' if not found. Return
317 -- Function: semantic-lex-keyword-p name
318 Return non-'nil' if a keyword with NAME exists in the keyword
319 table. Return 'nil' otherwise.
321 *Compatibility*: 'semantic-lex-keyword-p' introduced in semantic
322 version 2.0 supercedes 'semantic-flex-keyword-p' which is now
325 -- Function: semantic-lex-keyword-set name value
326 Set value of keyword with NAME to VALUE and return VALUE.
328 -- Function: semantic-lex-keyword-value name
329 Return value of keyword with NAME. Signal an error if a keyword
330 with NAME does not exist.
332 -- Function: semantic-lex-map-keywords fun &optional property
333 Call function FUN on every semantic keyword. If optional PROPERTY
334 is non-'nil', call FUN only on every keyword which as a PROPERTY
335 value. FUN receives a semantic keyword as argument.
337 *Compatibility*: 'semantic-lex-map-keywords' introduced in semantic
338 version 2.0 supercedes 'semantic-flex-map-keywords' which is now
341 -- Function: semantic-lex-keywords &optional property
342 Return a list of semantic keywords. If optional PROPERTY is
343 non-'nil', return only keywords which have a PROPERTY set (*note
346 *Compatibility*: 'semantic-lex-keywords' introduced in semantic
347 version 2.0 supercedes 'semantic-flex-keywords' which is now
351 File: grammar-fw.info, Node: put Decl, Next: token Decl, Prev: keyword Decl, Up: Declarations
356 The '%put' statement assigns properties to keywords (*note keyword
357 Decl::). For instance, the predefined 'summary' property assigns a help
358 string to a keyword. The help string is used by
359 'semantic-idle-summary-mode' for on-the-fly help.
361 -- %-Decl: %put KEYWORD-NAME PROPERTY VALUE
362 -- %-Decl: %put KEYWORD-NAME {PROPERTY1 VALUE1 ...}
363 -- %-Decl: %put {KEYWORD-NAME1 ...} PROPERTY VALUE
364 -- %-Decl: %put {KEYWORD-NAME1 ...} {PROPERTY1 VALUE1 ...}
365 Give to KEYWORD-NAME, or to several KEYWORD-NAMEs, a single
366 PROPERTY with VALUE, or a set of PROPERTYs with respective VALUEs.
369 Is a terminal symbol defined as a keyword.
371 Is a property name, which is a valid Emacs Lisp symbol.
373 Is a property value, a valid Emacs Lisp constant expression.
375 Keyword properties are stored in the keyword table (*note keyword
376 Decl::). The following API can be used to handle properties at run
379 -- Function: semantic-lex-keyword-put name property value
380 For keyword with NAME, set its PROPERTY to VALUE.
382 *Compatibility*: 'semantic-lex-keyword-put' introduced in semantic
383 version 2.0 supercedes 'semantic-flex-keyword-put' which is now
386 -- Function: semantic-lex-keyword-get name property
387 For keyword with NAME, return its PROPERTY value.
389 *Compatibility*: 'semantic-lex-keyword-get' introduced in semantic
390 version 2.0 supercedes 'semantic-flex-keyword-get' which is now
394 File: grammar-fw.info, Node: token Decl, Next: type Decl, Prev: put Decl, Up: Declarations
399 The '%token' statement declares a terminal symbol (a "token") which is
402 -- %-Decl: %token [<TYPE-NAME>] TOKEN-NAME MATCH-VALUE
403 -- %-Decl: %token [<TYPE-NAME>] TOKEN-NAME1 ...
404 Respectively declare one token with an optional type, and a match
405 value, or several tokens with the optional same type, and no match
409 Is an optional symbol, enclosed between '<' and '>', that
410 specifies (and implicitly declares) a "type" for this token
411 (*note type Decl::). If omitted the token has no type.
413 Is the terminal symbol used in grammar rules to represent this
416 Is an optional string. Depending on TYPE-NAME properties, it
417 will be interpreted as an ordinary string, a regular
418 expression, or have a more elaborate meaning. If omitted the
419 match value will be 'nil', which means that this token will be
420 considered as the default token of its type (*note type Decl::
421 for more information).
424 For historical compatibility, the form '%token NAME VALUE' actually
425 declares a keyword, and is strictly equivalent to
426 '%keyword NAME VALUE'. Because the former is ambiguous and could
427 be abandoned in future releases of semantic, we highly recommend to
428 use the latter to declare keywords!
430 In the generated library, token definitions are stored in the table of
431 declared types (*note type Decl::).
434 File: grammar-fw.info, Node: type Decl, Next: precedence Decl, Prev: token Decl, Up: Declarations
439 -- %-Decl: %type <TYPE-NAME> [PROPERTY1 VALUE1 ...]
441 Explicitly declare a lexical type, and optionally give it
445 Is a symbol that identifies the type.
447 Is a property name, a valid Emacs Lisp symbol.
449 Is a property value, a valid Emacs Lisp constant expression.
451 Even if '%token', '%keyword', and precedence declarations can
452 implicitly declare types, an explicit declaration is required for
455 - To assign it properties.
456 - To auto-generate a lexical rule that detects tokens of this
457 type. For more information, *note Auto-generation of lexical
461 Because the grammar framework is implemented in Emacs Lisp, which
462 is a dynamically typed language, the meaning of "type" is notably
463 different between semantic and Bison. In Bison grammars, "type"
464 means "data type", and associates an internal representation to
465 lexical tokens. In semantic grammars, "type" specifies how lexical
466 analysis will scan tokens of this type.
468 In the generated library, lexical type declarations are defined in the
469 constant 'LIBRARY-NAME--token-table'. The table value is an Emacs Lisp
470 obarray, available at run time in the parsed buffer, in the buffer local
471 variable 'semantic-lex-types-obarray'.
473 However you shouldn't use that variable directly. semantic provides the
474 following API to use with lexical types at run time.
476 -- Function: semantic-lex-type-symbol type
477 Return symbol with TYPE or 'nil' if not found.
479 -- Function: semantic-lex-type-p type
480 Return non-'nil' if a symbol with TYPE name exists.
482 -- Function: semantic-lex-type-set type value
483 Set value of symbol with TYPE name to VALUE and return VALUE.
485 -- Function: semantic-lex-type-value type &optional noerror
486 Return value of symbol with TYPE name. If optional argument
487 NOERROR is non-'nil' return 'nil' if a symbol with TYPE name does
488 not exist. Otherwise signal an error.
490 -- Function: semantic-lex-type-put type property value &optional add
491 For symbol with TYPE name, set its PROPERTY to VALUE. If optional
492 argument ADD is non-'nil', create a new symbol with TYPE name if it
493 does not already exist. Otherwise signal an error.
495 -- Function: semantic-lex-type-get type property &optional noerror
496 For symbol with TYPE name, return its PROPERTY value. If optional
497 argument NOERROR is non-'nil' return 'nil' if a symbol with TYPE
498 name does not exist. Otherwise signal an error.
500 -- Function: semantic-lex-map-types fun &optional property
501 Call function FUN on every lexical type. If optional PROPERTY is
502 non-'nil', call FUN only on every type symbol which as a PROPERTY
503 value. FUN receives a type symbol as argument.
505 -- Function: semantic-lex-types &optional property
506 Return a list of lexical type symbols. If optional PROPERTY is
507 non-'nil', return only type symbols which have PROPERTY set.
510 File: grammar-fw.info, Node: precedence Decl, Next: default-prec Decl, Prev: type Decl, Up: Declarations
512 2.3.7 precedence Decl
513 ---------------------
515 -- %-Decl: %left [<TYPE-NAME>] TOKEN1 ...
516 -- %-Decl: %right [<TYPE-NAME>] TOKEN1 ...
517 -- %-Decl: %nonassoc [<TYPE-NAME>] TOKEN1 ...
518 See also '%prec' in *note Grammar Rules::.
520 Specify the precedence and associativity of grammar terminals.
522 For more details, *note (wisent)Grammar format::, PRECEDENCE.
525 This information has meaning only in LALR grammars. Defining
526 precedence in a grammar that provides tagging information for
527 semantic isn't usually necessary.
530 File: grammar-fw.info, Node: default-prec Decl, Next: quotemode Decl, Prev: precedence Decl, Up: Declarations
532 2.3.8 default-prec Decl
533 -----------------------
535 -- %-Decl: %default-prec
536 -- %-Decl: %no-default-prec
537 See also '%prec' in *note Grammar Rules::.
539 '%no-default-prec' declares that you must specify precedence for
540 all rules that participate in precedence conflict resolution. The
541 default '%default-prec' indicates to use the precedence of the last
542 terminal symbol mentioned in the rule.
544 For more details, *note (wisent)Grammar format::, PRECEDENCE.
547 This information has meaning only in LALR grammars. Defining
548 precedence in a grammar that provides tagging information for
549 semantic isn't usually necessary.
552 File: grammar-fw.info, Node: quotemode Decl, Next: scopestart Decl, Prev: default-prec Decl, Up: Declarations
557 -- %-Decl: %quotemode SYMBOL
558 This is a mechanism used to specify how quoting worked in optional
559 lambda expressions. *note (bovine)Optional Lambda Expression::.
562 This information has meaning only in "bovine" grammars.
565 File: grammar-fw.info, Node: scopestart Decl, Next: start Decl, Prev: quotemode Decl, Up: Declarations
567 2.3.10 scopestart Decl
568 ----------------------
570 -- %-Decl: %scopestart NONTERMINAL
571 The 'scopestart' declaration specifies the name of a nonterminal
572 that is used for parsing the body of functional code. This is used
573 in the local context parser to find locally defined variables.
576 This information has meaning only in "bovine" grammars.
579 File: grammar-fw.info, Node: start Decl, Next: use-macros Decl, Prev: scopestart Decl, Up: Declarations
584 -- %-Decl: %start NONTERMINAL1 ...
585 Declare the nonterminal symbols that the parser can use as its
589 The exact meaning of start symbols depends on the parser. For more
590 information, *note (wisent)Start nonterminals::, and *note
591 (bovine)Starting Rules::.
594 File: grammar-fw.info, Node: use-macros Decl, Prev: start Decl, Up: Declarations
596 2.3.12 use-macros Decl
597 ----------------------
599 -- %-Decl: %use-macros LIBRARY {MACRO-NAME1 ...}
600 Declare grammar macros local in this grammar.
603 Is a symbol identifying the Elisp library where to find the
606 Is a symbol identifying a macro. By convention it should be
609 For more information on macros, *note Grammar Macros::.
611 When the Lisp code generator encounters a '%use-macros' declaration, it
612 automatically loads ('require') the specified LIBRARY and associates to
613 each MACRO-NAME an expander function named LIBRARY-MACRO-NAME.
617 %use-macros my-grammar-macros {MY-MACRO}
619 Tells the Lisp code generator to first '(require 'my-grammar-macros)',
620 then to call the function 'my-grammar-macros-MY-MACRO' to expand calls
621 to the 'MY-MACRO' macro.
623 Typically, the 'my-grammar-macros.el' library should look like this:
627 (defun my-grammar-macros-MY-MACRO (&rest args)
628 "Grammar macro that passes ARGS to `format' and return a string."
633 ;; Don't forget to provide myself!
634 (provide 'my-grammar-macros)
637 File: grammar-fw.info, Node: Grammar Rules, Next: Epilogue, Prev: Declarations, Up: Grammar File
642 A grammar rule has the following general form:
644 RESULT: COMPONENTS ...
647 RESULT is the nonterminal symbol that this rule describes, and
648 COMPONENTS are the various terminal and nonterminal symbols that are put
649 together by this rule (*note Terminal and Nonterminal Symbols::).
651 For example, this rule:
656 Says that two groupings of type 'exp', with a 'PLUS' token in between,
657 can be combined into a larger grouping of type 'exp'.
659 Multiple rules for the same RESULT are joined with the vertical-bar
660 character '|' as follows:
662 RESULT: RULE1-COMPONENTS...
663 | RULE2-COMPONENTS...
667 If COMPONENTS in a rule is empty, it means that RESULT can match the
668 empty string. For example, here is how to define a comma-separated
669 sequence of zero or more 'exp' groupings:
679 It is customary to write a comment ';;Empty' in each rule with no
683 In LALR grammars, a '%prec' modifier can be written after the
684 COMPONENTS of a rule to specify a terminal symbol whose precedence
685 should be used for that rule. The syntax is:
689 It assigns the rule the precedence of TOKEN, overriding the
690 precedence that would be deduced for it in the ordinary way. For
691 more details, *note (wisent)Grammar format::, PRECEDENCE.
693 Here is a typical example:
696 %left NEG ;; negation--unary minus
708 Scattered among the components can be ACTIONS that determine the
709 semantics of the rule. An action is an Emacs Lisp list form, for
714 To execute a sequence of forms, you can enclose them between braces like
722 Usually there is only one action and it follows the rule components.
724 The code in an action can refer to the semantic values of the components
725 matched by the rule with the construct '$N', which stands for the value
726 of the Nth component.
728 Here is a typical example:
736 This rule constructs an 'exp' from two smaller 'exp' groupings connected
737 by a plus-sign token. In the action, '$1' and '$3' refer to the
738 semantic values of the two component 'exp' groupings, which are the
739 first and third symbols on the right hand side of the rule. The sum
740 becomes the semantic value of the addition-expression just recognized by
741 the rule. If there were a useful semantic value associated with the
742 'PLUS' token, it could be referred to as '$2'.
744 Note that the vertical-bar character '|' is really a rule separator, and
745 actions are attached to a single rule.
747 By convention, if you don't specify an action for a rule, the value of
748 the first symbol in the rule becomes the value of the whole rule:
749 '(progn $1)'. The default value of an empty rule is 'nil'.
751 The exact default behavior depends on the parser. For more information,
752 *note (wisent)Wisent::, and *note (bovine)Bovine::, manuals.
755 In LALR grammars, you can have "mid-rule actions", that is semantic
756 actions put in the middle of a rule. These actions are written
757 just like usual end-of-rule actions, but they are executed before
758 the parser even recognizes the following components.
760 The mid-rule action itself counts as one of the components of the
761 rule. This makes a difference when there is another action later
762 in the same rule (and usually there is another at the end): you
763 have to count the actions along with the symbols when working out
764 which number N to use in '$N'.
766 The mid-rule action can also have a semantic value, and actions
767 later in the rule can refer to the value using '$N'.
769 There is no way to set the value of the entire rule with a mid-rule
770 action. The only way to set the value for the entire rule is with
771 an ordinary action at the end of the rule.
773 Here is an example taken from the 'semantic-grammar.wy' grammar in
779 (setq semantic-grammar-wy--nterm $1
780 semantic-grammar-wy--rindx 0)
782 ;; End-of-rule action
783 (TAG $1 'nonterminal :children $4)
787 File: grammar-fw.info, Node: Epilogue, Prev: Grammar Rules, Up: Grammar File
792 The EPILOGUE section contains arbitrary Emacs Lisp code which is copied
793 verbatim to the end of the parser file, just as the PROLOGUE is copied
794 to the beginning. This is the most convenient place to put anything
795 that you want to have in the parser file.
797 For example, it could be convenient to put the definition of the lexer
798 in the EPILOGUE, particularly if it includes lexical rules
799 auto-generated from declarations in the grammar.
801 If the EPILOGUE section is empty, you may omit the '%%' that separates
802 it from the grammar rules.
805 You can put a "footer" comment:
807 ;;; my-grammar.by ends here
809 At the end of the grammar. It will not be copied to the parser
810 file to avoid confusion with the Emacs Lisp library own footer.
813 File: grammar-fw.info, Node: Working with grammars, Next: Adding a new grammar mode, Prev: Grammar File, Up: Top
815 3 Working with grammars
816 ***********************
821 * Auto-generation of lexical rules::
827 File: grammar-fw.info, Node: Editing grammars, Next: Auto-generation of lexical rules, Up: Working with grammars
832 -- Command: semantic-grammar-create-package &optional force
833 Create package Lisp code from grammar in current buffer. Does
834 nothing if the Lisp code seems up to date. If optional argument
835 FORCE is non-'nil', unconditionally re-generate the Lisp code.
837 You can run the command 'semantic-grammar-create-package' with 'C-c C-c'
838 (or 'C-u C-c C-c' to unconditionally re-generate the Lisp code).
840 Additionally, when this command is run interactively, all open buffers
841 of that mode have their setup functions re-run. That way after
842 compiling your grammar, all relevant buffers will be actively using that
843 grammar so you can test what you have done.
845 -- Command: semantic-grammar-indent
846 Indent the current line. Use the Lisp or grammar indenter
847 depending on point location.
849 You can run the command 'semantic-grammar-indent' with '<TAB>'.
851 -- Command: semantic-grammar-complete
852 Attempt to complete the symbol under point. Completion is position
853 sensitive. If the cursor is in a match section of a rule, then
854 nonterminals symbols are scanned. If the cursor is in a Lisp
855 expression then Lisp symbols are completed.
857 You can run the command 'semantic-grammar-complete' with '<META> <TAB>'.
859 -- Command: semantic-grammar-find-macro-expander macro-name library
860 Visit the Emacs Lisp library where a grammar macro is implemented.
861 MACRO-NAME is a symbol that identifies a grammar macro. LIBRARY is
862 the name (sans extension) of the Emacs Lisp library where to start
863 searching the macro implementation. Lookup in included libraries,
864 if necessary. Find a function tag (in current tags table) whose
865 name contains MACRO-NAME. Select the buffer containing the tag's
866 definition, and move point there.
869 Enabling the 'global-semanticdb-minor-mode' is highly
870 recommended because this command uses the 'semanticdb-find'
871 feature to automatically search for a macro expander function
872 into included libraries. For more details, *note
873 (semantic-appdev)Semantic Database::.
875 You can run the command 'semantic-grammar-find-macro-expander' with
878 The characters '| ; % ( ) :' are "electric punctuations". Each time you
879 type one, the line is re-indented after the character is inserted.
881 -- Command: semantic-grammar-insert-keyword name
882 Insert a new '%keyword' declaration with NAME. Assumes it is typed
883 in with the correct casing.
885 You can run the command 'semantic-grammar-insert-keyword' with
889 File: grammar-fw.info, Node: Auto-generation of lexical rules, Next: Grammar Macros, Prev: Editing grammars, Up: Working with grammars
891 3.2 Auto-generation of lexical rules
892 ====================================
894 Using a '%type' statement, combined with '%keyword' and '%token' ones,
895 permits the declaration of a lexical type and associates it with
896 patterns that define how to match lexical tokens of that type.
898 The grammar construction process exploits that information to
899 _automagically_ generate the definition of a lexical rule (aka a "single
900 analyzer") for each explicitly declared lexical type.
902 It is then easy to put predefined and auto-generated lexical rules
903 together to build ad-hoc lexical analyzers.
905 This chapter details the auto-generation process, and how you can
906 control it to produce the lexical rules needed to scan your language.
911 * Type properties with a special meaning::
912 * Predefined well-known types::
915 File: grammar-fw.info, Node: The principle, Next: Type properties with a special meaning, Up: Auto-generation of lexical rules
921 File: grammar-fw.info, Node: Type properties with a special meaning, Next: Predefined well-known types, Prev: The principle, Up: Auto-generation of lexical rules
923 3.2.2 Type properties with a special meaning
924 --------------------------------------------
927 The value of the 'syntax' property should be a "syntactic regexp",
928 that is a regexp that matches buffer data based on the current
929 Emacs "syntax table".
931 For instance, to grab constituents of 'symbol' or 'keyword' types,
932 the 'syntax' property value will probably be:
934 '"\\(\\sw\\|\\s_\\)+"'
936 For well known types, the 'syntax' property has a predefined value
937 that should suit standard needs (*note Predefined well-known
941 The value of the 'matchdatatype' property is a symbol that
942 specifies which algorithm to use to match the tokens of this type.
943 These match algorithms are defined:
952 File: grammar-fw.info, Node: Predefined well-known types, Prev: Type properties with a special meaning, Up: Auto-generation of lexical rules
954 3.2.3 Predefined well-known types
955 ---------------------------------
957 Default values are provided for well known types like <keyword>,
958 <symbol>, <string>, <number>, <punctuation>, and <block>. Those types
959 assume that the correct patterns are provided by %keyword and %token
960 statements, a simple "%type <type>" declaration should generally suffice
961 to auto-generate a suitable lexical rule.
971 File: grammar-fw.info, Node: Grammar Macros, Next: BY grammars, Prev: Auto-generation of lexical rules, Up: Working with grammars
976 To keep grammars relatively independent of contextual implementations
977 you can use "grammar macros" in semantic actions, in place of direct
978 calls to Emacs Lisp functions.
980 The predefined 'TAG' macro is a good example:
982 (TAG $1 'nonterminal :children $4)
984 It offers a common syntax to produce a semantic tag, even if the
985 underlying implementation is different between LALR and LL grammars.
987 A grammar macro is defined by a general "macro name" (for example,
988 'TAG') associated to possibly several "macro expanders".
990 A macro expander is an Emacs Lisp function that operates on the
991 unevaluated expressions for the arguments, and returns a Lisp expression
992 containing these argument expressions or parts of them.
994 Macro names are used like Lisp function names in call expressions. To
995 help distinguish grammar macro calls from traditional Lisp function
996 calls, macro names are automatically highlighted in semantic actions.
998 For more goodies that might help in the development of macros, *Note
1001 Commonly used macros are provided by the current grammar mode. *Note
1002 Adding a new grammar mode::.
1004 There are also local macros that only affect the grammar where they are
1005 declared. *Note use-macros Decl::.
1008 File: grammar-fw.info, Node: BY grammars, Next: WY grammars, Prev: Grammar Macros, Up: Working with grammars
1013 BY grammars are in files with the '.by' extension associated to the
1014 'bovine-grammar-mode' major mode.
1016 In that mode, grammars are converted into an Emacs Lisp form
1017 understandable by the original semantic LL parser.
1019 For more details on how the LL parser works, *note the Bovine Parser
1020 Manual: (bovine)top.
1023 File: grammar-fw.info, Node: WY grammars, Prev: BY grammars, Up: Working with grammars
1028 WY grammars are in files with the '.wy' extension associated to the
1029 'wisent-grammar-mode' major mode.
1031 In that mode, grammars are converted into an Emacs Lisp form
1032 understandable by the semantic Bison-like LALR parser.
1034 For more details on how the LALR parser works, *note the Wisent Parser
1035 Manual: (wisent)top.
1038 File: grammar-fw.info, Node: Adding a new grammar mode, Next: GNU Free Documentation License, Prev: Working with grammars, Up: Top
1040 4 Adding a new grammar mode
1041 ***************************
1045 * Specialized Implementation::
1046 * Querying grammars::
1049 File: grammar-fw.info, Node: Specialized Implementation, Next: Querying grammars, Up: Adding a new grammar mode
1051 4.1 Specialized Implementation
1052 ==============================
1054 Each specialized grammar mode is responsible for implementing the
1055 following API. Implementations are done with _overload methods_. *note
1056 (semantic-langdev)Semantic Overload Mechanism::.
1058 * A keyword table builder. Can use the default implementation
1061 -- Function: semantic-grammar-keywordtable-builder
1062 Return the keyword table table value. This function can be
1063 overriden in semantic using the symbol
1064 'grammar-keywordtable-builder'.
1066 * A token table builder. Can use the default implementation
1069 -- Function: semantic-grammar-tokentable-builder
1070 Return the value of the table of lexical tokens. This
1071 function can be overriden in semantic using the symbol
1072 'grammar-tokentable-builder'.
1074 * A parser table builder Must be provided, there is no default
1077 -- Function: semantic-grammar-parsetable-builder
1078 Return the parser table value. This function can be overriden
1079 in semantic using the symbol 'grammar-parsetable-builder'.
1081 * A Parser setup code builder. Must be provided, there is no default
1084 -- Function: semantic-grammar-setupcode-builder
1085 Return the parser setup code form. This function can be
1086 overriden in semantic using the symbol
1087 'grammar-setupcode-builder'.
1089 * Common grammar macros. A set of predefined macros is provided.
1091 For more information on macros, *note Grammar Macros::.
1093 -- Variable: semantic-grammar-macros
1094 List of associations (MACRO-NAME . EXPANDER).
1097 File: grammar-fw.info, Node: Querying grammars, Prev: Specialized Implementation, Up: Adding a new grammar mode
1099 4.2 Querying grammars
1100 =====================
1102 In order to generate the intermediate Emacs Lisp code needed by your
1103 parser, you have to query the grammar for the code, declarations, and
1106 To obtain those information in a "context free" manner, grammar files
1107 are parsed by the semantic LALR parser to produce tags.
1109 To query a grammar you can use the powerful API provided by semantic.
1110 *note Application Development Manual: (semantic-appdev)top.
1112 For declarations, the grammar framework provides a specialized high
1118 * Querying Declarations::
1121 File: grammar-fw.info, Node: Grammar Tags, Next: Querying Declarations, Up: Querying grammars
1126 This section describes the available grammar tags. *note
1127 (semantic-appdev)Semantic Tags::.
1129 Each tag description has the form CLASS NAME OPTIONAL-ATTRIBUTES.
1131 -- tag: code "prologue"
1132 Tag produced from a PROLOGUE section (*note Prologue::). The
1133 prologue code is the text in between tag's bounds.
1135 -- tag: code "epilogue"
1136 Tag produced from the EPILOGUE section (*note Epilogue::). The
1137 epilogue code is the text in between tag's bounds.
1139 -- tag: start NONTERMINAL1 REST-NONTERMINALS
1140 Tag produced from a '%start' declaration (*note start Decl::).
1143 First nonterminal symbol name.
1145 List of nonterminal symbol names which follow the first one.
1146 Associated to the attribute ':rest'.
1148 -- tag: languagemode MODE1 REST-MODES
1149 Tag produced from a '%languagemode' declaration (*note languagemode
1153 First mode symbol name.
1155 List of mode symbol names which follow the first one.
1156 Associated to the attribute ':rest'.
1158 -- tag: scopestart NONTERMINAL
1159 Tag produced from a '%scopestart' declaration (*note scopestart
1163 Nonterminal symbol name.
1165 -- tag: quotemode SYMBOL
1166 Tag produced from a '%quotemode' declaration (*note quotemode
1170 Symbol name, value of quote mode.
1172 -- tag: assoc ASSOCIATIVITY TYPE-NAME TOKENS
1173 Tag produced from a '%left', '%right', or '%nonassoc' declaration
1174 (*note precedence Decl::).
1177 "left", "right", or "nonassoc".
1179 Symbol name of the token type. Associated to the attribute
1182 List of terminal symbol names. Associated to the attribute
1185 -- tag: assoc "default-prec" FLAG
1186 Tag produced from a '%default-prec', or '%no-default-prec'
1187 declaration (*note default-prec Decl::).
1190 '(list "t")' or '(list "nil")' for respectively
1191 '%default-prec' and '%no-default-prec'. Associated to the
1194 -- tag: keyword KEYWORD-NAME KEYWORD-VALUE
1195 Tag produced from a '%keyword' declaration (*note keyword Decl::).
1198 Name of the keyword symbol.
1200 Value of the keyword as a string. Associated to the attribute
1203 -- tag: token TOKEN-NAME1 TYPE-NAME MATCH-VALUE
1204 -- tag: token TOKEN-NAME1 TYPE-NAME REST-TOKENS
1205 Tag produced from a '%token' declaration (*note token Decl::).
1208 First or unique token symbol name.
1210 Symbol name of the token type. Associated to the attribute
1213 Value of the token as a string. Associated to the attribute
1216 List of token symbol names which follow the first one in the
1217 declaration. Associated to the attribute ':rest'.
1219 -- tag: type TYPE-NAME PROPERTIES
1220 Tag produced from a '%type' declaration (*note type Decl::).
1223 Symbol name of the type.
1225 List of properties. Each property is a pair '(SYMBOL . VALUE)'
1226 where SYMBOL is the property symbol name, and VALUE the
1227 property value as string which contains a readable Lisp
1228 expression. Associated to the attribute ':value'.
1230 -- tag: put KEYWORD-NAME1 REST-KEYWORDS PROPERTIES
1231 Tag produced from a '%put' declaration (*note put Decl::).
1234 First or unique keyword [or type] symbol name.
1236 List of keyword [or type] symbol names which follow the first
1237 one in the declaration. Associated to the attribute ':rest'.
1239 List of properties. Each property is a pair '(SYMBOL . VALUE)'
1240 where SYMBOL is the property symbol name, and VALUE the
1241 property value as string which contains a readable Lisp
1242 expression. Associated to the attribute ':value'.
1244 -- tag: macro "macro" LIBRARY MACRO-NAMES
1245 Tag produced from a '%use-macros' declaration (*note use-macros
1249 Library name. Associated to the attribute ':type'.
1251 List of macro names. Associated to the attribute ':value'.
1253 -- tag: nonterminal NONTERMINAL RULE-TAGS
1254 Tag produced from a nonterminal description (*note Grammar
1258 Nonterminal symbol name.
1260 List rule tags. Associated to the attribute ':children'.
1262 -- tag: rule RULE-NAME :value COMPONENTS :prec TERMINAL :expr ACTION
1263 Tag produced from an individual grammar rule (*note Grammar
1267 Generated rule name.
1269 List of rule's components. A component is a
1270 nonterminal/terminal symbol name, a string that represent a
1271 C-like character, or a list of one string element which
1272 contains the readable Lisp form of a mid-rule semantic action.
1273 Associated to the attribute ':value'.
1275 Terminal symbol name or a string that represent a C-like
1276 character. Associated to the attribute ':prec'.
1278 String which contains the readable Lisp form of the main
1279 semantic action. Associated to the attribute ':expr'.
1282 File: grammar-fw.info, Node: Querying Declarations, Prev: Grammar Tags, Up: Querying grammars
1284 4.2.2 Querying Declarations
1285 ---------------------------
1287 This section describes the high level API to query grammar declarations.
1289 -- Function: semantic-grammar-prologue
1290 Return grammar prologue code as a string value.
1293 -- Function: semantic-grammar-epilogue
1294 Return grammar epilogue code as a string value.
1297 -- Function: semantic-grammar-package
1298 Return the '%package' value as a string. If there is no '%package'
1299 statement in the grammar, return a default package name derived
1300 from the grammar file name.
1301 *Note package Decl::.
1303 -- Function: semantic-grammar-languagemode
1304 Return the '%languagemode' value as a list of symbols or 'nil'.
1305 *Note languagemode Decl::.
1307 -- Function: semantic-grammar-start
1308 Return the '%start' value as a list of symbols or 'nil'.
1311 -- Function: semantic-grammar-scopestart
1312 Return the '%scopestart' value as a symbol or 'nil'.
1313 *Note scopestart Decl::.
1315 -- Function: semantic-grammar-quotemode
1316 Return the '%quotemode' value as a symbol or 'nil'.
1317 *Note quotemode Decl::.
1319 -- Function: semantic-grammar-keywords
1320 Return the language keywords. That is an alist of (VALUE . TOKEN)
1321 where VALUE is the string value of the keyword and TOKEN is the
1322 terminal symbol identifying the keyword.
1323 *Note keyword Decl::.
1325 -- Function: semantic-grammar-keyword-properties keywords
1326 Return the list of KEYWORDS properties.
1327 *Note keyword Decl::, *Note put Decl::.
1329 -- Function: semantic-grammar-tokens
1330 Return defined lexical tokens. That is an alist (TYPE . DEFS)
1331 where type is a '%token <type>' symbol and DEFS is an alist of
1332 (TOKEN . VALUE). TOKEN is the terminal symbol identifying the
1333 token and VALUE is the string value of the token or 'nil'.
1336 -- Function: semantic-grammar-token-properties tokens
1337 Return properties of declared types. Types are explicitly declared
1338 by '%type' statements. Types found in TOKENS are those declared
1339 implicitly by '%token' statements. Properties can be set by '%put'
1340 and '%type' statements. Properties set by '%type' statements take
1341 precedence over those set by '%put' statements.
1342 *Note token Decl::, *Note type Decl::, *Note put Decl::.
1344 -- Function: semantic-grammar-use-macros
1345 Return macro definitions from '%use-macros' statements. Also load
1346 the specified macro libraries.
1347 *Note use-macros Decl::.
1350 File: grammar-fw.info, Node: GNU Free Documentation License, Next: Index, Prev: Adding a new grammar mode, Up: Top
1352 Appendix A GNU Free Documentation License
1353 *****************************************
1355 Version 1.1, March 2000
1357 Copyright (C) 2000 Free Software Foundation, Inc.
1358 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1360 Everyone is permitted to copy and distribute verbatim copies
1361 of this license document, but changing it is not allowed.
1365 The purpose of this License is to make a manual, textbook, or other
1366 written document "free" in the sense of freedom: to assure everyone
1367 the effective freedom to copy and redistribute it, with or without
1368 modifying it, either commercially or noncommercially. Secondarily,
1369 this License preserves for the author and publisher a way to get
1370 credit for their work, while not being considered responsible for
1371 modifications made by others.
1373 This License is a kind of "copyleft", which means that derivative
1374 works of the document must themselves be free in the same sense.
1375 It complements the GNU General Public License, which is a copyleft
1376 license designed for free software.
1378 We have designed this License in order to use it for manuals for
1379 free software, because free software needs free documentation: a
1380 free program should come with manuals providing the same freedoms
1381 that the software does. But this License is not limited to
1382 software manuals; it can be used for any textual work, regardless
1383 of subject matter or whether it is published as a printed book. We
1384 recommend this License principally for works whose purpose is
1385 instruction or reference.
1388 1. APPLICABILITY AND DEFINITIONS
1390 This License applies to any manual or other work that contains a
1391 notice placed by the copyright holder saying it can be distributed
1392 under the terms of this License. The "Document", below, refers to
1393 any such manual or work. Any member of the public is a licensee,
1394 and is addressed as "you".
1396 A "Modified Version" of the Document means any work containing the
1397 Document or a portion of it, either copied verbatim, or with
1398 modifications and/or translated into another language.
1400 A "Secondary Section" is a named appendix or a front-matter section
1401 of the Document that deals exclusively with the relationship of the
1402 publishers or authors of the Document to the Document's overall
1403 subject (or to related matters) and contains nothing that could
1404 fall directly within that overall subject. (For example, if the
1405 Document is in part a textbook of mathematics, a Secondary Section
1406 may not explain any mathematics.) The relationship could be a
1407 matter of historical connection with the subject or with related
1408 matters, or of legal, commercial, philosophical, ethical or
1409 political position regarding them.
1411 The "Invariant Sections" are certain Secondary Sections whose
1412 titles are designated, as being those of Invariant Sections, in the
1413 notice that says that the Document is released under this License.
1415 The "Cover Texts" are certain short passages of text that are
1416 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
1417 that says that the Document is released under this License.
1419 A "Transparent" copy of the Document means a machine-readable copy,
1420 represented in a format whose specification is available to the
1421 general public, whose contents can be viewed and edited directly
1422 and straightforwardly with generic text editors or (for images
1423 composed of pixels) generic paint programs or (for drawings) some
1424 widely available drawing editor, and that is suitable for input to
1425 text formatters or for automatic translation to a variety of
1426 formats suitable for input to text formatters. A copy made in an
1427 otherwise Transparent file format whose markup has been designed to
1428 thwart or discourage subsequent modification by readers is not
1429 Transparent. A copy that is not "Transparent" is called "Opaque".
1431 Examples of suitable formats for Transparent copies include plain
1432 ASCII without markup, Texinfo input format, LaTeX input format,
1433 SGML or XML using a publicly available DTD, and standard-conforming
1434 simple HTML designed for human modification. Opaque formats
1435 include PostScript, PDF, proprietary formats that can be read and
1436 edited only by proprietary word processors, SGML or XML for which
1437 the DTD and/or processing tools are not generally available, and
1438 the machine-generated HTML produced by some word processors for
1439 output purposes only.
1441 The "Title Page" means, for a printed book, the title page itself,
1442 plus such following pages as are needed to hold, legibly, the
1443 material this License requires to appear in the title page. For
1444 works in formats which do not have any title page as such, "Title
1445 Page" means the text near the most prominent appearance of the
1446 work's title, preceding the beginning of the body of the text.
1450 You may copy and distribute the Document in any medium, either
1451 commercially or noncommercially, provided that this License, the
1452 copyright notices, and the license notice saying this License
1453 applies to the Document are reproduced in all copies, and that you
1454 add no other conditions whatsoever to those of this License. You
1455 may not use technical measures to obstruct or control the reading
1456 or further copying of the copies you make or distribute. However,
1457 you may accept compensation in exchange for copies. If you
1458 distribute a large enough number of copies you must also follow the
1459 conditions in section 3.
1461 You may also lend copies, under the same conditions stated above,
1462 and you may publicly display copies.
1464 3. COPYING IN QUANTITY
1466 If you publish printed copies of the Document numbering more than
1467 100, and the Document's license notice requires Cover Texts, you
1468 must enclose the copies in covers that carry, clearly and legibly,
1469 all these Cover Texts: Front-Cover Texts on the front cover, and
1470 Back-Cover Texts on the back cover. Both covers must also clearly
1471 and legibly identify you as the publisher of these copies. The
1472 front cover must present the full title with all words of the title
1473 equally prominent and visible. You may add other material on the
1474 covers in addition. Copying with changes limited to the covers, as
1475 long as they preserve the title of the Document and satisfy these
1476 conditions, can be treated as verbatim copying in other respects.
1478 If the required texts for either cover are too voluminous to fit
1479 legibly, you should put the first ones listed (as many as fit
1480 reasonably) on the actual cover, and continue the rest onto
1483 If you publish or distribute Opaque copies of the Document
1484 numbering more than 100, you must either include a machine-readable
1485 Transparent copy along with each Opaque copy, or state in or with
1486 each Opaque copy a publicly-accessible computer-network location
1487 containing a complete Transparent copy of the Document, free of
1488 added material, which the general network-using public has access
1489 to download anonymously at no charge using public-standard network
1490 protocols. If you use the latter option, you must take reasonably
1491 prudent steps, when you begin distribution of Opaque copies in
1492 quantity, to ensure that this Transparent copy will remain thus
1493 accessible at the stated location until at least one year after the
1494 last time you distribute an Opaque copy (directly or through your
1495 agents or retailers) of that edition to the public.
1497 It is requested, but not required, that you contact the authors of
1498 the Document well before redistributing any large number of copies,
1499 to give them a chance to provide you with an updated version of the
1504 You may copy and distribute a Modified Version of the Document
1505 under the conditions of sections 2 and 3 above, provided that you
1506 release the Modified Version under precisely this License, with the
1507 Modified Version filling the role of the Document, thus licensing
1508 distribution and modification of the Modified Version to whoever
1509 possesses a copy of it. In addition, you must do these things in
1510 the Modified Version:
1512 A. Use in the Title Page (and on the covers, if any) a title
1513 distinct from that of the Document, and from those of previous
1514 versions (which should, if there were any, be listed in the History
1515 section of the Document). You may use the same title as a previous
1516 version if the original publisher of that version gives permission.
1517 B. List on the Title Page, as authors, one or more persons or
1518 entities responsible for authorship of the modifications in the
1519 Modified Version, together with at least five of the principal
1520 authors of the Document (all of its principal authors, if it has
1522 C. State on the Title page the name of the publisher of the
1523 Modified Version, as the publisher.
1524 D. Preserve all the copyright notices of the Document.
1525 E. Add an appropriate copyright notice for your modifications
1526 adjacent to the other copyright notices.
1527 F. Include, immediately after the copyright notices, a license
1528 notice giving the public permission to use the Modified Version
1529 under the terms of this License, in the form shown in the Addendum
1531 G. Preserve in that license notice the full lists of Invariant
1532 Sections and required Cover Texts given in the Document's license
1534 H. Include an unaltered copy of this License.
1535 I. Preserve the section entitled "History", and its title, and add
1536 to it an item stating at least the title, year, new authors, and
1537 publisher of the Modified Version as given on the Title Page. If
1538 there is no section entitled "History" in the Document, create one
1539 stating the title, year, authors, and publisher of the Document as
1540 given on its Title Page, then add an item describing the Modified
1541 Version as stated in the previous sentence.
1542 J. Preserve the network location, if any, given in the Document for
1543 public access to a Transparent copy of the Document, and likewise
1544 the network locations given in the Document for previous versions
1545 it was based on. These may be placed in the "History" section.
1546 You may omit a network location for a work that was published at
1547 least four years before the Document itself, or if the original
1548 publisher of the version it refers to gives permission.
1549 K. In any section entitled "Acknowledgements" or "Dedications",
1550 preserve the section's title, and preserve in the section all the
1551 substance and tone of each of the contributor acknowledgements
1552 and/or dedications given therein.
1553 L. Preserve all the Invariant Sections of the Document, unaltered
1554 in their text and in their titles. Section numbers or the
1555 equivalent are not considered part of the section titles.
1556 M. Delete any section entitled "Endorsements". Such a section may
1557 not be included in the Modified Version.
1558 N. Do not retitle any existing section as "Endorsements" or to
1559 conflict in title with any Invariant Section.
1561 If the Modified Version includes new front-matter sections or
1562 appendices that qualify as Secondary Sections and contain no
1563 material copied from the Document, you may at your option designate
1564 some or all of these sections as invariant. To do this, add their
1565 titles to the list of Invariant Sections in the Modified Version's
1566 license notice. These titles must be distinct from any other
1569 You may add a section entitled "Endorsements", provided it contains
1570 nothing but endorsements of your Modified Version by various
1571 parties-for example, statements of peer review or that the text has
1572 been approved by an organization as the authoritative definition of
1575 You may add a passage of up to five words as a Front-Cover Text,
1576 and a passage of up to 25 words as a Back-Cover Text, to the end of
1577 the list of Cover Texts in the Modified Version. Only one passage
1578 of Front-Cover Text and one of Back-Cover Text may be added by (or
1579 through arrangements made by) any one entity. If the Document
1580 already includes a cover text for the same cover, previously added
1581 by you or by arrangement made by the same entity you are acting on
1582 behalf of, you may not add another; but you may replace the old
1583 one, on explicit permission from the previous publisher that added
1586 The author(s) and publisher(s) of the Document do not by this
1587 License give permission to use their names for publicity for or to
1588 assert or imply endorsement of any Modified Version.
1590 5. COMBINING DOCUMENTS
1592 You may combine the Document with other documents released under
1593 this License, under the terms defined in section 4 above for
1594 modified versions, provided that you include in the combination all
1595 of the Invariant Sections of all of the original documents,
1596 unmodified, and list them all as Invariant Sections of your
1597 combined work in its license notice.
1599 The combined work need only contain one copy of this License, and
1600 multiple identical Invariant Sections may be replaced with a single
1601 copy. If there are multiple Invariant Sections with the same name
1602 but different contents, make the title of each such section unique
1603 by adding at the end of it, in parentheses, the name of the
1604 original author or publisher of that section if known, or else a
1605 unique number. Make the same adjustment to the section titles in
1606 the list of Invariant Sections in the license notice of the
1609 In the combination, you must combine any sections entitled
1610 "History" in the various original documents, forming one section
1611 entitled "History"; likewise combine any sections entitled
1612 "Acknowledgements", and any sections entitled "Dedications". You
1613 must delete all sections entitled "Endorsements."
1615 6. COLLECTIONS OF DOCUMENTS
1617 You may make a collection consisting of the Document and other
1618 documents released under this License, and replace the individual
1619 copies of this License in the various documents with a single copy
1620 that is included in the collection, provided that you follow the
1621 rules of this License for verbatim copying of each of the documents
1622 in all other respects.
1624 You may extract a single document from such a collection, and
1625 distribute it individually under this License, provided you insert
1626 a copy of this License into the extracted document, and follow this
1627 License in all other respects regarding verbatim copying of that
1630 7. AGGREGATION WITH INDEPENDENT WORKS
1632 A compilation of the Document or its derivatives with other
1633 separate and independent documents or works, in or on a volume of a
1634 storage or distribution medium, does not as a whole count as a
1635 Modified Version of the Document, provided no compilation copyright
1636 is claimed for the compilation. Such a compilation is called an
1637 "aggregate", and this License does not apply to the other
1638 self-contained works thus compiled with the Document, on account of
1639 their being thus compiled, if they are not themselves derivative
1640 works of the Document.
1642 If the Cover Text requirement of section 3 is applicable to these
1643 copies of the Document, then if the Document is less than one
1644 quarter of the entire aggregate, the Document's Cover Texts may be
1645 placed on covers that surround only the Document within the
1646 aggregate. Otherwise they must appear on covers around the whole
1651 Translation is considered a kind of modification, so you may
1652 distribute translations of the Document under the terms of section
1653 4. Replacing Invariant Sections with translations requires special
1654 permission from their copyright holders, but you may include
1655 translations of some or all Invariant Sections in addition to the
1656 original versions of these Invariant Sections. You may include a
1657 translation of this License provided that you also include the
1658 original English version of this License. In case of a
1659 disagreement between the translation and the original English
1660 version of this License, the original English version will prevail.
1664 You may not copy, modify, sublicense, or distribute the Document
1665 except as expressly provided for under this License. Any other
1666 attempt to copy, modify, sublicense or distribute the Document is
1667 void, and will automatically terminate your rights under this
1668 License. However, parties who have received copies, or rights,
1669 from you under this License will not have their licenses terminated
1670 so long as such parties remain in full compliance.
1672 10. FUTURE REVISIONS OF THIS LICENSE
1674 The Free Software Foundation may publish new, revised versions of
1675 the GNU Free Documentation License from time to time. Such new
1676 versions will be similar in spirit to the present version, but may
1677 differ in detail to address new problems or concerns. See
1678 http://www.gnu.org/copyleft/.
1680 Each version of the License is given a distinguishing version
1681 number. If the Document specifies that a particular numbered
1682 version of this License "or any later version" applies to it, you
1683 have the option of following the terms and conditions either of
1684 that specified version or of any later version that has been
1685 published (not as a draft) by the Free Software Foundation. If the
1686 Document does not specify a version number of this License, you may
1687 choose any version ever published (not as a draft) by the Free
1688 Software Foundation.
1690 ADDENDUM: How to use this License for your documents
1691 ====================================================
1693 To use this License in a document you have written, include a copy of
1694 the License in the document and put the following copyright and license
1695 notices just after the title page:
1698 Copyright (C) YEAR YOUR NAME.
1699 Permission is granted to copy, distribute and/or modify this document
1700 under the terms of the GNU Free Documentation License, Version 1.1
1701 or any later version published by the Free Software Foundation;
1702 with the Invariant Sections being LIST THEIR TITLES, with the
1703 Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
1704 A copy of the license is included in the section entitled ``GNU
1705 Free Documentation License''.
1706 If you have no Invariant Sections, write "with no Invariant Sections"
1707 instead of saying which ones are invariant. If you have no Front-Cover
1708 Texts, write "no Front-Cover Texts" instead of "Front-Cover Texts being
1709 LIST"; likewise for Back-Cover Texts.
1711 If your document contains nontrivial examples of program code, we
1712 recommend releasing these examples in parallel under your choice of free
1713 software license, such as the GNU General Public License, to permit
1714 their use in free software.
1717 File: grammar-fw.info, Node: Index, Prev: GNU Free Documentation License, Up: Top
1725 * %default-prec: default-prec Decl. (line 6)
1726 * %keyword: keyword Decl. (line 6)
1727 * %languagemode: languagemode Decl. (line 6)
1728 * %left: precedence Decl. (line 6)
1729 * %no-default-prec: default-prec Decl. (line 7)
1730 * %nonassoc: precedence Decl. (line 8)
1731 * %package: package Decl. (line 6)
1732 * %put: put Decl. (line 11)
1733 * %put <1>: put Decl. (line 12)
1734 * %put <2>: put Decl. (line 13)
1735 * %put <3>: put Decl. (line 14)
1736 * %quotemode: quotemode Decl. (line 6)
1737 * %right: precedence Decl. (line 7)
1738 * %scopestart: scopestart Decl. (line 6)
1739 * %start: start Decl. (line 6)
1740 * %token: token Decl. (line 9)
1741 * %token <1>: token Decl. (line 10)
1742 * %type: type Decl. (line 6)
1743 * %use-macros: use-macros Decl. (line 6)
1744 * assoc: Grammar Tags. (line 52)
1745 * assoc <1>: Grammar Tags. (line 65)
1746 * code: Grammar Tags. (line 11)
1747 * code <1>: Grammar Tags. (line 15)
1748 * keyword: Grammar Tags. (line 74)
1749 * languagemode: Grammar Tags. (line 28)
1750 * macro: Grammar Tags. (line 124)
1751 * nonterminal: Grammar Tags. (line 133)
1752 * put: Grammar Tags. (line 110)
1753 * quotemode: Grammar Tags. (line 45)
1754 * rule: Grammar Tags. (line 142)
1755 * scopestart: Grammar Tags. (line 38)
1756 * semantic-grammar-complete: Editing grammars. (line 26)
1757 * semantic-grammar-create-package: Editing grammars. (line 6)
1758 * semantic-grammar-epilogue: Querying Declarations.
1760 * semantic-grammar-find-macro-expander: Editing grammars. (line 34)
1761 * semantic-grammar-indent: Editing grammars. (line 20)
1762 * semantic-grammar-insert-keyword: Editing grammars. (line 56)
1763 * semantic-grammar-keyword-properties: Querying Declarations.
1765 * semantic-grammar-keywords: Querying Declarations.
1767 * semantic-grammar-keywordtable-builder: Specialized Implementation.
1769 * semantic-grammar-languagemode: Querying Declarations.
1771 * semantic-grammar-macros: Specialized Implementation.
1773 * semantic-grammar-package: Querying Declarations.
1775 * semantic-grammar-parsetable-builder: Specialized Implementation.
1777 * semantic-grammar-prologue: Querying Declarations.
1779 * semantic-grammar-quotemode: Querying Declarations.
1781 * semantic-grammar-scopestart: Querying Declarations.
1783 * semantic-grammar-setupcode-builder: Specialized Implementation.
1785 * semantic-grammar-start: Querying Declarations.
1787 * semantic-grammar-token-properties: Querying Declarations.
1789 * semantic-grammar-tokens: Querying Declarations.
1791 * semantic-grammar-tokentable-builder: Specialized Implementation.
1793 * semantic-grammar-use-macros: Querying Declarations.
1795 * semantic-lex-keyword-get: put Decl. (line 36)
1796 * semantic-lex-keyword-p: keyword Decl. (line 36)
1797 * semantic-lex-keyword-put: put Decl. (line 29)
1798 * semantic-lex-keyword-set: keyword Decl. (line 44)
1799 * semantic-lex-keyword-symbol: keyword Decl. (line 32)
1800 * semantic-lex-keyword-value: keyword Decl. (line 47)
1801 * semantic-lex-keywords: keyword Decl. (line 60)
1802 * semantic-lex-map-keywords: keyword Decl. (line 51)
1803 * semantic-lex-map-types: type Decl. (line 67)
1804 * semantic-lex-type-get: type Decl. (line 62)
1805 * semantic-lex-type-p: type Decl. (line 46)
1806 * semantic-lex-type-put: type Decl. (line 57)
1807 * semantic-lex-type-set: type Decl. (line 49)
1808 * semantic-lex-type-symbol: type Decl. (line 43)
1809 * semantic-lex-type-value: type Decl. (line 52)
1810 * semantic-lex-types: type Decl. (line 72)
1811 * start: Grammar Tags. (line 19)
1812 * token: Grammar Tags. (line 83)
1813 * token <1>: Grammar Tags. (line 84)
1814 * type: Grammar Tags. (line 99)
1820 Node: Overview
\7f1506
1821 Node: Grammar File
\7f5154
1822 Node: Terminal and Nonterminal Symbols
\7f5825
1823 Node: Prologue
\7f7513
1824 Node: Declarations
\7f8262
1825 Node: package Decl
\7f9154
1826 Node: languagemode Decl
\7f10004
1827 Node: keyword Decl
\7f10676
1828 Ref: semantic-lex-keyword-symbol
\7f11811
1829 Ref: semantic-lex-keyword-p
\7f11944
1830 Ref: semantic-lex-keyword-set
\7f12252
1831 Ref: semantic-lex-keyword-value
\7f12362
1832 Ref: semantic-lex-map-keywords
\7f12527
1833 Ref: semantic-lex-keywords
\7f12942
1834 Node: put Decl
\7f13248
1835 Ref: semantic-lex-keyword-put
\7f14402
1836 Ref: semantic-lex-keyword-get
\7f14668
1837 Node: token Decl
\7f14881
1838 Node: type Decl
\7f16528
1839 Ref: semantic-lex-type-symbol
\7f18213
1840 Ref: semantic-lex-type-p
\7f18305
1841 Ref: semantic-lex-type-set
\7f18410
1842 Ref: semantic-lex-type-value
\7f18539
1843 Ref: semantic-lex-type-put
\7f18791
1844 Ref: semantic-lex-type-get
\7f19062
1845 Ref: semantic-lex-map-types
\7f19319
1846 Ref: semantic-lex-types
\7f19567
1847 Node: precedence Decl
\7f19703
1848 Node: default-prec Decl
\7f20369
1849 Node: quotemode Decl
\7f21156
1850 Node: scopestart Decl
\7f21566
1851 Node: start Decl
\7f22048
1852 Node: use-macros Decl
\7f22496
1853 Node: Grammar Rules
\7f23772
1854 Node: Epilogue
\7f28521
1855 Node: Working with grammars
\7f29396
1856 Node: Editing grammars
\7f29746
1857 Ref: semantic-grammar-create-package
\7f29969
1858 Ref: semantic-grammar-indent
\7f30605
1859 Ref: semantic-grammar-complete
\7f30808
1860 Ref: semantic-grammar-find-macro-expander
\7f31210
1861 Ref: semantic-grammar-insert-keyword
\7f32284
1862 Node: Auto-generation of lexical rules
\7f32466
1863 Node: The principle
\7f33444
1864 Node: Type properties with a special meaning
\7f33618
1865 Node: Predefined well-known types
\7f34625
1866 Node: Grammar Macros
\7f35222
1867 Node: BY grammars
\7f36620
1868 Node: WY grammars
\7f37076
1869 Node: Adding a new grammar mode
\7f37515
1870 Node: Specialized Implementation
\7f37786
1871 Ref: semantic-grammar-keywordtable-builder
\7f38295
1872 Ref: semantic-grammar-tokentable-builder
\7f38592
1873 Ref: semantic-grammar-parsetable-builder
\7f38906
1874 Ref: semantic-grammar-setupcode-builder
\7f39198
1875 Ref: semantic-grammar-macros
\7f39529
1876 Node: Querying grammars
\7f39587
1877 Node: Grammar Tags
\7f40323
1878 Node: Querying Declarations
\7f45913
1879 Ref: semantic-grammar-prologue
\7f46184
1880 Ref: semantic-grammar-epilogue
\7f46301
1881 Ref: semantic-grammar-package
\7f46417
1882 Ref: semantic-grammar-languagemode
\7f46664
1883 Ref: semantic-grammar-start
\7f46803
1884 Ref: semantic-grammar-scopestart
\7f46933
1885 Ref: semantic-grammar-quotemode
\7f47063
1886 Ref: semantic-grammar-keywords
\7f47190
1887 Ref: semantic-grammar-keyword-properties
\7f47465
1888 Ref: semantic-grammar-tokens
\7f47594
1889 Ref: semantic-grammar-token-properties
\7f47945
1890 Ref: semantic-grammar-use-macros
\7f48391
1891 Node: GNU Free Documentation License
\7f48530