From f490cc22f589af9948fe4c2fb7099bd83f2664c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gu=C3=A9len?= Date: Fri, 4 Apr 2025 15:43:32 +0200 Subject: [PATCH] Parsing: Added a document to describe the underlying grammar --- grammar.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 grammar.md diff --git a/grammar.md b/grammar.md new file mode 100644 index 0000000..2ccae67 --- /dev/null +++ b/grammar.md @@ -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 -> ||