• retagged by
19,683 views
49 49 votes

Which one of the following statements is FALSE?

  1. Context-free grammar can be used to specify both lexical and syntax rules
  2. Type checking is done before parsing
  3. High-level language programs can be translated to different Intermediate Representations
  4. Arguments to a function can be passed using the program stack

4 Answers

Best answer
80 80 votes
A. Since Lexical rules are nothing but regular expressions, we can use CFGs to represent such rules.(Every Type-$3$ grammar is Type-$2$ grammar) Additionally, syntax rules can be represented by CFGs. (True)

B. Type checking is done during Semantic Analysis phase which comes after Parsing. (False)

C. We have various types of Intermediate Code Representations, ex $3$-address code, Postfix notation, Syntax trees. (True)

D. Program stack holds the activation record of the function called, which stores function parameters, return value, return address etc.(True)

Correct Answer: $B$
• edited by
2 2 votes
B is clearly false as type checking is done using SDTs which is basically semantic analysis.SDTs are basically parse trees hence parsing needs to be done first and then only can we do type checking.
1 1 vote

A. Context-free grammar can be used to specify both lexical and syntax rules
Theoretically Valid

  1. Lexical rules (tokens) are specified using regular expressions (regular grammar).
  2. Context-free grammar (CFG) is used to specify syntax rules (structure of sentences).

    So, CFG cannot specify both lexical and syntax rules — only syntax.

Let’s break it down:

🔹 Lexical rules:

  • Lexical rules define tokens (identifiers, keywords, numbers, etc.).

  • These are usually described by regular expressions or regular grammars, because the lexical structure of programming languages is regular, not context-free.

🔹 Syntax rules:

  • Syntax rules describe how tokens are combined to form valid statements or expressions.

  • These are specified using context-free grammars (CFGs)

Since every regular language (Type 3) is also a context-free language (Type 2),
it’s theoretically true that a context-free grammar can describe lexical rules as well — because CFGs can represent all regular languages.

But here’s the compiler design interpretation:

B. Type checking is done before parsing
Also false, but let’s compare.

  • Parsing happens before type checking.

  • Type checking is part of semantic analysis, which occurs after parsing.

But since only one statement is expected to be false, we must check which is more wrong according to compiler design context.

C. High-level language programs can be translated to different Intermediate Representations
 True — compilers often use multiple IRs (e.g., AST, three-address code, SSA form).

D. Arguments to a function can be passed using the program stack
 True — standard calling conventions use the program stack to pass arguments.

The Answer should be A ,B if they haven't asked which one of the following 

  • A: True (theoretically valid)

  • B: False (type checking occurs after parsing)

  • C: True

  • D: True

So the most accurate False is (B)

 

• edited by
Answer:
Position:
Show:

Related questions

22 22 votes
6 6 answers
12.1k
12.1k views
Arjun asked Feb 16, 2024
12,147 views
​​​Consider the following two sets:$$\begin{array}{|ll|ll|}\hline & \textbf{Set X} & & \textbf{Set Y} \\\hline \text{ P.} & \text{Lexical Analyzer } & \text{1.}& \text...
50 50 votes
5 answers 5 answers
16.4k
16.4k views
Madhav asked Feb 14, 2017
16,407 views
Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it:$$\begin{array}{|l|l|}\hline \text{P. Syntax t...
34 34 votes
1 answers 1 answer
8.5k
8.5k views
Akash Kanase asked Feb 12, 2016
8,526 views
Match the following:$$\begin{array}{|ll|ll|}\hline \text{(P)} & \text{Lexical analysis} & \text{(i)} & \text{Leftmost derivation} \\\hline \text{(Q)} & \text{Top down pa...
47 47 votes
3 answers 3 answers
13.5k
13.5k views
Kathleen asked Sep 22, 2014
13,491 views
Match all items in Group 1 with the correct options from those given in Group 2.$$\begin{array}{|ll|ll|}\hline \rlap{\textbf{Group 1}} & & \rlap{\textbf{Group 2}} \\\hli...