aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-05-09 00:36:06 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-05-10 23:14:52 +0900
commitdd5fd3372cdb53e7a3a36b5ef61b0b0c35023798 (patch)
treee29796e3c0aee95e443aeabe6b24e2ed4c81dac0 /README.md
parentAdd #assign directive (diff)
downloadurubu-dd5fd3372cdb53e7a3a36b5ef61b0b0c35023798.tar.gz
urubu-dd5fd3372cdb53e7a3a36b5ef61b0b0c35023798.tar.xz
Add ordered symbol notation
Diffstat (limited to 'README.md')
-rw-r--r--README.md17
1 files changed, 10 insertions, 7 deletions
diff --git a/README.md b/README.md
index bf89c10..047f6c2 100644
--- a/README.md
+++ b/README.md
@@ -28,8 +28,8 @@ vartan uses BNF-like DSL to define your grammar. As an example, let's write a gr
#name expr;
#prec (
- #left mul div
- #left add sub
+ #left mul div
+ #left add sub
);
expr
@@ -505,7 +505,9 @@ If you want to change precedence, `#assign` directive helps you. `#assign` direc
When the right-most terminal symbol of an alternative has precedence or associativity defined explicitly, the alternative inherits its precedence and associativity.
-`#prec` directive assigns the same precedence as a specified symbol to an alternative.
+`#prec` directive assigns the same precedence as a specified symbol to an alternative and disables associativity.
+
+You can define an ordered symbol with the form `$<ID>`. The ordered symbol is an identifier having only precedence, and you can use it in `#prec` directive applied to an alternative. The ordered symbol helps you to resolve shift/reduce conflicts without terminal symbol definitions.
The grammar for simple four arithmetic operations and assignment expression can be defined as follows:
@@ -513,9 +515,10 @@ The grammar for simple four arithmetic operations and assignment expression can
#name example;
#prec (
- #left mul div
- #left add sub
- #right assign
+ #assign $uminus
+ #left mul div
+ #left add sub
+ #right assign
);
expr
@@ -525,7 +528,7 @@ expr
| expr div expr
| id assign expr
| int
- | sub int #prec mul // This `sub` means a unary minus symbol.
+ | sub int #prec $uminus // This `sub` means a unary minus symbol.
| id
;