SableCC in a C# desktop application

View: New views
8 Messages — Rating Filter:   Alert me  

SableCC in a C# desktop application

by MatthiasVanneste :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I've just discovered SableCC and I would like to use it in a C# desktop application. I've used the C# output module by Indrek Mandre. I'm using the demo grammar and translator code used in the thesis to mess around with. What I'm trying is this :

//Main Code//

TextReader txtReader = new StreamReader(ofdSource.OpenFile());

String file = "";

Parser p = new Parser(new Lexer(txtReader));

Start tree = p.Parse();

translation tr = new translation(ref file);

tree.Apply(tr);

txtTarget.Text = "...Finished";

//End Main Code//

//Translator Code//

public class translation : DepthFirstAdapter
{
        private String file;

        public translation(ref string f)
        {
            file = f;
        }

        public void caseTNumber(TNumber node)
         {
             file.Insert(file.Length, node.Text + "\n");
         }
}

//End Translator Code//

My aim is for the translator to, when encountering a number, to write it to the provided string.
Unfortunately, it seems as the translator methods are not being called at all. I don't know if it can even work like this? If anyone has any tips or advise I would appreciate to get it.

Thx.

Greetings,

Matt.
 

RE: SableCC in a C# desktop application

by Christopher Van Kirk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This is the fragment we use:

StringReader reader = new StringReader( input );

Lexer l = new Lexer(reader);
Parser p = new Parser(l);
Start ast = p.Parse();

ast.Apply(new TreeWalker());


It doesn't seem different from yours.


Have you looked at the lexer output to verify that your language is
generating a TNumber token when you expect it to?

Chris...

-----Original Message-----
From:
sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...
[mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@....
org] On Behalf Of MatthiasVanneste
Sent: Friday, July 17, 2009 4:35 PM
To: SableCC-Discussion@...
Subject: SableCC in a C# desktop application


Hi all,

I've just discovered SableCC and I would like to use it in a C# desktop
application. I've used the C# output module by Indrek Mandre. I'm using the
demo grammar and translator code used in the thesis to mess around with.
What I'm trying is this :

//Main Code//

TextReader txtReader = new StreamReader(ofdSource.OpenFile());

String file = "";

Parser p = new Parser(new Lexer(txtReader));

Start tree = p.Parse();

translation tr = new translation(ref file);

tree.Apply(tr);

txtTarget.Text = "...Finished";

//End Main Code//

//Translator Code//

public class translation : DepthFirstAdapter
{
        private String file;

        public translation(ref string f)
        {
            file = f;
        }

        public void caseTNumber(TNumber node)
         {
             file.Insert(file.Length, node.Text + "\n");
         }
}

//End Translator Code//

My aim is for the translator to, when encountering a number, to write it to
the provided string.
Unfortunately, it seems as the translator methods are not being called at
all. I don't know if it can even work like this? If anyone has any tips or
advise I would appreciate to get it.

Thx.

Greetings,

Matt.
 
--
View this message in context:
http://www.nabble.com/SableCC-in-a-C--desktop-application-tp24529943p2452994
3.html
Sent from the SableCC - User mailing list archive at Nabble.com.


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: SableCC in a C# desktop application

by Indrek Mandre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Friday 17 July 2009 10:34:50 MatthiasVanneste wrote:

> Hi all,
>
> I've just discovered SableCC and I would like to use it in a C# desktop
> application. I've used the C# output module by Indrek Mandre. I'm using the
> demo grammar and translator code used in the thesis to mess around with.
> What I'm trying is this :
>
> //Main Code//
>
> TextReader txtReader = new StreamReader(ofdSource.OpenFile());
>
> String file = "";
>
> Parser p = new Parser(new Lexer(txtReader));
>
> Start tree = p.Parse();
>
> translation tr = new translation(ref file);
>
> tree.Apply(tr);
>
> txtTarget.Text = "...Finished";
>
> //End Main Code//
>
> //Translator Code//
>
> public class translation : DepthFirstAdapter
> {
>         private String file;
>
>         public translation(ref string f)
>         {
>             file = f;
>         }
>
>         public void caseTNumber(TNumber node)
>          {
>              file.Insert(file.Length, node.Text + "\n");
>          }
> }
>
> //End Translator Code//
>
> My aim is for the translator to, when encountering a number, to write it to
> the provided string.
> Unfortunately, it seems as the translator methods are not being called at
> all. I don't know if it can even work like this? If anyone has any tips or
> advise I would appreciate to get it.
>

Hi!

The problem you have here is the name of the case method.
It should probably be "CaseTNumber" - it uses the C# Camel
Casing style for naming members with first letter capital
as well. See the generated analysis.cs file for prototypes.

Regards,
Indrek

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

RE: SableCC in a C# desktop application

by MatthiasVanneste :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've been checking the AST and it is correct, I used a very simple example (15 * 3).
But I can't seem to make it call the outAFactorExpr(AFactorExpr node) method.

Gr.
Matt

Christopher Van Kirk wrote:
This is the fragment we use:

StringReader reader = new StringReader( input );

Lexer l = new Lexer(reader);
Parser p = new Parser(l);
Start ast = p.Parse();

ast.Apply(new TreeWalker());


It doesn't seem different from yours.


Have you looked at the lexer output to verify that your language is
generating a TNumber token when you expect it to?

Chris...

-----Original Message-----
From:
sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@lists.sablecc.org
[mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@lists.sablecc.
org] On Behalf Of MatthiasVanneste
Sent: Friday, July 17, 2009 4:35 PM
To: SableCC-Discussion@lists.sablecc.org
Subject: SableCC in a C# desktop application


Hi all,

I've just discovered SableCC and I would like to use it in a C# desktop
application. I've used the C# output module by Indrek Mandre. I'm using the
demo grammar and translator code used in the thesis to mess around with.
What I'm trying is this :

//Main Code//

TextReader txtReader = new StreamReader(ofdSource.OpenFile());

String file = "";

Parser p = new Parser(new Lexer(txtReader));

Start tree = p.Parse();

translation tr = new translation(ref file);

tree.Apply(tr);

txtTarget.Text = "...Finished";

//End Main Code//

//Translator Code//

public class translation : DepthFirstAdapter
{
        private String file;

        public translation(ref string f)
        {
            file = f;
        }

        public void caseTNumber(TNumber node)
         {
             file.Insert(file.Length, node.Text + "\n");
         }
}

//End Translator Code//

My aim is for the translator to, when encountering a number, to write it to
the provided string.
Unfortunately, it seems as the translator methods are not being called at
all. I don't know if it can even work like this? If anyone has any tips or
advise I would appreciate to get it.

Thx.

Greetings,

Matt.
 
--
View this message in context:
http://www.nabble.com/SableCC-in-a-C--desktop-application-tp24529943p2452994
3.html
Sent from the SableCC - User mailing list archive at Nabble.com.


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@lists.sablecc.org
http://lists.sablecc.org/listinfo/sablecc-discussion


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@lists.sablecc.org
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: SableCC in a C# desktop application

by Indrek Mandre-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


It's OutAFactorExpr (capital 'O'). Check the analysis.cs for prototypes.

Regards,
Indrek

On Mon, Jul 20, 2009 at 12:39 PM, MatthiasVanneste <matthias.vanneste@...> wrote:

I've been checking the AST and it is correct, I used a very simple example
(15 * 3).
But I can't seem to make it call the outAFactorExpr(AFactorExpr node)
method.


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: SableCC in a C# desktop application

by Christopher Van Kirk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Hmm, that's weird. According to Microsoft, Camel Case is what he has there ( caseWhatever ), and what he should have is Pascal Case ( CaseWhatever ). Wikipedia has the opposite opinion on what the meaning of Camel Case is ( CaseWhatever ). Confusing.

Nice to see you're still out there Indrek.

--- On Mon, 7/20/09, Indrek Mandre <indrek@...> wrote:

> From: Indrek Mandre <indrek@...>
> Subject: Re: SableCC in a C# desktop application
> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
> Date: Monday, July 20, 2009, 6:21 PM
> On Friday 17 July 2009 10:34:50
> MatthiasVanneste wrote:
> > Hi all,
> >
> > I've just discovered SableCC and I would like to use
> it in a C# desktop
> > application. I've used the C# output module by Indrek
> Mandre. I'm using the
> > demo grammar and translator code used in the thesis to
> mess around with.
> > What I'm trying is this :
> >
> > //Main Code//
> >
> > TextReader txtReader = new
> StreamReader(ofdSource.OpenFile());
> >
> > String file = "";
> >
> > Parser p = new Parser(new Lexer(txtReader));
> >
> > Start tree = p.Parse();
> >
> > translation tr = new translation(ref file);
> >
> > tree.Apply(tr);
> >
> > txtTarget.Text = "...Finished";
> >
> > //End Main Code//
> >
> > //Translator Code//
> >
> > public class translation : DepthFirstAdapter
> > {
> >         private String
> file;
> >
> >         public
> translation(ref string f)
> >         {
> >         
>    file = f;
> >         }
> >
> >         public void
> caseTNumber(TNumber node)
> >          {
> >             
> file.Insert(file.Length, node.Text + "\n");
> >          }
> > }
> >
> > //End Translator Code//
> >
> > My aim is for the translator to, when encountering a
> number, to write it to
> > the provided string.
> > Unfortunately, it seems as the translator methods are
> not being called at
> > all. I don't know if it can even work like this? If
> anyone has any tips or
> > advise I would appreciate to get it.
> >
>
> Hi!
>
> The problem you have here is the name of the case method.
> It should probably be "CaseTNumber" - it uses the C# Camel
> Casing style for naming members with first letter capital
> as well. See the generated analysis.cs file for
> prototypes.
>
> Regards,
> Indrek
>
> _______________________________________________
> SableCC-Discussion mailing list
> SableCC-Discussion@...
> http://lists.sablecc.org/listinfo/sablecc-discussion
>

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: SableCC in a C# desktop application

by Indrek Mandre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm a tad confused about this as well.

According to wikipedia:
http://en.wikipedia.org/wiki/Identifier_naming_convention#Microsoft.27s_.NET
or
http://msdn.microsoft.com/en-us/library/x2dbyw72(VS.71).aspx
Quote: '''Microsoft .NET recommends upper camel case
(aka "Pascal Style") for most identifiers. (lower camel case is
recommended for parameters)'''

I don't really like camel case myself (either lower or upper camel)
but as microsoft recommended it and all of the .NET API-s use it,
I went with the upper camel (or oh well, lets call it Pascal Case
to clear any confusion for the future).

Regards,
Indrek

On Friday 24 July 2009 03:56:30 Christopher Van Kirk wrote:
> Hmm, that's weird. According to Microsoft, Camel Case is what he has there
> ( caseWhatever ), and what he should have is Pascal Case ( CaseWhatever ).
> Wikipedia has the opposite opinion on what the meaning of Camel Case is (
> CaseWhatever ). Confusing.
>

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: SableCC in a C# desktop application

by Niklas Matthies :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The best way to minimize confusion is to call it UpperCamelCase and
lowerCamelCase. ;)

-- Niklas Matthies

On Fri 2009-07-24 at 04:36h, Indrek Mandre wrote on sablecc-discussion:

>
> I'm a tad confused about this as well.
>
> According to wikipedia:
> http://en.wikipedia.org/wiki/Identifier_naming_convention#Microsoft.27s_.NET
> or
> http://msdn.microsoft.com/en-us/library/x2dbyw72(VS.71).aspx
> Quote: '''Microsoft .NET recommends upper camel case
> (aka "Pascal Style") for most identifiers. (lower camel case is
> recommended for parameters)'''
>
> I don't really like camel case myself (either lower or upper camel)
> but as microsoft recommended it and all of the .NET API-s use it,
> I went with the upper camel (or oh well, lets call it Pascal Case
> to clear any confusion for the future).
>
> Regards,
> Indrek
>
> On Friday 24 July 2009 03:56:30 Christopher Van Kirk wrote:
> > Hmm, that's weird. According to Microsoft, Camel Case is what he has there
> > ( caseWhatever ), and what he should have is Pascal Case ( CaseWhatever ).
> > Wikipedia has the opposite opinion on what the meaning of Camel Case is (
> > CaseWhatever ). Confusing.
> >
>
> _______________________________________________
> SableCC-Discussion mailing list
> SableCC-Discussion@...
> http://lists.sablecc.org/listinfo/sablecc-discussion


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion