- 1
- 0
- 约1.82万字
- 约 57页
- 2021-12-08 发布于北京
- 举报
Chapter 2 Scanning(lexical analysis)OutlineWhat is lexical analysis?Writing a lexerSpecifying tokens: regular expressionsDFAs, NFAsDFA simulationNFA-DFA conversionSource code (character stream)token streamif (b == 0) a = b;Lexical Analysisif(b==0)a=b;Syntax AnalysisSemantic Analysis2.1 Scanning Process2.1 Scanning Process?Identifier: x y11 elsen_i00? Integer: 2 1000 -500 5L? Floating point: 2.0 0.00020 .02 1. 1e5 0.e-10? String: “x” “He said, \“Are you?\””? Comment:/** don’t change this **/? Keyword: if else while break? Symbol: + * { } ++ [ ] =2.2 Regular Expression ? Describe programming language tokens using regular expressions!? A Regular Expression (RE) is defined inductively:a ordinary character stands for itselfε the empty stringR|S either R or S (alternation), where R, S = RERS R followed by S (concatenation), where R, S = RER* concatenation of a RE R zero or more times (R* = ε|R|RR|RRR|RRRR…)? Precedence Rules and Parentheses alternation concatenation repetition2.2 Regular ExpressionExample 1)?∑={ a,b,c} the set of all strings over this alphabet that contain exactly one b.(a|c)*b(a|c)* 2)? ∑={ a,b,c} the set of all strings that contain at most one b.(a|c)*|(a|c)*b(a|c)* (a|c)*(b|ε)(a|c)*the same language may be generated by many different regular expressions.2.2 Regular Expression 3) ∑={ a,b}the set of strings consists of a single b surrounded by the same number of a’s. S = {b,aba,aabaa,aaabaaa,……} = { anban | n≠0}This set can not be described by a regular expression. “Regular expression can’t count ”A Regular Set : a set of strings that is the language for a regular expression is distinguished from other sets 2.2 Regular ExpressionR+ one or more strings from L(R): R(R*)R? optional R: (R|ε)[abce] one of the listed characters: (a|b|c|e)[a-z] one character from this range:(a|b|c|d|e|…|y|z)[^ab] anything but one of the listed chars[^a-z] one character not from this range2.2 Regular Expression1.Numbers nat = [0-9]+signedNat
您可能关注的文档
最近下载
- Toyota丰田TOTAL HUMAN MODEL FOR SAFETY (THUMS)用户手册.pdf
- 人教版高中物理选择性必修第二册教材习题答案.pdf VIP
- 2026年春冀教版(三起)(新教材)小学英语三年级第二学期教学计划及进度表.pdf
- (高清版)B-T 41972-2022 铸铁件 铸造缺陷分类及命名.pdf VIP
- 江苏南京金陵中学2024-2025学年高一下学期期末考试数学试卷[含解析].pdf VIP
- 中考语文散文专题训练----曹伟明散文(含解析).doc VIP
- 2026云南大学附属中学西山学校招聘聘任制教师50人备考题库及1套完整答案详解.docx VIP
- 又丑又高的莎拉读后感 .docx VIP
- 七年级数学全册公式定理汇总.docx VIP
- 2025年港澳台华侨生入学考试高考物理试卷真题(含答案详解).pdf VIP
原创力文档

文档评论(0)