Giter VIP home page Giter VIP logo

c-scanner's Introduction

拓展 - 两种框架

  • 分层架构:
    • 优点:可以起到解耦合作用,降低复杂度
    • 缺点:速度低
TCP/IP协议栈
 | 应用层  |
 | 传输层  |
 | 网路层  |
 |数据链路层|
  • 流水线模型:编译器

流程

Token: 类比词语

AST: 抽象语法树

  *.c       Token流      AST      优化后的AST
   |           |          |          |            
  -->[词法分析]-->[语法分析]-->[语义分析]-->[生成中间代码]    编译器的前端  
                                            |
                                            ├── 中间代码 类似于java的字节码
                                            |
[机器代码]<-[平台相关优化]<-[平台无关优化]<-[中间代码优化]      编译器的后端
                                                            llvm
  1. 词法分析

    eg.

    我/喜欢/聪明又美丽的/asumi
       |
      词语:Token
  2. 语法分析

    Abstract Syntax Tree
    
        [句子]
       /  |  \
     主   谓   宾
     I  LOVE  asumi 
             /
           定语:smart/pretty
  3. 语义分析

    结合上下文(类比C语言作用域),推断句子的含义

词法分析

 a = value + sum(5, 123);
 读取得到start 表示Token的起始位置      
    |   
   [a][ ][=][ ][v][a][l][u][e][ ][+][s][u][m][(][5][,][ ][1][2][3][)][;]
       |
      curr下一个要读的字符                                            

通过有限状态机理论解析Token:switch + while + if 组合就可以得到

    'a': 标识符
    '=': 判断两种状态,== 或 =
    'v': 标识符
    '+': 判断三种状态, ++ += +
    's': 标识符状态
    '(': 停止
    '5': 数字状态
    ',': 单字符token
    '1': 数字状态
    ')': 单字符token
start token
a a
= =
v value
+ +
s sum
( )
5 5
, ,
1 123
) )
; ;

c-scanner's People

Contributors

looechao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.