Intro

2020-04-15  本文已影响0人  官子寒

1. Intro

1.1 Compilers and Interpreters

FORTRAN - 第一款编译语言

1.2 Phases of Compilers

2. Lexical Analysis

2.1 Lexical Analysis

Token<Token Name, Attribute>

2.1.1 Input Buffering

2.2 Regular Languages

Regular Expressions: 正则表达式


L(e) \rightarrow m: meaning function maps to its syntax to semantics

eg:

  1. Integer: a non-empty string of digits digit digit^* = digit^+
  2. Identifier: Strings of letters or digits, starting with a letter


2.3 匹配

2.3.1 匹配规则

Maximal Much: choose the longer one when either the shorter one and the longer one is a feasible string
Priority First
Match none: put error last in the priority

2.4 Finite Automata

accept: 1) end of state 2) in accpet state


2.4.1 RegularExpression to NFA

2.4.2 NFA to DFA

\epsilon- closure

NFA转DFA的子集构造(subset construction)算法
什么是NFA(不确定的有穷自动机)和DFA(确定的有穷自动机)
从NFA到DFA

2.4.3 Transition Table

3. Parsing

3.1 Limitations of Regular Language

????

3.2 Parsing VS. Lexical Analysis

Phase Input Output
Lexer String of Characters String of tokens
Parser String of tokens Parse Tree

3.3 Context-Free Gramars

3.4 Derivation

3.4.1 Parse Tree

3.5 Ambiguity

3.6 Error Handling

Purpose of the Compilers:

  1. To detect non-valid prorams
  2. To transform the valid ones

3.6.1 Ways of Error Handling

1. 出现错误的情况

  1. 栈顶是终结符时,与输入不匹配
  2. 栈顶是非终结符时,在预测分析表中没有与输入相匹配的

3.7 Abstract Syntax Tree

3.8 Parsing Algorithms

3.8.1 Recursive Descent Parsing

Problem:

  1. left recursive
  1. right recursive
    规范规约:最左规约
    规范推导:最右推导

3.8.2 自顶向下方法的问题

问题1:当同一非终结符的多个候选式存在多个共同前缀的时候,会产生回溯问题
问题2:无限循环,原因是左递归文法会形成循环

将含有A \rightarrow A\alpha格式的产生的文法定义为直接左递归的文法
两步及两步以上推导的文法叫做间接左递归文法

1.消除直接左递归

2.消除间接左递归

3.提取公共前缀

3.9 Predictive Parsing

3.9.1 定义

accept LL(K) grammars

\epsilon空产生式:

3.9.2 First Sets & Follow Sets


First Sets和Follow Sets教程


3.9.3 LL1语法

3.10 Bottom-Up Parsing

3.10.1 Shift-reduce 移入-规约分析

Reduce: unexamined

Shift

3.10.2 Handles 句柄

3.10.3 SLR

Recognizing Valid Prefix


3.10.4 LR(1)

3.10.5 LALR分析法

Valid Items


3.10.3 SLR(K)

reduce/reuce conflict
shift/reduce conflict

3.10.4 SLR Improvements


上一篇 下一篇

猜你喜欢

热点阅读