Parsing: Added a document to describe the underlying grammar

This commit is contained in:
Jérôme Guélen 2025-04-04 15:43:32 +02:00
parent 9d13ade4a6
commit bd1c469a7f
No known key found for this signature in database

49
grammar.md Normal file
View file

@ -0,0 +1,49 @@
## Initial Grammar (Left recursivity)
This grammar is conceived to take into account both left associativity
and priority of operators to wit () is of highest priority followed by |
and then || and && which share the same priority (priorization therefore
occurs because of left associativity).
LINE -> CMDS eol
CMDS -> CMDS LIST_OP PIPELINE
CMDS -> PIPELINE
PIPELINE -> PIPELINE | GROUP_OR_SIMPLE
PIPELINE -> GROUP_OR_SIMPLE
GROUP_OR_SIMPLE -> (CMDS) REDIR
GROUP_OR_SIMPLE -> SIMPLE
SIMPLE -> REDIR word REDIR SIMPLE_LST
SIMPLE_LST -> word REDIR SIMPLE_LST
SIMPLE_LST -> ε
REDIR -> > word REDIR
REDIR -> >> word REDIR
REDIR -> < word REDIR
REDIR -> << word REDIR
REDIR -> ε
LIST_OP -> &&
LIST_OP -> ||
## Grammar after removal of left recursivity
The same priorities as the previous version except it is now LL(1) and
therefore compatible with descending syntax analysisi (LL(1)).
LINE -> CMDS eol
CMDS -> PIPELINE OPT_CMDS
OPT_CMDS -> LIST_OP PIPELINE OPT_CMDS
OPT_CMDS -> ε
PIPELINE -> GROUP_OR_SIMPLE OPT_PIPELINE
OPT_PIPELINE -> | GROUP_OR_SIMPLE OPT_PIPELINE
OPT_PIPELINE -> ε
GROUP_OR_SIMPLE -> (CMDS) REDIR
GROUP_OR_SIMPLE -> SIMPLE
SIMPLE -> REDIR word REDIR SIMPLE_LST
SIMPLE_LST -> word REDIR SIMPLE_LST
SIMPLE_LST -> ε
REDIR -> > word REDIR
REDIR -> >> word REDIR
REDIR -> < word REDIR
REDIR -> << word REDIR
REDIR -> ε
LIST_OP -> &&
LIST_OP -> ||