<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: ANTLR By Example: Part 4: Tree Parsing</title>
	<link>http://www.alittlemadness.com/2006/07/06/antlr-by-example-part-4-tree-parsing/</link>
	<description>A man needs a little madness, or else he never dares cut the rope and be free. -Nikos Kazantzakis</description>
	<pubDate>Wed, 07 Jan 2009 03:51:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: Jason</title>
		<link>http://www.alittlemadness.com/2006/07/06/antlr-by-example-part-4-tree-parsing/#comment-897</link>
		<author>Jason</author>
		<pubDate>Tue, 08 Aug 2006 11:30:22 +0000</pubDate>
		<guid>http://www.alittlemadness.com/2006/07/06/antlr-by-example-part-4-tree-parsing/#comment-897</guid>
		<description>Designker,

The factory is not defined in the grammar files: it is a manually created class in our application.  The factory has a method:

NotifyCondition createCondition(String condition)

which creates a notify condition object based on the condition string (e.g. "success" creates a SuccessNotifyCondition object).  These *NotifyCondition classes are also a manually-created part of our application.  You will need to adapt the example to suit you application!</description>
		<content:encoded><![CDATA[<p>Designker,</p>
<p>The factory is not defined in the grammar files: it is a manually created class in our application.  The factory has a method:</p>
<p>NotifyCondition createCondition(String condition)</p>
<p>which creates a notify condition object based on the condition string (e.g. &#8220;success&#8221; creates a SuccessNotifyCondition object).  These *NotifyCondition classes are also a manually-created part of our application.  You will need to adapt the example to suit you application!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Designker</title>
		<link>http://www.alittlemadness.com/2006/07/06/antlr-by-example-part-4-tree-parsing/#comment-849</link>
		<author>Designker</author>
		<pubDate>Sun, 06 Aug 2006 20:53:17 +0000</pubDate>
		<guid>http://www.alittlemadness.com/2006/07/06/antlr-by-example-part-4-tree-parsing/#comment-849</guid>
		<description>Following the instructions fails to create 10 files. Instead 8 are created and there are errors due to unresolvable type "NotifyConditionFactory". Where in the grammar file should the details be for creating the NotifyConditionFactory class?

NotifyConditionTreeParserTokenTypes.java
NotifyConditionTreeParserTokenTypes.txt are the files that it fails to create. The entire G file from the ttorial is

header {
    
}


class NotifyConditionLexer extends Lexer;

// Words, which include our operators
WORD: ('a'..'z' &#124; 'A'..'Z' &#124; '.')+ ;

// Grouping
LEFT_PAREN: '(';
RIGHT_PAREN: ')';

WHITESPACE
    : (' ') { $setType(Token.SKIP); }
    ;
    
class NotifyConditionParser extends Parser;

options {
        buildAST=true;
}

orexpression
    :   andexpression ("or"^ andexpression)*
    ;

andexpression
    : notexpression ("and"^ notexpression)*
    ;

notexpression
    : ("not"^)? atom
    ;

atom
    : condition
    &#124; LEFT_PAREN! orexpression RIGHT_PAREN!
    ;

condition
    : "true"
    &#124; "false"
    &#124; "success"
    &#124; "failure"
    &#124; "error"
    &#124; "changed"
    &#124; "changed.by.me"
    &#124; "state.change"
    ;
    

class NotifyConditionTreeParser extends TreeParser;
{
    private NotifyConditionFactory factory;

    public void setNotifyConditionFactory(NotifyConditionFactory factory)
    {
        this.factory = factory;
    }
}

cond
    : #("and" cond cond)
    &#124; #("or" cond cond)
    &#124; #("not" cond)
    &#124; condition
    ;

condition
    : "true"
    &#124; "false"
    &#124; "success"
    &#124; "failure"
    &#124; "error"
    &#124; "changed"
    &#124; "changed.by.me"
    &#124; "state.change"
    ;</description>
		<content:encoded><![CDATA[<p>Following the instructions fails to create 10 files. Instead 8 are created and there are errors due to unresolvable type &#8220;NotifyConditionFactory&#8221;. Where in the grammar file should the details be for creating the NotifyConditionFactory class?</p>
<p>NotifyConditionTreeParserTokenTypes.java<br />
NotifyConditionTreeParserTokenTypes.txt are the files that it fails to create. The entire G file from the ttorial is</p>
<p>header {</p>
<p>}</p>
<p>class NotifyConditionLexer extends Lexer;</p>
<p>// Words, which include our operators<br />
WORD: (&#8217;a&#8217;..&#8217;z&#8217; | &#8216;A&#8217;..&#8217;Z&#8217; | &#8216;.&#8217;)+ ;</p>
<p>// Grouping<br />
LEFT_PAREN: &#8216;(&#8217;;<br />
RIGHT_PAREN: &#8216;)&#8217;;</p>
<p>WHITESPACE<br />
    : (&#8217; &#8216;) { $setType(Token.SKIP); }<br />
    ;</p>
<p>class NotifyConditionParser extends Parser;</p>
<p>options {<br />
        buildAST=true;<br />
}</p>
<p>orexpression<br />
    :   andexpression (&#8221;or&#8221;^ andexpression)*<br />
    ;</p>
<p>andexpression<br />
    : notexpression (&#8221;and&#8221;^ notexpression)*<br />
    ;</p>
<p>notexpression<br />
    : (&#8221;not&#8221;^)? atom<br />
    ;</p>
<p>atom<br />
    : condition<br />
    | LEFT_PAREN! orexpression RIGHT_PAREN!<br />
    ;</p>
<p>condition<br />
    : &#8220;true&#8221;<br />
    | &#8220;false&#8221;<br />
    | &#8220;success&#8221;<br />
    | &#8220;failure&#8221;<br />
    | &#8220;error&#8221;<br />
    | &#8220;changed&#8221;<br />
    | &#8220;changed.by.me&#8221;<br />
    | &#8220;state.change&#8221;<br />
    ;</p>
<p>class NotifyConditionTreeParser extends TreeParser;<br />
{<br />
    private NotifyConditionFactory factory;</p>
<p>    public void setNotifyConditionFactory(NotifyConditionFactory factory)<br />
    {<br />
        this.factory = factory;<br />
    }<br />
}</p>
<p>cond<br />
    : #(&#8221;and&#8221; cond cond)<br />
    | #(&#8221;or&#8221; cond cond)<br />
    | #(&#8221;not&#8221; cond)<br />
    | condition<br />
    ;</p>
<p>condition<br />
    : &#8220;true&#8221;<br />
    | &#8220;false&#8221;<br />
    | &#8220;success&#8221;<br />
    | &#8220;failure&#8221;<br />
    | &#8220;error&#8221;<br />
    | &#8220;changed&#8221;<br />
    | &#8220;changed.by.me&#8221;<br />
    | &#8220;state.change&#8221;<br />
    ;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
