ImageVerifierCode 换一换
格式:PPT , 页数:57 ,大小:697KB ,
资源ID:13324098      下载积分:10 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/13324098.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(程序设计语言概念(ConceptsofProgrammingLanguages)英文第10版第3章.ppt)为本站上传会员【仙人****88】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

程序设计语言概念(ConceptsofProgrammingLanguages)英文第10版第3章.ppt

1、Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,Copyright 2012 Pearson Education.All rights reserved.,1-,*,Chapter 3,Describing Syntax and Semantics,Copyright 2012 Addison-Wesley.All rights reserved.,1-,2,Chapter 3 Topics,Introducti

2、on,The General Problem of Describing Syntax,Formal Methods of Describing Syntax,Attribute Grammars,Describing the Meanings of Programs:Dynamic Semantics,Copyright 2012 Addison-Wesley.All rights reserved.,1-,3,Introduction,Syntax:,the form or structure of the expressions,statements,and program units,

3、Semantics:,the meaning of the expressions,statements,and program units,Syntax and semantics provide a languages definition,Users of a language definition,Other language designers,Implementers,Programmers(the users of the language),Copyright 2012 Addison-Wesley.All rights reserved.,1-,4,The General P

4、roblem of Describing Syntax:Terminology,A,sentence,is a string of characters over some alphabet,A,language,is a set of sentences,A,lexeme,is the lowest level syntactic unit of a language(e.g.,*,sum,begin,),A,token,is a category of lexemes(e.g.,identifier),Copyright 2012 Addison-Wesley.All rights res

5、erved.,1-,5,Formal Definition of Languages,Recognizers,A recognition device reads input strings over the alphabet of the language and decides whether the input strings belong to the language,Example:syntax analysis part of a compiler,-Detailed discussion of syntax analysis appears in,Chapter 4,Gener

6、ators,A device that generates sentences of a language,One can determine if the syntax of a particular sentence is syntactically correct by comparing it to the structure of the generator,Copyright 2012 Addison-Wesley.All rights reserved.,1-,6,BNF and Context-Free Grammars,Context-Free Grammars,Develo

7、ped by Noam Chomsky in the mid-1950s,Language generators,meant to describe the syntax of natural languages,Define a class of languages called context-free languages,Backus-Naur Form(1959),Invented by John Backus to describe the syntax of Algol 58,BNF is equivalent to context-free grammars,Copyright

8、2012 Addison-Wesley.All rights reserved.,1-,7,BNF Fundamentals,In BNF,abstractions are used to represent classes of syntactic structures-they act like syntactic variables(also called,nonterminal symbols,or just,terminals,),Terminals,are lexemes or tokens,A rule has a left-hand side(LHS),which is a n

9、onterminal,and a right-hand side(RHS),which is a string of terminals and/or nonterminals,BNF Fundamentals,(continued),Nonterminals are often enclosed in angle brackets,Examples of BNF rules:,identifier|identifier,if,then,Grammar:a finite non-empty set of rules,A,start symbol,is a special element of

10、the nonterminals of a grammar,Copyright 2012 Addison-Wesley.All rights reserved.,1-,8,Copyright 2012 Addison-Wesley.All rights reserved.,1-,9,BNF Rules,An abstraction(or nonterminal symbol)can have more than one RHS,|begin end,Copyright 2012 Addison-Wesley.All rights reserved.,1-,10,Describing Lists

11、Syntactic lists are described using recursion,ident,|ident,A derivation is a repeated application of rules,starting with the start symbol and ending with a sentence(all terminal symbols),Copyright 2012 Addison-Wesley.All rights reserved.,1-,11,An Example Grammar,|;,=,a|b|c|d,+|-,|const,Copyright 20

12、12 Addison-Wesley.All rights reserved.,1-,12,An Example Derivation,=,=,=a=,=a=+,=a=+,=a=b+,=a=b+const,Copyright 2012 Addison-Wesley.All rights reserved.,1-,13,Derivations,Every string of symbols in a derivation is a,sentential form,A,sentence,is a sentential form that has only terminal symbols,A,lef

13、tmost derivation,is one in which the leftmost nonterminal in each sentential form is the one that is expanded,A derivation may be neither leftmost nor rightmost,Copyright 2012 Addison-Wesley.All rights reserved.,1-,14,Parse Tree,A hierarchical representation of a derivation,const,a,=,b,+,Copyright 2

14、012 Addison-Wesley.All rights reserved.,1-,15,Ambiguity in Grammars,A grammar is,ambiguous,if and only if it generates a sentential form that has two or more distinct parse trees,Copyright 2012 Addison-Wesley.All rights reserved.,1-,16,An Ambiguous Expression Grammar,|const,/|-,const,const,const,con

15、st,const,const,-,-,/,/,Copyright 2012 Addison-Wesley.All rights reserved.,1-,17,An Unambiguous Expression Grammar,If we use the parse tree to indicate precedence levels of the operators,we cannot have ambiguity,-|,/const|const,const,const,const,/,-,Copyright 2012 Addison-Wesley.All rights reserved.,

16、1-,18,Associativity of Operators,Operator associativity can also be indicated by a grammar,-+|const (ambiguous),-+const|const (unambiguous),const,const,const,+,+,Copyright 2012 Addison-Wesley.All rights reserved.,1-,19,Extended BNF,Optional parts are placed in brackets ,-ident(),Alternative parts of

17、 RHSs are placed inside parentheses and separated via vertical bars,(+|-)const,Repetitions(0 or more)are placed inside braces ,letter letter|digit,Copyright 2012 Addison-Wesley.All rights reserved.,1-,20,BNF and EBNF,BNF,+,|-,|,*,|/,|,EBNF,(+|-),(*|/),Copyright 2012 Addison-Wesley.All rights reserve

18、d.,1-,21,Recent Variations in EBNF,Alternative RHSs are put on separate lines,Use of a colon instead of,=,Use of,opt,for optional parts,Use of,oneof,for choices,Copyright 2012 Addison-Wesley.All rights reserved.,1-,22,Static Semantics,Nothing to do with meaning,Context-free grammars(CFGs)cannot desc

19、ribe all of the syntax of programming languages,Categories of constructs that are trouble:,-Context-free,but cumbersome(e.g.,types of operands in expressions),-Non-context-free(e.g.,variables must,be declared before they are used),Copyright 2012 Addison-Wesley.All rights reserved.,1-,23,Attribute Gr

20、ammars,Attribute grammars(AGs)have additions to CFGs to carry some semantic info on parse tree nodes,Primary value of AGs:,Static semantics specification,Compiler design(static semantics checking),Copyright 2012 Addison-Wesley.All rights reserved.,1-,24,Attribute Grammars,:Definition,Def,:An attribu

21、te grammar is a context-free grammar G=(S,N,T,P)with the following additions:,For each grammar symbol,x,there is a set,A(x),of attribute values,Each rule has a set of functions that define certain attributes of the nonterminals in the rule,Each rule has a(possibly empty)set of predicates to check fo

22、r attribute consistency,Copyright 2012 Addison-Wesley.All rights reserved.,1-,25,Attribute Grammars:Definition,Let,X,0,X,1,.X,n,be a rule,Functions of the form,S(X,0,)=f(A(X,1,),.,A(X,n,),define,synthesized attributes,Functions of the form,I(X,j,)=f(A(X,0,),.,A(X,n,),for i=j =,-+|,A|B|C,actual_type,

23、synthesized for,and,expected_type,:inherited for,Copyright 2012 Addison-Wesley.All rights reserved.,1-,27,Attribute Grammar,(continued),Syntax rule:,1+2,Semantic rules:,.actual_type,1.actual_type,Predicate:,1.actual_type=2.actual_type,.expected_type=.actual_type,Syntax rule:,id,Semantic rule:,.actu

24、al_type,lookup(.string),Copyright 2012 Addison-Wesley.All rights reserved.,1-,28,Attribute Grammars,(continued),How are attribute values computed?,If all attributes were inherited,the tree could be decorated in top-down order.,If all attributes were synthesized,the tree could be decorated in bottom-

25、up order.,In many cases,both kinds of attributes are used,and it is some combination of top-down and bottom-up that must be used.,Copyright 2012 Addison-Wesley.All rights reserved.,1-,29,Attribute Grammars,(continued),.expected_type,inherited from parent,1.actual_type,lookup(A),2.actual_type,lookup(

26、B),1.actual_type=?2.actual_type,.actual_type,1.actual_type,.actual_type=?.expected_type,Copyright 2012 Addison-Wesley.All rights reserved.,1-,30,Semantics,There is no single widely acceptable notation or formalism for describing semantics,Several needs for a methodology and notation for semantics:,P

27、rogrammers need to know what statements mean,Compiler writers must know exactly what language constructs do,Correctness proofs would be possible,Compiler generators would be possible,Designers could detect ambiguities and inconsistencies,Operational Semantics,Operational Semantics,Describe the meani

28、ng of a program by executing its statements on a machine,either simulated or actual.The change in the state of the machine(memory,registers,etc.)defines the meaning of the statement,To use operational semantics for a high-level language,a virtual machine is needed,Copyright 2012 Addison-Wesley.All r

29、ights reserved.,1-,31,Copyright 2012 Addison-Wesley.All rights reserved.,1-,32,Operational Semantics,A,hardware,pure interpreter would be too expensive,A,software,pure interpreter also has problems,The detailed characteristics of the particular computer would make actions difficult to understand,Suc

30、h a semantic definition would be machine-dependent,Copyright 2012 Addison-Wesley.All rights reserved.,1-,33,Operational Semantics(continued),A better alternative:A complete computer simulation,The process:,Build a translator(translates source code to the machine code of an idealized computer),Build

31、a simulator for the idealized computer,Evaluation of operational semantics:,Good if used informally(language manuals,etc.),Extremely complex if used formally(e.g.,VDL),it was used for describing semantics of PL/I.,Copyright 2012 Addison-Wesley.All rights reserved.,1-,34,Operational Semantics(continu

32、ed),Uses of operational semantics:,-Language manuals and textbooks,-Teaching programming languages,Two different levels of uses of operational semantics:,-Natural operational semantics,-Structural operational semantics,Evaluation,-Good if used informally(language,manuals,etc.),-Extremely complex if

33、used formally (e.g.,VDL),Denotational Semantics,Based on recursive function theory,The most abstract semantics description method,Originally developed by Scott and Strachey(1970),Copyright 2012 Addison-Wesley.All rights reserved.,1-,35,Denotational Semantics-,continued,The process of building a deno

34、tational specification for a language:,-Define a mathematical object for each language,entity,Define a function that maps instances of the language entities onto instances of the corresponding mathematical objects,The meaning of language constructs are defined by only the values of the programs vari

35、ables,Copyright 2012 Addison-Wesley.All rights reserved.,1-,36,Denotational Semantics:,program state,The state of a program is the values of all its current variables,s=,Let,VARMAP,be a function that,when given a variable name and a state,returns the current value of the variable,VARMAP(i,j,s)=v,j,C

36、opyright 2012 Addison-Wesley.All rights reserved.,1-,37,Decimal Numbers,0|1|2|3|4|5|,6|7|8|9|,(0|1|2|3|,4|5|6|7|,8|9),M,dec,(0)=0,M,dec,(1)=1,M,dec,(9)=9,M,dec,(0)=10*M,dec,(),M,dec,(1)=10*M,dec,()+1,M,dec,(9)=10*M,dec,()+9,Copyright 2012 Addison-Wesley.All rights reserved.,1-,38,Expressions,Map exp

37、ressions onto Z,error,We assume expressions are decimal numbers,variables,or binary expressions having one arithmetic operator and two operands,each of which can be an expression,Copyright 2012 Addison-Wesley.All rights reserved.,1-,39,Expressions,M,e,(,s),=,case of,=M,dec,(,s),=,if VARMAP(,s)=undef

38、then error,else VARMAP(,s),=,if(M,e,(.,s)=undef,OR M,e,(.,s)=,undef),then error,else,if(.=,+,then,M,e,(.,s)+,M,e,(.,s),else M,e,(.,s)*,M,e,(.,s),.,Copyright 2012 Addison-Wesley.All rights reserved.,1-,40,Assignment Statements,Maps state sets to state sets U,error,M,a,(x:=E,s),=,if M,e,(E,s)=error,t

39、hen error,else s=,.,where for j=1,2,.,n,if i,j,=x,then v,j,=M,e,(E,s),else v,j,=VARMAP(i,j,s),Copyright 2012 Addison-Wesley.All rights reserved.,1-,41,Logical Pretest Loops,Maps state sets to state sets U,error,M,l,(while B do L,s),=,if M,b,(B,s)=undef,then error,else if M,b,(B,s)=false,then s,else

40、if M,sl,(L,s)=error,then error,else M,l,(while B do L,M,sl,(L,s),Copyright 2012 Addison-Wesley.All rights reserved.,1-,42,Loop Meaning,The meaning of the loop is the value of the program variables after the statements in the loop have been executed the prescribed number of times,assuming there have

41、been no errors,In essence,the loop has been converted from iteration to recursion,where the recursive control is mathematically defined by other recursive state mapping functions,-Recursion,when compared to iteration,is easier,to describe with mathematical rigor,Copyright 2012 Addison-Wesley.All rig

42、hts reserved.,1-,43,Evaluation of Denotational Semantics,Can be used to prove the correctness of programs,Provides a rigorous way to think about programs,Can be an aid to language design,Has been used in compiler generation systems,Because of its complexity,it are of little use to language users,Cop

43、yright 2012 Addison-Wesley.All rights reserved.,1-,44,Copyright 2012 Addison-Wesley.All rights reserved.,1-,45,Axiomatic Semantics,Based on formal logic(predicate calculus),Original purpose:formal program verification,Axioms or inference rules are defined for each statement type in the language(to a

44、llow transformations of logic expressions into more formal logic expressions),The logic expressions are called,assertions,Copyright 2012 Addison-Wesley.All rights reserved.,1-,46,Axiomatic Semantics(continued),An assertion before a statement(a,precondition,)states the relationships and constraints a

45、mong variables that are true at that point in execution,An assertion following a statement is a,postcondition,A,weakest precondition,is the least restrictive precondition that will guarantee the postcondition,Copyright 2012 Addison-Wesley.All rights reserved.,1-,47,Axiomatic Semantics Form,Pre-,post

46、 form:,P statement Q,An example,a=b+1 a 1,One possible precondition:,b 10,Weakest precondition:,b 0,Copyright 2012 Addison-Wesley.All rights reserved.,1-,48,Program Proof Process,The postcondition for the entire program is the desired result,Work back through the program to the first statement.If th

47、e precondition on the first statement is the same as the program specification,the program is correct.,Copyright 2012 Addison-Wesley.All rights reserved.,1-,49,Axiomatic Semantics:Assignment,An axiom for assignment statements (x=E):Q,x-E,x=E Q,The Rule of Consequence:,Copyright 2012 Addison-Wesley.A

48、ll rights reserved.,1-,50,Axiomatic Semantics:Sequences,An inference rule for sequences of the form S1;S2,P1 S1 P2,P2 S2 P3,Axiomatic Semantics:Selection,An inference rules for selection,-,if,B,then,S1,else,S2,B and P S1 Q,(not B)and P S2 Q,P,if,B,then,S1,else,S2 Q,Copyright 2012 Addison-Wesley.All

49、rights reserved.,1-,51,Copyright 2012 Addison-Wesley.All rights reserved.,1-,52,Axiomatic Semantics:Loops,An inference rule for logical pretest loops,P,while,B,do,S,end,Q,where I is the loop invariant(the inductive hypothesis),Copyright 2012 Addison-Wesley.All rights reserved.,1-,53,Axiomatic Semant

50、ics:Axioms,Characteristics of the loop invariant:I must meet the following conditions:,P=I,-the loop invariant must be true initially,I B I,-evaluation of the Boolean must not change the validity of I,I and B S I,-I is not changed by executing the body of the loop,(I and(not B)=Q,-if I is true and B

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服