715 views
3 votes
3 votes
How are constants recogonized by the lexical analyser like

interger 1234     floating point  1234.56789

and what happens when we have -1234  and -1234.56789 how many tokens are generated in this case(each of this case) ?

is "-" considered seperately ?

1 Answer

2 votes
2 votes
For generating the number of tokens, following are considered as one:

1.) Keywords: if, else, while, do, for, float,..,etc.

2.) Identifiers: letter followed by letter or underscore or digit.

3.) Constant(consider any real number): 4,10,5.5

4.) Punctuation Symbols: :, ;, , , {, }, [, ], ?

5.) Operators: Relational Operator-> < , >, <=, >=, ==, etc

                       Logical Operator-> &&, ||, !

                       Bitwise Operatore-> &, |, ^(Ex-OR), <<, >>

6.) Few more: +, ++, -, --,/,*,+=,-=,=,etc

Now according to your question integer 1234 will be considered as ONE TOKEN (refer constant discussed above)

and , -1234.56789 will be considered as two token( first for - sign and  second for 1234.56789)

Hope, this clears your doubt and help in understanding of the concept.

Related questions

2.0k
views
1 answers
3 votes
Hirak asked Jun 9, 2019
2,003 views
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 delimi...
1.9k
views
3 answers
2 votes
kman30 asked Jan 21, 2019
1,850 views
How many tokens in thisa>>=1;and a! , Will >>= and a! be treated as a single token ?
640
views
1 answers
0 votes
Vipin Rai asked Dec 12, 2018
640 views
int main(){ int a,b; a = 10; b = 11; printf(“%d %d”, a++,b );}The number of tokens is
384
views
0 answers
1 votes
Venkat Sai asked Oct 6, 2017
384 views
Once the parser makes the list of legitimate tokens available to the error recovery routine then this routine can decide whether a remaining input’s prefix matches one ...