in Compiler Design retagged by
5,548 views
6 votes
6 votes

in Compiler Design retagged by
5.5k views

4 Comments

@sudso .......plz give any refernce.....
0
0
edited by

i think its not a lexical error
1 -- > token (integer constant)
xab --> token (identifier)

this is the output screen shot on gcc compiler

0
0
#include<stdio.h>
int main()
{
  int +-;
}

Here for this programm you may say that "+-" gives lexical error

but it does not

here is output screenshot

here is identified as token

1
1

3 Answers

22 votes
22 votes
Best answer
1xab - is not a valid token in C (as variable names cannot start with a digit and numbers cannot have a letter other than 'x' (for hex) or 'l' (for long) and also not a valid keyword) and hence lexical error. It could have been x1ab, _x1ab etc. both would have given a semantic error for variable not defined.
selected by
by

4 Comments

Thank you Sir for your comment.

Is my below assumption correct?
Token separators are:
1)whitespaces
2)operators
3) special symbols like
     ( ) , { } " :

And also are there more valid token separators apart from this?
0
0

And also here 

https://gateoverflow.in/204111/gate2018-37

We didn't considered token separator concept here.why so?

Is this because in gcc, FA considers token separator to distinguish between tokens.

And here this question has given its own token pattern which does not considers token separator.

0
0

First of all that is invalid, right?

@tp21

You can't have a lexeme pattern like that. So, I think the discussion ends there itself?

 

0
0
3 votes
3 votes

It is a lexical error at earliest as we can see that the token "1xab" will be treated as an identifier ..But we know as per standard naming convention in C language , the variable name cannot begin with "1" ..

So it will be an invalid token..Hence the error concerned will be lexical error at the earliest..

Hence A) is correct answer..

4 Comments

if digit in anywhere other than starting then its valid or not??
0
0
It is valid in all other cases except beginning
0
0
Undeclared variable is syntax or Symantic error
0
0

Undeclared variable is not a syntax error..

https://gateoverflow.in/262335/number-of-tokens

0
0
0 votes
0 votes
Lexical analyser scan the program and generate token store into symbol table and return token id.
Token may be
Keyword
Identifier(function or variable)
Operators
Special symbols.
So 1xba not any things
So it produces Lexical error