tracing HLL compiler actions

bsdz blairuk at googlemail.com
Sun Feb 15 19:19:02 UTC 2009


For any future visitors of this thread...

I discovered that NQP built-ins are not available in the actions.pm
file. However, it appears my own language's built-ins are. So to be
able to print info to your console from your the compiler in
actions.pm ensure you have your own built-in say/print/printf method
defined.

On 13 Feb, 23:04, bsdz <blai... at googlemail.com> wrote:
> > BTW, to get the AST, I would guess you'd want to do $( $<parameters>[0] ).
>
> Thanks - that was particularly helpful :)
>
> > --trace=4 may do what you want.
>
> Was there a command I could use in NQP to send output to the trace
> log?
>
> On 13 Feb, 22:52, Jonathan Worthington <jonat... at jnthn.net> wrote:
>
> > bsdz wrote:
> > > I am attempting to write a language and need to trace what is
> > > happening in my actions.pm methods.
>
> > > I have tried writing 2 similar rules based on Squak: -
>
> > > rule func_def {
> > >     'func' <identifier> <parameters>?
> > > ...
>
> > > and
>
> > > rule func_def2 {
> > >     'func' <identifier> <parameters>
> > > ...
>
> > > When I compare the parse tree targets I noticed the first
> > > implementation wraps my  <parameters> node into a ResizablePMCArray.
> > > So I am guessing if I leave out parameters in my code then I will
> > > still get an empty $<parameters> key in my $/.
>
> > Yes - because you have a quantifier (?) there, you get an array. It will
> > in this case have either zero or one elements.
>
> > > So I am wondering if I should test the existence of parameters in my
> > > action.pm with: -
>
> > > if $<parameters> { ...
>
> > This is fine - it gets if the ResizablePMCArray is true, which it is if
> > it has any elements.
>
> > > or
>
> > > if $($<parameters>) > 0 { ...
>
> > This is probably an error. If you want to check the number of elements,
> > put it in array context and numify.
>
> > if +@($<parameters>) > 0 { ... }
>
> > But what you wrote above is shorter and clearer. BTW, to get the AST, I
> > would guess you'd want to do $( $<parameters>[0] ).
>
> > > Is there any way I can get the compiler to send a trace statement to
> > > the console something along the lines of "say $/" or otherwise. I have
> > > noticed a "--trace" option but couldn't find the relevant docs.
>
> > --trace=4 may do what you want.
>
> > Hope this helps,
>
> > Jonathan
>
> > _______________________________________________http://lists.parrot.org/mailman/listinfo/parrot-dev
>
> _______________________________________________http://lists.parrot.org/mailman/listinfo/parrot-dev


More information about the parrot-dev mailing list