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

Re: Tokens priority



>I know it is possible to use states in order to solve this problem. Is
there any
>other way (except from the obvious:
> sentence =
> {case1} litteral name litteral |
> {case2} litteral litteral litteral;)

Why not eliminate the unwanted alternative from the grammar after the AST
has been built?

e.g.:

sentence =
  [l1]:litteral [l2]:litteral [l3]:litteral |
  {temp} [l1]:litteral name [l3]:litteral;

class ModifyAST extends D.P.A.
{
  outATempSentence(... node)
  {
    node.replaceBy(
      new ASentence(node.getL1(),
        new Litteral(node.getName().getText()),
        node.getL3()));
  }
}

Etienne


-----Original Message-----
From: Benjamin Ryzman <Benjamin.Ryzman@SOLsoft.Com>
To: sablecc-list@sable.mcgill.ca <sablecc-list@sable.mcgill.ca>
Date: Tuesday, March 31, 1998 9:25 AM
Subject: Tokens priority


>I understand SableCC Lexer relies on the order of tokens declaration for
their
>recognition. This is a problem for me in the following example:
>
>Tokens
> litteral = 'litteral';
> name = (letter | digit)+;
>
>Productions
> sentence = litteral name litteral;
>
>If the sentence is "litteral foo litteral", the parser will recognize it.
However,
>if the sentence is "litteral litteral litteral", it won't (the series of
tokens
>"litteral litteral litteral" is not a sentence production).
>
>If I rearange the tokens declaration in the inverse order, then the parser
will not
>recognise any of the sentences (it will always be recognized as a
production of "name
>name name", which is not declared).
>
>I know it is possible to use states in order to solve this problem. Is
there any
>other way (except from the obvious:
> sentence =
> {case1} litteral name litteral |
> {case2} litteral litteral litteral;)
>
>Sorry if it's a really simple matter, my background in parsing is very
scarce,
>I'm just trying to use SableCC in a real world application.
>
>--
>Benjamin Ryzman   "Deliver yesterday, code today, think tomorrow."
>Software Engineer, NetPartitioner(TM) design team.
>SOLsoft SA, 4bis rue de la Gare, 92300 Levallois-Perret, France.