Results 1 to 3 of 3
  1. #1
    dragstang86 is offline Member
    Join Date
    Jun 2011
    Posts
    46
    Rep Power
    0

    Default Is my recursive decent parse correct?

    I am trying to get a better grasp of recursive decent parsing and wanted to make sure this would be correct.

    <repeat_statement> -> REPEAT<statement>UNTIL<expression>;

    Java Code:
    boolean parseRepeatStatement(){
    
       if(token == REPEAT){
          token = getNextToken();
    
          if(parseStatement()){
             if(token == UNTIL){
                token = getNextToken();
    
                if(parseExpression()){
                   if(token == ';')
                      return true;
                }
             }
          }
       }
       return false;
    
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Is my recursive decent parse correct?

    It looks almost fine to me: if the getNextToken() method removes the current token from the input stream. why don't you call that method after it has seen that semi colon and just before your code returns true? Otherwise you have to explain what your code does exactly ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    dragstang86 is offline Member
    Join Date
    Jun 2011
    Posts
    46
    Rep Power
    0

    Default Re: Is my recursive decent parse correct?

    I understand what you are saying. Thanks for the help

Similar Threads

  1. These components should at least TRY to look decent
    By blackbird in forum AWT / Swing
    Replies: 12
    Last Post: 07-29-2011, 07:00 PM
  2. Please help - can't seem to correct this...
    By jmjbreezin in forum New To Java
    Replies: 7
    Last Post: 05-09-2011, 01:39 PM
  3. Recursive and Non-Recursive powersets?
    By csisdifficult in forum New To Java
    Replies: 5
    Last Post: 04-20-2011, 02:45 AM
  4. Are my comments correct?
    By twiggy62 in forum New To Java
    Replies: 2
    Last Post: 02-08-2010, 05:34 AM
  5. Decent Book For JBuilder 2006
    By MayheM in forum New To Java
    Replies: 2
    Last Post: 08-12-2008, 01:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •