mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Parsing: Added a document to describe the underlying grammar
This commit is contained in:
parent
9d13ade4a6
commit
bd1c469a7f
1 changed files with 49 additions and 0 deletions
49
grammar.md
Normal file
49
grammar.md
Normal 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 -> ||
|
||||||
Loading…
Add table
Add a link
Reference in a new issue