tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,36 @@
|
|||
tokenize=: ' ' <;._1@, deb
|
||||
|
||||
ops=: ;:'+ - * / ^'
|
||||
doOp=: plus`minus`times`divide`exponent`push@.(ops&i.)
|
||||
parse=:3 :0
|
||||
stack=: i.0 2
|
||||
for_token.tokenize y do.doOp token end.
|
||||
1{:: ,stack
|
||||
)
|
||||
|
||||
parens=:4 :0
|
||||
if. y do. '( ',x,' )' else. x end.
|
||||
)
|
||||
|
||||
NB. m: precedence, n: is right associative, y: token
|
||||
op=:2 :0
|
||||
L=. m - n
|
||||
R=. m - -.n
|
||||
smoutput;'operation: ';y
|
||||
'Lprec left Rprec right'=. ,_2{.stack
|
||||
expr=. ;(left parens L > Lprec);' ';y,' ';right parens R > Rprec
|
||||
stack=: (_2}.stack),m;expr
|
||||
smoutput stack
|
||||
)
|
||||
|
||||
plus=: 2 op 0
|
||||
minus=: 2 op 0
|
||||
times=: 3 op 0
|
||||
divide=: 3 op 0
|
||||
exponent=: 4 op 1
|
||||
|
||||
push=:3 :0
|
||||
smoutput;'pushing: ';y
|
||||
stack=: stack,_;y
|
||||
smoutput stack
|
||||
)
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
parse '3 4 2 * 1 5 - 2 3 ^ ^ / +'
|
||||
pushing: 3
|
||||
+-+-+
|
||||
|_|3|
|
||||
+-+-+
|
||||
pushing: 4
|
||||
+-+-+
|
||||
|_|3|
|
||||
+-+-+
|
||||
|_|4|
|
||||
+-+-+
|
||||
pushing: 2
|
||||
+-+-+
|
||||
|_|3|
|
||||
+-+-+
|
||||
|_|4|
|
||||
+-+-+
|
||||
|_|2|
|
||||
+-+-+
|
||||
operation: *
|
||||
+-+-----+
|
||||
|_|3 |
|
||||
+-+-----+
|
||||
|3|4 * 2|
|
||||
+-+-----+
|
||||
pushing: 1
|
||||
+-+-----+
|
||||
|_|3 |
|
||||
+-+-----+
|
||||
|3|4 * 2|
|
||||
+-+-----+
|
||||
|_|1 |
|
||||
+-+-----+
|
||||
pushing: 5
|
||||
+-+-----+
|
||||
|_|3 |
|
||||
+-+-----+
|
||||
|3|4 * 2|
|
||||
+-+-----+
|
||||
|_|1 |
|
||||
+-+-----+
|
||||
|_|5 |
|
||||
+-+-----+
|
||||
operation: -
|
||||
+-+-----+
|
||||
|_|3 |
|
||||
+-+-----+
|
||||
|3|4 * 2|
|
||||
+-+-----+
|
||||
|2|1 - 5|
|
||||
+-+-----+
|
||||
pushing: 2
|
||||
+-+-----+
|
||||
|_|3 |
|
||||
+-+-----+
|
||||
|3|4 * 2|
|
||||
+-+-----+
|
||||
|2|1 - 5|
|
||||
+-+-----+
|
||||
|_|2 |
|
||||
+-+-----+
|
||||
pushing: 3
|
||||
+-+-----+
|
||||
|_|3 |
|
||||
+-+-----+
|
||||
|3|4 * 2|
|
||||
+-+-----+
|
||||
|2|1 - 5|
|
||||
+-+-----+
|
||||
|_|2 |
|
||||
+-+-----+
|
||||
|_|3 |
|
||||
+-+-----+
|
||||
operation: ^
|
||||
+-+-----+
|
||||
|_|3 |
|
||||
+-+-----+
|
||||
|3|4 * 2|
|
||||
+-+-----+
|
||||
|2|1 - 5|
|
||||
+-+-----+
|
||||
|4|2 ^ 3|
|
||||
+-+-----+
|
||||
operation: ^
|
||||
+-+-----------------+
|
||||
|_|3 |
|
||||
+-+-----------------+
|
||||
|3|4 * 2 |
|
||||
+-+-----------------+
|
||||
|4|( 1 - 5 ) ^ 2 ^ 3|
|
||||
+-+-----------------+
|
||||
operation: /
|
||||
+-+-------------------------+
|
||||
|_|3 |
|
||||
+-+-------------------------+
|
||||
|3|4 * 2 / ( 1 - 5 ) ^ 2 ^ 3|
|
||||
+-+-------------------------+
|
||||
operation: +
|
||||
+-+-----------------------------+
|
||||
|2|3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3|
|
||||
+-+-----------------------------+
|
||||
3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3
|
||||
Loading…
Add table
Add a link
Reference in a new issue