Computer Knowledge

Programming Languages and Compilers

2,284 Questions

Programming languages and compilers involve the rules, syntax, and semantics used to write and execute software programs. Key areas include scripting languages, object oriented concepts, and parsing algorithms like top down parsers. Practice these computer science questions to build proficiency for technical and computer knowledge exams.

Object oriented languagesScripting languagesCompilers and parsersProgramming syntax

Programming Languages and Compilers Questions

Multiple choice
  1.   class abc {
       Public static void main(String args[]) {……………}
      }
    
  2.   class abc {
       public Static void main(String args[]) {……………}
      }
    
  3.   class abc {
       Public static void Main(String args[]) {……………}
      }
    
  4.   class abc {
       public static void main(String args[]) {……………}
      }
    
Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The correct format for a Java program is as follows: class abc { public static void main(String args[]) { …………… } } Here, the keywords class, public and static must be in lower case. String is the class name.

Multiple choice
  1. L is necessarily finite.

  2. L is regular but not necessarily finite.

  3. L is context free but not necessarily regular.

  4. L is recursive but not necessarily context free.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The strings of a language L can be effectively enumerated means a Turing machine exists for language L which will enumerate all valid strings of the language.If the string is in lexicographic order then TM will accept the string and halt in the final state. But, if the string is not lexicographic order then TM will reject the string and halt in non-final state.Thus, L is recursive language.We can not construct PDA for language L. So, the given language is not context free.

Multiple choice
  1. $L_1$ $\in P$ and $L_2$ is finite
  2. $L_1$ $\in NP$ and $L_2$ $\in P$
  3. $L_1$ is undecidable and $L_2$ is decidable
  4. $L_1$ is recursively enumerable and $L_2$ is recursive
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

We have one to one mapping for all instances of L1 to L2. L1 is given to be undecidable. Further L1 is polynomial time reducible to L2. (By given mapping). Now if L2 is decidable then there is algorithm to solve L2 in polytime. But then we can solve every instance of L1 in polytime, making L1 also decidable. Contradiction  

Multiple choice
  1. (i), (iii)

  2. (ii), (iii)

  3. (i), (ii)

  4. (i), (ii), (iii)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The front end performs lexical and syntax analysis (validating statements), semantic analysis (determining content/meaning), and constructs intermediate representation for subsequent phases. All three functions are part of front-end processing.

Multiple choice
  1. recursive descent parsing

  2. shift reduce parsing

  3. operator precedence parsing

  4. none of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Top-down parsing is also called recursive descent parsing because it recursively expands non-terminals starting from the root. Shift-reduce and operator precedence are bottom-up techniques.

Multiple choice
  1. right most derivation

  2. left most derivation

  3. right most derivation in reverse

  4. left most derivation in reverse

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Top-down parsers (including predictive parsers) use leftmost derivation - they expand the leftmost non-terminal at each step. Rightmost derivation is used by bottom-up parsers.

Multiple choice
  1. machine code

  2. intermediate code

  3. a stream of tokens

  4. a parse tree

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

 The output of lexical analyzer is a stream of tokens.

Multiple choice
  1. canonical derivation sequence

  2. canonical reduction sequence

  3. both (1) and (2) above

  4. none of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Handle pruning is used in LR parsing to efficiently find the canonical reduction sequence - the unique reverse of rightmost derivation. It helps identify handles without exploring all possibilities.

Multiple choice
  1. LL

  2. <font size="2">C</font>anonical LR

  3. SLR

  4. LALR

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Canonical LR (CLR) is the most powerful parsing method - it handles all grammars that LR parsing can handle, while SLR, LALR, and LL are progressively more restrictive subsets.