[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 4fe014a 394/434: Updating documentatio
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator 4fe014a 394/434: Updating documentation regarding operator precedence |
Date: |
Mon, 29 Nov 2021 16:00:23 -0500 (EST) |
branch: externals/parser-generator
commit 4fe014a47fbd1daaf48b696e48b5236364c20ddb
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Updating documentation regarding operator precedence
---
README.md | 4 +---
docs/Syntax-Analysis.md | 20 ++++++++++++++++++++
docs/Syntax-Analysis/LR0.md | 36 ++++++++++++++++++++++++++++++++++++
docs/Syntax-Analysis/LRk.md | 36 ++++++++++++++++++++++++++++++++++++
4 files changed, 93 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index e2b7477..67fc98c 100644
--- a/README.md
+++ b/README.md
@@ -3,9 +3,7 @@
[](https://www.gnu.org/licenses/gpl-3.0.txt)
[](https://travis-ci.org/cjohansson/emacs-parser-generator)
-The idea of this plugin is to provide functions for various kinds of
context-free grammar parser generations with support for
syntax-directed-translations (SDT) and semantic actions (SA) and the
possibility of exporting parsers and translators (as elisp code) to enable
plugin-agnostic usage. This project is also about implementing algorithms
described in the book `The Theory of Parsing, Translation and Compiling (Volume
1)` by `Alfred V. Aho and Jeffrey D. Ullman` (1972). Also this proje [...]
-
-This is just started, so most stuff are *WIP*.
+The idea of this plugin is to provide functions for various kinds of
context-free grammar parser generations with support for
syntax-directed-translations (SDT) and semantic actions (SA) and the
possibility of exporting parsers and translators (as generated elisp code) to
enable Emacs plugin-agnostic usage. This project is also about implementing
algorithms described in the book `The Theory of Parsing, Translation and
Compiling (Volume 1)` by `Alfred V. Aho and Jeffrey D. Ullman` (1972). [...]
## Lexical Analysis
diff --git a/docs/Syntax-Analysis.md b/docs/Syntax-Analysis.md
index b384185..9659f1e 100644
--- a/docs/Syntax-Analysis.md
+++ b/docs/Syntax-Analysis.md
@@ -39,10 +39,30 @@ Grammar consists of `N`, `T`, `P` and `S`, where `N` is
non-terminals, `T` is te
* P = `'((S (A B)) (A (B a) e) (B (C b) C) (C c e))`
* S = `'S`
+Example:
+
``` emacs-lisp
(parser-generator-set-grammar '((S A B C) (a b c) ((S (A B)) (A (B a) e) (B (C
b) C) (C c e)) S))
```
+Productions can include context-sensitive attributes like this:
+
+``` emacs-lisp
+((S (A B %prec first)) (A (B a %weight) e) (B (C b) C) (C c e))
+```
+
+### Global attributes
+
+A list of valid attributes can be set in the variable
`parser-generator--global-attributes`.
+
+### Context-sensitive attributes
+
+A list of valid attributes can be set in the variable
`parser-generator--context-sensitive-attributes`.
+
+### Global declaration
+
+Can be set in variable `parser-generator--global-declaration`. This may be
used differently in different parsing algorithms.
+
### e-identifier
The symbol defined in variable `parser-generator--e-identifier`, with
default-value: 'e`, symbolizes the e symbol. The symbol is allowed in some
grammars and not in others.
diff --git a/docs/Syntax-Analysis/LR0.md b/docs/Syntax-Analysis/LR0.md
index 39c8a4d..fed7694 100644
--- a/docs/Syntax-Analysis/LR0.md
+++ b/docs/Syntax-Analysis/LR0.md
@@ -21,6 +21,42 @@ Example with grammar with production: S -> SaSb and S is
non-terminal and a, b a
* A is the production LHS
* B, C is parts of the production RHS, if the dot is at the left B is nil and
C is the entire RHS. If the dot is at the right then B is the production RHS
and C is nil, otherwise B and C contains parts of the RHS
+## Declaring operator precedence
+
+You can set global symbol operator precedence and also context-sensitive
precedence, like in GNU Bison. Example
+
+``` emacs-lisp
+(setq
+ parser-generator--global-attributes
+ '(%left %precedence %right))
+ (setq
+ parser-generator-lr--global-precedence-attributes
+ '(%left %precedence %right))
+ (setq
+ parser-generator--context-sensitive-attributes
+ '(%prec))
+ (setq
+ parser-generator-lr--context-sensitive-precedence-attribute
+ '%prec)
+ (setq
+ parser-generator--global-declaration
+ '((%left a)
+ (%right b)
+ (%left c)
+ (%precedence FIRST)))
+(parser-generator-set-grammar
+ '(
+ (Sp S A B)
+ (a b c)
+ (
+ (Sp S)
+ (S (A c) B)
+ (A (a b %prec a))
+ (B (a b c %prec FIRST))
+ )
+ Sp))
+```
+
## Parse
Perform a right-parse of input-stream. Example from
[Wikipedia](https://en.wikipedia.org/wiki/LR_parser#Constructing_LR(0)_parsing_tables).
diff --git a/docs/Syntax-Analysis/LRk.md b/docs/Syntax-Analysis/LRk.md
index 25fa359..db12254 100644
--- a/docs/Syntax-Analysis/LRk.md
+++ b/docs/Syntax-Analysis/LRk.md
@@ -22,6 +22,42 @@ Example with grammar with production: S -> SaSb and S is
non-terminal and a, b a
* B, C is parts of the production RHS, if the dot is at the left B is nil and
C is the entire RHS. If the dot is at the right then B is the production RHS
and C is nil, otherwise B and C contains parts of the RHS
* L is the item look-ahead
+## Declaring operator precedence
+
+You can set global symbol operator precedence and also context-sensitive
precedence, like in GNU Bison. Example
+
+``` emacs-lisp
+(setq
+ parser-generator--global-attributes
+ '(%left %precedence %right))
+ (setq
+ parser-generator-lr--global-precedence-attributes
+ '(%left %precedence %right))
+ (setq
+ parser-generator--context-sensitive-attributes
+ '(%prec))
+ (setq
+ parser-generator-lr--context-sensitive-precedence-attribute
+ '%prec)
+ (setq
+ parser-generator--global-declaration
+ '((%left a)
+ (%right b)
+ (%left c)
+ (%precedence FIRST)))
+(parser-generator-set-grammar
+ '(
+ (Sp S A B)
+ (a b c)
+ (
+ (Sp S)
+ (S (A c) B)
+ (A (a b %prec a))
+ (B (a b c %prec FIRST))
+ )
+ Sp))
+```
+
## LR items for prefix (S)
Calculate the set of LR items valid for any viable prefix S.
- [elpa] externals/parser-generator e070522 396/434: Fixed broken link in documentation, (continued)
- [elpa] externals/parser-generator e070522 396/434: Fixed broken link in documentation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5b95baf 401/434: More work on last feature, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 4da88bf 406/434: Added another test for e-identifier in middle of rule, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 72796d0 408/434: Fixed bug with FIRST calculation with multiple symbols and e-identifiers, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 843bc57 398/434: Fixed invalid reference to parser-generator to fetch translation by production number, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7eb8cab 397/434: Small fixes to documentation about syntax analysis, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 3a178ed 393/434: Exported LR parser now passes all tests, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c606043 389/434: Passing all tests with new precedence generation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator cfa9561 407/434: Added TODO item, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 21fef5c 388/434: Passing all tests for infix calculator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 4fe014a 394/434: Updating documentation regarding operator precedence,
ELPA Syncer <=
- [elpa] externals/parser-generator aafb3cc 411/434: Passing test for grammar containing e-identifier in middle or a rule, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator b8de1c4 414/434: LR-exporter now supports optional header, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e157091 413/434: Fixed error signaling in invalid LR-parser and generated LR-parser, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 827aa5c 433/434: Another bug for same thing, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator ee78a6c 430/434: LR-parser now passes terminal data to SDT for non-terminals containing only one symbol, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 3657a68 427/434: Merge branch 'master' of git.cvj.se:/home/git/emacs-parser-generator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 2481361 425/434: Improved readme, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e59baa8 416/434: Added move feature of lex-analyzer into exported LR lex-analyzer, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 29568c3 428/434: Added support for copyright text in exported LR-parser, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 4a3a51d 434/434: Added FSF copyright headers, ELPA Syncer, 2021/11/29