0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

minimalでinteractiveなshellの作成

0
Last updated at Posted at 2026-09-19
((unset $PATH) && ls) && tekitou || echo "Command Failed"

のようなコマンドを入力すると

コマンドが実行されて返ってくる、インタラクティブなShellScript実行機を作成しました。
(要するにBashのミニマムバージョン)

github: https://github.com/Hen00af/minishell

ASTの解説もこのリポに添付しています。

文脈自由文法(CFG)に関しては以下のとおりに定義しました。

S           → AND_OR

AND_OR      → PIPELINE AND_OR_TAIL

AND_OR_TAIL → '&&' PIPELINE AND_OR_TAIL
            | '||' PIPELINE AND_OR_TAIL
            | ε

PIPELINE    → COMMAND_OR_SUBSHELL PIPELINE_TAIL

PIPELINE_TAIL → '|' COMMAND_OR_SUBSHELL PIPELINE_TAIL
              | ε

COMMAND_OR_SUBSHELL → COMMAND
                    | SUBSHELL

COMMAND     → SIMPLE REDIR_LIST
            | SIMPLE
            | REDIR_LIST

REDIR_LIST  → REDIR REDIR_LIST
            | ε

REDIR       → '<' WORD
            | '>' WORD
            | '>>' WORD
            | '<<' WORD

SIMPLE      → WORD WORD*

SUBSHELL    → '(' AND_OR ')'

構文解析の際のAST作成の際に参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?