how to get left hand side symbol in action

2019-05-06 Thread r0ller
Hi All,

Is it possible in *any* way to get the left hand side symbol in an action of a 
rule? Say, I have:

A : B C
{
    std:cout<<"left hand side symbol is:"

Re: Bison + Flex on C++ don't work

2019-05-06 Thread uxio prego
Maybe related?

/usr/local$ find . | grep -i bison | grep -i lib
./Cellar/bison/3.1/lib
./Cellar/bison/3.1/lib/liby.a
[...]

I miss the dynamic version but

🤷‍♀️

Cheers,

Sent from my iPhone

> On 6 May 2019, at 02:37, Joao Pedro Abreu De Souza  wrote:
> 
> Hi folks. My friend Nicholas and I are trying to make a compiler for a
> simpler language(just expressions by now) with flex and bison using C++.
> 
> Using
> https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html
> as a guide, we code the repository below, but when We try
> 
> bison -d parser.yy -o parser.cc
> lex scanner.l
> g++ lex.yy.cc parser.cc main.cc -o cppimp
> 
> 
> Give us the error in the file
> 
> repository : https://github.com/nicholas-barcelos/Cppimp
> 
> We try to change headers of place, move definitions of class, but nothing
> work. What are we making wrong? Thanks in advance
> 
> ___
> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Re: how to get left hand side symbol in action

2019-05-06 Thread Giacinto Cifelli
Hi,

you refer to the left-hand side with $$. Provided it has a 'printable'
type (int, char *, string), it should output.

BR,
Giacinto

On Mon, May 6, 2019 at 11:28 AM r0ller  wrote:
>
> Hi All,
>
> Is it possible in *any* way to get the left hand side symbol in an action of 
> a rule? Say, I have:
>
> A : B C
> {
> std:cout<<"left hand side symbol is:"< };
>
> I tried to find it out myself and googled a lot but didn't find anything:(
>
> Best regards,
> r0ller
> ___
> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison


Re: how to get left hand side symbol in action

2019-05-06 Thread Uxio Prego
I thought they mean the [non terminal] **symbol**,
instead of the actual object?

Regards,

> On 6 May 2019, at 14:27, Giacinto Cifelli  wrote:
> 
> Hi,
> 
> you refer to the left-hand side with $$. Provided it has a 'printable'
> type (int, char *, string), it should output.
> 
> BR,
> Giacinto
> 
> On Mon, May 6, 2019 at 11:28 AM r0ller  wrote:
>> 
>> Hi All,
>> 
>> Is it possible in *any* way to get the left hand side symbol in an action of 
>> a rule? Say, I have:
>> 
>> A : B C
>> {
>>std:cout<<"left hand side symbol is:"<> };
>> 
>> I tried to find it out myself and googled a lot but didn't find anything:(
>> 
>> Best regards,
>> r0ller
>> ___
>> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison
> 
> ___
> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison


___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison


Re: how to get left hand side symbol in action

2019-05-06 Thread r0ller
Yes, correct: I'd need the non terminal symbol itself.

Best regards,
r0ller

 Eredeti levél 
Feladó: Uxio Prego < uxio.pr...@gmail.com (Link -> mailto:uxio.pr...@gmail.com) 
>
Dátum: 2019 május 6 14:30:10
Tárgy: Re: how to get left hand side symbol in action
Címzett: Giacinto Cifelli < gciof...@gmail.com (Link -> 
mailto:gciof...@gmail.com) >

I thought they mean the [non terminal] **symbol**,
instead of the actual object?

Regards,

> On 6 May 2019, at 14:27, Giacinto Cifelli  wrote:
>
> Hi,
>
> you refer to the left-hand side with $$. Provided it has a 'printable'
> type (int, char *, string), it should output.
>
> BR,
> Giacinto
>
> On Mon, May 6, 2019 at 11:28 AM r0ller  wrote:
>>
>> Hi All,
>>
>> Is it possible in *any* way to get the left hand side symbol in an action of 
>> a rule? Say, I have:
>>
>> A : B C
>> {
>> std:cout<<"left hand side symbol is:"<> };
>>
>> I tried to find it out myself and googled a lot but didn't find anything:(
>>
>> Best regards,
>> r0ller
>> ___
>> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison
>
> ___
> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison
 
___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Re: how to get left hand side symbol in action

2019-05-06 Thread Hans Åberg

> On 6 May 2019, at 11:28, r0ller  wrote:
> 
> Hi All,
> 
> Is it possible in *any* way to get the left hand side symbol in an action of 
> a rule? Say, I have:
> 
> A : B C
> {
> std:cout<<"left hand side symbol is:"< };
> 
> I tried to find it out myself and googled a lot but didn't find anything:(

In the C++ parser, one can write:
  std::cout << “LHS: " << yytname_[yylhs.type_get()] << std::endl;

Used for debugging, perhaps there is a more reliable macro.



___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Re: how to get left hand side symbol in action

2019-05-06 Thread uxio prego


Sent from my iPhone

> On 6 May 2019, at 14:50, Hans Åberg  wrote:
> 
> 
>> On 6 May 2019, at 11:28, r0ller  wrote:
>> 
>> Hi All,
>> 
>> Is it possible in *any* way to get the left hand side symbol in an action of 
>> a rule? Say, I have:
>> 
>> A : B C
>> {
>>std:cout<<"left hand side symbol is:"<> };
>> 
>> I tried to find it out myself and googled a lot but didn't find anything:(
> 
> In the C++ parser, one can write:
>  std::cout << “LHS: " << yytname_[yylhs.type_get()] << std::endl;
> 
> Used for debugging, perhaps there is a more reliable macro.
> 
> 

Thanks for the hint.
Do you mean you know that it won’t work in a C parser or yacc compatibility?

> 
> ___
> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Re: how to get left hand side symbol in action

2019-05-06 Thread Hans Åberg

> On 6 May 2019, at 15:21, uxio prego  wrote:
> 
>> On 6 May 2019, at 14:50, Hans Åberg  wrote:
>> 
>>> On 6 May 2019, at 11:28, r0ller  wrote:
>>> 
>>> Is it possible in *any* way to get the left hand side symbol in an action 
>>> of a rule? Say, I have:
>>> 
>>> A : B C
>>> {
>>>   std:cout<<"left hand side symbol is:"<>> };
>> 
>> In the C++ parser, one can write:
>> std::cout << “LHS: " << yytname_[yylhs.type_get()] << std::endl;
>> 
>> Used for debugging, perhaps there is a more reliable macro.
> 
> Thanks for the hint.
> Do you mean you know that it won’t work in a C parser or yacc compatibility?

It probably has a similar thing there. Check in the generated parser.



___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Re: how to get left hand side symbol in action

2019-05-06 Thread r0ller
Hi Hans,

Works like a charm! Thanks!

Best regards,
r0ller

 Eredeti levél 
Feladó: Hans Åberg < haber...@telia.com (Link -> mailto:haber...@telia.com) >
Dátum: 2019 május 6 14:50:48
Tárgy: Re: how to get left hand side symbol in action
Címzett: r0ller < r0l...@freemail.hu (Link -> mailto:r0l...@freemail.hu) >
> On 6 May 2019, at 11:28, r0ller  wrote:
>
> Hi All,
>
> Is it possible in *any* way to get the left hand side symbol in an action of 
> a rule? Say, I have:
>
> A : B C
> {
> std:cout<<"left hand side symbol is:"< };
>
> I tried to find it out myself and googled a lot but didn't find anything:(
In the C++ parser, one can write:
std::cout << “LHS: " << yytname_[yylhs.type_get()] << std::endl;
Used for debugging, perhaps there is a more reliable macro.
 
___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Re: how to get left hand side symbol in action

2019-05-06 Thread Akim Demaille


> Le 6 mai 2019 à 14:50, Hans Åberg  a écrit :
> 
> 
>> On 6 May 2019, at 11:28, r0ller  wrote:
>> 
>> Hi All,
>> 
>> Is it possible in *any* way to get the left hand side symbol in an action of 
>> a rule? Say, I have:
>> 
>> A : B C
>> {
>>std:cout<<"left hand side symbol is:"<> };
>> 
>> I tried to find it out myself and googled a lot but didn't find anything:(
> 
> In the C++ parser, one can write:
>  std::cout << “LHS: " << yytname_[yylhs.type_get()] << std::endl;

But it's an internal detail, there is no guarantee it won't change.

r0ller, what is your exact need?
___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Re: how to get left hand side symbol in action

2019-05-06 Thread r0ller
Hi Akim,

I bumped into this when writing the tech guide for my project last week. As you 
know, in my project it's possible to generate the bison source if you've set up 
your grammar rules in a db table (called grammar). However, in certain cases 
one may want to have different action implementation than the default one and 
actually in one case it's even a must: when you want to add a linguistic 
feature at a syntactic level like marking a verb in a sentence as main verb. In 
such a case an additional method must be called. Although, it's possible to 
enter the action implementation code directly in the specific field (called 
action) of the db record in question, it's more convenient to just put a file 
name there and the source generator tool will do the job for you. The problem 
emerges when you have more than one rule where you'd like to have the same 
action implementation, for example:

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);
}

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.

While when being able to tell what the lhs symbol is, one implementation will 
be enough for both "A:B C" and "D:E F" that can be saved in one file and the 
same file name can be put in the action fields of the corresponding db records:

{
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=yytname_[yylhs.type_get()];//<--Here the symbol is 
not 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);
}

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.

Thanks for any hints!:)

Best regards,
r0ller

 Eredeti levél 
Feladó: Akim Demaille < a...@lrde.epita.fr (Link -> mailto:a...@lrde.epita.fr) >
Dátum: 2019 május 6 18:09:56
Tárgy: Re: how to get left hand side symbol in action
Címzett: Hans Åberg < haber...@telia.com (Link -> mailto:haber...@telia.com) >
> Le 6 mai 2019 à 14:50, Hans Åberg  a écrit :
>
>
>> On 6 May 2019, at 11:28, r0ller  wrote:
>>
>> Hi All,
>>
>> Is it possible in *any* way to get the left hand side symbol in an action of 
>> a rule? Say, I have:
>>
>> A : B C
>> {
>> std:cout<<"left hand side symbol is:"<> };
>>
>> I tried to find it out myself and googled a lot but didn't find anything:(
>
> In the C++ parser, one can write:
> std::cout << “LHS: " << yytname_[yylhs.type_get()] << std::endl;

But it's an internal detail, there is no guarantee it won't change.

r0ller, what is your exact need?
___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Re: how to get left hand side symbol in action

2019-05-06 Thread Hans Åberg

> On 6 May 2019, at 18:09, Akim Demaille  wrote:
> 
>> Le 6 mai 2019 à 14:50, Hans Åberg  a écrit :
>> 
>> 
>>> On 6 May 2019, at 11:28, r0ller  wrote:
>>> 
>>> Hi All,
>>> 
>>> Is it possible in *any* way to get the left hand side symbol in an action 
>>> of a rule? Say, I have:
>>> 
>>> A : B C
>>> {
>>>   std:cout<<"left hand side symbol is:"<>> };
>>> 
>>> I tried to find it out myself and googled a lot but didn't find anything:(
>> 
>> In the C++ parser, one can write:
>> std::cout << “LHS: " << yytname_[yylhs.type_get()] << std::endl;
> 
> But it's an internal detail, there is no guarantee it won't change.

Right, so it might be a feature request for the longer term. Perhaps a 
variation of $ and @ that gives access to the name, or the raw stack value in 
case there are more stuff to access.



___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison