Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Parse/parsing? [closed]

Tags:

java

parsing

You could say that parsing a string of characters is analyzing this string to find tokens, or items and then create a structure from the result.

In your example, calling Integer.parseInt on a string is parsing this string to find an integer.

So, if you have:

String someString = "123";

And then you invoke:

int i = Integer.parseInt( someString );

You're telling java to analyze the "123" string and find an integer there.

Other example:

One of the actions the java compiler does, when it compiles your source code is to "parse" your .java file and create tokens that match the java grammar.

When you fail to write the source code properly ( for instance forget to add a ; at the end of a statement ), it is the parser who identifies the error.

Here's more information: http://en.wikipedia.org/wiki/Parse


Parsing is to read the value of one object to convert it to another type. For example you may have a string with a value of "10". Internally that string contains the Unicode characters '1' and '0' not the actual number 10. The method Integer.parseInt takes that string value and returns a real number.

String tenString = "10"

//This won't work since you can't add an integer and a string
Integer result = 20 + tenString;

//This will set result to 30
Integer result = 20 + Integer.parseInt(tenString);

From dictionary.reference.com:

Computers. to analyze (a string of characters) in order to associate groups of characters with the syntactic units of the underlying grammar.

The context of the definition is the translation of program text or a language in the general sense into its component parts with respect to a defined grammar -- turning program text into code. In the context of a particular language keyword, though, it generally means to convert the string value of a fundamental data type into an internal representation of that data type. For example, the string "10" becomes the number (integer) 10.


Parsing can be considered as a synonym of "Breaking down into small pieces" and then analysing what is there or using it in a modified way. In Java, Strings are parsed into Decimal, Octal, Binary, Hexadecimal, etc. It is done if your application is taking input from the user in the form of string but somewhere in your application you want to use that input in the form of an integer or of double type. It is not same as type casting. For type casting the types used should be compatible in order to caste but nothing such in parsing.