4 ms·
Icon (and SNOBOL before that) had an alternate syntax that was more verbose but more readable. s := "this is a string" s ? {
by ebiester 10y ago
Icon (and SNOBOL before that) had an alternate syntax that was more verbose but more readable.
s := "this is a string"
s ? { # Establish string scanning environment
while not pos(0) do { # Test for end of string
tab(many(' ')) # Skip past any blanks
word := tab(upto(' ') | 0) # the next word is up to the next blank -or- the end of the line
write(word) # write the word
}
}
I should implement something like this in ruby some day... (I did it in java long ago, but this was before you just threw things up to github and I have long since lost it.)
- sublimeloge 10y agoFor those who haven't seen the language before, I think it's also useful to know what expression evaluation in Icon works using a recursive backtracking algorithm. This means that the most natural way of writing a string scanning parser (like the one above) more or less automatically gives you a recursive backtracking parser. Like ebiester, I too have found it to be a nice way to do certain kinds of simple string parsing.
- norswap 10y agoNice notation. Looks like a grammar with a bit more fancyness thrown in. I have a tool that does this kind of stuff: https://github.com/norswap/whimsy/blob/master/doc/autumn/README.md https://github.com/norswap/whimsy/blob/master/doc/autumn/REA... I should try to implement something like this, to see how hard it would be (I think not too much, but I might overlook something).