grammatica-users
[Top][All Lists]
Advanced

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

Re: [Grammatica-users] Simple question


From: Per Cederberg
Subject: Re: [Grammatica-users] Simple question
Date: Fri, 11 Mar 2005 19:42:50 +0100

There are two options I think. The first one would be to use the
%ignore% flag on the tokens and then completely remove them from
the productions. This would mean that these tokens are ignored
anywhere in the input, which might be a bit strange (as it should
probably be a parse error to use them in other places than what
you intended).

The second, and better, option is to handle the "skipping" in
your Analyzer subclass. If the token name is DUMMY, you'd do
like this:

   protected Node exitDummy(Token node) {
       return null;
   }

By returning null from the exit-method the node will not be
included in the resulting parse tree. You'll then call the
parser like this:

   my = new MyParser(new FileReader(file), new MyAnalyzer());
   my.parse();

Hope this helps!

/Per

On fri, 2005-03-11 at 11:41 -0500, Luc Morin wrote:
> Hi all,
>  
> Is it possible to have certain tokens to be part of a production, but
> not to be included in the parse tree ?
>  
> For example, I want to create a parse tree from the following line:
>  
>  
> <5 1> = "allo" ? <6> : <7<8 1>>
>  
> Which is a conditional expression. I "need" the < and > tokens to be
> compatible with some third party software, but I don't want to clutter
> the parse tree with them.
>  
> I'd also like to get rid of the =, ? and : tokens
>  
> I find that if I use the %ignore% directive for those tokens, I get
> parse errors because of unreckognized tokens.
>  
> Right now the parse tree looks like this:
>  
> File(2001)
>   Expression(2002)
>     Property(2004)
>       SMALLER_THAN(1005): "<", line: 1, col: 1
>       Propnum(2005)
>         NUMBER(1007): "5", line: 1, col: 2
>       Index(2006)
>         NUMBER(1007): "1", line: 1, col: 4
>       GREATER_THAN(1004): ">", line: 1, col: 5
>     CondStatement(2003)
>       EQUAL(1003): "=", line: 1, col: 7
>       QUOTED_STRING(1006): ""allo"", line: 1, col: 9
>       Q_MARK(1001): "?", line: 1, col: 16
>       Property(2004)
>         SMALLER_THAN(1005): "<", line: 1, col: 18
>         Propnum(2005)
>           NUMBER(1007): "6", line: 1, col: 19
>         GREATER_THAN(1004): ">", line: 1, col: 20
>       COLON(1002): ":", line: 1, col: 22
>       Property(2004)
>         SMALLER_THAN(1005): "<", line: 1, col: 24
>         Propnum(2005)
>           NUMBER(1007): "7", line: 1, col: 25
>         Property(2004)
>           SMALLER_THAN(1005): "<", line: 1, col: 26
>           Propnum(2005)
>             NUMBER(1007): "8", line: 1, col: 27
>           Index(2006)
>             NUMBER(1007): "1", line: 1, col: 29
>           GREATER_THAN(1004): ">", line: 1, col: 30
>         GREATER_THAN(1004): ">", line: 1, col: 31
>  
>  
> I'd like it to look like this:
>  
>  
> File(2001)
>   Expression(2002)
>     Property(2004)
>       Propnum(2005)
>         NUMBER(1007): "5", line: 1, col: 2
>       Index(2006)
>         NUMBER(1007): "1", line: 1, col: 4
>     CondStatement(2003)
>       QUOTED_STRING(1006): ""allo"", line: 1, col: 9
>       Property(2004)
>         Propnum(2005)
>           NUMBER(1007): "6", line: 1, col: 19
>       Property(2004)
>         Propnum(2005)
>           NUMBER(1007): "7", line: 1, col: 25
>         Property(2004)
>           Propnum(2005)
>             NUMBER(1007): "8", line: 1, col: 27
>           Index(2006)
>             NUMBER(1007): "1", line: 1, col: 29
> 
>  
>  
>  
> Here's the grammar:
>  
> ------------------------8<----------------------------
>  
> %header%
> GRAMMARTYPE = "LL"
> DESCRIPTION = "A grammar for a new form generator."
> AUTHOR = "Luc Morin"
> VERSION = "1.0"
> DATE = "10 march 2005"
>  
> %tokens%
> Q_MARK = "?"
> COLON = ":"
> EQUAL = "="
> GREATER_THAN = ">" 
> SMALLER_THAN = "<"
> QUOTED_STRING = <<"[^"]*">>
> NUMBER = <<[0-9]+>>
> WHITESPACE = <<[ \t\n\r]+>> %ignore%
>  
> %productions%
> File = Expression+ ;
> Expression = Property [CondStatement] ;
> CondStatement = EQUAL QUOTED_STRING Q_MARK Property COLON Property ;
> Property = SMALLER_THAN Propnum [Index] [Property] GREATER_THAN ;
> Propnum = NUMBER ;
> Index = NUMBER ;
>  
>  
> ------------------------8<----------------------------
>  
>  
>  
> Is that at all possible ? I find that it makes "navigating" the tree
> easier.
>  
> Regards,
>  
>  
> Luc Morin
>  
> Electrical Designer
> Wulftec / M.J. Maillis Group
> address@hidden
> Ph.: (819) 838-4232 ext. 232
> Fx.: (819) 838-5539
>  
> www.wulftec.com
> www.maillis.gr
>  
> << Avis de confidentialité >>
> Ce courrier électronique ainsi que tous les documents qui y sont
> attachés sont de nature privilégiée et confidentielle et sont destinés
> à l'utilisation exclusive du ou des destinataire(s) ci-haut
> mentionné(s) . Toute autre personne ayant reçu ce message par
> erreur est priée de bien vouloir s'abstenir de divulguer, distribuer
> ou reproduire ce message et/ou son contenu. Si le destinataire ne peut
> être rejoint ou vous est inconnu, nous vous prions d'informer
> immédiatement l'expéditeur de ce présent message par retour de
> courriel en plus d'effacer ce message et détruire toutes les copies.
> Merci.
> 
>  
> 
> << Confidentiality Notice >>
> 
> This e-mail message and any files transmitted with it are
> confidential, may be privileged and are intended for the exclusive use
> of the addressee(s). Any other person is strictly prohibited from
> disclosing, distributing or reproducing it. If the addressee cannot be
> reached or is unknown to you, please inform the sender by return
> e-mail immediately, delete this e-mail message and destroy all copies.
> Thank you.
> 
> 
>  
> _______________________________________________
> Grammatica-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
-- 
Per Cederberg
Systemarkitekt & Processmentor
Tel:   073-664 69 13
Epost: address@hidden
Webb:  http://www.percederberg.net/software/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]