Appendix A The BCPL Language

Size: px
Start display at page:

Download "Appendix A The BCPL Language"

Transcription

1 Appendix A The BCPL Language I've used BCPL as the language of illustration throughout most of this book because it is designed as a system-programming language and is especially suited to the special problems of compilerwriting (a recurrent joke is that BCPL is designed as a language in which to write the BCPL compiler!). It is suitable for this purpose mainly because of the ease with which the program can manipulate pointers. In addition it is untyped - all BCPL values are merely treated as 'bitstrings' - so that the program can do just about anything that you might require to do with a pointer. Recursion is efficient in BCPL (see chapter 13). I have taken many liberties with BCPL syntax in examples, mainly inspired by the need to compress complicated algorithms into the space of a single page. I have used if-then-else in place of BCPL's test-then-or for no other reason than the first construction will be more familiar to many users: I have used elsf because it abbreviates the programs. I have used dot-suffix notation 'nodep.x' rather than 'nodep!x' or 'xanodep' because I believe it will be more familiar to many readers. Apologies to BCPL fanatics (and to BCPL's designer>, but I defend myself by saying that my task is to explain compiler algorithms, not the syntax of BCPL. In what follows I explain only those portions of BCPL (and pseudo-bcpl) which I have used in examples. The language is much more powerful and elegant than I have made it seem - I commend its use to all readers. Statements BCPL provides several forms of iterative and conditional statements. In general, if there are two uses for a statement, BCPL provides two different syntaxes hence while, until, repeatwhile, repeatuntil and repeat are all provided in BCPL. Semicolons aren't usually needed to separate statements, although I have used them where one statement follows another on a single line. The then or do symbol is usually unnecessary, but I have

2 382 Understanding and Writing Compilers generally included it to avoid confusing those readers unused to the language. 1. Assignment statement: <lhs-exprlist> := <exprlist> The <lhsexpr>s can be <name> <expr>!<expr>!<expr> <name>.<name> 2. Procedure call: <expr><> <expr><<exprlist>) - BCPL makes you indicate parameterless procedures by showing an empty parameter list; there is only call-by-value. 3. Iterative statements: while <expr> do <statement> until <expr> do <statement> <statement> repeat <statement> repeatwhile <expr> <statement> repeatuntil <expr> Test is either before execution of <statement> (while, until) or after execution of statement <repeat, repeatwhile, repeatuntil>. 4. Selection of cases: switchon <expr> into <statement> The <statement> must case <constant>: or default:. contain case labels of the case <constant> <constant>: form or 5. Conditional statement (not strict BCPL): if <expr> then <statement> if <expr> then <statement> else <statement> if <expr> then <statement> elsf <expr> then 6. Compound statements: { <statement>* } { <declaration>* <statement>* } 7. Control statements: break - exit from current iterative statement Loop - end present iteration of current iterative statement endcase - exit from current switchon statement

3 Appendix A: The BCPL Language 383 Declarations 8. Variable declarations: let <namelist> = <exprlist> 9. Procedures and functions: let <name>() be <statement> let <name>(<namelist>) be <statement> let <name>() = <expr> let <name><<namelist>) = <expr> Note that the <expr> in a function declaration is usually a valof expression. Expressions There are many kinds of BCPL operator, both binary and unary. I have assumed that all unary operators have the highest priority, that arithmetic operators come next with their conventional priorities, relational operators next, and finally Logical operators. In cases of confusion I've used brackets. Conditional expressions have the Lowest priority. In translation examples I have used an invented operator: the '++' operator which takes a string and appends a character. It is quite unrealistic, but I hope you see what it means. 10. Value of a statement: valof <statement> The <statement> must contain a resultis <expr> statement 11. Unary I* address-of *I!<expr> I* contents-of *I +<expr>, -<expr> I* unary integer arithmetic *I \ <expr> I* Logical 'not' *I 12. Function calls: <expr>() <expr>(<exprlist>) 13. Binary operators: <expr>!<expr> <expr>.<name> +, -,*,I, rem <, <=, =, \=, >=, > &, I ++ I* subscript operator *I I* field-select operator *I I* integer arithmetic *I I* integer relations *I I* Logical 'and' and 'or' *I I* string concatenation *I 'V!n' is similar to V(n] in most other Languages, 'P.a' is

4 384 Understanding and Writing Compilers similar to SIMULA 67's P.a, PASCAL's PA.a and ALGOL 68's a of P. 14. Conditional expressions: <expr0> -> <expr1>, <expr 2> If the value of <expro> is true then <expr1> is evaluated: otherwise <expr 2> is evaluated.

5 Appendix B Assembly Code Used in Examples I have been consistent in using a single-address, multi-register machine as my illustration in examples. The code format is: <operation-code> <register-number>, <address> where an address is either a <number> or <number>(<register>) Examples: JUMPFALSE 1, 44 ADD 1, 3217(7) ADDr 5, 2.. Any register may be used as an address modifier or as an accumulator. There are a fixed number of registers (the exact number doesn't matter). Sometimes (e.g. JUMP) the register doesn't matter and is omitted, sometimes (e.g. FIXr) the address is omitted I find it best to divide instructions into different groups distinguished by a Lower-case Letter at the end of the operation code. This makes Logically different operations, which on many real machines are implemented by widely differing instructions, visually distinct. The suffixes are: - no suffix means a store-to-register operation STORE, which is of course register-to-store) (except - 'r' means register-to-register - 's' means register-to-store 'n' means the <address> part is to be interpreted as a number 'a' means the <address> part is to be interpreted as an address - this may seem just Like 'n' but on some machines it isn't! - 'i' means indirect addressing- the memory cell addressed contains the actual address to be used in the instruction.

6 386 Understanding and Writing Compilers Examples of the differences: ADD 1, 2 means add the contents of store Location 2 to register 1 AD Dr 1, 2 means add the contents of register 2 to register 1 ADDs 1, 2 means add the contents of register 1 to store Location 2 ADDn 1, 2(4) means add the number which is formed by adding 2 and the contents of register 4, to register ADD a 1, 2(4) means add the address which is formed by combining 2 and the contents of register 4, to register 1 I hope the instruction-names are fairly indicative of their operation. In the examples I've mostly used LOAD, STORE, JSUB, SKIP?? and the arithmetic operations. Here is a table which may clarify matters: Instruction LOAD STORE INCRST DECRST STOZ STOO INCSKP DECSKP ADD SUB NEGr MULT DIV (I have used analogue of denotes the FIXr FLOATr Explanation place a value in a register place a value in a memory cell add one to store Location subtract one from store Location set all bits in store Location to zero set all bits in store Location to one increment store Location; skip next instruction if result is zero decrement store Location; skip next instruction if result is zero add two values subtract one value from another negate value in register multiply two values divide one value by another fadd, fsub etc. to denote the floating-point these instructions. Likewise xsub, xdiv etc. 'exchanged' or 'reverse' variant - see chapter 5) convert floating point number in register to fixed-point convert fixed point number in register to floating point

7 Appendix B: Assembly code used in examples 387 SKIP SKIPLT SKIPLE SKIPNE SKIPEQ SKIPGE SKIPGT JUMP JUMPLT JUMPLE JUMPNE JUMPEQ JUMPGE JUMPGT JUMPTRUE JUMPFALSE jump over the next instruction jump over the next instruction if register value is less than (LT) store value ditto, but relation is 'Less or equal' ditto, but relation is 'not equal' ditto, but relation is 'equal' ditto, but relation is 'greater or equal' ditto, but relation is 'greater than' transfer control to indicated address transfer control only if register value is less than (LT) zero ditto, but if less than or equal to zero ditto, but if not equal to zero ditto, but if equal to zero ditto, but if greater than or equal to zero ditto, but if greater than zero transfer control if register contains special TRUE value ditto, but for FALSE value JSUB L, a transfer control to indicated address, storing address of next instruction (return address) in register RETN, a return to indicated address PUSH p, a POP p, a transfer contents of address a to top of stack indicated by register p, increase p decrement stack pointer p, transfer contents of top of stack to address a PUSHSUB, POPRETN analogous to JSUB, RETN but link address is on the stack rather than in a register. INC p, a DEC p, a add contents of Location a to stack register p and check that p is not outside bounds of stack space subtract contents of location a from stack pointer and check limits of stack. Some of the instructions in this list may seem to have the same effect as others, but I have in general included an instruction for each simple machine-code operation which I have needed to illustrate. Using such a Large instruction set makes my task easier than it would otherwise be, of course, but some real machines have larger sets still (e.g. the DEC PDP-10). I've never yet seen a machine with a SKIPTRUE or a JUMPTRUE instruction, given that TRUE is to be represented as a specific non-zero bit pattern, but I have felt the need for it in practice!

8 Bibliography The most important item in a compiler-writing bibliography isn't referenced here: it is a compiler, which should be written in a system programming language to compile some language which you know fairly well. Reading such a compiler will clarify many of the points which are made in this book. If you can get hold of the source code of any compiler on your machine then don't be ashamed to read it and don't be ashamed to copy algorithms from it if that will save you time. A good compiler to look out for is that for BCPL: most versions of the BCPL compiler are based on the original written by Martin Richards. Books and papers referenced in the text above are: Aho A.V., Ullman J.D. (1978) "Principles of Design", Addison-Wesley. Compiler Aho A.V., Johnson S.C. (1974> "LR parsing", Computing Surveys 6, 1, pp Baker H. (1978> "List Processing in Real Time on a Serial Computer" Comm. ACM 21, 4, pp Brooker R.A., MacCallum I.R., Morris D., Rohl "The compiler-compiler", Annual Review Programming 3, pp J.S. <1963) of Automatic Dijkstra E.W., Lamport L., Martin A.J., Scholten C.S.and Steffens E.F.M. (1978> "On-the-Fly Garbage Colle.ction: An Exercise in Cooperation", Comm. ACM 21, 11, pp Foster J.M. (1968) "A Syntax Improving Device", Computer J, 11,1, pp Geschke C.M. <1972> "Global Program Optimizations", Ph.D. thesis, Carnegie-Mellon University

9 Bibliography 389 Gries D. <1971) "Compiler Construction Computers", John Wiley, for Digital Horning J.J. (1974) "LR parsing", in Bauer et al., "Compiler Construction - An advanced course", Springer-Verlag. Hunter R.B., McGettrick A.D., Patel R. (1977) "LL versus LR parsing with illustrations from ALGOL 68", SIGPLAN notices 12, 6, pp Irons E. T. (1961) "An error-correcting parse algorithm", Comm. ACM, 4,1 pp Knuth D.E. <1971> "An Empirical Study of FORTRAN programs", Software - Practice and Experience, 1, 2, pp Knuth D.E. <1965) "On the Parsi11g of Languages from Left to Right", Information and Control 8, 6, pp Landin P.J. (1965) "A Correspondence between ALGOL 60 and Church's Lambda-Notation", Comm ACM 8,2 and 8,3, pp and McCarthy et al. (1965) "LISP 1.5 Programmer's Manual", MIT Press, Rohl J.S. (1975) "An Introduction to Compiler Writing", MacDonald and Janes, Reynolds J.C. (1972> "Definitional Interpreters for higherorder programming languages", Proc 27th ACM National Conf, Steele G.L. (1977) "Arithmetic Shifting Considered Harmful", SIGPLAN notices, 12, 11, pp Weizenbaum J. (1977) "Computer Power and Human Reason", Freema11, San Francisco. Wichmann B.A. (1975) "Ackerma11n's function, a study efficiency of calling procedures", National Laboratory report. in the Physical Wulf W., Johnsson R.K., Weinstock C.B., Hobbs S.O. (1973), "The design of an optimizing compiler", Computer Science Dept. Technical Report, Carnegie-Mellon University (published in modified form under the same title by American Elsevier, 1975).

10 Index

11 Index 391 Accessible state 337 accurate optimisation 155 action procedure 272, 305, 346 activation record 244 activation record structure 14, 72, 182, 193, 359 address calculation 136 address protection 202 address vector 141, 144 advantage of optimisation 158 ALGOL 60 ambiguity 265 ALGOL 68 ref 191, 228, 239 ALGOL 68 struct 148 ambiguity 263, 267 ambiguous grammar 264 analysis 9 argument check 182 argument information 196, 200 argument passing 198 argument preparation 183, 195 arithmetical code fragment 77 array array array array access as argument as result bounds check array array array space allocation declaration assembly code debugger assignment statement associative memory atype field auto-coder , 141, , , automatic error recovery 344, 347 Backtracking 52, 251, 286, 289, 290 Backus-Naur form basic block BCPL ambiguity binary chop Lookup block block entry block exit block Level addressing block structure 131, BNF Boolean 'and' Boolean 'not' Boolean 'or' Boolean constant , 282, , , Boolean operation Boolean operator Boolean variable bottom-up analysis branch break point break statement Burroughs B6500 Cache memory call by name call by need call by reference call by result call by value CDC 7600 character code character input Chomsky Chomsky hierarchy class class-item closure clustering co-processing COBOL data hierarchy code filter code motion code optimisation code refinement code region coding , , , 215, 235, , , 162, , collision 123, 124 comment stripping 64 common sub-expression 156, 166 compact code 179 compile-time error 15 compiler-compiler completed item 306, compound statement 114 conditional expression 103 conditional operation 95 conformity clause 151 consolidator 66 constant evaluation 163 constant folding 162, 163 constant nationalisation 128 constant table 128 context clash 290, 291, 292, 320 context dependence 347 context dependent syntax 274

12 392 Understanding and Writing Compilers context free grammar context-sensitive grammar control context control flow control state cost of development 157, 158, 351 cost of interpretation cost of optimisation cost of procedure call 183, 187, 200, 229, 230, CRAY cross reference listing 122 crucial code fragment 37, 75, 136, 151, 153, 231 Dangling pointer 237, 239 data frame 129, 139, 180 data structure 34, 136 debugging language 377 declarative program 174 deep binding 365, 366 deferred storage 162, 164 derivation 257, 262 derivation tree 257 derived 262 directly derive 262 display 219 DO nest 113 DO statement 111 dope vector 137, 143 dump location 84 dynamic array 189, 226 dynamic binding 365 Effective environment 243 efficiency 60 efficiency of compilation 56, 123 efficient object program 351 emulator environment , 229, , 210, 211, 231, environment addressing 210 environment link 216 environment representation 213 environment support 177 epilogue 117, 183, 190 equivalent grammar 263, 264 error checking code 143, 146 error correction 52, 297 error detection 52, 295, 301, 312, 316, 318 error handling 15, 35, 52, 64, 295, 308, 344 error recognition 286, 289 error recovery 52, 287, 297, 306, 346 error reporting 52, 287, 289, 295, 299, 344 error-checking code 140 essential order 160 event tracing 378 eventually derive 262 examination 249, 285 experimental programming 356 expression analysis 301 F register factoring finite state FIRST* list FIRST+ list FIRSTOP list 178, 1e8, 202, 232 machine fixed-size array fixed-size vector fixup fixup chain Flabe l follower list for statement , , , , , 68, 69 forking 331, 333, FORTRAN array access FORTRAN environment forward reference function function function 69, call in expression 88 side-effect 156, 167 Garbage collection 182, 191, 234, 236, 239, 244 generative grammar global data access GOTO goto statement grammar 40, 42, 255, Hacking hardware design hash addressing hash chaining hash key heap , , , 148

13 heap compaction 236 heap fragmentation 236 heap space allocation 236 heap space reclamation 236 heap storage 191, 228, 234, 235, 245 hierarchical qualification 131 ICL 2900 identifier item Iliffe vector imitative interpreter in-core compiler incomplete specification , , , 357 Index 70 indirect Left recursion 285 initial order 160 inner Loop 123, 157 input conversion 56 input filter 320 input state 318, 320 interactive debugging 377 interpretation 171 interpreter 354 item 57 item code 63 item description 62 item representation 62, 119 Jumping code 94, 97, 100,101 Keyword 64, 119, 127 keyword recognition 63 L register 178 Label address 130 Label as argument 191, 226 Label fixup 69 Labelled statement 301 LALR(1) analysis 340 LALR (1 ) state 342 Language 254 Language design 173, 365 Language restriction 155, 180, 182, 228, 235 LASTOP list 311 Lazy evaluation 197 Leaf 25 Left context 326 Left derivation 326, 344 Left recursion 263, 281, 333 Lexical analyser generator 272 Lexical Lexical Library Lifetime analysis error Line reconstruction Line-by-Line input Linearising interpreter Linking Linking Loader LISP compilation Listing LL(1) analysis LL <1) Language Load-time allocation Load-time check Load-time error handling Loader Loader efficiency Long identifier Long-range syntax Lookahead set Loop statement Loop-invariant code LR table encoding LR (Q) closure LR (Q) item LR (Q) state LR(0) table LR (1) analysis LR(1> item LR (1) Language LR (1) reduction LR(1> state LR(k) analysis LR (k) stack Macro processing micro-process microprocessor microprogram mixed-type expression mpsd 11, 239, , , , , , , 88, 146, MUS 172, multi-pass compilation multi-word result multiple descriptors multiplicative array access mutual recursion 203, N-ary node name argument name item ,

14 394 Understanding and Writing Compilers name tree lookup naming store nested procedure call 199, 230, net effect 158 node 25 node reversal 156 non-local data access 213, 217, 220, 226, 231 non-local goto 227 non-recursive procedure 188 non-terminal symbol 259 null symbol 278, 284 Object description 13, 33, 115, 128, 139, 147, 203 object descriptor 118 object program efficiency 178, 228 off-line debugging on-line debugging one-pass compiling one-symbol-look-ahead one-track one-track grammar one-track interpreter operator grammar operator precedence operator priority 43, operator-precedence optimisation 12, 22, 111, 145, 153 optimisation from code optimisation from the tree option in production order of computation order of evaluation 103, output conversion overhead 115, 117, 195, 230, 240, overlay allocation Panic dump parallel analysis , , , , 183, 244 parameter conversion parameter information parse tree parser generator parser transcriber parsing PASCAL record , , , , , passing argument information 197 peephole optimisation permissive analyser phase of compilation phrase phrase structure piecemeal development plagiarism pointer pointer lifetime pointer map pointer variable POP instruction Post postcall fragment 183, 190, 234, 243 postfix postfix string precall fragment 183, 190, precedence matrix pretty-printer printint procedure , , 235 procedure procedure activation 14, 180, 188, procedure address 130 procedure as argument 191, 218, 220 procedure call 177, 180, 228, 229 procedure declaration 116 procedure entry 117 procedure exit 117 procedure level addressing 178, 210, 225, 238 procedure return 177, 180, 181, 228 procedure tracing 378 process record structure 363 production 256, 259 program input 57 prologue 117, 183, 190, 204 PUSH instruction 229 Quadruple Re-hashing recognition record record access record vector 38, , ,

15 Index 395 record-type declaration 147 recursion 177 recursive operator precedence 322 recursive procedure reduce reduce-reduce conflict reduction 310, redundant code 162, reference argument region register allocation 165 register dumping regular grammar relational expression relational operator relocatable binary relocating relocation relocation counter repetition in production resultis statement return statement reverse operation reverse Polish right derivation right recursion root , , , , , 164, 94, , , 284, run-time address 129, run-time argument check 186, 195 run-time argument checking 203 run-time check 193, 200, 243 run-time debugging 66, 69, 193, 221, 238, 355, 356, 359, 366, 373 run-time editing 368 run-time error 16, 140 run-time support 13, 72, 177, 228 Scanner generator scope searchmaze procedure secondary error secondary error report self embedding symbol self-embedding symbol semantics sentence sente11ce symbol , , , sentential form 259, separate compilatio11 203, sequential table Lookup shallow binding 365, shift shift-reduce conflict short-range syntax shunting algorithm SID simple precedence simple translation simple-item SIMULA 67 class single-pass compilation SLR(1) analysis SLR(1) reduction soft machine 172, spelling correctio11 spelling error stack allocation stack checking , , , , , 203 stack extensio11 stack handling 188, 197, 228, 229, 231 stack searching state-transition table static allocation 130, static binding storage compaction 236, storage fragmentatio11 store access store shadowing strength reduction stri11g walking structure editing structured program structured statement sub-optimisation 31, 154, subroutine Library successor state switch procedure symbol table 10, 22, 64, 118, 147, 148 symbol table descriptor 118, 128 syntax syntax analysis syntax graph system programming , , 240 T register 188, 193, 199, 202, 229, 233

16 396 U~derstanding and Writing Compilers table Lookup temporary Location terminal symbol textual Level textual scope thunk Habel top-down a~alysis 42, 48, 249, 277 top-dow~ interpreter 303 TranAddress procedure TranAnd procedure TranArg procedure 200, 204 TranArithExpr procedure Tra~AssignStat procedure TranBinOp procedure 78, 79, 85, 91 TranBLock procedure 114, 133 TranBooLExpr procedure 98, 101, 103 TranCompoundStat procedure 114 TranCondExpr procedure 103 TranDecl procedure 114, 115 TranForStat procedure 110 TranlfStatement procedure 98 TranLeaf procedure 79 Tra~LoopStat procedure 107 TranProcCall procedure 199 TranProcDecl procedure 117, 133 TranRecAccess procedure 148 TranRelation procedure 100 TranResultisStat procedure 117 TranReturnStat procedure 117 transition matrix 321 translation 10 TranStatement procedure 109 TranVecAccess procedure 137 TranWhileStat procedure 107 tree building 313, 344 tree output 38, 50 tree representation 25 tree walking 22, 25 tree weighting 84 triple 38, 45, 313 two Level grammar 274 two-pass compilation 17 two-pass compiling 203, 206 type 34, 48, 91, 128 type 0 grammar 259 type 1 grammar 260 type 2 grammar 260 type 3 grammar 260, 268 type checking 92, 148 Unambiguous grammar 267, 293, 295, 318, 343 unary operator 312, 313, 318, 320 undefined value 376 union type 151 Value argument 196, 200 van Wijngaarden grammar 274 variant field 151 variant record 151 vector 136 vector access 136 vector argument 141, 201 vector bounds check 140 vector declaration vector processi~g vector space allocation 191 Warshall's algorithm 272 weighted tree where declaration while statement 107

Understanding and Writing Compilers

Understanding and Writing Compilers Understanding and Writing Compilers Macmillan Computer Science Series Consulting Editor Professor F. H. Sumner, University of Manchester G. M. Birtwistle, Discrete Event Modelling on Simula Richard Bornat,

More information

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1 Table of Contents About the Authors... iii Introduction... xvii Chapter 1: System Software... 1 1.1 Concept of System Software... 2 Types of Software Programs... 2 Software Programs and the Computing Machine...

More information

Appendix A The DL Language

Appendix A The DL Language Appendix A The DL Language This appendix gives a description of the DL language used for many of the compiler examples in the book. DL is a simple high-level language, only operating on integer data, with

More information

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program. COMPILER DESIGN 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the target

More information

VIVA QUESTIONS WITH ANSWERS

VIVA QUESTIONS WITH ANSWERS VIVA QUESTIONS WITH ANSWERS 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the

More information

PRINCIPLES OF COMPILER DESIGN

PRINCIPLES OF COMPILER DESIGN PRINCIPLES OF COMPILER DESIGN 2 MARK QUESTIONS WITH ANSWERS UNIT I 1. What is a Complier? A Complier is a program that reads a program written in one language-the source language-and translates it in to

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More information

CST-402(T): Language Processors

CST-402(T): Language Processors CST-402(T): Language Processors Course Outcomes: On successful completion of the course, students will be able to: 1. Exhibit role of various phases of compilation, with understanding of types of grammars

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

SYLLABUS UNIT - I UNIT - II UNIT - III UNIT - IV CHAPTER - 1 : INTRODUCTION CHAPTER - 4 : SYNTAX AX-DIRECTED TRANSLATION TION CHAPTER - 7 : STORA

SYLLABUS UNIT - I UNIT - II UNIT - III UNIT - IV CHAPTER - 1 : INTRODUCTION CHAPTER - 4 : SYNTAX AX-DIRECTED TRANSLATION TION CHAPTER - 7 : STORA Contents i SYLLABUS UNIT - I CHAPTER - 1 : INTRODUCTION Programs Related to Compilers. Translation Process, Major Data Structures, Other Issues in Compiler Structure, Boot Strapping and Porting. CHAPTER

More information

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised: EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 2017-09-11 This lecture Regular expressions Context-free grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)

More information

Syntax Analysis, VII One more LR(1) example, plus some more stuff. Comp 412 COMP 412 FALL Chapter 3 in EaC2e. target code.

Syntax Analysis, VII One more LR(1) example, plus some more stuff. Comp 412 COMP 412 FALL Chapter 3 in EaC2e. target code. COMP 412 FALL 2017 Syntax Analysis, VII One more LR(1) example, plus some more stuff Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon,

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

More information

Principles of Programming Languages [PLP-2015] Detailed Syllabus

Principles of Programming Languages [PLP-2015] Detailed Syllabus Principles of Programming Languages [PLP-2015] Detailed Syllabus This document lists the topics presented along the course. The PDF slides published on the course web page (http://www.di.unipi.it/~andrea/didattica/plp-15/)

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

More information

Appendix Set Notation and Concepts

Appendix Set Notation and Concepts Appendix Set Notation and Concepts In mathematics you don t understand things. You just get used to them. John von Neumann (1903 1957) This appendix is primarily a brief run-through of basic concepts from

More information

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

Compiler Design Aug 1996

Compiler Design Aug 1996 Aug 1996 Part A 1 a) What are the different phases of a compiler? Explain briefly with the help of a neat diagram. b) For the following Pascal keywords write the state diagram and also write program segments

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

CS606- compiler instruction Solved MCQS From Midterm Papers

CS606- compiler instruction Solved MCQS From Midterm Papers CS606- compiler instruction Solved MCQS From Midterm Papers March 06,2014 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 Final Term MCQ s and Quizzes CS606- compiler instruction If X is a

More information

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-00 014 Subject: PPL Class : CSE III 1 P a g e DEPARTMENT COMPUTER SCIENCE AND ENGINEERING S No QUESTION Blooms Course taxonomy level Outcomes UNIT-I

More information

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI UNIT I - LEXICAL ANALYSIS 1. What is the role of Lexical Analyzer? [NOV 2014] 2. Write

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

Question Bank. 10CS63:Compiler Design

Question Bank. 10CS63:Compiler Design Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a

More information

Intermediate Representations

Intermediate Representations COMP 506 Rice University Spring 2018 Intermediate Representations source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701) Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov 2014 Compiler Design (170701) Question Bank / Assignment Unit 1: INTRODUCTION TO COMPILING

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics ISBN Chapter 3 Describing Syntax and Semantics ISBN 0-321-49362-1 Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Copyright 2009 Addison-Wesley. All

More information

Lexical and Syntax Analysis. Top-Down Parsing

Lexical and Syntax Analysis. Top-Down Parsing Lexical and Syntax Analysis Top-Down Parsing Easy for humans to write and understand String of characters Lexemes identified String of tokens Easy for programs to transform Data structure Syntax A syntax

More information

CS5363 Final Review. cs5363 1

CS5363 Final Review. cs5363 1 CS5363 Final Review cs5363 1 Programming language implementation Programming languages Tools for describing data and algorithms Instructing machines what to do Communicate between computers and programmers

More information

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996. References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapter 5 of Programming languages: Concepts

More information

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Topic IV. Block-structured procedural languages Algol and Pascal. References: References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 10( 2) and 11( 1) of Programming

More information

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation Comp 204: Computer Systems and Their Implementation Lecture 22: Code Generation and Optimisation 1 Today Code generation Three address code Code optimisation Techniques Classification of optimisations

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]

More information

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous. Section A 1. What do you meant by parser and its types? A parser for grammar G is a program that takes as input a string w and produces as output either a parse tree for w, if w is a sentence of G, or

More information

Programming Language Syntax and Analysis

Programming Language Syntax and Analysis Programming Language Syntax and Analysis 2017 Kwangman Ko (http://compiler.sangji.ac.kr, kkman@sangji.ac.kr) Dept. of Computer Engineering, Sangji University Introduction Syntax the form or structure of

More information

Languages and Compilers

Languages and Compilers Principles of Software Engineering and Operational Systems Languages and Compilers SDAGE: Level I 2012-13 3. Formal Languages, Grammars and Automata Dr Valery Adzhiev vadzhiev@bournemouth.ac.uk Office:

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing

More information

Torben./Egidius Mogensen. Introduction. to Compiler Design. ^ Springer

Torben./Egidius Mogensen. Introduction. to Compiler Design. ^ Springer Torben./Egidius Mogensen Introduction to Compiler Design ^ Springer Contents 1 Lexical Analysis 1 1.1 Regular Expressions 2 1.1.1 Shorthands 4 1.1.2 Examples 5 1.2 Nondeterministic Finite Automata 6 1.3

More information

Stating the obvious, people and computers do not speak the same language.

Stating the obvious, people and computers do not speak the same language. 3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what

More information

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

UNIT-II. Part-2: CENTRAL PROCESSING UNIT Page1 UNIT-II Part-2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:

More information

Garbage In/Garbage SIGPLAN Out

Garbage In/Garbage SIGPLAN Out COMFY A Comfortable Set of Control Primitives for Machine Language Programming Author: Henry G. Baker, http://home.pipeline.com/ hbaker1/home.html; hbaker1@pipeline.com Henry G. Baker 1 Laboratory for

More information

Wednesday, September 9, 15. Parsers

Wednesday, September 9, 15. Parsers Parsers What is a parser A parser has two jobs: 1) Determine whether a string (program) is valid (think: grammatically correct) 2) Determine the structure of a program (think: diagramming a sentence) Agenda

More information

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs: What is a parser Parsers A parser has two jobs: 1) Determine whether a string (program) is valid (think: grammatically correct) 2) Determine the structure of a program (think: diagramming a sentence) Agenda

More information

LECTURE NOTES ON COMPILER DESIGN P a g e 2

LECTURE NOTES ON COMPILER DESIGN P a g e 2 LECTURE NOTES ON COMPILER DESIGN P a g e 1 (PCCS4305) COMPILER DESIGN KISHORE KUMAR SAHU SR. LECTURER, DEPARTMENT OF INFORMATION TECHNOLOGY ROLAND INSTITUTE OF TECHNOLOGY, BERHAMPUR LECTURE NOTES ON COMPILER

More information

COMPILERS BASIC COMPILER FUNCTIONS

COMPILERS BASIC COMPILER FUNCTIONS COMPILERS BASIC COMPILER FUNCTIONS A compiler accepts a program written in a high level language as input and produces its machine language equivalent as output. For the purpose of compiler construction,

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA. R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is

More information

MIDTERM EXAM (Solutions)

MIDTERM EXAM (Solutions) MIDTERM EXAM (Solutions) Total Score: 100, Max. Score: 83, Min. Score: 26, Avg. Score: 57.3 1. (10 pts.) List all major categories of programming languages, outline their definitive characteristics and

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

UNIT 3

UNIT 3 UNIT 3 Presentation Outline Sequence control with expressions Conditional Statements, Loops Exception Handling Subprogram definition and activation Simple and Recursive Subprogram Subprogram Environment

More information

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing Roadmap > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing The role of the parser > performs context-free syntax analysis > guides

More information

Chapter 3. Describing Syntax and Semantics

Chapter 3. Describing Syntax and Semantics Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings of Programs:

More information

Context-free grammars

Context-free grammars Context-free grammars Section 4.2 Formal way of specifying rules about the structure/syntax of a program terminals - tokens non-terminals - represent higher-level structures of a program start symbol,

More information

Language Reference Manual simplicity

Language Reference Manual simplicity Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

More information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4303 April 9, 2010 14.00-15.30 This exam (6 pages) consists of 52 True/False

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Lecture 7: Deterministic Bottom-Up Parsing

Lecture 7: Deterministic Bottom-Up Parsing Lecture 7: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Tue Sep 20 12:50:42 2011 CS164: Lecture #7 1 Avoiding nondeterministic choice: LR We ve been looking at general

More information

Understanding and Writing Compilers

Understanding and Writing Compilers Understanding and Writing Compilers A do-it-yourself guide Richard Bornat Middlesex University, London. richard@bornat.me.uk First published 1979. Internet edition 2007; corrected 2008. Copyright c 1979,

More information

Syntax Analysis Part I

Syntax Analysis Part I Syntax Analysis Part I Chapter 4: Context-Free Grammars Slides adapted from : Robert van Engelen, Florida State University Position of a Parser in the Compiler Model Source Program Lexical Analyzer Token,

More information

Principles of Programming Languages COMP251: Syntax and Grammars

Principles of Programming Languages COMP251: Syntax and Grammars Principles of Programming Languages COMP251: Syntax and Grammars Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong, China Fall 2007

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:

More information

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 20 Intermediate code generation Part-4 Run-time environments

More information

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram CS6660 COMPILER DESIGN Question Bank UNIT I-INTRODUCTION TO COMPILERS 1. Define compiler. 2. Differentiate compiler and interpreter. 3. What is a language processing system? 4. List four software tools

More information

3.5 Practical Issues PRACTICAL ISSUES Error Recovery

3.5 Practical Issues PRACTICAL ISSUES Error Recovery 3.5 Practical Issues 141 3.5 PRACTICAL ISSUES Even with automatic parser generators, the compiler writer must manage several issues to produce a robust, efficient parser for a real programming language.

More information

Monday, September 13, Parsers

Monday, September 13, Parsers Parsers Agenda Terminology LL(1) Parsers Overview of LR Parsing Terminology Grammar G = (Vt, Vn, S, P) Vt is the set of terminals Vn is the set of non-terminals S is the start symbol P is the set of productions

More information

Single-pass Static Semantic Check for Efficient Translation in YAPL

Single-pass Static Semantic Check for Efficient Translation in YAPL Single-pass Static Semantic Check for Efficient Translation in YAPL Zafiris Karaiskos, Panajotis Katsaros and Constantine Lazos Department of Informatics, Aristotle University Thessaloniki, 54124, Greece

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

More information

DEMO A Language for Practice Implementation Comp 506, Spring 2018

DEMO A Language for Practice Implementation Comp 506, Spring 2018 DEMO A Language for Practice Implementation Comp 506, Spring 2018 1 Purpose This document describes the Demo programming language. Demo was invented for instructional purposes; it has no real use aside

More information

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table SYMBOL TABLE: A symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating

More information

4. An interpreter is a program that

4. An interpreter is a program that 1. In an aboslute loading scheme, which loader function is accomplished by programmer? A. Allocation B. LInking C. Reallocation D. both (A) and (B) 2. A compiler program written in a high level language

More information

Compiler Design Overview. Compiler Design 1

Compiler Design Overview. Compiler Design 1 Compiler Design Overview Compiler Design 1 Preliminaries Required Basic knowledge of programming languages. Basic knowledge of FSA and CFG. Knowledge of a high programming language for the programming

More information

LECTURE 18. Control Flow

LECTURE 18. Control Flow LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a

More information

Programming Language Specification and Translation. ICOM 4036 Fall Lecture 3

Programming Language Specification and Translation. ICOM 4036 Fall Lecture 3 Programming Language Specification and Translation ICOM 4036 Fall 2009 Lecture 3 Some parts are Copyright 2004 Pearson Addison-Wesley. All rights reserved. 3-1 Language Specification and Translation Topics

More information

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B. CSE 3302 Test 1 1. Preprocessor macros are associated with: A. C B. Java C. JavaScript D. Pascal 2. (define x (lambda (y z) (+ y z))) is an example of: A. Applying an anonymous function B. Defining a function

More information

CS 415 Midterm Exam Spring SOLUTION

CS 415 Midterm Exam Spring SOLUTION CS 415 Midterm Exam Spring 2005 - SOLUTION Name Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you

More information

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

SEMANTIC ANALYSIS TYPES AND DECLARATIONS SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether

More information

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given MUHAMMAD FAISAL MIT 4 th Semester Al-Barq Campus (VGJW01) Gujranwala faisalgrw123@gmail.com MEGA File Solved MCQ s For Final TERM EXAMS CS508- Modern Programming Languages Question No: 1 ( Marks: 1 ) -

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad -500 043 INFORMATION TECHNOLOGY TUTORIAL QUESTION BANK Name : PRINCIPLES OF PROGRAMMING LANGUAGES Code : A40511 Class : II B. Tech

More information

3. Parsing. Oscar Nierstrasz

3. Parsing. Oscar Nierstrasz 3. Parsing Oscar Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes. http://www.cs.ucla.edu/~palsberg/ http://www.cs.purdue.edu/homes/hosking/

More information

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input. flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input. More often than not, though, you ll want to use flex to generate a scanner that divides

More information

Lecture 8: Deterministic Bottom-Up Parsing

Lecture 8: Deterministic Bottom-Up Parsing Lecture 8: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Fri Feb 12 13:02:57 2010 CS164: Lecture #8 1 Avoiding nondeterministic choice: LR We ve been looking at general

More information

Principles of Compiler Design

Principles of Compiler Design Principles of Compiler Design Intermediate Representation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Unambiguous Program representation

More information

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms

More information

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d) CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known.

Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known. SEMANTIC ANALYSIS: Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known. Parsing only verifies that the program consists of tokens

More information

Using an LALR(1) Parser Generator

Using an LALR(1) Parser Generator Using an LALR(1) Parser Generator Yacc is an LALR(1) parser generator Developed by S.C. Johnson and others at AT&T Bell Labs Yacc is an acronym for Yet another compiler compiler Yacc generates an integrated

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl Compilerconstructie najaar 2013 http://www.liacs.nl/home/rvvliet/coco/ Rudy van Vliet kamer 124 Snellius, tel. 071-527 5777 rvvliet(at)liacs(dot)nl college 1, dinsdag 3 september 2013 Overview 1 Why this

More information

Lexical and Syntax Analysis

Lexical and Syntax Analysis Lexical and Syntax Analysis (of Programming Languages) Top-Down Parsing Lexical and Syntax Analysis (of Programming Languages) Top-Down Parsing Easy for humans to write and understand String of characters

More information

Time : 1 Hour Max Marks : 30

Time : 1 Hour Max Marks : 30 Total No. of Questions : 6 P4890 B.E/ Insem.- 74 B.E ( Computer Engg) PRINCIPLES OF MODERN COMPILER DESIGN (2012 Pattern) (Semester I) Time : 1 Hour Max Marks : 30 Q.1 a) Explain need of symbol table with

More information

ICOM 4036 Spring 2004

ICOM 4036 Spring 2004 Language Specification and Translation ICOM 4036 Spring 2004 Lecture 3 Copyright 2004 Pearson Addison-Wesley. All rights reserved. 3-1 Language Specification and Translation Topics Structure of a Compiler

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Qualifying Exam in Programming Languages and Compilers

Qualifying Exam in Programming Languages and Compilers Qualifying Exam in Programming Languages and Compilers University of Wisconsin Fall 1991 Instructions This exam contains nine questions, divided into two parts. All students taking the exam should answer

More information

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail. Code No: R05320502 Set No. 1 1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail. 2. Construct predictive parsing

More information

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised: EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing Görel Hedin Revised: 2017-09-04 This lecture Regular expressions Context-free grammar Attribute grammar

More information