+ 4
How compiler knows type of the variable whether string or integer type?
7 Answers
+ 5
Depends on the programming language. Some such as Java, you need to define what the datatype is, but others such as javascript are more flexible.
I assume first they check for "" to see if it is a string. If it is not, they check for a true or false to see if it is a boolean. If it isn't they check for an operator to see if it is a calculation of what type.
Then thet check for a word to see if it's another variable, or a [] to see if it is an array, lastly a number to see if it is an integer, and if it is a point value they make is a double.
+ 3
string delimited by " "
see lexing and tokenising
+ 3
What is Lexing and tokenising
+ 3
Lexing and tokenising are same things. Converting a big string into small identifiable strings.
+ 2
NT Janyani
lexing :
https://www.pythonmembers.club/2018/05/01/building-a-lexer-in-JUMP_LINK__&&__python__&&__JUMP_LINK-tutorial/
tokenising :
identifies the separated pieces like
if " then type -> string etc
+ 2
you need to define them, like
int a; a = 6.
float f; f = 3.5
double d; d= 3.14
string abc; ="hello world"
char a = 'z'
you need to define them accordingly
0
As stated previously, it depends on the language. C for instance will ask you to specify before hand the type of your variable. Also, strings and chars are usually presented within quotes or double quotes.
Example in C:
int pear = 2;
int apple = 5;
char strawberry[15] = "Hello World";
Some languages like Python will automatically assign the most coherent type to a variable although you can still decide to specify it yourself.