Comments (5)
词法分析 (单词)
例如:
识别到是字母或者数字,就继续识别下去;
如果识别了 \n 换行处理;
1. 分析空白分隔符
2. 分析换行符
3. 数字
4. 字符或字符串
5. 标识符
6. 运算符和分隔符
v8的词法分析
const a ='abc'
序列二元组: {'Identifier': 'const'}、{'Identifier': 'a'}、{'Operator': '='}、{'String': 'abc'}
from r-books.
语法分析 (语法)
语法分析生成语法树 = 序列二元组 + 语法分析。
产生式的背景
例如:
var a = 1;
变量声明 标志符 = 常量。
变量声明 标志符 = 常量, 标志符 = 常量。
....
这么一个单独的是没有问题的。
但是,以下就要结合上下文去分析了,单独处理是不行的。
var a = 1;
function b (c) {
a = 100;
return a + c;
}
c = b(666) > 0 ? 1 : 0;
或者说: 有很多的规则,例如有 if else、有function的不同写法等。
对于人来说,你只要知道语言编写的规则就行了:
- 如果是使用固定模板去套用匹配,拓展能力不够。
- 为了让语言更加的灵活,就可能需要很多的模板匹配规则,但是怎么让机器去识别呢?
- 所以,我们用模板描述模板
from r-books.
产生式 (常见BNF)
3.3.2 产生式的具体示例
BNF范式(巴科斯范式)到底是什么?
::= : 我们还没有定义完的内容,右边的replacement继续定义。
类似中文: 一般是主谓宾。主语可以是 名词或者代词。谓语一般是动词。宾语是形容词、名次、代词。
故主谓宾,就是 是非终止符,因为还可以被其他例如名词、动词等代替。
1. <句子> ::= <主><谓><宾语>
2. <主语> ::= <名词>|<代词>
3. <谓语>::=<动词>
4. <宾语>::=<形容词>|<名词>|<代词>
5. <代词>::=<我>
6. <动词>::=<吃>
7. ...
1中的右侧就是 234表示 非终止符,但是56的右边就找不到符号进一步代替了,这样描述就结束了。
换成 语言就是 <符号> ::= <使用符号的表达式>
exp ::= number("*"|"/") exp | number // 非终结符
number ::= [0-9]+ // 终结符
from r-books.
AST
from r-books.
语义分析 (语义)
ts是做语语义分析的专家。单词没有问题、语法也没有问题,那后面就是来check 你描述的一句话是否有问题了。
var a = 1;
var c = a + b; // 但是b没有定义啊~ 语义就问题
中间代码生成 和 优化
生成目标代码
from r-books.
Related Issues (5)
- [R] 半小时漫画经济学 HOT 1
- [R] Principles (E) HOT 4
- [R] Principles (C) - P1 HOT 5
- [R] 如何系统思考 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from r-books.