Parsing problem for Java datatypes in a Text

Posted on 2006-04-24
Last Modified: 2013-11-23
I need a logic/algorithm based on Java which can return me the type of the input parameter. The input parameter is a text. But the function has to analyse the text and find out whether the input (can be)/is of type int, String, float or enum or an array of primitive data types.


The input parameter is: (("ABC","DEF"), (1,2,3), 5.5, (5.2, 6.2,8.8), (RED, BLUE)). Here the function should return me the result as:

DataType-1 is array of String (as the String are always represented in quotes).
DataType-2 is an array of integers
DataType-3 is of type float
DataType-4 is an array of float
DataType-5 is an array of enum, say Color. (Enum always represented without quotes)

Validation should be taken care for non-matching "(" or")". Also for mixed type datatype not allowed.

Due to time constraint this question is being asked. I am looking for some available parsers or expert solution which is failure-proof. Thanks in Advance.
Question by:ranjeevrajan
    LVL 86

    Accepted Solution

    You could make something with regular expressions
    LVL 30

    Assisted Solution

    There are some open-source parser generators in Java:
    LVL 30

    Expert Comment

    BTW that input parameter is not really correct Java. I don't know what it is supposed to be.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    java JDK Download 7 50
    array220 challenge 8 32
    json example 39 83
    mapAB Challlenge 35 59
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now