Hey, I fixed while/asteration! Cool
Cat's Eye Technologies
11 years ago
182 | 182 | + 0 2 |
183 | 183 | = 2 |
184 | 184 | |
185 | Alternatives can select code to be executed, basically. | |
186 | ||
187 | | main = set L = nil & (aorb & set L = el(L) | cord & set L = le(L)) & | |
188 | | return L. | |
189 | | aorb = "a" | "b". | |
190 | | cord = "c" | eorf. | |
191 | | eorf = "e" | "f". | |
192 | + e | |
193 | = le(nil) | |
194 | ||
185 | 195 | When a production is called, the result that it evaluates to may be stored |
186 | 196 | in a variable. Variables are local to the production. |
187 | 197 | |
438 | 448 | |
439 | 449 | For now, let's evaluate some backwards S-expressions. |
440 | 450 | |
441 | DEFINITELY SOME PROBLEMS WITH `{while}`; we're not restoring context | |
442 | properly when we try/except. | |
451 | Whew, finally got `{}` (while) working correctly. Although, this result isn't | |
452 | quite what I had in mind, but it does parse... | |
443 | 453 | |
444 | 454 | | main = sexp. |
445 | 455 | | sexp = symbol | list. |
449 | 459 | | ")" & |
450 | 460 | | return L. |
451 | 461 | | symbol = "cons" | "head" | "tail" | "nil" | "a" | "b" | "c". |
452 | + (cons (a cons(b nil)) | |
453 | = cons(a, cons(b, nil)) | |
454 | ||
455 | ||
456 | | main = set L = nil & (aorb & set L = el(L) | cord & set L = le(L)) & | |
457 | | return L. | |
458 | | aorb = "a" | "b". | |
459 | | cord = "c" | eorf. | |
460 | | eorf = "e" | "f". | |
461 | + e | |
462 | = le(nil) | |
462 | + (cons (a (cons b nil))) | |
463 | = cons(cons(cons(nil, cons(b, cons(cons, nil))), cons(a, nil)), cons(cons, nil)) | |
463 | 464 | |
464 | 465 | So let's write it in the less intuitive, recursive way: |
465 | 466 |