Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/dc
- [q] sX
- # calculate syntax scoring table
- 3 d 1:s
- 19* d 2:s
- 21* d 3:s
- 21* 4:s
- 0 ss # syntax score = 0
- [ lt;s ls+ ss 3Q ] sS # syntax error: add value from table, exit 3 levels
- [ 4- 0 ] sO # open token: tok exp-stack -> 0 close-tok exp-stack
- [ lt !=S ] sC # close token: (tok != exp-top, syntax) exp-rest
- [
- 10~ st sl # line exp-stack -> exp-stack (t = token, l = rest of line)
- lt d 4<O # exp -> (tok > 4, open) tok exp, open returns: 0 exp
- 0!=C # else ((tok|0) != 0 closed) exp
- ll d 0!=P # exp -> line exp (loop if line not zero)
- ] sP
- [
- c 0 ? d 0=X # clear stack, get input line, exit if 0
- rs. # remove sentinel zero
- lPx # attempt parse
- lMx # loop
- ] sM
- lMx
- [Part 1: ]n lsp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement