<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[std::shared_ptr mit yacc]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe ein paar schwierigkeiten shared_ptrs in mein yacc file einzubauen (ohne boost)...wie bekomme ich das am besten hin?</p>
<p>mein background research hat folgendes ergeben:</p>
<pre><code>%union in yacc/bison only allows POD types...hmm
</code></pre>
<pre><code>%{
#include &lt;cstdio&gt;
#include &lt;cstdlib&gt;
#include &lt;cassert&gt;
#include &lt;memory&gt;
#include &quot;Token.h&quot;
#include &quot;Tree.h&quot;

extern void yyerror(char* message);
extern int yylex(void);
extern int yyparse(void);

%}

%union {
	int ival;	/* NUMBER */
	int opval;	/* ADDOP MULOP */
	Tree *tval;
}

%left &lt;opval&gt; 	ADDOP
%left &lt;opval&gt; 	MULOP
%token &lt;ival&gt;	NUMBER

%type &lt;tval&gt; expr

%%

expr_list
	: expr_list expr '\n' 
		{ $2-&gt;print(0); 
		  fprintf(stderr, &quot;Value = %d\n&quot;, eval($2)); }
	| expr '\n' 
		{ $1-&gt;print(0); 
		  fprintf(stderr, &quot;Value = %d\n&quot;, eval($1)); }

expr 
	: expr ADDOP expr 
		{ $$ = new Tree(Token(ADDOP,$2),$1,$3); }
	| expr MULOP expr 
		{ $$ = new Tree(Token(MULOP,$2),$1,$3); }
	| '(' expr ')'
		{ $$ = $2; }
	| NUMBER
		{ $$ = new Tree(Token(NUMBER,$1),nullptr,nullptr); }
	;

%%
</code></pre>
<p>ich moechte:</p>
<pre><code>new Tree(Token(NUMBER,$1),nullptr,nullptr)
</code></pre>
<p>durch:</p>
<pre><code>std::make_shared&lt;Tree&gt;(new Tree(Token(ADDOP,$2),$1,$3))
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/332319/std-shared_ptr-mit-yacc</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 03:46:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/332319.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Apr 2015 06:56:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Wed, 22 Apr 2015 06:56:51 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe ein paar schwierigkeiten shared_ptrs in mein yacc file einzubauen (ohne boost)...wie bekomme ich das am besten hin?</p>
<p>mein background research hat folgendes ergeben:</p>
<pre><code>%union in yacc/bison only allows POD types...hmm
</code></pre>
<pre><code>%{
#include &lt;cstdio&gt;
#include &lt;cstdlib&gt;
#include &lt;cassert&gt;
#include &lt;memory&gt;
#include &quot;Token.h&quot;
#include &quot;Tree.h&quot;

extern void yyerror(char* message);
extern int yylex(void);
extern int yyparse(void);

%}

%union {
	int ival;	/* NUMBER */
	int opval;	/* ADDOP MULOP */
	Tree *tval;
}

%left &lt;opval&gt; 	ADDOP
%left &lt;opval&gt; 	MULOP
%token &lt;ival&gt;	NUMBER

%type &lt;tval&gt; expr

%%

expr_list
	: expr_list expr '\n' 
		{ $2-&gt;print(0); 
		  fprintf(stderr, &quot;Value = %d\n&quot;, eval($2)); }
	| expr '\n' 
		{ $1-&gt;print(0); 
		  fprintf(stderr, &quot;Value = %d\n&quot;, eval($1)); }

expr 
	: expr ADDOP expr 
		{ $$ = new Tree(Token(ADDOP,$2),$1,$3); }
	| expr MULOP expr 
		{ $$ = new Tree(Token(MULOP,$2),$1,$3); }
	| '(' expr ')'
		{ $$ = $2; }
	| NUMBER
		{ $$ = new Tree(Token(NUMBER,$1),nullptr,nullptr); }
	;

%%
</code></pre>
<p>ich moechte:</p>
<pre><code>new Tree(Token(NUMBER,$1),nullptr,nullptr)
</code></pre>
<p>durch:</p>
<pre><code>std::make_shared&lt;Tree&gt;(new Tree(Token(ADDOP,$2),$1,$3))
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2451156</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451156</guid><dc:creator><![CDATA[geri1]]></dc:creator><pubDate>Wed, 22 Apr 2015 06:56:51 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Wed, 22 Apr 2015 07:20:39 GMT]]></title><description><![CDATA[<p>Was für ein yacc benutzt Du denn?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451158</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451158</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Wed, 22 Apr 2015 07:20:39 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Wed, 22 Apr 2015 08:00:49 GMT]]></title><description><![CDATA[<p>ich bin hier auf osx und windows.</p>
<p>auf osx verwende ich: yacc + lex: <a href="http://www.unix.com/man-page/osx/1/yacc/" rel="nofollow">http://www.unix.com/man-page/osx/1/yacc/</a><br />
auf windows verwende ich: bison + flex</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451161</guid><dc:creator><![CDATA[geri1]]></dc:creator><pubDate>Wed, 22 Apr 2015 08:00:49 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Wed, 22 Apr 2015 08:07:36 GMT]]></title><description><![CDATA[<p>Also bison in beiden Fällen, wenn ich Deinen Link richtig interpretiere.</p>
<p>Dann steht doch einiges in der Doku dazu: <a href="http://www.gnu.org/software/bison/manual/html_node/C_002b_002b-Variants.html#C_002b_002b-Variants" rel="nofollow">http://www.gnu.org/software/bison/manual/html_node/C_002b_002b-Variants.html#C_002b_002b-Variants</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451164</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Wed, 22 Apr 2015 08:07:36 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Wed, 22 Apr 2015 09:33:13 GMT]]></title><description><![CDATA[<p>ich weiss trotzdem nicht wie ich shared_ptr einbauen kann ohne boost::variant!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451181</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451181</guid><dc:creator><![CDATA[geri1]]></dc:creator><pubDate>Wed, 22 Apr 2015 09:33:13 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Wed, 22 Apr 2015 17:36:08 GMT]]></title><description><![CDATA[<p>hab das hier auf osx:</p>
<pre><code>$ yacc --version
bison (GNU Bison) 2.3
Written by Robert Corbett and Richard Stallman.

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ flex --version
flex 2.5.35 Apple(flex-31)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2451249</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451249</guid><dc:creator><![CDATA[geri1]]></dc:creator><pubDate>Wed, 22 Apr 2015 17:36:08 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Wed, 22 Apr 2015 21:49:13 GMT]]></title><description><![CDATA[<p>mit folgenden change bekomme ich diesen fehler... vorschlaege/loesungen?</p>
<pre><code>y.tab.cpp:1123:11: error: call to implicitly-deleted default constructor of 'YYSTYPE'
  YYSTYPE yyval;
</code></pre>
<pre><code>%{ 
#include &lt;cstdio&gt; 
#include &lt;cstdlib&gt; 
#include &lt;cassert&gt; 
#include &lt;memory&gt; 
#include &quot;Token.h&quot; 
#include &quot;Tree.h&quot; 

extern void yyerror(char* message); 
extern int yylex(void); 
extern int yyparse(void); 

%} 

%union { 
    int ival;   /* NUMBER */ 
    int opval;  /* ADDOP MULOP */ 
    std::shared_ptr&lt;Tree&gt; tval; 
} 

%left &lt;opval&gt;   ADDOP 
%left &lt;opval&gt;   MULOP 
%token &lt;ival&gt;   NUMBER 

%type &lt;tval&gt; expr 

%% 

expr_list 
    : expr_list expr '\n' 
        { $2.get()-&gt;print(0); 
          fprintf(stderr, &quot;Value = %d\n&quot;, eval($2.get())); } 
    | expr '\n' 
        { $1.get()-&gt;print(0); 
          fprintf(stderr, &quot;Value = %d\n&quot;, eval($1.get())); } 

expr 
    : expr ADDOP expr 
        { $$ = std::make_shared&lt;decltype($$)&gt;(new Tree(Token(ADDOP,$2),$1,$3)); } 
    | expr MULOP expr 
        { $$ = std::make_shared&lt;decltype($$)&gt;(new Tree(Token(MULOP,$2),$1,$3)); } 
    | '(' expr ')' 
        { $$ = $2; } 
    | NUMBER 
        { $$ = std::make_shared&lt;decltype($$)&gt;(new Tree(Token(NUMBER,$1),nullptr,nullptr)); } 
    ; 

%%
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2451284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451284</guid><dc:creator><![CDATA[geri1]]></dc:creator><pubDate>Wed, 22 Apr 2015 21:49:13 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Thu, 23 Apr 2015 08:50:01 GMT]]></title><description><![CDATA[<p>geri1 schrieb:</p>
<blockquote>
<pre><code>$$ = std::make_shared&lt;decltype($$)&gt;(new Tree(Token(ADDOP,$2),$1,$3));
</code></pre>
</blockquote>
<p>make_shared will keinen Pointer haben, sondern die Argumente, um den selber anzulegen.<br />
siehe [url] <a href="http://www.cplusplus.com/reference/memory/make_shared" rel="nofollow">http://www.cplusplus.com/reference/memory/make_shared</a> [/url]</p>
<p>also eher so:</p>
<pre><code>$$ = std::make_shared&lt;Tree&gt;(Token(ADDOP, $2), $1, $3));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2451313</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451313</guid><dc:creator><![CDATA[__cu]]></dc:creator><pubDate>Thu, 23 Apr 2015 08:50:01 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Thu, 23 Apr 2015 11:50:33 GMT]]></title><description><![CDATA[<p>ok, habe deine changes eingebaut. jedoch bekomme ich noch folgende errors:</p>
<pre><code>$ mingw32-make clean; mingw32-make
rm -f y.tab.* lex.yy.* y.output y.tab.o lex.yy.o Token.o Tree.o Eval.o main.o ma
in.exe
bison  -dv -o y.tab.cpp calc.y
g++ -g -Wall -std=gnu++11   -c -o y.tab.o y.tab.cpp
y.tab.cpp:1058:9: error: use of deleted function 'YYSTYPE::YYSTYPE()'
 YYSTYPE yylval;
         ^
y.tab.cpp:123:15: note: 'YYSTYPE::YYSTYPE()' is implicitly deleted because the d
efault definition would be ill-formed:
 typedef union YYSTYPE
               ^
calc.y:18:24: error: union member 'YYSTYPE::tval' with non-trivial 'constexpr st
d::shared_ptr&lt;_Tp&gt;::shared_ptr() [with _Tp = Tree]'
  std::shared_ptr&lt;Tree&gt; tval;
                        ^
y.tab.cpp: In function 'int yyparse()':
y.tab.cpp:1110:30: error: use of deleted function 'YYSTYPE::YYSTYPE()'
     YYSTYPE yyvsa[YYINITDEPTH];
                              ^
y.tab.cpp:1110:30: error: use of deleted function 'YYSTYPE::~YYSTYPE()'
y.tab.cpp:123:15: note: 'YYSTYPE::~YYSTYPE()' is implicitly deleted because the
default definition would be ill-formed:
 typedef union YYSTYPE
               ^
calc.y:18:24: error: union member 'YYSTYPE::tval' with non-trivial 'std::shared_
ptr&lt;Tree&gt;::~shared_ptr()'
  std::shared_ptr&lt;Tree&gt; tval;
                        ^
y.tab.cpp:1110:30: error: use of deleted function 'YYSTYPE::~YYSTYPE()'
     YYSTYPE yyvsa[YYINITDEPTH];
                              ^
y.tab.cpp:1122:11: error: use of deleted function 'YYSTYPE::YYSTYPE()'
   YYSTYPE yyval;
           ^
y.tab.cpp:1122:11: error: use of deleted function 'YYSTYPE::~YYSTYPE()'
y.tab.cpp:1296:12: error: use of deleted function 'YYSTYPE&amp; YYSTYPE::operator=(c
onst YYSTYPE&amp;)'
   *++yyvsp = yylval;
            ^
y.tab.cpp:123:15: note: 'YYSTYPE&amp; YYSTYPE::operator=(const YYSTYPE&amp;)' is implici
tly deleted because the default definition would be ill-formed:
 typedef union YYSTYPE
               ^
calc.y:18:24: error: union member 'YYSTYPE::tval' with non-trivial 'std::shared_
ptr&lt;_Tp&gt;&amp; std::shared_ptr&lt;_Tp&gt;::operator=(const std::shared_ptr&lt;_Tp&gt;&amp;) [with _Tp
 = Tree]'
  std::shared_ptr&lt;Tree&gt; tval;
                        ^
y.tab.cpp:1326:9: error: use of deleted function 'YYSTYPE&amp; YYSTYPE::operator=(co
nst YYSTYPE&amp;)'
   yyval = yyvsp[1-yylen];
         ^
y.tab.cpp:1388:12: error: use of deleted function 'YYSTYPE&amp; YYSTYPE::operator=(c
onst YYSTYPE&amp;)'
   *++yyvsp = yyval;
            ^
y.tab.cpp:1414:35: warning: deprecated conversion from string constant to 'char*
' [-Wwrite-strings]
       yyerror (YY_(&quot;syntax error&quot;));
                                   ^
y.tab.cpp:1528:12: error: use of deleted function 'YYSTYPE&amp; YYSTYPE::operator=(c
onst YYSTYPE&amp;)'
   *++yyvsp = yylval;
            ^
y.tab.cpp:1557:35: warning: deprecated conversion from string constant to 'char*
' [-Wwrite-strings]
   yyerror (YY_(&quot;memory exhausted&quot;));
                                   ^
y.tab.cpp: In function 'void __static_initialization_and_destruction_0(int, int)
':
y.tab.cpp:1058:9: error: use of deleted function 'YYSTYPE::~YYSTYPE()'
 YYSTYPE yylval;
         ^
y.tab.cpp: In function 'void __tcf_0()':
y.tab.cpp:1058:9: error: use of deleted function 'YYSTYPE::~YYSTYPE()'
&lt;builtin&gt;: recipe for target 'y.tab.o' failed
mingw32-make: *** [y.tab.o] Error 1
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2451333</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451333</guid><dc:creator><![CDATA[geri1]]></dc:creator><pubDate>Thu, 23 Apr 2015 11:50:33 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Thu, 23 Apr 2015 11:55:28 GMT]]></title><description><![CDATA[<p>folgender thread erklaert das porblem:</p>
<pre><code>http://stackoverflow.com/questions/26964941/lex-yacc-no-member-name-and-declaration-error
</code></pre>
<p>wie kann ich das problem fixen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451334</guid><dc:creator><![CDATA[geri1]]></dc:creator><pubDate>Thu, 23 Apr 2015 11:55:28 GMT</pubDate></item><item><title><![CDATA[Reply to std::shared_ptr mit yacc on Sun, 26 Apr 2015 10:37:29 GMT]]></title><description><![CDATA[<p>help!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451589</guid><dc:creator><![CDATA[geri1]]></dc:creator><pubDate>Sun, 26 Apr 2015 10:37:29 GMT</pubDate></item></channel></rss>