about summary refs log tree commit diff stats
path: root/apps/tile/main.mu
Commit message (Expand)AuthorAgeFilesLines
* 6796Kartik Agaram2020-09-161-38/+7
* 6792Kartik Agaram2020-09-161-1/+0
* 6790 experiment: explicit flushKartik Agaram2020-09-161-0/+1
* 6789 - tile: print keystrokes to screenKartik Agaram2020-09-161-0/+44
* 6787Kartik Agaram2020-09-161-2/+33
* 6776 - new app: a programming environmentKartik Agaram2020-09-131-0/+3
. Agaram <vc@akkartik.com> 2015-10-27 14:38:57 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-10-27 14:38:57 -0700 2291 - parsing property trees' href='/akkartik/mu/commit/055parse_tree.cc?h=main&id=a17f9186c17073e07eef6f046dcc1b15f08ed73c'>a17f9186 ^
c4e143d6 ^

a17f9186 ^
















1f7e3c05 ^
08cf048f ^
a17f9186 ^




6808ff7d ^

a17f9186 ^

6808ff7d ^


08cf048f ^
6808ff7d ^
1f7e3c05 ^
6808ff7d ^




a17f9186 ^
6808ff7d ^

a17f9186 ^
6808ff7d ^

9cfd925a ^
1ead3562 ^
15f79a66 ^
6808ff7d ^
15f79a66 ^




acc4792d ^
ff8d96ae ^
69e418d7 ^
1ead3562 ^
b0bf5321 ^




69e418d7 ^



ff8d96ae ^


1ead3562 ^
b0bf5321 ^
ff8d96ae ^
8a3d101e ^
ff8d96ae ^
bb33c5e8 ^
c4e143d6 ^





ff8d96ae ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99




                                                                              
                                                
          

                                               
                                                               


                                               

                                                    
















                                                    
                                      
                                 




                         

                                                         

                        


                               
                         
                                
                                        




                                            
   

                        
 

                                          
                                                 
          
                                                              
 




                      
                                                                                
 
                                           
          




                                                                                                   



                              


                                                                            
          
                                                          
 
                                       
 
                                                                     





                                                                               

                                                                
// So far instructions can only contain linear lists of properties. Now we add
// support for more complex trees of properties in dilated reagents. This will
// come in handy later for expressing complex types, like "a dictionary from
// (address to array of charaters) to (list of numbers)".

:(scenario dilated_reagent_with_nested_brackets)
def main [
  {1: number, foo: (bar (baz quux))} <- copy 34
]
+parse:   product: {1: "number", "foo": ("bar" ("baz" "quux"))}

:(before "End Parsing Reagent Property(value)")
value = parse_string_tree(value);
:(before "End Parsing Reagent Type Property(value)")
value = parse_string_tree(value);

:(code)
string_tree* parse_string_tree(string_tree* s) {
  assert(!s->left && !s->right);
  if (s->value.at(0) != '(') return s;
  string_tree* result = parse_string_tree(s->value);
  delete s;
  return result;
}

string_tree* parse_string_tree(const string& s) {
  istringstream in(s);
  in >> std::noskipws;
  return parse_string_tree(in);
}

string_tree* parse_string_tree(istream& in) {
  skip_whitespace_but_not_newline(in);
  if (!has_data(in)) return NULL;
  if (in.peek() == ')') {
    in.get();
    return NULL;
  }
  if (in.peek() != '(') {
    string_tree* result = new string_tree(next_word(in));
    return result;
  }
  in.get();  // skip '('
  string_tree* result = NULL;
  string_tree** curr = &result;
  while (in.peek() != ')') {
    assert(has_data(in));
    *curr = new string_tree("");
    skip_whitespace_but_not_newline(in);
    if (in.peek() == '(')
      (*curr)->left = parse_string_tree(in);
    else
      (*curr)->value = next_word(in);
    curr = &(*curr)->right;
  }
  in.get();  // skip ')'
  return result;
}

:(scenario dilated_reagent_with_type_tree)
% Hide_errors = true;  // 'map' isn't defined yet
def main [
  {1: (foo (address array character) (bar number))} <- copy 34
]
# just to avoid errors
container foo [
]
container bar [
]
+parse:   product: {1: ("foo" ("address" "array" "character") ("bar" "number"))}

:(scenario dilated_reagent_in_static_array)
def main [
  {1: (array (address number) 3)} <- create-array
  5:address:number <- new number:type
  {1: (array (address number) 3)} <- put-index {1: (array (address number) 3)}, 0, 5:address:number
  *5:address:number <- copy 34
  6:number <- copy *5:address:number
]
+run: creating array of size 4
+mem: storing 34 in location 6

//: an exception is 'new', which takes a type tree as its ingredient *value*

:(scenario dilated_reagent_with_new)
def main [
  x:address:address:number <- new {(address number): type}
]
+new: size of ("address" "number") is 1

:(before "End Post-processing(expected_product) When Checking 'new'")
{
  string_tree* tmp_type_names = parse_string_tree(expected_product.type->name);
  delete expected_product.type;
  expected_product.type = new_type_tree(tmp_type_names);
  delete tmp_type_names;
}
:(before "End Post-processing(type_name) When Converting 'new'")
type_name = parse_string_tree(type_name);