[antlr-interest] semantic predicate affects nothing

Markus Kuhla bace.spam at gmx.net
Mon Jun 18 11:44:10 PDT 2007


Hi Kay,

Thanks a lot!!! It works. You cannot imagine how many weeks I tried to get this (besides a lot of other stuff of course ;)).

I had to adapt this thus other characters at the beginning of the line are allowed too:

text_lines
 : text  (inline | text)*  NEWLINE  text_lines?
 | (OPEN ~NEWLINE) =>  inline  (inline | text)*  NEWLINE  text_lines?
 ;

Best,
Markus


> Hi Markus!
> 
> On Jun 18, 2007, at 2:31 AM, Markus Kuhla wrote:
> 
> > page		:	paragraph *;
> > paragraph 	:	text_parag  |  block;
> > text_paragr	:	(OPEN ((NEWLINE)=>{false}? )) => text_line+;
> 
> I think the reason why the semantic predicate is not generated into  
> the code is that there isn't any matching done immediately after it,  
> but I'm not totally sure.
> 
> Does this help:
> 
> text_paragr	:	(OPEN ~NEWLINE)=> text_line+;
> 
> I can't test it right now, but I think it should do the trick.  
> Synpred reads as "there must be OPEN followed by not NEWLINE" to  
> match text_line+.
> For the actual predicate evalutation look in the code for rule  
> paragraph, as the predicate is hoisted from text_paragraph.
> This is the code I get for the grammar then:
> 
>     // /tmp/Test.g:5:1: paragraph : ( text_paragr | block );
>      public final void paragraph() throws RecognitionException {
>          try {
>              // /tmp/Test.g:5:14: ( text_paragr | block )
>              int alt2=2;
>              int LA2_0 = input.LA(1);
> 
>              if ( (LA2_0==NEWLINE||LA2_0==ANY) ) {
>                  alt2=1;
>              }
>              else if ( (LA2_0==OPEN) ) {
>                  int LA2_2 = input.LA(2);
> 
>                  if ( (LA2_2==NEWLINE) ) {
>                      alt2=2;
>                  }
>                  else if ( ((LA2_2>=CLOSE && LA2_2<=ANY)) ) {
>                      alt2=1;
>                  }
>                  else {
>                      if (backtracking>0) {failed=true; return ;}
>                      NoViableAltException nvae =
>                          new NoViableAltException("5:1: paragraph :  
> ( text_paragr | block );", 2, 2, input);
> 
>                      throw nvae;
>                  }
>              }
>              else {
>                  if (backtracking>0) {failed=true; return ;}
>                  NoViableAltException nvae =
>                      new NoViableAltException("5:1: paragraph :  
> ( text_paragr | block );", 2, 0, input);
> 
>                  throw nvae;
>              }
>              switch (alt2) {
>                  case 1 :
>                      // /tmp/Test.g:5:14: text_paragr
>                      {
>                      pushFollow(FOLLOW_text_paragr_in_paragraph22);
>                      text_paragr();
>                      _fsp--;
>                      if (failed) return ;
> 
>                      }
>                      break;
>                  case 2 :
>                      // /tmp/Test.g:5:30: block
>                      {
>                      pushFollow(FOLLOW_block_in_paragraph28);
>                      block();
>                      _fsp--;
>                      if (failed) return ;
> 
>                      }
>                      break;
> 
>              }
>          }
>          catch (RecognitionException re) {
>              reportError(re);
>              recover(input,re);
>          }
>          finally {
>          }
>          return ;
>      }
> 
> 
> HTH,
> 
> -k
> 
> -- 
> Kay Röpke
> http://classdump.org/
> 
> 
> 

-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail


More information about the antlr-interest mailing list