说明分析教案讲稿compiler2ch.pptxVIP

  • 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

文档评论(0)

1亿VIP精品文档

相关文档