<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>C++ parsing libraries for symbolic input.</title>
		<link>http://www.allegro.cc/forums/view/610113</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 07 May 2012 17:37:45 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m using a windows GUI (made with Irrlicht, but it doesn&#39;t matter) with textbox and I want some library written with C++ and made for parsing symbols, etc. Basically I create the mnemonic and some run time machinery sorts the mnenomics out to do some operation. Is there such a thing? Is yacc/bison or lex capable of this or thats made for making a compiler?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Wed, 25 Apr 2012 23:25:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How about <a href="https://github.com/axilmar/parserlib">this</a>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 27 Apr 2012 17:17:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In your calculator.cpp example you have AST declarations, what are those for? It starts on line 61 and goes to 155?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Mon, 30 Apr 2012 03:34:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The AST declarations are the classes of the objects that the source code is converted into.</p><p>For example, when the rule &#39;num&#39; is parsed successfully, an object of type &#39;num_t&#39; is created.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Mon, 30 Apr 2012 18:50:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Would it be easy to modify the code to include mnemonics as operators such as run,pause,repeat, etc?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Tue, 01 May 2012 09:42:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, it would be easy. Just write the grammar, then the objects you wish the input to be converted to, and you&#39;re good to go.</p><p>I can assist you in it, if you tell me which commands would you like to support.</p><p>EDIT:</p><p>For example, if your input consists of simple commands, your grammar can be like this:</p><div class="source-code snippet"><div class="inner"><pre>rule whitespace <span class="k3">=</span> <span class="k3">*</span>expr<span class="k2">(</span><span class="s">' '</span><span class="k2">)</span><span class="k2">;</span>
rule run_command <span class="k3">=</span> <span class="s">"run"</span><span class="k2">;</span>
rule pause_command <span class="k3">=</span> <span class="s">"pause"</span><span class="k2">;</span>
rule command <span class="k3">=</span> run_command <span class="k3">|</span> pause_command<span class="k2">;</span>
rule grammar <span class="k3">=</span> <span class="k3">*</span>command<span class="k2">;</span>
</pre></div></div><p>

Your AST would look like this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> command <span class="k2">:</span> <span class="k1">public</span> ast_node <span class="k2">{</span>
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">class</span> run <span class="k2">:</span> <span class="k1">public</span> command <span class="k2">{</span>
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">class</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_613.html" target="_blank">pause</a> <span class="k2">:</span> <span class="k1">public</span> command <span class="k2">{</span>
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">class</span> commands <span class="k2">:</span> <span class="k1">public</span> ast_container <span class="k2">{</span>
public:
    ast_list<span class="k3">&lt;</span>command&gt; commands<span class="k2">;</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>

And the connections between the grammar and the AST would look like this:</p><div class="source-code snippet"><div class="inner"><pre>ast<span class="k3">&lt;</span>commands&gt; ast_commands<span class="k2">(</span>grammar<span class="k2">)</span><span class="k2">;</span>
ast<span class="k3">&lt;</span>run&gt; ast_run_command<span class="k2">(</span>run_command<span class="k2">)</span><span class="k2">;</span>
ast<span class="k3">&lt;</span>pause&gt; ast_pause_command<span class="k2">(</span>pause_command<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

You could then parse the input with the following code:</p><div class="source-code snippet"><div class="inner"><pre>error_list errors<span class="k2">;</span>
commands <span class="k3">*</span>cmds<span class="k2">;</span>
parse<span class="k2">(</span>input, grammar, whitespace, errors, cmds<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

When the above returns, the pointer &#39;cmds&#39; would contain a pointer to a commands object, with all the commands the user typed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Wed, 02 May 2012 15:03:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Whee, parsing is fun!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Thu, 03 May 2012 01:09:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Do you mean it or was it sarcasm?</p><p>In case it was sarcasm, could you please indicate to me in which areas should the parser library be improved?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Thu, 03 May 2012 10:37:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What would I need to compile your calculator example using codeblocks. Anything tricky or special.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954017#target">axilmar</a> said:</div><div class="quote"><p>Yes, it would be easy. Just write the grammar, then the objects you wish the input to be converted to, and you&#39;re good to go.</p><p>I can assist you in it, if you tell me which commands would you like to support.</p></div></div><p>

I can see now from your edits on how to do it. It seems in my case I have a gui which would grab the text input and invoke the rule for example &quot;run&quot; when the gui button is pressed. Then I would use that to set a boolean in some other class to true. So far I think I could manage that.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954054#target">Tobias Dammers</a> said:</div><div class="quote"><p>Whee, parsing is fun!</p></div></div><p>

This is the real world, who the <span class="cuss"><span>fuck</span></span> plays games around here anyways? <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Thu, 03 May 2012 13:00:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> This is the real world, who the  plays games around here anyways? <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" /></p></div></div><p>If you&#39;re <i>not</i> having fun, why do it?  If it&#39;s only for money, I feel sorry for you.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 03 May 2012 13:03:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954092#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>If you&#39;re not having fun, why do it? If it&#39;s only for money, I feel sorry for you.</p></div></div><p>

Its for making a simple interface for a 3d engine. Basically my theory is that using a text box input would allow me to design a gui with only one text box and one button and use commands to do things. Right now I have 20 text boxes and 4 buttons and the gui is getting really complicatedly ugly and difficult to read.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Thu, 03 May 2012 14:02:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So simplifying it is at least satisfying, if not fun?  OK then.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 03 May 2012 14:10:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954097#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>So simplifying it is at least satisfying, if not fun? OK then.</p></div></div><p>

Sometimes I get this angry feeling whenever I type code with c++, its not the same with Python though. Its the wordiness of it all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Thu, 03 May 2012 14:11:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954086#target">axilmar</a> said:</div><div class="quote"><p>
Do you mean it or was it sarcasm?
</p></div></div><p>
I absolutely sincerely meant it. Writing parsers is fun.</p><p>Except if you use (f)lex/bison/yacc; those are atrociously hard to use, full of obscure edge cases, and the output has the aesthetic appeal of elephant droppings.</p><p>I&#39;ve written quite a bunch of parsers myself lately: a few iterations of a template engine in PHP (started out as a four-line function that went something like preg_match_all -&gt; array_map -&gt; str_replace, but by now, it&#39;s a fully-fledged template language with loops and includes and whatnot). A fast C parser for a custom network protocol. A few parsers (query strings, POST message bodies, HTTP requests, etc.) for an experimental web server framework. Another template engine, this time in Haskell (allowing for arbitrary Haskell expressions to be interpolated into the template while still providing HTML-encoding where needed). A parser for my custom sheet music language, also in Haskell.</p><p>So yes, writing parsers <i>is</i> fun.</p><p>I like the parser-combinator approach - build a generic parser interface, a bunch of atomic parsers, a bunch of combinator parsers, and then build your final parser from these blocks, following along a BNF representation of the grammar. Haskell&#39;s Parsec library takes this to the extreme, providing a native Haskell syntax that closely resembles BNF itself:
</p><div class="source-code snippet"><div class="inner"><pre>literal <span class="k3">=</span> stringLiteral
        <span class="k3">&lt;</span><span class="k3">|</span><span class="k3">&gt;</span> charLiteral
        <span class="k3">&lt;</span><span class="k3">|</span><span class="k3">&gt;</span> numberLiteral
</pre></div></div><p>
But even in a language with less flexible syntax, a similar parser can be built. E.g., in (functional-style) C++, the above could look like this:
</p><div class="source-code snippet"><div class="inner"><pre>AST_Expression<span class="k3">*</span> parseLiteral<span class="k2">(</span>ParserState<span class="k3">&amp;</span> p<span class="k2">)</span> <span class="k2">{</span>
    AST_Expression<span class="k3">*</span> e<span class="k2">;</span>
    <span class="k1">if</span> <span class="k2">(</span>e <span class="k3">=</span> parseStringLiteral<span class="k2">(</span>p<span class="k2">)</span><span class="k2">)</span> <span class="k1">return</span> e<span class="k2">;</span>
    <span class="k1">if</span> <span class="k2">(</span>e <span class="k3">=</span> parseCharLiteral<span class="k2">(</span>p<span class="k2">)</span><span class="k2">)</span> <span class="k1">return</span> e<span class="k2">;</span>
    <span class="k1">if</span> <span class="k2">(</span>e <span class="k3">=</span> parseNumberLiteral<span class="k2">(</span>p<span class="k2">)</span><span class="k2">)</span> <span class="k1">return</span> e<span class="k2">;</span>
    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span> <span class="c">// fail, no parse.</span>
<span class="k2">}</span>
</pre></div></div><p>
Or you could do it OOP-style, which would yield something like:
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">class</span> LiteralParser <span class="k2">:</span> <span class="k1">public</span> BaseParser<span class="k3">&lt;</span>AST_Expression&gt; <span class="k2">{</span>
<span class="number">  2</span>    private:
<span class="number">  3</span>    AlternativesParser<span class="k3">&lt;</span>AST_Expression&gt;<span class="k3">*</span> subparser<span class="k2">;</span>
<span class="number">  4</span>    public:
<span class="number">  5</span>    LiteralParser<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  6</span>        subparser <span class="k3">=</span> <span class="k1">new</span> AlternativesParser<span class="k3">&lt;</span>AST_Expression&gt;<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>        subparser-&gt;addAlternative<span class="k2">(</span><span class="k1">new</span> StringLiteralParser<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>        subparser-&gt;addAlternative<span class="k2">(</span><span class="k1">new</span> CharLiteralParser<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>        subparser-&gt;addAlternative<span class="k2">(</span><span class="k1">new</span> NumberLiteralParser<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>    <span class="k2">}</span>
<span class="number"> 11</span>    <span class="k1">virtual</span> ~LiteralParser<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 12</span>        <span class="k1">delete</span> subparser<span class="k2">;</span>
<span class="number"> 13</span>    <span class="k2">}</span>
<span class="number"> 14</span>    <span class="k1">virtual</span> AST_Expression<span class="k3">*</span> parse<span class="k2">(</span>ParserState<span class="k3">&amp;</span> p<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 15</span>        <span class="k1">return</span> subparser-&gt;parse<span class="k2">(</span>p<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>    <span class="k2">}</span>
<span class="number"> 17</span><span class="k2">}</span>
<span class="number"> 18</span><span class="c">// implementing AlternativesParser left as an exercise to the reader...</span>
</div></div><p>

I guess at this point it may be obvious why I like Haskell.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Thu, 03 May 2012 14:39:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954091#target">verthex</a> said:</div><div class="quote"><p> What would I need to compile your calculator example using codeblocks. Anything tricky or special.</p></div></div><p>Nothing tricky or special. A Codeblocks project file is already provided for the specific example.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954102#target">Tobias Dammers</a> said:</div><div class="quote"><p> So yes, writing parsers is fun.</p></div></div><p>Maybe it is, but it is a solved problem for me. This parser library allows me to convert any grammar to an AST, even if the grammar has left recursion.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> But even in a language with less flexible syntax, ... I guess at this point it may be obvious why I like Haskell.</p></div></div><p>But my c++ parser has EBNF-like syntax too. Unless I overlook something, I do not see Haskell having a particular advantage over c++ in this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Thu, 03 May 2012 15:41:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey, I&#39;m not attacking anyone here. Just saying that at least for me, Haskell is the perfect fit for these things. There&#39;s about a dozen reasons, but the obvious one is how ridiculously expressive the language is, and how little boilerplate there is in typical Haskell code. C++ isn&#39;t bad at all, but you can&#39;t deny it is pretty verbose.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Fri, 04 May 2012 01:54:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you please show me how to do the Model-View-Controller pattern in Haskell?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 04 May 2012 10:27:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954154#target">axilmar</a> said:</div><div class="quote"><p>
Can you please show me how to do the Model-View-Controller pattern in Haskell?
</p></div></div><p>
Just like I&#39;d do it in any other language, only I do it in Haskell. In fact, the Haskell community has produced some very fine building blocks for MVC-style web development (assuming that&#39;s what you&#39;re talking about). Really, MVC can be done in Haskell just like in any other language - it&#39;s an architectural pattern, not a language-specific one.</p><p>Also, I don&#39;t see how this has anything to do with the fact that I prefer Haskell over C++ for building parsers.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Fri, 04 May 2012 13:06:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954160#target">Tobias Dammers</a> said:</div><div class="quote"><p> Really, MVC can be done in Haskell just like in any other language</p></div></div><p>The MVC pattern requires mutable objects, which Haskell does not have. </p><p>I have tried to do the MVC pattern in Haskell, but it eludes me, perhaps because I am too accustomed to imperative programming.</p><p>So, since you seem to have more experience in Haskell than me, could you please post some code on how to do the MVC pattern? more specifically, how to do the Model part?</p><p>I&#39;ll give you what I wanted to achieve: I was trying to make a pacman level editor. My model, in Java, looked like this:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>    <span class="k1">public</span> interface LevelContainerObserver <span class="k2">{</span>
<span class="number">  2</span>        <span class="k1">void</span> handleEvent<span class="k2">(</span>LevelContainerEvent e<span class="k2">)</span><span class="k2">;</span>
<span class="number">  3</span>    <span class="k2">}</span>
<span class="number">  4</span>
<span class="number">  5</span>    <span class="k1">public</span> <span class="k1">class</span> LevelContainer <span class="k2">{</span>
<span class="number">  6</span>        <span class="k1">private</span> List<span class="k3">&lt;</span>Level&gt; m_levels<span class="k2">;</span>
<span class="number">  7</span>        <span class="k1">private</span> List<span class="k3">&lt;</span>LevelContainerObserver&gt; m_observers<span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span>        <span class="k1">private</span> <span class="k1">void</span> invokeObservers<span class="k2">(</span>LevelContainerEvent ev<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 10</span>            ListIterator<span class="k3">&lt;</span>LevelContainerObserver&gt; it <span class="k3">=</span> m_levelObservers.getIterator<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>            <span class="k1">while</span><span class="k2">(</span>it.hasNext<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 12</span>                LevelContainerObserver o <span class="k3">=</span> it.next<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>                o.handleEvent<span class="k2">(</span>ev<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>            <span class="k2">}</span>
<span class="number"> 15</span>        <span class="k2">}</span>
<span class="number"> 16</span>
<span class="number"> 17</span>        <span class="k1">public</span> <span class="k1">void</span> addLevel<span class="k2">(</span>Level level<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 18</span>            m_levels.add<span class="k2">(</span>level<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>            invokeObservers<span class="k2">(</span><span class="k1">new</span> AddLevelContainerEvent<span class="k2">(</span>level<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>        <span class="k2">}</span>
<span class="number"> 21</span>
<span class="number"> 22</span>        <span class="k1">public</span> <span class="k1">void</span> removeLevel<span class="k2">(</span>Level level<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 23</span>            m_levels.remove<span class="k2">(</span>level<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>            invokeObservers<span class="k2">(</span><span class="k1">new</span> RemoveLevelContainerEvent<span class="k2">(</span>level<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>        <span class="k2">}</span>
<span class="number"> 26</span>
<span class="number"> 27</span>        <span class="k1">public</span> <span class="k1">void</span> clearLevels<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 28</span>            m_levels.clear<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>            invokeObservers<span class="k2">(</span><span class="k1">new</span> ClearLevelContainerEvent<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>        <span class="k2">}</span>
<span class="number"> 31</span>    <span class="k2">}</span>
</div></div><p>

The model obviously had other classes as well (Level, LevelObserver, etc).</p><p>The model allowed the view (Swing classes) to be linked to the model so as that when the model changed, the view was automatically refreshed.</p><p>I would be extremely pleased if you could do just the above class in Haskell for me. Personally, I tried to do it but I always end up with type errors.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 04 May 2012 16:00:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954163#target">axilmar</a> said:</div><div class="quote"><p>
The MVC pattern requires mutable objects, which Haskell does not have. 
</p></div></div><p>
Uh... what? No. MVC, again, is an architectural pattern; whether or not your programming language provides mutable data structures or not is completely irrelevant.</p><p>Just because Haskell values are immutable doesn&#39;t mean you can&#39;t have mutable state; you just have to implement it on top of immutable objects (this is what the State, Reader and Writer monads and monad transformers are for). You don&#39;t modify objects in-place; instead, you write your logic in terms of functions that map old state to new state, and wrap them in a State monad to provide the syntactic sugar to make them behave as if they were mutable.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I would be extremely pleased if you could do just the above class in Haskell for me. Personally, I tried to do it but I always end up with type errors.
</p></div></div><p>
I&#39;d have to look into how Haskell&#39;s GTK bindings do things, but my guess would be that Java&#39;s event listener model doesn&#39;t translate easily to Haskell; you&#39;ll have to do it the Haskell way.</p><p>I&#39;d design it so that the controller polls the view for input, then dispatches it to the model and receives a response that tells it what has been changed; this in turn would be used to update the view accordingly. The controller would probably run some kind of main loop, something like:
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>data AppState <span class="k3">=</span> AppState <span class="k2">{</span>
<span class="number">  2</span>                    appstateView <span class="k2">:</span><span class="k2">:</span> View,
<span class="number">  3</span>                    appstateModel <span class="k2">:</span><span class="k2">:</span> Model
<span class="number">  4</span>                <span class="k2">}</span>
<span class="number">  5</span>
<span class="number">  6</span>mainLoop <span class="k2">:</span><span class="k2">:</span> AppState <span class="k3">-</span><span class="k3">&gt;</span> IO AppState
<span class="number">  7</span>mainLoop a <span class="k3">=</span>
<span class="number">  8</span>    <span class="k1">if</span> isExitCondition a
<span class="number">  9</span>        then a
<span class="number"> 10</span>        <span class="k1">else</span> <span class="k2">(</span>mainLoopStep a <span class="k3">&gt;</span><span class="k3">&gt;</span><span class="k3">=</span> mainLoop<span class="k2">)</span>
<span class="number"> 11</span>
<span class="number"> 12</span>mainLoopStep <span class="k2">:</span><span class="k2">:</span> AppState <span class="k3">-</span><span class="k3">&gt;</span> IO AppState
<span class="number"> 13</span>mainLoopStep a <span class="k3">=</span> <span class="k1">do</span>
<span class="number"> 14</span>    let view <span class="k3">=</span> appstateView a
<span class="number"> 15</span>        model <span class="k3">=</span> appstateModel a
<span class="number"> 16</span>    command <span class="k3">&lt;</span><span class="k3">-</span> getNextCommand view
<span class="number"> 17</span>    <span class="k2">(</span>newModel, commandResult<span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">-</span> runCommand model command
<span class="number"> 18</span>    newView <span class="k3">&lt;</span><span class="k3">-</span> processCommandResult view commandResult
<span class="number"> 19</span>    <span class="k1">return</span> $ a <span class="k2">{</span> view <span class="k3">=</span> newView<span class="k2">;</span> model <span class="k3">=</span> newModel <span class="k2">}</span>
</div></div><p>
And then you could define a bunch of commands and command results, and implement runCommand and processCommandResult to dispatch them.</p><p>Note, however, that I haven&#39;t written any desktop GUI applications in a while, and there are probably more elegant ways of solving this. For starters, you could wrap the main loop in a state monad of type AppState, but I&#39;ll leave it as explicit as this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Fri, 04 May 2012 19:04:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s not MVC. There are no registrations and unregistrations of observers anywhere in your code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 04 May 2012 19:20:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>MVC does not mandate registrations and unregistrations of observers. The whole event listener / observer pattern thing is a Javaism (or rather, a class-based-OOP-ism), and it doesn&#39;t translate to other paradigms as-is. It is completely orthogonal to MVC design. MVC simply means: Model = representation of domain logic; View = present data to the user; Controller = get user input and dispatch to model and view.</p><p>The observer pattern is one way of doing this, but it&#39;s not the only one, and not necessarily the best.</p><p>Here&#39;s the relevant wikipedia entry to remind you: <a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Fri, 04 May 2012 19:59:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Tobias got owned by an axilmar setup. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 05 May 2012 01:05:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Heh, yeah. Walked right into at least two consecutive strawmen. At least we have established that Haskell is unsuitable for building parsers because I don&#39;t know how to implement Swing event listeners with it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Sat, 05 May 2012 02:11:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The wikipedia article says that &quot;the view observes the model&quot;, and therefore the solution you provided is not an implementation of the MVC pattern.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Sat, 05 May 2012 02:52:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Get your quotes right.</p><p>Also, I believe your original argument went something like this: If I fail to provide an implementation of Java-style event listeners in Haskell, then it logically follows that Haskell is less suitable for implementing parsers than C++.</p><p>Yeah, makes perfect sense.</p><p>Oh, and for the record: In your example, the view doesn&#39;t really observe the model either. It merely passes a bunch of callbacks into the model, and then the model updates the view. Technically speaking.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Sat, 05 May 2012 15:44:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>First of all, the wikipedia article says:</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> 2. the View, which observes the state.</p></div></div><p>So, my quotes are correct. </p><p>Secondly, you are wrong, my request for the MVC pattern in Haskell has nothing to do with parsers. I am really curious on how to do the MVC pattern in Haskell, that&#39;s just all there is.</p><p>Thirdly, in my example, it is the View class that installs the callbacks in the Model, so, the View really observes the Model.</p><p>With all this in mind, can you show me how to do the MVC pattern with observers in Haskell or not?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Sat, 05 May 2012 16:56:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/954212#target">axilmar</a> said:</div><div class="quote"><p> So, my quotes are correct.</p></div></div><p>No, because you said the view observes the model.  The article actually says that the view observes the state of the application, and the model is just a representation of the state, not the state itself.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sat, 05 May 2012 22:57:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The Wikipedia article says that the Model represents the application&#39;s state, and the View observes the application&#39;s state. So, Model = State and the View observes the Model, which is actually how MVC is implemented in every language.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Sun, 06 May 2012 17:01:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It seems we&#39;re getting down to semantics. Who would&#39;ve thought? <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc ( Arvidsson)</author>
		<pubDate>Sun, 06 May 2012 17:17:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried downloading Antlr 2.7 and I found the calc example a little confusing. There&#39;s a file named calc.g shown below, how do this get compiled with the MAIN.cpp file? I&#39;m using codeblocks btw...</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>options <span class="k2">{</span>
<span class="number">  2</span>  language<span class="k3">=</span><span class="s">"Cpp"</span><span class="k2">;</span>
<span class="number">  3</span><span class="k2">}</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="k1">class</span> CalcParser extends Parser<span class="k2">;</span>
<span class="number">  6</span>options <span class="k2">{</span>
<span class="number">  7</span>  buildAST <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>  <span class="c">// uses CommonAST by default</span>
<span class="number">  8</span><span class="k2">}</span>
<span class="number">  9</span>
<span class="number"> 10</span>expr
<span class="number"> 11</span>  <span class="k2">:</span>  mexpr <span class="k2">(</span>PLUS^ mexpr<span class="k2">)</span><span class="k3">*</span> SEMI<span class="k3">!</span>
<span class="number"> 12</span>  <span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>mexpr
<span class="number"> 15</span>  <span class="k2">:</span>  atom <span class="k2">(</span>STAR^ atom<span class="k2">)</span><span class="k3">*</span>
<span class="number"> 16</span>  <span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>atom:  INT
<span class="number"> 19</span>  <span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="k1">class</span> CalcLexer extends Lexer<span class="k2">;</span>
<span class="number"> 22</span>
<span class="number"> 23</span>WS_  <span class="k2">:</span>  <span class="k2">(</span><span class="s">' '</span>
<span class="number"> 24</span>  <span class="k3">|</span>  <span class="s">'\t'</span>
<span class="number"> 25</span>  <span class="k3">|</span>  <span class="s">'\n'</span>
<span class="number"> 26</span>  <span class="k3">|</span>  <span class="s">'\r'</span><span class="k2">)</span>
<span class="number"> 27</span>    <span class="k2">{</span> _ttype <span class="k3">=</span> ANTLR_USE_NAMESPACE<span class="k2">(</span>antlr<span class="k2">)</span>Token::SKIP<span class="k2">;</span> <span class="k2">}</span>
<span class="number"> 28</span>  <span class="k2">;</span>
<span class="number"> 29</span>
<span class="number"> 30</span>LPAREN:  <span class="s">'('</span>
<span class="number"> 31</span>  <span class="k2">;</span>
<span class="number"> 32</span>
<span class="number"> 33</span>RPAREN:  <span class="s">')'</span>
<span class="number"> 34</span>  <span class="k2">;</span>
<span class="number"> 35</span>
<span class="number"> 36</span>STAR:  <span class="s">'*'</span>
<span class="number"> 37</span>  <span class="k2">;</span>
<span class="number"> 38</span>
<span class="number"> 39</span>PLUS:  <span class="s">'+'</span>
<span class="number"> 40</span>  <span class="k2">;</span>
<span class="number"> 41</span>
<span class="number"> 42</span>SEMI:  <span class="s">';'</span>
<span class="number"> 43</span>  <span class="k2">;</span>
<span class="number"> 44</span>
<span class="number"> 45</span><span class="k1">protected</span>
<span class="number"> 46</span>DIGIT
<span class="number"> 47</span>  <span class="k2">:</span>  <span class="s">'0'</span>..<span class="s">'9'</span>
<span class="number"> 48</span>  <span class="k2">;</span>
<span class="number"> 49</span>
<span class="number"> 50</span>INT  <span class="k2">:</span>  <span class="k2">(</span>DIGIT<span class="k2">)</span><span class="k3">+</span>
<span class="number"> 51</span>  <span class="k2">;</span>
<span class="number"> 52</span>
<span class="number"> 53</span><span class="k1">class</span> CalcTreeWalker extends TreeParser<span class="k2">;</span>
<span class="number"> 54</span>
<span class="number"> 55</span>expr returns <span class="k2">[</span><span class="k1">float</span> r<span class="k2">]</span>
<span class="number"> 56</span><span class="k2">{</span>
<span class="number"> 57</span>  <span class="k1">float</span> a,b<span class="k2">;</span>
<span class="number"> 58</span>  r<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>
<span class="number"> 59</span><span class="k2">}</span>
<span class="number"> 60</span>  <span class="k2">:</span>  #<span class="k2">(</span>PLUS a<span class="k3">=</span>expr b<span class="k3">=</span>expr<span class="k2">)</span>  <span class="k2">{</span>r <span class="k3">=</span> a<span class="k3">+</span>b<span class="k2">;</span><span class="k2">}</span>
<span class="number"> 61</span>  <span class="k3">|</span>  #<span class="k2">(</span>STAR a<span class="k3">=</span>expr b<span class="k3">=</span>expr<span class="k2">)</span>  <span class="k2">{</span>r <span class="k3">=</span> a<span class="k3">*</span>b<span class="k2">;</span><span class="k2">}</span>
<span class="number"> 62</span>  <span class="k3">|</span>  i:INT      <span class="k2">{</span>r <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_53.html" target="_blank">atof</a><span class="k2">(</span>i-&gt;getText<span class="k2">(</span><span class="k2">)</span>.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span><span class="k2">}</span>
<span class="number"> 63</span>  <span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Mon, 07 May 2012 06:32:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610113/953678#target">axilmar</a> said:</div><div class="quote"><p> How about <a href="https://github.com/axilmar/parserlib">this</a>?
</p></div></div><p>g++ 4.6.3 on Ubuntu has problems with the latest source due to <span class="source-code"><span class="k1">not</span></span> and <span class="source-code"><span class="k1">and</span></span>. Using the previous commit works.</p><p>Also had to change line 98 of the calculator:
</p><div class="source-code snippet"><div class="inner"><pre>diff <span class="k3">-</span><span class="k3">-</span>git a<span class="k3">/</span>examples<span class="k3">/</span>calculator<span class="k3">/</span>calculator.cpp b<span class="k3">/</span>examples<span class="k3">/</span>calculator<span class="k3">/</span>calculator
<a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a> <span class="n">7c8fa18</span>..ea0e6c6 <span class="n">100644</span>
<span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> a<span class="k3">/</span>examples<span class="k3">/</span>calculator<span class="k3">/</span>calculator.cpp
<span class="k3">+</span><span class="k3">+</span><span class="k3">+</span> b<span class="k3">/</span>examples<span class="k3">/</span>calculator<span class="k3">/</span>calculator.cpp
@@ <span class="k3">-</span><span class="n">95</span>,<span class="n">7</span> <span class="k3">+</span><span class="n">95</span>,<span class="n">7</span> @@ <span class="k1">class</span> binary_expr_t <span class="k2">:</span> <span class="k1">public</span> expr_t <span class="k2">{</span>
 public:
     ast_ptr<span class="k3">&lt;</span>expr_t&gt; left, right<span class="k2">;</span>
 
<span class="k3">-</span>    <span class="k1">virtual</span> <span class="k1">void</span> print<span class="k2">(</span><span class="k1">int</span> depth, <span class="k1">int</span> tab<span class="k2">)</span> <span class="k1">const</span> <span class="k3">=</span> <span class="n">0</span> <span class="k2">{</span>
<span class="k3">+</span>    <span class="k1">virtual</span> <span class="k1">void</span> print<span class="k2">(</span><span class="k1">int</span> depth, <span class="k1">int</span> tab<span class="k2">)</span> <span class="k1">const</span> <span class="k2">{</span>
         left-&gt;print<span class="k2">(</span>depth<span class="k2">)</span><span class="k2">;</span>
         right-&gt;print<span class="k2">(</span>depth<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 07 May 2012 07:12:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Jesus H. Christ, I thought I knew all of c++!!! TIL that the words &#39;not&#39; and &#39;and&#39; are reserved keywords, as alternatives to operators!</p><p>It&#39;s part of the <a href="http://stackoverflow.com/questions/2419805/when-did-and-become-an-operator-in-c">C++03 standard, section 2.5</a>.</p><p>I fixed the code, thanks Matthew.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Mon, 07 May 2012 17:37:45 +0000</pubDate>
	</item>
</rss>
