(Compiler theory) Lecture programming language and its grammar

basic concepts

  1. Alphabet
  • Alphabet operations: multiplication, n-th power, n closure, the Kleene closure (any symbol string set)
    -

0 power is an empty string Here Insert Picture Description

  • String operations: connecting, exponentiation
    -

Defined grammar

  1. Grammar formal definition:
    -
  2. Terminator: the basic language of symbolic token
  • Not enclosed in angle brackets portion
    Here Insert Picture Description
  1. Nonterminal symbol: indicates the syntax component symbols
  • With angle brackets portion
    Here Insert Picture Description
    Here Insert Picture Description
  1. S start symbol: the grammar largest grammatical elements.
    Here Insert Picture Description

Definition Language

  1. Sentence: meet the rules of grammar end symbol string . A sentence that does not contain nonterminals sentence.
    Here Insert Picture Description
    Here Insert Picture Description

How to determine whether a word string satisfying the relation of the sentence? Deduction and reduction

  1. Language
    Here Insert Picture Description
  2. Derivation
  3. Reduction
  4. Operation on language
  • and
  • connection
  • power
  • Closure is
  • Brooklyn closure

Classification grammar

  1. Type 0 grammar: unrestricted grammar / phrase structure grammar
    Here Insert Picture Description
  2. Type 1 grammar: context-sensitive grammar (CSG)
  • Production does not contain null
    Here Insert Picture Description
  1. Type 2 grammar: context-free grammar (CFG)
    Here Insert Picture Description
  2. Type 3 Grammar: Regular Grammar
    Here Insert Picture Description
  3. Relationship four kinds of grammar: the gradual restrictions, contains step by step
    Here Insert Picture Description

CFG parse tree

  1. Sentence phrases: analysis of each of them in sub-edge tree tree
  2. Direct phrases: height edge sub-tree 2
    Here Insert Picture Description
  • Direct production phrase must be a right portion, a right portion of the production but not necessarily directly given sentence phrases
  1. Ambiguous grammar: If a grammar can be generated for more than a sentence parse tree
    Here Insert Picture Description
Published 109 original articles · won praise 128 · views 40000 +

Guess you like

Origin blog.csdn.net/JAck_chen0309/article/details/104498270