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

Cast problem in Parse



Hello,

 I've got a probleme when i call the Parse fonction generated
by sablecc with that grammar file:

Package UnionScript; // package name

Helpers
  ascii_char = [32 .. 127] ;

  // letters and digits
  letter = [['a' .. 'z'] + ['A' .. 'Z']];
  digit = ['0' .. '9'] ;

  // un-printable characters
  tab = 9 ;
  cr = 13 ;
  lf = 10 ;
  blank = ' ' ;

Tokens

  // arithmetic symbols
  plus = '+' ;
  minus = '-' ;
  mult = '*' ;
  div = '/' ;

  //KeyWord
  if = 'if' ;
  then = 'then' ;
  else = 'else' ;

  // identifiers
  identifier = letter (letter | digit)* ;

  // numbers
  number = digit+; // integer numbers only

  lbrace = '}' ;
  rbrace = '{' ;

  // symbols separators
  lparen = '(' ;
  rparen = ')' ;
  coma = ',' ;
  semi = ';' ;

  // blanks
  blanks = blank | cr lf | cr | lf | tab ;

Ignored Tokens
  blanks ;

Productions

  // expressions
  block = lbrace expression block_tail* rbrace;
  block_tail = semi expression ;

  expression =
    {ifexp} ifexp |
    {term} term |
    {plus} expression plus term |
    {minus} expression minus term ;

  term =
    {factor} factor |
    {mult} term mult factor |
    {div} term div factor;

  factor =
    {identifier} identifier |
    {number} number |
    {expression} lparen expression rparen;

  ifexp =
    {ifexp} if expression then block optional_else ;

  optional_else =
    {else}  else block |
    {empty} ;

// end of grammar.

I just try to parse "1+1"
And the java VM say it to me:
java.lang.ClassCastExeception: UnionScript/node/TIdentifier

I have found the line which generate the exception, it is in the
file Parser.java:

Node new12()
{
	TIdentifier node1 = (TIdentifier) pop(); // Here
	AIdentifierFactor node = new .....
...
}

I Have try some random modification but, each time, the same
exception is thrown, with different cast.

If I try to parse "{1+1}", it says:
[1,1] Unknown token: {

?????
Help

Thx.

Jean-Daniel Michaud
EPITA Promo 2004
KGB supercomputer Serbian ammunition radar BATF cracking NSA
assassination CIA FBI World Trade Center fissionable Khaddafi security