help-bison
[Top][All Lists]
Advanced

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

Re: how to get left hand side symbol in action


From: r0ller
Subject: Re: how to get left hand side symbol in action
Date: Fri, 10 May 2019 11:02:30 +0200 (CEST)

Hi Akim,

I agree, the logging could look better:) You're also right about that I could 
introduce some placeholder symbols for my own framework and then I could 
generate the parent symbol in user defined action implementations as well. I 
also considered that option. The only thing is that first I wanted to check if 
bison provides such a feature out of the box and when Hans gave me the answer, 
I was happy that I don't have to develop anything on top:)

-"I don't understand why you don't put the actions in the db itself, but that's 
your choice."

The users can put the action implementation directly in the db as well. So 
using the external files is just a convenience feature as you don't have to put 
manually an action implementation to a field of a db record which I find a bit 
cumbersome compared to putting there only the name of a file. DB editors 
usually won't offer syntax highlight for example. This makes life easier I 
think especially if you want to use the same action implementation for more 
than one rule. Which is currently a bit hindered by not being able to get the 
lhs symbol as just because of that you still need as many separate files as 
many different lhs symbols you have for the rules you want to use the 
implementation for.

But as you also mentioned, I could as well introduce my own symbols which could 
be replaced during generating the bison source. So no worries:)

-"Don't do that. I clearly stated that it is not guaranteed to work."

Ok, I'll indicate in the guide that it's a misuse of bison internals and if one 
wants to avoid that shall put the action implementations in separate files and 
use the lhs symbol of the rule literally.

"Also, am I understanding that you don't actually felt the need for the feature 
in practice, but only for teaching something?"

Kind of, as it's not crucial:) I bumped into the issue (of creating different 
action implementations just because of the lhs symbol) when writing the guide 
(so yes, teaching others how to use the framework) and thought about how I 
could make it more convenient. So I googled and finally asked the question here 
as I haven't found anything. The rest of the story you know:)

Best regards,
r0ller

-------- Eredeti levél --------
Feladó: Akim Demaille < address@hidden (Link -> mailto:address@hidden) >
Dátum: 2019 május 10 08:47:53
Tárgy: Re: how to get left hand side symbol in action
Címzett: r0ller < address@hidden (Link -> mailto:address@hidden) >
Hi r0ller,
> Le 6 mai 2019 à 21:13, r0ller <address@hidden> a écrit :
>
> Hi Akim,
>
> [...]
> A : B C
> {<!-- -->
> const node_info& main_node=sparser->get_node_info($1);
> const node_info& dependent_node=sparser->get_node_info($2);
> sparser->add_feature_to_leaf(main_node,"main_verb");
> std::string parent_symbol="A";//<--Here the symbol is hardcoded
> logger::singleton()==NULL?(void)0:logger::singleton()->log(0,parent_symbol+"->"+main_node.symbol+"
>  "+dependent_node.symbol);
> $$=sparser->combine_nodes(parent_symbol,main_node,dependent_node);
> }
>
> D : E F
> {<!-- -->
> const node_info& main_node=sparser->get_node_info($1);
> const node_info& dependent_node=sparser->get_node_info($2);
> sparser->add_feature_to_leaf(main_node,"main_verb");
> std::string parent_symbol="D";//<--Here the symbol is hardcoded
> logger::singleton()==NULL?(void)0:logger::singleton()->log(0,parent_symbol+"->"+main_node.symbol+"
>  "+dependent_node.symbol);
> $$=sparser->combine_nodes(parent_symbol,main_node,dependent_node);
> }
I believe we already discussed about this, but I don't understand
why your API for logging looks this way. You should use a free
standing function that encapsulates all this 'singleton()' sequence
you repeat.
But back to the point: you are *generating* the grammar, so I
do not understand why *you* don't generate the name directly.
Actually, I guess most of your action can synthesized from data
stored in your data base, in addition to the symbol names.
> This means, that one would need to save these two "snippets" in two different 
> files, say snippet1 and snippet2 and put the two file names in the action 
> fields of the corresponding db records.
I don't understand why you don't put the actions in the db itself,
but that's your choice.
Still, you can perfectly introduce your own syntax for your external
files, and process them before pasting them. Say
> std::string parent_symbol="%LHS_NAME%";
> These examples you can find in the tech guide towards the end of section 
> 'Generating syntactic rules and machine learning':
> https://github.com/r0ller/alice/wiki/Technical-Guide-and-Documentation#Option-2-3
>
> and the other one towards the end of section 'Tagging':
> https://github.com/r0ller/alice/wiki/Technical-Guide-and-Documentation#Tagging
>
> Though, as I changed it today after Hans's suggestion, you'll now find the 
> same implementation at those two places.
Don't do that. I clearly stated that it is not guaranteed to work.
Also, am I understanding that you don't actually felt the need for
the feature in practice, but only for teaching something?
Cheers!


reply via email to

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