[antlr-interest] Antlr parse cannot parse the file completly

amol Bhagavat amol_bhagavat at yahoo.co.uk
Mon Oct 15 22:08:30 PDT 2007


Hi ,
   
  Hw to implement a rule in grammar which will check EOF of a file.
  My parser comes out of parsing if it could not parse some wrong syntax.
  I want it to parse the file to the end & leave the wrong syntax.
   
  Your help is very much necessary.........
   
  thanks.

amol Bhagavat <amol_bhagavat at yahoo.co.uk> wrote:
    Hi , it seems due to some rule only & i able to find out which rule makes it to stop it.
  But to my surprise , its a part of rule if i remove it works smoothly & if i adds that it parses half.
   
  I generate the lexer & parser in java language & to parse c language code.
  I am pasting some part of my grammer here...
  The implementation is to find a specific variable in function definition parameters
  for ex. int function(MSGQ_TYPE  MessgQNew)
             {
                  int abc; 
                 --------
                  ---------
              }
   
   
   
   String MesgQSring = "MSGQ_TYPE";
 boolean isMesgQType(String name) {   
   if ( MesgQSring.equals(name) )
    {
      return true;
    }  
  return false;
 }
   
  translation_unit
scope Symbols; // entire file is a scope
@init {
  $Symbols::messageqnames = new HashSet();  
}
   
   
  parameterwithfptr
 : fptrDeclarationsub
 | (mesgqtypechk)? mesgobject
 | parameter_declaration
 ; 
   
  mesgqtypechk
 :{isMesgQType(input.LT(1).getText())}? IDENTIFIER
 ;
  mesgobject
 :IDENTIFIER
  {
   {$Symbols::messageqnames.add($IDENTIFIER.text);}
   }
   ;
   
  Now If i removes "(mesgqtypechk)? mesgobject" this part of the rule , it works.
  Not understanding why? IS there any way i can solve this problem?
  

Jim Idle <jimi at temporal-wave.com> wrote:
        v\:* {behavior:url(#default#VML);}  o\:* {behavior:url(#default#VML);}  w\:* {behavior:url(#default#VML);}  .shape {behavior:url(#default#VML);}                Either your parser is bombing out early or some construct is lacking within it and it is just stopping at some point because of this. For a start, make sure that you have a rule that looks for EOF as the last token, as this might help you see why it is stopping early. After that, if cannot debug it in ANTLRWorks, then you need to debug it in the target language (I am presuming Java here as you don’t say, and Netbeans does a decent job if so).
   
  Jim
   
        From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of amol Bhagavat
Sent: Thursday, October 11, 2007 12:55 AM
To: antlr
Subject: [antlr-interest] Antlr parse cannot parse the file completly


   
    Hi,

     

    Need your help.

     

    With the help of ANTLR i generated lexer & parser from the grammar . The grammer i developed for my requirement is to trace out indirect function calls like function pointers.

     

    My project directory contains 500+ files.I give one file at a time to the parser.

    But it seems it does not parse the file completely... i have put some information below about the lines it lefts out.

     

    FileName         Detects Upto Line       Last Line in the file        Difference

    file1                 20997                        21415                           418

    file2                 15047                        15672                           625

    file3                 8187                          8187                             0

    file4                 430                           450                               20

    file5                18870                        18920                            50

    file6                7957                          7988                             31

     

     

    I tried to use the java command like this

    java -Xmx1024m Main doutput.txt>goutput.txt

     

    (The doutput contains the file paths & goutput contains the parsed data.)

    But still it same.

    Pls let me know am i doing mistake anywhere or some limitation??

     

    Many Thanks..

     

     

    file1 

    
    
---------------------------------
  
  Yahoo! Answers - Get better answers from someone who knows. Try it now.
  No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.7/1062 - Release Date: 10/10/2007 5:11 PM



  No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.7/1062 - Release Date: 10/10/2007 5:11 PM


    
---------------------------------
  For ideas on reducing your carbon footprint visit Yahoo! For Good this month. 

       
---------------------------------
 Yahoo! Answers - Get better answers from someone who knows. Tryit now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071016/3181e4e2/attachment-0001.html 


More information about the antlr-interest mailing list