Example: marketing

Compilers: Principles, Techniques, and Tools

CompilersSecond EditionPrinciples, Techniques, & ToolsThis page intentionally left blank CompilersSecond EditionPrinciples, Techniques, & ToolsAlfred V. AhoColumbia UniversityMonica S. LamStanford UniversityRavi SethiAvayaJeffrey D. UllmanStanford UniversityPublisher Greg Tobin Executive Editor Michael Hirsch Acquisitions Editor Matt Goldstein Project Editor Katherine Harutunian Associate Managing Editor Jeffrey Holcomb Cover Designer Joyce Cosentino Wells Digital Assets Manager Marianne Groth Media Producer Bethany Tidd Senior Marketing Manager Michelle Brown Marketing Assistant Sarah Milmore Senior Author Support/ Technology Specialist Joe Vetere

puter graphics, gaming, matrix op erations and man y other areas. Studen ts use compiler-comp onen t generators suc h as ANTLR, Lex, and Y acc and the syn tax-directed translation tec hniques discussed in c hapters t w o and v e to build their compilers. A follo w-on graduate course has fo cused on material in Chapters 9 through 12, emphasizing ...

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Compilers: Principles, Techniques, and Tools

1 CompilersSecond EditionPrinciples, Techniques, & ToolsThis page intentionally left blank CompilersSecond EditionPrinciples, Techniques, & ToolsAlfred V. AhoColumbia UniversityMonica S. LamStanford UniversityRavi SethiAvayaJeffrey D. UllmanStanford UniversityPublisher Greg Tobin Executive Editor Michael Hirsch Acquisitions Editor Matt Goldstein Project Editor Katherine Harutunian Associate Managing Editor Jeffrey Holcomb Cover Designer Joyce Cosentino Wells Digital Assets Manager Marianne Groth Media Producer Bethany Tidd Senior Marketing Manager Michelle Brown Marketing Assistant Sarah Milmore Senior Author Support/ Technology Specialist Joe Vetere

2 Senior Manufacturing Buyer Carol Melville Cover Image Scott Ullman of Strange Tonic Productions ( )Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Addison-Wesley was aware of a trademark claim, the designations have been printed in initial caps or all caps. This interior of this book was composed in of Congress Cataloging-in-Publication Data Compilers : principles, techniques, and Tools / Alfred V. Aho .. [et al.]. -- 2nd ed. p.

3 Cm. Rev. ed. of: Compilers, principles, techniques, and Tools / Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman. 1986. ISBN 0-321-48681-1 (alk. paper) 1. Compilers (Computer programs) I. Aho, Alfred V. II. Aho, Alfred V. Compilers, principles, techniques, and Tools . 2007 '53--dc22 2006024333 Copyright 2007 Pearson Education, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher.

4 Printed in the United States of America. For information on obtaining permission for use of material in this work, please submit a written request to Pearson Education, Inc., Rights and Contracts Department, 75 Arlington Street, Suite 300, Boston, MA 02116, fax your request to 617-848-7047, or e-mail at 1 2 3 4 5 6 7 8 9 10 CW 10 09 08 07 06 PrefaceInthetimesincethe1986editionofthi sbook,theworldofcompilerdesignhaschanged signi , ndbugsinsoftware,andmostimportantly, \front-end"technology|grammars,regularex pressions,parsers,andsyntax-directedtran slators| , ,orevenmaintain, ,theory, , rsthalfinanundergraduatecourseandtheseco ndhalfofthebook|stressingcodeoptimizatio n| , ,regularexpressions, nite-statemachines.

5 Top-down(recursive-descent,LL)andbottom- up(LRanditsvariants).Chapter5introducest heprincipalideasinsyntax-directedde , ,generationofcodefromexpressionsandbasic blocks, ,including owgraphs,data- owframeworks, , ,aliasing,anddata- ,Harvard, ,asenior/ rst-yeargraduatecourseonprogram-minglang uagesandtranslatorshasbeenregularlyo eredusingmaterialfromthe ,musicsynthesis,com-putergraphics,gaming , ,Lex,andYaccandthesyntax-directedtransla tiontechniquesdiscussedinchapterstwoand , ,aone-quarterintroductorycoursecoversrou ghlythemate-rialinChapters1through8.

6 Java-basedsystemcalledJoeqforimplementin gdata- \computer-sciencesophistication,"includi ngatleastasecondcourseonprogramming, , ,orstudentsnotenrolledinaclassmayenrolli nan\omnibusclass"thatallowsthemtodotheho meworksasatutorial(withoutaninstructor-c reatedclass).Gradiancequestionslooklikeo rdinaryquestions, ,youareallowedtotryagain, nderrataaswelearnofthem, eringofcompiler-relatedcoursesasweteacht hem,includinghomeworks,solutions, :viiiPREFACED omenicoBianculli,PeterBosch,MarcioBuss,M arcEaddy,StephenEdwards,VibhavGarg,KimHa zelwood,GauravKc,WeiLi,MikeSmith,ArtStam ness,KrystaSvore,OlivierTardieu, , ,Monicawouldliketothankhercolleaguesonth eSUIFcom-pilerteamforan18-yearlessononco mpiling.

7 GeraldAigner,DzintarsAvots,SamanAmarasin ghe,JenniferAnderson,MichaelCarbin,Geral dCheong,AmerDiwan,RobertFrench,AnwarGhul oum,MaryHall,JohnHennessy,DavidHeine,Shi h-WeiLiao,AmyLim,BenjaminLivshits,Michae lMartin,DrorMaydan,ToddMowry,BrianMurphy ,Je reyOplinger,KarenPieper,Mar-tinRinard,Ol atunjiRuwase,ConstantineSapuntzakis,Patr ickSathyanathan,MichaelSmith,StevenTjian g,Chau-WenTseng,ChristopherUnkel,JohnWha ley,RobertWilson,ChristopherWilson, , , , ,StanfordCAJune, ,Patterns, ' ' , rstpos, (1) (0) (1) (1) (1) \Dangling-Else" ' xSDT' ' ' 'sforL-AttributedDe ' ' ' ' ,Continue-, ' neandNona (SOR) ' erOver ' ' ' ' , ,beforeaprogramcanberun,it , ,machinear-chitecture,languagetheory,alg orithms, ,weintroducethedi erentformsoflanguagetranslators,giveahig hleveloverviewofthestructureofatypicalco mpiler, ,acompilerisaprogramthatcanreadaprogrami nonelan-guage|thesourcelanguage|andtrans lateitintoanequivalentprograminanotherla nguage|thetargetlanguage.

8 :AcompilerIfthetargetprogramisanexecutab lemachine-languageprogram,itcanthenbecal ledbytheusertoprocessinputsandproduceout puts; ,aninterpreterappearstodirectlyexecuteth eoperationsspeci edinthesourceprogramoninputssuppliedbyth euser, ,however,canusuallygivebettererrordiagno sticsthanacompiler, :Javalanguageprocessorscombinecompilatio nandinterpreta-tion, tofthisarrangementisthatbytecodescompile dononemachinecanbeinterpretedonanotherma chine, ,someJavacompil-ers,calledjust-in-timeco mpilers, :AhybridcompilerInadditiontoacompiler,se veralotherprogramsmayberequiredtocreatea nexecutabletargetprogram, , ,calledmacros, , ,sotherelocatablemachinecodemayhavetobel inkedtogetherwithotherrelocatableobject lesandlibrary ,wherethecodeinone lemayrefertoalocationinanother :Whatisthedi erencebetweenacompilerandaninterpreter?

9 :Whataretheadvantagesof(a)acompilerovera ninterpreter(b)aninterpreteroveracompile r? :Whatadvantagesaretheretoalanguage-proce ssingsysteminwhichthecompilerproducesass emblylanguageratherthanmachinelanguage? leslibrary lestargetmachinecodeLinker/Loaderrelocat ablemachinecodeAssemblertargetassemblypr ogramCompilermodi , ,thenitmustprovideinformativemessages, , ; ,weseethatitoperatesasasequenceofphases, ,severalphasesmaybegroupedtogether, , :Phasesofacompilerentiresourceprogram, , , ,thelexicalanalyzerproducesasoutputatoke noftheformhtoken-name;attribute-valueith atitpassesontothesubsequentphase, ,the rstcomponenttoken-nameisanabstractsymbol thatisusedduringsyntaxanalysis, ,supposeasourceprogramcontainstheassignm entstatementposition=initial+rate*60( ) ;1i,whereidisanabstractsymbolstandingfor identi erholdsinformationabouttheidenti er, , , ;2i, +isalexemethatismappedintothetokenh+ ;3i, *isalexemethatismappedintothetokenh ( )afterlexicalanalysisasthesequenceoftoke nshid;1ih=ihid;2ih+ihid.

10 3ih ih60i( )Inthisrepresentation,thetokennames=,+,a nd areabstractsymbolsfortheassignment,addit ion,andmultiplicationoperators, ,forthelexeme60weshouldmakeupatokenlikeh number;4i, +rate*60 LexicalAnalyzerhid;1ih=ihid;2ih+ihid;3ih ih60irateid1=id2+t1 CodeGeneratorLDFR2,id3t1=id3* ,R2,# ,id2 ADDFR1,R1,R2 STFid1,R1t3=id2+t2t2=id3*t1t1=inttofloat (60)IntermediateCodeGeneratorSemanticAna lyzerSyntaxAnalyzer3 initial2 position1+=hid;1i+hid;2i60intto oathid;3i hid;2i hid;1i=hid; ( ) +rate* withhid; ;3irepresentstheidenti makesitexplicitthatwemust + ,labeled=,indicatesthatwemuststoretheres ultofthisadditionintothelocationfortheid enti , , , ,manyprogram-minglanguagede nitionsrequireanarrayindextobeaninteger.


Related search queries