Hi -

On 11/26/16, 11:16 AM, "Tomsy Paul" <[email protected]> wrote:

>I want to do some processing with the variables in an expression. For
>example, from the expression i==j in,
>
>
>
>if i==j then writeln("yes");
>
>
>I want to get the lexemes i and j and also their other attributes, say
>types. I am doing something with the compiler, so I would like to know
>how I can get this from within the Expr or its derived classes. I tried a
>
>printf("%s",$2->parentSymbol->name); //Simplified grammar, if id == id
>then...
>
>
>from chapel.ypp, but it resulted in an internal error.

Generally speaking, if you are making some sort of code analysis or
transformation that doesn't use type information, that can happen
during parse time or in an early pass (such as cleanup.cpp). But,
if a transformation happens during after parse time, you'll have to
add AST elements to preserve the right information until it
is transformed into something the rest of the compiler already
understands.

Generally, the parser uses functions in AST/build.cpp
to build up the AST. So, I wouldn't normally write any
code other than a call to something in AST/build.cpp in
the parser grammar. It probably makes sense for
you to add a new function in AST/build.cpp. Reading through
some of the existing functions there is a good place to start.

In your example, I'm not sure what i==j exactly will turn in to,
but you can use something like

  chpl myprogram --log= --log-ids

and then look at

  log/myprogram*

in order to understand what is stored in the AST. Usually I
try to understand such an AST dump and then go from there
to understanding how to write code working with the relevant
AST classes.

Hope that helps,

-michael

------------------------------------------------------------------------------
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to