Awesome q2a theme
0 votes
29 views

Identify lexical, syntax and semantic errors from the following C program. Write line number, error message, and type of the error for each error in the program 

 

01: float Factorial(int N) {

02:   float F;

03:   F==1;

04:   while(i<F)

05:        F*=i;

06:   return F

07: }

08: Void mane()

09:   integer r;

10:   r=Factorial(5);

11:   IF(r>0)

12:      PrintResult(r);

13: }

in Compiler Design by (5 points)
edited by | 29 views

1 Answer

0 votes

Lexical Errors:

Line no. 9, no such keyword as integer

Syntactic error:

Line no. 6 Semicolon is missing

Line no. 8 opening brace is missing

Line no. 9 two identifiers can’t follow each other (integer is a valid identifier)



Semantic error:

Line no. 5 i is undeclared

Line no. 5 i should be incremented, F *= i++ would fix this

Line no. 10 r is undeclared

Line no. 11 IF is an undeclared identifier


Line no. 12 PrintResult is not defined

by (3.2k points)
edited by
+1
line 11: IF can be a function, rt ?

may it undeclared.

 

line 4 : it may lead to infinite loop, you can't catch it.

line 9 : two identifiers can possible, if by using typedef we declare integer as int
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
9,092 questions
3,152 answers
14,579 comments
95,935 users