2025-04-04 15:43:32 +02:00
|
|
|
## 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).
|
|
|
|
|
|
2025-04-06 14:25:52 +02:00
|
|
|
```
|
2025-04-04 15:43:32 +02:00
|
|
|
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 -> ||
|
2025-04-06 14:25:52 +02:00
|
|
|
```
|
|
|
|
|
|
2025-04-04 15:43:32 +02:00
|
|
|
|
|
|
|
|
## Grammar after removal of left recursivity
|
|
|
|
|
|
|
|
|
|
The same priorities as the previous version except it is now LL(1) and
|
2025-04-08 12:14:38 +02:00
|
|
|
therefore compatible with descending syntax analysis (LL(1)).
|
2025-04-04 15:43:32 +02:00
|
|
|
|
2025-04-06 14:25:52 +02:00
|
|
|
```
|
2025-04-04 15:43:32 +02:00
|
|
|
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
|
2025-04-08 19:56:46 +02:00
|
|
|
SIMPLE -> REDIR word REDIR SIMPLE_LST
|
2025-04-04 15:43:32 +02:00
|
|
|
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 -> ||
|
2025-04-06 14:25:52 +02:00
|
|
|
```
|