[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in SableCC 2.17.2?



 

Mariusz Nowostawski wrote:

Hi Xuan Baldauf,

I think the problem is caused by mixing set and non-set helpers inside
set-based operation.

Helpers
  char            = [0..127];
  separators      = ';' | ',' ;
  tokenchar       = [char-separators];

As you can notice, seperators is not a set but a list of alternatives. If
you make it a set, like:

  separators      = [';' + ','] ;

all will work correctly.

(Btw, it will throw another exception, due to lack of any tokens
definitions, I believe. It would be nicer to simply tell that there is no
tokens for constructing DFA, so I will fix it today,  before 2.17.3.
Anything else?)

Thank you Mariusz for pointing that out. I thought that the bar-operator is just a set-ORing operator, as the plus-operator is (Somewhere in the mailing list archive, I read about "old style" and "new style", so I assumed that this is just an issue of style, not an issue of different meanings.)

Where can I find documentation about the grammar definition file format (except the thesis and the example grammars)?

Are there any difference between a "set of alternatives of characters" and a "set of characters" in using them? (Does the former have advantages that the latter cannot have and vice versa?)

My real "separators" helper definition is something like this:

separators =
 '(' |
 ')' |
 '<' |
 '>' |
 '@' |
 ',' |
 ';' |
 ':' |
 '\\' |
 '"' |
 '/' |
 '[' |
 ']' |
 '?' |
 '=' |
 '{' |
 sp |
 ht;

Unfortunately, I cannot convert it to something like this:

separators = [
 '(' +
 ')' +
 '<' +
 '>' +
 '@' +
 ',' +
 ';' +
 ':' +
 '\\' +
 '"' +
 '/' +
 '[' +
 ']' +
 '?' +
 '=' +
 '{' +
 sp +
 ht;
]

With the current syntax, I have to write this (which is ugly):

separators  =
[
  [
    [
      [
        [
          '(' +
          ')'
        ] + [
          '<' +
          '>'
        ]
      ] + [
        [
          '@' +
          ','
        ] + [
          ';' +
          ':'
        ]
      ]
    ] + [
      [
        [
          '\' +
          '"'
        ] + [
          '/' +
          '['
        ]
      ] + [
        [
          ']' +
          '?'
        ] + [
          '=' +
          '{'
        ]
      ]
    ]
  ] + [
    ht +
    sp
  ]
];

I hope you agree with me. What about changing the "sablecc-2"-grammar from

    set =
        {operation} l_bkt [left]:basic  bin_op [right]:basic  r_bkt |
        {interval}  l_bkt [left]:P.char d_dot  [right]:P.char r_bkt;

to something like this (I'm not an expert in writing sablecc-grammars)?:

    set           = set_operation | set_interval;
    set_interval  = l_bkt [left]:P.char d_dot  [right]:P.char r_bkt;
    set_operation = l_bkt [left]:basic  bin_operation*  r_bkt;
    bin_operation = bin_op [right]:basic;
 
So I could write my "compound character set" in a much more cleaner way.

 

PS. what does the "mn" stand in your example Package declaration?
Just curious.

This is "Medium.net", the company I'm working for.
 

best regards
Mariusz

On Tue, 21 Aug 2001, Xuan Baldauf wrote:

> Hello,
>
> please try out the attached grammar file. SableCC fails with
> a runtime exception covering due to a class cast exception.
>
> Xuân.


P.S.: After converting the '|' to '['..'+'..']'-constructs, I get following exception for my grammar I try to write:

java.lang.NullPointerException
        at org.sablecc.sablecc.Grammar.FIRST(Grammar.java:313)
        at org.sablecc.sablecc.Grammar.FIRST(Grammar.java:292)
        at org.sablecc.sablecc.Grammar.computeFirst(Grammar.java:278)
        at org.sablecc.sablecc.Grammar.computeLALR(Grammar.java:88)
        at org.sablecc.sablecc.GenParser.caseStart1(GenParser.java:109)
        at org.sablecc.sablecc.node.Start1.apply(Start1.java:17)
        at org.sablecc.sablecc.SableCC.processGrammar(SableCC.java:269)
        at org.sablecc.sablecc.SableCC.processGrammar(SableCC.java:195)
        at org.sablecc.sablecc.SableCC.start(SableCC.java:146)
        at org.sablecc.sablecc.Executable.Main(Executable.java:74)
        at org.sablecc.sablecc.SableCC.main(SableCC.java:297)

Attached is my grammar reduced to a test case. I hope that I do not trigger some documented problem again...
 

Package com.mn.tools.test.bugs.sablecc;

Helpers

	tokenchar												= [[0x0000..0xFFFF]-','];

Tokens

	token														=	tokenchar+;
	comma														=	',';

Productions

	token_list			=	token token_list_tail*;
//token_list_tail	= token;						// works
	token_list_tail	= ( token );				// exception
//token_list_tail	= ( comma token );	// exception