PCD_Theory_Paper Solution_Nov_Dec_2017.docx - Paper Solution Nov\/Dec 2017(Revised Principles of Compiler Design Marks 80 Time:3 Hrs Subject Teacher

PCD_Theory_Paper Solution_Nov_Dec_2017.docx - Paper...

This preview shows page 1 - 3 out of 27 pages.

Paper Solution Nov/Dec 2017 (Revised) Principles of Compiler Design Marks: 80 Time :3 Hrs. Subject Teacher: Prachi Joshi Section A Q.1 a) Explain role of lexical analyzer with suitable diagram. (5M) Fig 1: Role of Lexical Analyzer (1) Lexical analysis is the first phase of a compiler. It takes the modified source code from language preprocessors that are written in the form of sentences. (1M) The lexical analyzer breaks these syntaxes into a series of tokens, by removing any whitespace or comments in the source code. If the lexical analyzer finds a token invalid, it generates an error. The lexical analyzer works closely with the syntax analyzer. It reads character streams from the source code, checks for legal tokens, and passes the data to the syntax analyzer when it demands. (1) Lexemes are said to be a sequence of characters (alphanumeric) in a token. There are some predefined rules for every lexeme to be identified as a valid token. These rules are defined by grammar rules, by means of a pattern. (1) A pattern explains what can be a token, and these patterns are defined by means of regular expressions. In programming language, keywords, constants, identifiers, strings, numbers, operators and punctuations symbols can be considered as tokens. For example, in C language, the variable declaration line (1M) int value = 100 ; contains the tokens: int ( keyword ), value ( identifier ), = ( operator ), 100 ( constant ) and ; ( symbol ). b) What is cross compilation? Compare with boot strapping. (5M) A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is run. Cross compiler tools are generally found in use to generate compiles for embedded system or multiple platforms. It is a tool that one
Image of page 1
must use for a platform where it is inconvenient or impossible to compile on that platform, like microcontrollers that run with a minimal amount of memory for their own purpose. (2M) The fundamental use of a cross compiler is to separate the build environment from the target environment. Bootstrapping is the process of writing a compiler (or assembler) in the source programming language that it intends to compile . Applying this technique leads to a self- hosting compiler . (1M) Compiling for multiple machines. For example, a company may wish to support several different versions of an operating system or to support several different operating systems. By using a cross compiler, a single build environment can be set up to compile for each of targets. Compiling on a server farm. Similar to compiling for multiple machines, a complicated build that involves many compile operations can be executed across any machine that is free regardless of its brand or current version of an operating system. (1M) When developing software for a new platform, or the emulator of a future platform, one uses a cross compiler to compile necessary tools such as the operating system and a native compiler. (1M) Use of virtual machines (such as Java's JVM) resolves some of the reasons for which cross compilers Typically the hardware architecture differs (e.g. compiling a program
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 27 pages?

  • Spring '16
  • 213

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes