Every problem might not have a solution right now, but don’t forget that but every solution was once a problem.
--Your friends at LectureNotes

Note for Compiler Design - CD by Mohit Kaushik

  • Compiler Design - CD
  • Note
  • A.I.J.H.M COLLEGE - Jat
  • 3 Topics
  • Uploaded 1 year ago
Mohit Kaushik
Mohit Kaushik
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

Compiler Design COMPILER DESIGN Paper Code: M.Sc.-301 UNIT – I Overview of language processing: Preprocessors, compiler, assembler, interpreters, linkers & loaders , structure of a compiler, phases of a compiler. Lexical Analysis: Role of Lexical Analysis, Lexical Analysis Vs. Parsing, Token, patterns and Lexemes, Lexical Errors, Regular Expression, Definitions for the language constructs, Strings, Sequences, Comments, Transition diagram for recognition of tokens, Reserved words and identifiers, Examples. Created By: Mohit Kaushik Website: http://luckyshah.website2.me 1

Text from page-2

Compiler Design Introduction of Compiler design: Compiler is a software which converts a program written in high level language (Source Language) to low level language (Object/Target/Machine Language).  Cross Compiler that runs on a machine ‘A’ and produces a code for another machine ‘B’. It is capable of creating code for a platform other than the one on which the compiler is running.  Source-to-source Compiler or trans-compiler or trans-piler is a compiler that translates source code written in one programming language into source code of another programming language. Language processing systems (using Compiler) – We know a computer is a logical assembly of Software and Hardware. The hardware knows a language, that is hard for us to grasp, consequently we tend to write programs in high-level language, that is much less complicated for us to comprehend and maintain in thoughts. 2

Text from page-3

Compiler Design Now these programs go through a series of transformation so that they can readily be used machines. This is where language procedure systems come handy.  High Level Language – If a program contains #define or #include directives such as #include or #define it is called HLL. They are closer to humans but far from machines. These (#) tags are called preprocessor directives. They direct the pre-processor about what to do.  Pre-Processor – The pre-processor removes all the #include directives by including the files called file inclusion and all the #define directives using macro expansion. It performs file inclusion, augmentation, macro-processing etc.  Assembly Language – Its neither in binary form nor high level. It is an intermediate state that is combination of machine instructions and some other useful data needed for execution.  Assembler – For every platform (Hardware + OS) we will have a assembler. They are not universal since for each platform we have one. The output of assembler is called object file. Its translates assembly language to machine code.  Interpreter – An interpreter converts high level language into low level machine language, just like a compiler. But they are different in the way the read the input. The Compiler in on go reads the inputs, does the processing and executes the source code whereas the assembler does the same line by line. Interpreted programs are usually slower with respect to compiled ones. 3

Text from page-4

Compiler Design  Re-locatable Machine Code – It can be loaded at any point and can be run. The address within the program will be in such a way that it will cooperate for the program movement.  Loader/Linker – It converts the re-locatable code into absolute code and tries to run the program resulting in a running program or an error message (or sometimes both can happen). Linker loads variety of object files into a single file to make it executable. Then loader loads it in memory and executes it. Phases of a Compiler – There are two major phases of compilation, which in turn have many parts. Each of them are take input from the output of the previous level and work in a coordinated way. 4

Lecture Notes