Search:

Type: Posts; User: Norm

Search: Search took 0.09 seconds.

  1. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    At line 137 the code called the get() method with an index that is out of bounds: -1
    Indexes range in valid from 0 to the length-1. Add code to test that the index variable's value is in range...
  2. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    Please copy the full text of the error message and paste it here. It has important info about the error.



    use a loop and the System.out.print() method to put the String on the same line as the...
  3. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    You are converting char to int. '4' = 52
    Try this:

    System.out.println("char 4="+(int)'4'); // char 4=52

    If the ArrayList contains char values, then you need to treat them as char, not...
  4. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    The []s is array notation. With an ArrayList you use get methods to access elements in the list.
    See the API doc for the ArrayList class.
  5. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    Use the substring() method
  6. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    Used the substring() method to pick off the first letter, make it uppercase and then use concatenation to build the word again.
  7. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    You should use the equals() method to compare the contents of String objects, NOT the == operator.

    I assume tokens[i] is a String.
  8. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    You can't use the equals() method to test if an array contains an element. You need to use a loop to look at each element in the array one by one using the equals() method with each element.
    ...
  9. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    In a statement, what part is the "position"? I haven't see the syntax for a statement and don't know what part of a statement is the "position".


    I'm not sure what you are asking. If the...
  10. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    Not sure how the parser is scanning the tokens in the statement and finding the required next token.
    The posted code has hard coded index values instead of using variables so that the code can know...
  11. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    The StringTokenizer class has methods for getting tokens from a String using some delimiters. You need to call the methods to get the Strings.
  12. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    Please explain.

    What is strTok? Is it a String or is it an instance of a method that has a nextToken() method?
  13. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    I don't know what use counting the tokens will be to help parse the statement.

    If the current token is "are" then the next token must be a number.
    Notice I used current and next to describe the...
  14. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    I'm not sure why you are counting the tokens. If the current token is: "is" then the next token needs to be "a"
    and the number of items would be set to 1.
    The parser walks through the statement...
  15. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    Please edit your post and wrap your code with code tags:


    YOUR CODE HERE

    to get highlighting and preserve formatting.
  16. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    I haven't worked with writing parsers for years. In school we studied different language syntax rules and used BNF to define a language for a compiler writing project. I haven't done much with...
  17. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    Writing a parser for a statement is easier if that statement's contents are well defined.
    Consider the java language. It has several different types of statements that are all well defined. The...
  18. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    It all depends on the syntax and how the parsing is to be done. For example are all the tokens delimited by spaces?
    The split() method uses a regular expression that can be powerful for some...
  19. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    Have you looked at defining a syntax for the statements that you are trying to parse?
  20. Thread: java parser

    by Norm
    Replies
    48
    Views
    4,693

    Re: java parser

    The String class has some useful methods for separating parts of a String into tokens. What were your problems with its methods?
    Also the StreamTokenizer has some useful methods for doing the same....
Results 1 to 20 of 20