Вы находитесь на странице: 1из 2

Assignment 2

6th SEM B.Tech CSE

Paper Code: BCS 304 C


Paper Title: Compiler Design 4

Q1)
Explain how, starting with a compiler for language X that runs on system Z, you might use cross-
compilation to create a compiler for language X, written in X, that runs on system Y and generates
code for system Y. What extra problems arise if system Y is “bare”—that is, has no operating system
or compilers for any language? (Recall that Unix is written in C and thus must be compiled before its
facilities can be used.)

Q2)
Most programming languages, such as C and C++, are compiled directly into the machine language of
a “real” microprocessor (for example, an Intel x86 or Sparc). Java takes a different approach. It is
commonly compiled into the machine language of the JVM. The JVM is not implemented in its own
microprocessor, but is instead interpreted on some existing processor. This allows Java to be run on a
wide variety of machines, thereby making it highly platform independent. Explain why building an
interpreter for a virtual machine like the JVM is easier and faster than building a complete Java
compiler. What are the disadvantages of this virtual machine approach?

Q3)
Write a grammar that recognizes a C variable declaration made up of the following keywords:
int char long float double signed unsigned short const volatile and a variable name.

Q4)
Try to write a context-free grammar that correctly parses both "time flies like an arrow" and "fruit flies
like a banana."

Q5)
The following context-free grammar can parse all the lowercase roman numerals from 1-99.
The terminal symbols are { c, l, x, v, i } and the initial symbol is S.
S → xTU | lX | X T → c | l X → xX | U U → iY | vI | I Y → x | v I → iI | ɛ
1. Draw a parse tree for 42: “xlii”
2. Is this grammar ambiguous?
3. Write semantic actions for each of the 14 rules in the grammar (remember X → A|B is short
for X → A and X → B) to calculate the decimal value of the input string. You can associate a
synthesized attribute val to each of the non-terminals to store their value. The final value
should be returned in S.val.
Q6) In the following context-free grammar, the symbols 0, 1, 2 and 3 are terminals and S is the initial
symbol. S → 0 | 1 S 2 S 3 | 1 A 3 A → S | A S 1. Explain briefly why this grammar is not LL(1). 2.
Convert this grammar to an equivalent that is LL(1). 3. For the grammar of the previous subtask,
construct the complete LL(1) parsing table. 4. Show all the steps required to parse the input string: 1 1
02030

Вам также может понравиться