CST to AST transformations

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

CST to AST transformations

by Henrique Rocha :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm having a really hard time trying to understand some aspects of
this functionality.
I want a program to be a list of declarations or function definitions.
How would I do the transformations?

program = decl_or_def* {-> New program([decl_or_def]) };

decl_of_def {-> ????? } = /* what should I place here? */
      {typedef} typedef type id {-> New typedef(type, id); }
    | {function} function_definition {-> function_definition.function};

function_definition {-> function} =
    type id l_par params* r_par l_brace var_decl* statement* r_brace
        {-> New function(type, id, [params.param], [var_decl], [statement]) };

I know I'm doing something wrong, I just don't know why.
Thanks very much.

--
Henrique Rocha
www.hmrocha.com
ExpertRating Certified Windows XP Professional
ExpertRating Certified Unix Shell Script Professional
ExpertRating Certified Unix Professional
ExpertRating Certified Object-Oriented Concepts Professional
ExpertRating Certified Professional Computer Technician Skills
ExpertRating Certified HTML 4 Professional

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

Parent Message unknown Re: CST to AST transformations

by Christopher Van Kirk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


That fragment is for the return type of the concrete production. The problem with yours is that you're trying to return two different types of abstract production. What you probably need to do is adjust your abstract definitions to group together the productions that you want to be related in this way...for example:

decl_of_def {-> declaration } = /* what should I place here? */
      {typedef} typedef type id {-> New declaration.typedef(type, id); }
    | {function} function_definition {-> New declaration.func_def( function_definition.function ) };

and in the AST section something like

declaration
   {typedef} type id |
   {func_def} function


--- On Sun, 4/12/09, Henrique Rocha <hmrocha@...> wrote:

> From: Henrique Rocha <hmrocha@...>
> Subject: CST to AST transformations
> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
> Date: Sunday, April 12, 2009, 1:13 AM
> Hi,
>
> I'm having a really hard time trying to understand some
> aspects of
> this functionality.
> I want a program to be a list of declarations or function
> definitions.
> How would I do the transformations?
>
> program = decl_or_def* {-> New program([decl_or_def])
> };
>
> decl_of_def {-> ????? } = /* what should I place here?
> */
>       {typedef} typedef type id {-> New
> typedef(type, id); }
>     | {function} function_definition {->
> function_definition.function};
>
> function_definition {-> function} =
>     type id l_par params* r_par l_brace var_decl*
> statement* r_brace
>         {-> New function(type, id,
> [params.param], [var_decl], [statement]) };
>
> I know I'm doing something wrong, I just don't know why.
> Thanks very much.
>
> --
> Henrique Rocha
> www.hmrocha.com
> ExpertRating Certified Windows XP Professional
> ExpertRating Certified Unix Shell Script Professional
> ExpertRating Certified Unix Professional
> ExpertRating Certified Object-Oriented Concepts
> Professional
> ExpertRating Certified Professional Computer Technician
> Skills
> ExpertRating Certified HTML 4 Professional
>
> _______________________________________________
> 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: CST to AST transformations

by Henrique Rocha :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It worked. Thank you very, very much. =)


On Sat, Apr 11, 2009 at 8:29 PM, Christopher Van Kirk
<chris.vankirk@...> wrote:

>
> That fragment is for the return type of the concrete production. The problem with yours is that you're trying to return two different types of abstract production. What you probably need to do is adjust your abstract definitions to group together the productions that you want to be related in this way...for example:
>
> decl_of_def {-> declaration } = /* what should I place here? */
>      {typedef} typedef type id {-> New declaration.typedef(type, id); }
>    | {function} function_definition {-> New declaration.func_def( function_definition.function ) };
>
> and in the AST section something like
>
> declaration
>   {typedef} type id |
>   {func_def} function
>
>
> --- On Sun, 4/12/09, Henrique Rocha <hmrocha@...> wrote:
>
>> From: Henrique Rocha <hmrocha@...>
>> Subject: CST to AST transformations
>> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
>> Date: Sunday, April 12, 2009, 1:13 AM
>> Hi,
>>
>> I'm having a really hard time trying to understand some
>> aspects of
>> this functionality.
>> I want a program to be a list of declarations or function
>> definitions.
>> How would I do the transformations?
>>
>> program = decl_or_def* {-> New program([decl_or_def])
>> };
>>
>> decl_of_def {-> ????? } = /* what should I place here?
>> */
>>       {typedef} typedef type id {-> New
>> typedef(type, id); }
>>     | {function} function_definition {->
>> function_definition.function};
>>
>> function_definition {-> function} =
>>     type id l_par params* r_par l_brace var_decl*
>> statement* r_brace
>>         {-> New function(type, id,
>> [params.param], [var_decl], [statement]) };
>>
>> I know I'm doing something wrong, I just don't know why.
>> Thanks very much.
>>
>> --
>> Henrique Rocha
>> www.hmrocha.com
>> ExpertRating Certified Windows XP Professional
>> ExpertRating Certified Unix Shell Script Professional
>> ExpertRating Certified Unix Professional
>> ExpertRating Certified Object-Oriented Concepts
>> Professional
>> ExpertRating Certified Professional Computer Technician
>> Skills
>> ExpertRating Certified HTML 4 Professional
>>
>> _______________________________________________
>> 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
>



--
Henrique Rocha
www.hmrocha.com
ExpertRating Certified Windows XP Professional
ExpertRating Certified Unix Shell Script Professional
ExpertRating Certified Unix Professional
ExpertRating Certified Object-Oriented Concepts Professional
ExpertRating Certified Professional Computer Technician Skills
ExpertRating Certified HTML 4 Professional

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