Skip to content

Simulation Flow

KIM CHAN HEE edited this page Mar 10, 2023 · 1 revision

Simulation Flow

1. Input

  • Initialize
  • Readline

2. Parsing

  • Lexical analysis (=Tokenizing)
  • Syntax analysis (=Make Parse Tree)

3. Word Expansion

  • Parameter and Variable Expansions
  • Word Splitting
  • Pathname Expansions
  • Quote Removal

4. Command Execution

  • Redirection
  • Builtin Commands
  • Simple Command Execution

1. Input

Intitialize

  • Shell setting
  • Validator

Readline

  • Used by readline library.
  • Accepts input up to and including the newline character ('\n').
  • Checking this time EOF
  • Pass the received characters to the parser as a null-terminated string, excluding newline characters ('\n').
  • Add history
  • How to use ?
    • brew install readline
    • Makefile env
      • RDLINE_DIR   =     $(shell brew --prefix readline)
      • READLINE     =     -L$(RDLINE_DIR)/lib/ -lreadline
      • INCS             =     -I ./include -I$(RDLINE_DIR)/include

2. Parsing

Lexical analysis (=Tokenizing)

  • Types of Token

    • WORD
    • OPERATOR
      • BRACE_LEFT((), BRACE_RIGHT()), LOGICAL_AND(&&), LOGICAL_OR(||), PIPELINE(|), RDIR_IN(<), RDIR_OUT(>), RDIR_HEREDOC(<<), RDIR_APPEND(>>)
  • Split by

    • blank: space, tab, (Do not include newline)
    • operator (consist of non blank metacharacters): "(", ")", "|", "||", "&&", "<", ">", "<<", ">>"
  • Notes

    • Unclosed quote, Unclosed Double quote, Unpaired Bracket,Unpaired Operator -> syntax error

Syntax analysis (=Make AST Parse Tree)

3. Word Expansion

Parameter and Variable Expansions

  • Positional Parameters: $N (N is digit)

  • Special Parameters

    • ?: exit status of the most recent pipeline
    • *: wild card
  • Environment Variables: ${VARIABLE_NAME}

Word Splitting

Pathname Expansions

Quote Removal

4. Command Execution

Redirection

Builtin Commands

Simple Command Execution

  • Error case
    • No such file or directory(/contains && does not exist)
    • No such file or directory(/contains && does not exist)
    • Permission denied(Include && Exist But Permissions denied)
    • No such file or directory(/contains && Exist But No such file)
    • command not found(/none && does not exist)

Clone this wiki locally