edited by
3,762 views
9 votes
9 votes

MISSPELLING OF KEYWORDS CAUSE WHICH TYPE OF ERROR- SYNTAX ERROR OR LEXICAL ERROR??

printf("%d") without any integer argument will cause which type of error??

edited by

2 Answers

16 votes
16 votes

Misspelling of keywords mean it will be treated as an identifier by a compiler..As there is only change in spelling of keyword , so it is considered to be a valid token because this satisfies the pattern as needed by dfa of lexical analyser..

It is not a syntax error either as syntax error is something which is related to violation of grammar by any of the statements..

Now say int is mistakeably written as 'inta' ..Now it is identified as an identifier..But its type is not mentioned as there is no "int" in declaration part..Hence it will be a type checking error which is related to semantic phase..

As far as the statement   "printf("%d)" is concerned , it will neither give compilation error nor give runtime error. It will give a valid output..For more clarification on this query , plz check the following :

https://stackoverflow.com/questions/437816/behaviour-of-printf-when-printing-a-d-without-supplying-variable-name

1 votes
1 votes

Lexical Analyzer is too primitive to think about keyword error as an actual error as the knowledge it has is localized and it will treat it as a basic token.

This is a snippet from the Dragon Book to make things more clear.

Related questions

2 votes
2 votes
3 answers
2
kman30 asked Jan 21, 2019
1,693 views
How many tokens in thisa>>=1;and a! , Will >>= and a! be treated as a single token ?
0 votes
0 votes
1 answer
3
Vipin Rai asked Dec 12, 2018
565 views
int main(){ int a,b; a = 10; b = 11; printf(“%d %d”, a++,b );}The number of tokens is
3 votes
3 votes
0 answers
4
Kiran Karwa asked Jan 20, 2018
357 views
what type of error is caused if function name is same as a keyword name?