+1  A: 

On your first question, I don't think that relying on browsers to correct any kind of mistakes is a good idea regardless the scope of your project (well, maybe except when you're actually doing bug tests on the browser itself). Some browsers might do an awesome job on that while others might fail miserably. The best way to make sure the output syntax is correct (or at least as correct as possible) is to send it with a correct syntax to the browser in the first place.

Regarding your second question, since you're trying to have correct BBCode converted to correct HTML, if your input is [b][i]zzz[/b]ccc[/i], its correct HTML equivalent would be <i><b>zzz</b>ccc</i> and not <b>[i]zzz</b>ccc[/i]. And this is where things get complicated as you would not be writing just a converter anymore, but also a syntax checker/correcter. I have written a similar script in PHP for a rather weird game engine scripting language but the logic could be easily applied to your case. Basically, I had a flag set for each opening tag and checked if the closing tag was in the right position. Of course, this gives limited functionality but for what I needed it did the trick. If you need more advanced search patterns, I think you're stuck with regex.

FreekOne
Thanks for the answer. But I am still wondering whether "BBCode to HTML" specification (standardized rules of transforming BBCode -> HTML) exists?
Roman
You are most welcome. As far as I know, there isn't really a standardized set of conversion rules for converting from BBcode to HTML. After a quick search, I found http://www.bbcode-to-html.com/ to be quite rich in features and supported tags.Perhaps you could run a few tests on it and see how it handles your code.
FreekOne
A: 

If you're only going to implement B, I and U, which aren't terribly important tags, why not simply have a counter for each of those tags: +1 each time it is opened, and -1 each time it's closed.

At the end of a forum post (or whatever) if there are still-open tags, simply close them. If the user puts in invalid bbcode, it may look strange for the duration of their post, but it won't be disastrous.

Chris
But why `[b]z` must be rendered as `<b>z</b>`? I think its not a good idea to automatically try guess where user wanted to use BBCode tags and where he simply wanted to enter `[b]z` 'as it is'. In general I want to know if **there is some standard BBCode to HTML transformation rules**, or everyone implements it in way **he** considers valid??
Roman