/tutorial/backtracking/expand_expression/expand_expression.html
HTML | 156 lines | 139 code | 17 blank | 0 comment | 0 complexity | c06184d4718e836190eb80de9dc72886 MD5 | raw file
1<html><head> 2 3<title>The tutorial expand_expression</title> 4 5<style> 6 7 8body { 9 background-color: white; 10 margin: 3px; 11} 12 13body * { 14/* 15 margin: 0px 0px 5px 0px; 16*/ 17} 18 19h1 { 20 background-color: #3366FF; 21 font-size: 300%; 22 color: white; 23 text-align: center; 24 font-weight: normal; 25 padding: 10px; 26} 27 28h2 { 29 background-color: #3366FF; 30 font-size: 150%; 31 color: white; 32 text-align: left; 33 font-weight: normal; 34 padding: 5px; 35} 36 37.i { 38 background-color: yellow; 39 font-size: 110%; 40 color: #3366FF; 41 text-align: center; 42 font-weight: bolder; 43 padding: 10px 30px 10px 30px; 44} 45 46p { 47/* 48 text-align: justify; 49*/ 50} 51 52pre { 53 margin: 3px 50px 3px 50px; 54 padding: 3px 5px 3px 5px; 55 border: 2px dashed #3366FF; 56 background: #eef; 57} 58 59.class { 60 font-weight: bolder; 61 color: #3366FF; 62} 63 64.sesign { 65 text-align: center; 66 font-size: small; 67 font-style: italic; 68} 69 70</style> 71 72</head><body> 73 74<h1>The tutorial expand_expression</h1> 75<div class="i"> 76<p>This tutorial shows basic use of the cluster backtracking.</p> 77<p>The same example: expanding syntactic expression, is 78written using two differents ways: <span class="class">ABSTRACT</span> and <span class="class">TREE</span>. 79It is recommended to start with <span class="class">TREE</span>.</p></div> 80<a name="sommaire"/><h2>Sommaire</h2> 81<div class="s"><ul class="s"> 82 <li><a href="#chap-1">How to compile?</a></li> 83 <li><a href="#chap-2">What does it do?</a></li> 84 <li><a href="#chap-3">How does 'tree' works?</a></li> 85 <li><a href="#chap-4">How does 'abstract' works?</a></li> 86</ul></div> 87 88<a name="chap-1"/><h2>How to compile?</h2> 89<div class="c2"> 90<p>In both case, just type:</p> 91<p> se c -clean -o a_nick_name expand_expression</p> 92</div> 93<a name="chap-2"/><h2>What does it do?</h2> 94<div class="c2"> 95<p>Each of the 2 programs performs syntaxic expansion. 96For example, putting the line</p> 97<p><pre> 98 (Hello + Hi) the ( + great) world! 99</pre></p> 100<p>at input will produce the output:</p> 101<p><pre> 102 (1) Hello the world! 103 (2) Hello the great world! 104 (3) Hi the world! 105 (4) Hi the great world! 106</pre></p> 107<p>The grammar of the inputs are:</p> 108<p><pre> 109 input ::= alternative; 110 alternative ::= sequence ['+' sequence]...; 111 sequence ::= [term]...; 112 term ::= '(' alternative ')' | "a term"; 113</pre></p> 114<p>Exercice: write a program that does the same syntaxic expansion. 115(trick: reuse the parser of the tutorial)</p> 116</div> 117<a name="chap-3"/><h2>How does 'tree' works?</h2> 118<div class="c2"> 119<p>The tree example uses the most usable class of the 120backtracking cluster: the class <span class="class">BACKTRACKING</span>.</p> 121<p>The class <span class="class">BACKTRACKING</span> make an exploration of the 122and/or graphes made of <span class="class">BACKTRACKING_NODE</span> instances. Many 123usefull <span class="class">BACKTRACKING_NODE</span> inheriters are defined and 124useables.</p> 125<p>The syntaxic expression is transformed to a such 126and/or structure. Alternatives does use <span class="class">BACKTRACKING_NODE_OR_PAIR</span> 127that make a or between two nodes. Sequences does use 128<span class="class">BACKTRACKING_NODE_AND_PAIR</span> that make a and between to nodes. 129In both cases, the order of the nodes is meaningful. 130Two other predefined nodes are used: the_true_node 131(of class <span class="class">BACKTRACKING_NODE_TRUE</span>) for empty terms, and, 132the_false_node (of class <span class="class">BACKTRACKING_NODE_FALSE</span>) for 133errors of syntax.</p> 134<p>To get practical results, the terms are using a local 135class <span class="class">STRING_NODE</span> that records what to print in a local 136field. When explored these nodes push the string on the 137and call the feature continue. Not that covariance is 138used.</p> 139<p>The use of that class is easy: define the features 140'get_context' and 'restore_context'. These features 141will be called during the exploration to save the 142context before to explore an alternative and to restore 143it during the backtracking. These feature are defined 144as returning <span class="class">ANY</span> but please make a covariant redefinition 145as in exemples, where the context, an <span class="class">INTEGER</span>, records the 146count of items pushed.</p> 147</div> 148<a name="chap-4"/><h2>How does 'abstract' works?</h2> 149<div class="c2"> 150<p>The abstract example does exactly the same that tree except 151that it uses a more abstract class <span class="class">ABSTRACT_BACKTRACKING</span>.</p> 152<p>That class is intended to be used when structures to be 153explored can not be derived from <span class="class">BACKTRACKING_NODE</span>. </p> 154</div> 155 156</body></html>