diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-10 21:35:42 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-10 21:43:45 -0800 |
commit | 76755b2836b0dadd88f82635f661f9d9df77604d (patch) | |
tree | f4f4429510c739fd1f9e51edd10e03c27107acba /html/055parse_tree.cc.html | |
parent | 080e9cb73fa55cdc862f1dd7593df56e0a6302b8 (diff) | |
download | mu-76755b2836b0dadd88f82635f661f9d9df77604d.tar.gz |
2423 - describe shape-shifting in html docs
Diffstat (limited to 'html/055parse_tree.cc.html')
-rw-r--r-- | html/055parse_tree.cc.html | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/html/055parse_tree.cc.html b/html/055parse_tree.cc.html new file mode 100644 index 00000000..7d9e158f --- /dev/null +++ b/html/055parse_tree.cc.html @@ -0,0 +1,117 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - 055parse_tree.cc</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } +body { font-family: monospace; color: #eeeeee; background-color: #080808; } +* { font-size: 1.05em; } +.traceContains { color: #008000; } +.Comment { color: #9090ff; } +.Delimiter { color: #a04060; } +.Special { color: #ff6060; } +.Identifier { color: #804000; } +.Constant { color: #00a0a0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment">// So far instructions can only contain linear lists of properties. Now we add</span> +<span class="Comment">// support for more complex trees of properties in dilated reagents. This will</span> +<span class="Comment">// come in handy later for expressing complex types, like "a dictionary from</span> +<span class="Comment">// (address to array of charaters) to (list of numbers)".</span> + +<span class="Delimiter">:(scenario dilated_reagent_with_nested_brackets)</span> +recipe main [ + <span class="Delimiter">{</span><span class="Constant">1</span>: number<span class="Delimiter">,</span> foo: <span class="Delimiter">(</span>bar <span class="Delimiter">(</span>baz quux<span class="Delimiter">))}</span><span class="Special"> <- </span>copy <span class="Constant">34</span> +] +<span class="traceContains">+parse: product: {"1": "number", "foo": <"bar" : <<"baz" : <"quux" : <>>> : <>>>}</span> + +<span class="Delimiter">:(before "End Parsing Reagent Property(value)")</span> +value = parse_string_tree<span class="Delimiter">(</span>value<span class="Delimiter">);</span> + +<span class="Delimiter">:(code)</span> +string_tree* parse_string_tree<span class="Delimiter">(</span>string_tree* s<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!s<span class="Delimiter">-></span>left && !s<span class="Delimiter">-></span>right<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>s<span class="Delimiter">-></span>value<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != <span class="Constant">'('</span><span class="Delimiter">)</span> <span class="Identifier">return</span> s<span class="Delimiter">;</span> + string_tree* result = parse_string_tree<span class="Delimiter">(</span>s<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + delete s<span class="Delimiter">;</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +string_tree* parse_string_tree<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> + istringstream in<span class="Delimiter">(</span>s<span class="Delimiter">);</span> + in >> std::noskipws<span class="Delimiter">;</span> + <span class="Identifier">return</span> parse_string_tree<span class="Delimiter">(</span>in<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +string_tree* parse_string_tree<span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">')'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> + <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="Constant">'('</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + string_tree* result = new string_tree<span class="Delimiter">(</span>next_word<span class="Delimiter">(</span>in<span class="Delimiter">));</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="Comment">// skip '('</span> + string_tree* result = <span class="Constant">NULL</span><span class="Delimiter">;</span> + string_tree** curr = &result<span class="Delimiter">;</span> + while <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="Constant">')'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>!in<span class="Delimiter">.</span>eof<span class="Delimiter">());</span> + *curr = new string_tree<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> + skip_whitespace<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + skip_ignored_characters<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'('</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>left = parse_string_tree<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + else + <span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>value = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span> + curr = &<span class="Delimiter">(</span>*curr<span class="Delimiter">)-></span>right<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> <span class="Comment">// skip ')'</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario dilated_reagent_with_type_tree)</span> +<span class="Special">% Hide_errors = true; // 'map' isn't defined yet</span> +recipe main [ + <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>foo <span class="Delimiter">(</span>address array character<span class="Delimiter">)</span> <span class="Delimiter">(</span>bar number<span class="Delimiter">))}</span><span class="Special"> <- </span>copy <span class="Constant">34</span> +] +<span class="Comment"># just to avoid errors</span> +container foo [ +] +container bar [ +] +<span class="traceContains">+parse: product: {"1": <"foo" : <<"address" : <"array" : <"character" : <>>>> : <<"bar" : <"number" : <>>> : <>>>>}</span> + +<span class="Comment">//: an exception is 'new', which takes a type tree as its ingredient *value*</span> + +<span class="Delimiter">:(scenario dilated_reagent_with_new)</span> +recipe main [ + x:address:number<span class="Special"> <- </span>new <span class="Delimiter">{(</span>foo bar<span class="Delimiter">)</span>: type<span class="Delimiter">}</span> +] +<span class="Comment"># type isn't defined so size is meaningless, but at least we parse the type correctly</span> +<span class="traceContains">+new: size of <"foo" : <"bar" : <>>> is 1</span> + +<span class="Delimiter">:(before "End Post-processing(type_name) When Converting 'new'")</span> +type_name = parse_string_tree<span class="Delimiter">(</span>type_name<span class="Delimiter">);</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |