GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
197 views
I came across few Compiler Design Doubts, Please provide your cent.

$Q_1 :$ Can lexical analyser detect some/any type of errors?

I think yes, because while scanning to identify tokens, it may be the cases that a string pattern doesn't match with any keyword (or) entry in symbol table and gives error. But a detailed explaination will be appreciated.

$Q_2:$ In which phase of compilation Scope Checking happens? I guess sematic analyser, but I have no valid explaination

$Q_3: \color{navy}{A \rightarrow Aa}$ (Left linear) $\color{navy}{A \rightarrow aA}$(Right Linear). What can be said about $\color{navy}{A \rightarrow aAb}$
asked in Compiler Design by Veteran (24.6k points)   | 197 views

Q3:$A\rightarrow aAb$ is also known as Linear grammar.

What do we say about $A \rightarrow aAb$? Whether it is considered as left (or) right linear. (or) none of these $2$.

none of these 2.

You can say,

Every left (or) right linear grammar are Linear grammar but converse is not true.

And, $A \rightarrow AbA$ and $A \rightarrow AA$ are both Right and Left linear ??

how ?
Because, derivation can go like $\Rightarrow$

$A \rightarrow AbA$

$\Rightarrow $$A \rightarrow (AbA)bA$ and so on.
No.given grammar is not even linear.Follow the definition of linear grammar.

Yes,(you are right) the definition of left and right linear says all nonterminals. But the above $2$ grammars are both left and right-recursive. right??

yes above grammar both left and right-recursive.

1 Answer

+3 votes

Can lexical analyser detect some type of errors?
Yes it is True. Lexical Analyser detect lex error.

Can lexical analyser detect any type of errors?
No, it cant detect syntax or semantic error.

In which phase of compilation Scope Checking happens?
Semantic Analyser. Generally type checking takes place when output is coming out. It is possible onl if there is no lex and no syntax error. (http://www.cs.virginia.edu/kim/courses/cs471/lec/cs471-11-semantic.pdf)

A→Aa (Left linear),  A→aA (Right Linear).
 A→aAb it is CFG

answered by Veteran (45.8k points)  
I read in some pdf that semantic checking can also take place in two phase syntax analyser. Is it true?
Who detects following error : {} 0+0 else if enum a = 4[]+3[] + *1 - 4;


Top Users Apr 2017
  1. akash.dinkar12

    3514 Points

  2. Divya Bharti

    2546 Points

  3. Deepthi_ts

    2040 Points

  4. rude

    1966 Points

  5. Tesla!

    1768 Points

  6. Shubham Sharma 2

    1610 Points

  7. Debashish Deka

    1588 Points

  8. Arunav Khare

    1454 Points

  9. Kapil

    1424 Points

  10. Arjun

    1420 Points

Monthly Topper: Rs. 500 gift card

22,076 questions
28,042 answers
63,235 comments
24,135 users