minishell/grammar.md
2025-04-06 15:49:52 +02:00

1.4 KiB

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			-> ||