Arithmetic evaluation: Difference between revisions

J: more illuminating example
(J: more illuminating example)
Line 1,172:
 
You can also display the syntax tree, for example:
<lang j> parse '1+12*3/(4-5)'
┌─────────────────────────────────────────────────────┬───────────────────┐
┌─────────────────────────┬───────┐
│┌───┬───────┬───┬───────┬───┬─┬───────┬───┬───────┬─┐│┌───────┬─┬───────┐│
│┌───┬───────┬───┬───────┐│┌─┬─┬─┐│
││┌─┐│┌─────┐│┌─┐│┌─────┐│┌─┐│(│┌─────┐│┌─┐│┌─────┐│)│││┌─┬─┬─┐│4│┌─┬─┬─┐││
││┌─┐│┌─────┐│┌─┐│┌─────┐│││1│2│3││
│││$│││┌─┬─┐│││+│││┌─┬─┐│││└─┴─┴─┘│*│││┌─┬─┐│││%││ ││┌─┬─┐│││-│││┌─┬─┐││ ││││1│2│3││ ││6│7│8│││
││└─┘│││0│2│││└─┘│││0│3│││└─┘│ │││0│4│││└─┘│││0│5│││ │││└─┴─┴─┘│ │└─┴─┴─┘││
││└─┘│││0│1│││└─┘│││0│1││││ │
││ ││└─┴─┘││ ││└─┴─┘│││││└─┴─┘││ ││└─┴─┘││ ││└─┴─┘││ ││└───────┴─┴───────┘│
││ │└─────┘│ │└─────┘│││└─────┘│ │ │└─────┘│ │└─────┘│ ││
│└───┴───────┴───┴───────┴───┴─┴───────┴───┴───────┴─┘│ │
│└───┴───────┴───┴───────┘│ │
└─────────────────────────────────────────────────────┴───────────────────┘</lang>
└─────────────────────────┴───────┘</lang>
 
At the top level, the first box is a list of terminals, and the second box represents their parsed structure within the source sentence, with numbers indexing the respective terminals.
6,962

edits