1,827 views
3 votes
3 votes

 

The above diagram is Transition Diagrams for identifiers. As we can see that the identifier is said to be accepted if it starts with a letter and ends with a valid delimiter, which includes blank symbol, arithmetic, logical operator, left parenthesis, right parenthesis, +, :, ; etc.

Now say i declare an identifier int 4n; I understand that this (4n) is not a valid identifier as it starts with a number..

Now say i declare another identifier int n+ ; Does lexical analyzer accept it? I know that it will give compilation error but that is not my interest, i solely want to know will this be accepted by the lexical analyzer or not?

P.S→ I think it will because identifier ends with a delimiter and + is a valid delimiter and the error in declaration will not be detected at this stage...

1 Answer

0 votes
0 votes
int 4n//lexical error

Here $4n$ is valid two token (4 and n), but lexical analyzer cannot recognize it as valid pattern.So, it will give lexical error.


int n+;//syntax error.

Because , 'n+' not matching with any C program syntax. So, it will give syntax error.


Lexical error- Pattern mismatch.

Syntax error- Symbolic representation

Semantic error-Meaning 

Detail here:https://stackoverflow.com/questions/34834926/difference-between-lexical-and-syntax-error

https://softwareengineering.stackexchange.com/questions/113800/whats-the-difference-between-syntax-and-semantics

 

edited by

Related questions

2 votes
2 votes
5 answers
1
Mizuki asked Nov 11, 2018
1,779 views
What it the number of tokens in the following line?printf("%d numbers.", &x);
1 votes
1 votes
2 answers
2
Lovejeet Singh asked Nov 7, 2018
1,159 views
How will the compiler detect whether "if" is a keyword or an identifier?Please tell me the concept behind this.
1 votes
1 votes
1 answer
4
ankit_thawal asked Feb 1, 2018
714 views
1. macros are not considered as tokens in tokenizing.2.#include considered as single token2.stdio.h considered as single token. Are the above statements true?