编译原理05-parser-antlr
五、ANTLR 4 语法分析器
语法分析
二异性文法
若文法G对同一句子产生不止一棵分析树,则称G是二义的。
If-Then-Else的二异性
1234567891011121314//IfStat.g4stat : 'if' expr 'then' stat | 'if' expr 'then' stat 'else' stat | expr ;->//IfStatOpenMatched.g4stat : matched_stat | open_statmatched_stat : 'if' expr 'then' matched_stat 'else' matched_stat | expr ;open_stat : 'if' expr 'then' stat | 'if' expr 'then ...
编译原理04-automata
四、自动机理论与词法分析器生成器
自动机-Automation/Automata
两大要素:状态集S 和 状态转移函数$\delta$
元胞自动机-Cellular Automation/CA
根据表达/计算能力的强弱,自动机可以分为不同的层次
目标
正则表达式RE => 词法分析器
非自动性有穷自动机-NFA/Nondeteministic Finite Automaton
$A$是一个五元组 $A = (\Sigma , S, s_{0},\delta,F)$:
1.字母表$\Sigma$$(\epsilon \notin \Sigma)$
2.有穷的状态集合$S$
3.唯一的初始状态$s_{0} \in S$
4.状态转移函数$ \delta $
$$
\delta : S \times (\Sigma \cup \lbrace \epsilon \rbrace) \to 2^S
$$
5.接受状态集合$F \subseteq S$
约定:所有没有对应出边的字符默认指向一个不存在的空状态$\varnothing$
(非确定性)有穷自动机是一类极其简单的计算装置
它可以 ...
数据管理基础chapter_02
一、关系、关系模式和关系数据库
域
域是一组具有相同数据类型的值的集合。
笛卡尔积(Cartesian Product)
1.给定一组域D1,D2,…,Dn ,允许其中某些域是相同的。
2.D1,D2,…,Dn的笛卡尔积为
$$
D_{1} \times D_{2} \times … \times D_{n} = \lbrace (d_{1},d_{2},…,d_{n}) \mid d_{i} \in D_{i},i = 1,2,…,n \rbrace
$$
性质:1)所有域的所有取值的一个组合 2)不能重复
元组(Tuple)
笛卡尔积中每一个元素(d1,d2,…,dn)叫作一个n元组(n-tuple)或简称元组
分量(Component)
笛卡尔积元素(d1,d2,…,dn)中的每一个值di叫作一个分量
基数(Cardinal number)
若Di(i=1,2,…,n)为有限集,其基数为mi (i = 1,2,… ,n),则D1×D2×…×Dn的基数M为:
$$
M = \prod_{i = 1}^n m_{i}
$$
关系(Relation)
D1,D2,D3,…,Dn的笛卡尔 ...
编译原理01-lexer-antlr
一、词法分析器
词法分析器的三种设计方式
词法分析器生成器,手写词法分析器,自动化词法分析器
词法分析器生成器
talk is cheap,show me code
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647grammar SimpleExpr;@header {package simpleexpr;}prog : stat* EOF ;stat : expr ';' | ID '=' expr ';' | 'if' expr ';' ;expr : expr ('*' | '/') expr | expr ('+' | '-') expr | '(' expr ')' | I ...