Loading ...
Sorry, an error occurred while loading the content.
 

Re: probably too obvious to see it - plz help

Expand Messages
  • tdjastrzebski
    It should choose StringLiteral when n is followed by . So how do I fix it ? Tom Jastrzebski ... handle ... http://docs.yahoo.com/info/terms/
    Message 1 of 5 , Jul 31, 2003
      It should choose StringLiteral when 'n' is followed by '\''.
      So how do I fix it ?
      Tom Jastrzebski

      --- In antlr-interest@yahoogroups.com, mzukowski@y... wrote:
      > So if it sees "n" which rule is it supposed to choose? You need to
      handle
      > the two possibilities prefixed with 'n' in one rule.
      >
      > Monty
      >
      > -----Original Message-----
      > From: tdjastrzebski [mailto:tdjastrzebski@y...]
      > Sent: Thursday, July 31, 2003 4:14 PM
      > To: antlr-interest@yahoogroups.com
      > Subject: [antlr-interest] probably too obvious to see it - plz help
      >
      >
      > I ma probably too tireed to see it. Why following two lexer rules
      > cause nondeterminism (k=2).
      >
      > Identifier
      > : ('a'..'z')+
      > ;
      > StringLiteral
      > : ('n')? '\'' (~'\'')* '\''
      > ;
      >
      > StringLiteral rule is supposed to match unicode strings like:
      > n'blabla'
      >
      > Thanks in advance.
      > Tom Jastrzebski
      >
      > full test grammar:
      >
      > options {
      > language = "Java";
      > }
      >
      > class TestParser extends Parser;
      > options {
      > k = 2;
      > }
      >
      > expression
      > : (Identifier | StringLiteral) EOF
      > ;
      >
      > class TestLexer extends Lexer;
      > options {
      > k = 2;
      > }
      >
      > Identifier
      > : ('a'..'z')+
      > ;
      >
      > StringLiteral
      > : ('n')? '\'' (~'\'')* '\''
      > ;
      >
      >
      >
      >
      > Your use of Yahoo! Groups is subject to
      http://docs.yahoo.com/info/terms/
    • Matt Benson
      This is probably not the best way, but it works. I added a semantic predicate to the IDENTIFIER rule: IDENTIFIER ... ; -Matt ...
      Message 2 of 5 , Aug 1, 2003
        This is probably not the best way, but it works. I
        added a semantic predicate to the IDENTIFIER rule:

        IDENTIFIER
        : {LA(2) != '\''}? ('a'..'z')+
        ;

        -Matt

        --- tdjastrzebski <tdjastrzebski@...> wrote:
        > It should choose StringLiteral when 'n' is followed
        > by '\''.
        > So how do I fix it ?
        > Tom Jastrzebski
        >
        > --- In antlr-interest@yahoogroups.com,
        > mzukowski@y... wrote:
        > > So if it sees "n" which rule is it supposed to
        > choose? You need to
        > handle
        > > the two possibilities prefixed with 'n' in one
        > rule.
        > >
        > > Monty
        > >
        > > -----Original Message-----
        > > From: tdjastrzebski [mailto:tdjastrzebski@y...]
        > > Sent: Thursday, July 31, 2003 4:14 PM
        > > To: antlr-interest@yahoogroups.com
        > > Subject: [antlr-interest] probably too obvious to
        > see it - plz help
        > >
        > >
        > > I ma probably too tireed to see it. Why following
        > two lexer rules
        > > cause nondeterminism (k=2).
        > >
        > > Identifier
        > > : ('a'..'z')+
        > > ;
        > > StringLiteral
        > > : ('n')? '\'' (~'\'')* '\''
        > > ;
        > >
        > > StringLiteral rule is supposed to match unicode
        > strings like:
        > > n'blabla'
        > >
        > > Thanks in advance.
        > > Tom Jastrzebski
        > >
        > > full test grammar:
        > >
        > > options {
        > > language = "Java";
        > > }
        > >
        > > class TestParser extends Parser;
        > > options {
        > > k = 2;
        > > }
        > >
        > > expression
        > > : (Identifier | StringLiteral) EOF
        > > ;
        > >
        > > class TestLexer extends Lexer;
        > > options {
        > > k = 2;
        > > }
        > >
        > > Identifier
        > > : ('a'..'z')+
        > > ;
        > >
        > > StringLiteral
        > > : ('n')? '\'' (~'\'')* '\''
        > > ;
        > >
        > >
        > >
        > >
        > > Your use of Yahoo! Groups is subject to
        > http://docs.yahoo.com/info/terms/
        >
        >
        >
        >
        > Your use of Yahoo! Groups is subject to
        > http://docs.yahoo.com/info/terms/
        >
        >


        __________________________________
        Do you Yahoo!?
        Yahoo! SiteBuilder - Free, easy-to-use web site design software
        http://sitebuilder.yahoo.com
      Your message has been successfully submitted and would be delivered to recipients shortly.