# Lp Quiz Test 1

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
| By VirenD
V
VirenD
Community Contributor
Quizzes Created: 1 | Total Attempts: 188
Questions: 10 | Attempts: 188

Settings

• 1.

### How many tokens are there in the following code snippet? Consider semicolon as a token.int f(int n){static int i=1;if(n>= 5) printf("Value = %d”, n);n=n+i;i++;return f(n);}

• A.

42

• B.

40

• C.

36

• D.

44

A. 42
Explanation
The code snippet consists of multiple tokens including keywords (int, static, if, printf, return), identifiers (f, n, i), operators (=, >=, ++), literals (5, 1), punctuations ({, }, (, ), ;), and a format specifier (%d). Counting all these tokens gives a total of 42.

Rate this question:

• 2.

### Compute FIRST of ‘S’ for the following grammar:S → ABb | bAA → BSb | λB →ab | λ

• A.

A,b,λ

• B.

A,b

• C.

A,λ

• D.

B

B. A,b
Explanation
The FIRST of 'S' for the given grammar is {a, b}. This is because 'S' can derive either 'ABb' or 'bAA'. The FIRST of 'ABb' is {a} and the FIRST of 'bAA' is {b}. Therefore, the FIRST of 'S' is the union of the FIRST of 'ABb' and the FIRST of 'bAA', which is {a, b}.

Rate this question:

• 3.

### Compute FOLLOW of ‘B’ for the following grammar:S → ABb | bAA → BSb | λB →ab | λ

• A.

B,λ

• B.

A,b,λ

• C.

A,λ

• D.

A,b

D. A,b
Explanation
The FOLLOW set of a non-terminal symbol in a grammar consists of all the terminals that can appear immediately to the right of that non-terminal in any derivation. In this case, the non-terminal 'B' can appear immediately to the right of 'a' and 'b'. Therefore, the correct answer is 'a,b'.

Rate this question:

• 4.

### A top down parser generates

• A.

Right most derivation

• B.

Right most derivation in reverse

• C.

Left most derivation

• D.

Left most derivation in reverse

C. Left most derivation
Explanation
A top-down parser generates a left-most derivation. This means that it starts with the start symbol of the grammar and repeatedly replaces the leftmost non-terminal symbol with a production rule until it derives the input string. The left-most derivation is the process of deriving the input string from the start symbol by always replacing the leftmost non-terminal symbol. This is in contrast to a right-most derivation, where the rightmost non-terminal symbol is always replaced.

Rate this question:

• 5.

### Is the following grammar LL(1)? Give reason.S → Ab | aA → Sb | b

• A.

Yes

• B.

No, because of left recursion

• C.

No, because of ambiguity

• D.

None of these

B. No, because of left recursion
Explanation
The given grammar is not LL(1) because of left recursion. Left recursion occurs when a non-terminal symbol appears as the first symbol on the right-hand side of a production rule. In this case, the non-terminal symbol "A" appears as the first symbol in the production rule "A → Sb". This left recursion makes it impossible to determine which production rule to apply when parsing the grammar using LL(1) parsing technique, as it leads to an infinite loop.

Rate this question:

• 6.

### Which one of the following lexeme is said to be a token without looking at next character?

• A.

+

• B.

-

• C.

>

• D.

None

D. None
Explanation
The answer "none" is correct because without looking at the next character, it is impossible to determine whether any of the given lexemes should be considered as a token. A token is a meaningful unit of code, and in order to determine whether a lexeme should be considered a token, it is necessary to consider the context and the surrounding characters. Without this information, it is not possible to definitively classify any of the given lexemes as tokens.

Rate this question:

• 7.

### A programmer, by mistake, writes an instruction to divide, instead of a multiply, such error can be detected by a/an

• A.

Compiler

• B.

Interpreter

• C.

Compiler or interpreter test

• D.

None of these

D. None of these
Explanation
This error cannot be detected by a compiler, interpreter, or a compiler or interpreter test because dividing instead of multiplying is a logical error that does not violate the syntax rules of the programming language. The program will run without any errors, but the output will be incorrect. Therefore, none of the given options can detect this specific error.

Rate this question:

• 8.

### A compiler for a high level language that runs on one machine and produce code for different machine is called

• A.

Optimizing compiler

• B.

One pass compiler

• C.

Cross compiler

• D.

Multipass compiler

C. Cross compiler
Explanation
A compiler for a high-level language that runs on one machine and produces code for different machines is called a cross compiler. This type of compiler is designed to generate executable code for a target machine that is different from the machine on which the compiler is running. It allows developers to write code in a high-level language and then compile it into machine code that can be executed on a different architecture or platform. Cross compilers are commonly used in software development for creating programs that can run on multiple platforms or operating systems.

Rate this question:

• 9.

### Intermediate code generation phase gets input from

• A.

Lexical analyzer

• B.

Syntax analyzer

• C.

Semantic analyzer

• D.

Error handling

C. Semantic analyzer
Explanation
The intermediate code generation phase receives input from the semantic analyzer. This is because the semantic analyzer is responsible for checking the meaning and correctness of the code, ensuring that it follows the rules and constraints of the programming language. Once the semantic analysis is complete, the intermediate code generation phase can then use this information to generate an intermediate representation of the code that can be further optimized and translated into machine code.

Rate this question:

• 10.

### LL(1) is

• A.

Left to right, leftmost derivation , 0 lookahead symbol

• B.

Left to right, leftmost derivation , 1 lookahead symbol

• C.

Left to left, right most derivation , 1 lookahead symbol

• D.

Left to right, right most derivation , 1 lookahead symbol

B. Left to right, leftmost derivation , 1 lookahead symbol
Explanation
LL(1) is a parsing method where the input is scanned from left to right, and the leftmost non-terminal symbol is always chosen for expansion. It also uses a lookahead of 1 symbol to determine which production rule to apply. This means that the next input symbol is examined to determine the correct production to use. Therefore, the correct answer is "Left to right, leftmost derivation, 1 lookahead symbol."

Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

• Current Version
• Mar 20, 2023
Quiz Edited by
ProProfs Editorial Team
• Jan 31, 2017
Quiz Created by
VirenD

Related Topics