+ 4

How compiler knows type of the variable whether string or integer type?

21st Jun 2018, 6:29 PM
Nitin Janyani
Nitin Janyani - avatar
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.
21st Jun 2018, 6:37 PM
Andre Daniel
Andre Daniel - avatar
+ 3
string delimited by " " see lexing and tokenising
21st Jun 2018, 6:34 PM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 3
What is Lexing and tokenising
21st Jun 2018, 6:35 PM
Nitin Janyani
Nitin Janyani - avatar
+ 3
Lexing and tokenising are same things. Converting a big string into small identifiable strings.
22nd Jun 2018, 6:22 PM
Vikash Pal
Vikash Pal - avatar
+ 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
21st Jun 2018, 6:39 PM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 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
22nd Jun 2018, 6:59 AM
Kanishk Mewal
Kanishk Mewal - avatar
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.
24th Jun 2018, 8:30 PM
Alex Wolf
Alex Wolf - avatar