Live data from Hacker News

The difference between top-down parsing and bottom-up parsing

qntm.org

41–45 of 45 posts

Re: The difference between top-down parsing and bottom-up parsing

#42

What do you call it if you're just using a big list of regexes? I've seen that used for a simple dialog scripting language in a game.

If the language is simple enough to be parsed with only regular expressions, then the language does not have context-free grammar, so bottom-up/top-down distinction does not apply. This also means that the language cannot have recursive productions, e.g. cannot support expressions.

But it depends on how the list of regexes is used. If it is used as part of a recursive paring routine, then it is a recursive-descent parser where lexing and parsing happens in the same pass.

Re: The difference between top-down parsing and bottom-up parsing

#43

Earlier quoted context omitted.

Could you expand on this? What's a memoized token stream?

A token stream that preserves token identities. Say you have a token stream of [t0, t1] and add a new token t2 between t0 and t1 to get [t0, t2, t1]. What you want is to be able to identify t0 and t1 in the new stream as being the same tokens as in the old stream. If you simply re-lex to get new tokens, that won't happen, and if you use character offsets as your token identities, t1 in the new and old stream will hav…

Thanks. To figure out what's damaged, it seems like you have to do a diff somewhere? It sounds like this is done at the character level rather than the token level?

Re: The difference between top-down parsing and bottom-up parsing

#44

Earlier quoted context omitted.

A token stream that preserves token identities. Say you have a token stream of [t0, t1] and add a new token t2 between t0 and t1 to get [t0, t2, t1]. What you want is to be able to identify t0 and t1 in the new stream as being the same tokens as in the old stream. If you simply re-lex to get new tokens, that won't happen, and if you use character offsets as your token identities, t1 in the new and old stream will hav…

Thanks. To figure out what's damaged, it seems like you have to do a diff somewhere? It sounds like this is done at the character level rather than the token level?

No diff, just do the re-lex and damage the tree on the boundaries of where the user typed. My techniques (also, see glitch) usually just assume change has happened since the reprocessing is incremental anyways and won't cascade if nothing has really changed (when reprocessing a tree, the parent is damaged if the end token changed, I guess you could call that a diff).

Re: The difference between top-down parsing and bottom-up parsing

#45
post #30

Earlier quoted context omitted.

JSON or XML would also work. Except that few people like languages based on XML, and I haven't seen anyone seriously try JSON. Perhaps someone should try to build a JSON-like language that's close to how most programmers like to write their code?

Yeah, this is why no one likes languages based on XML: http://thedailywtf.com/articles/We-Use-BobX If you were going to do it, I'm certain you'd want to use a more human-writable format such as YAML or TOML instead of JSON or XML. But doing so means you're living out Greenspun's Tenth Rule. Again, just use a Lisp. http://www.defmacro.org/ramblings/lisp.html

I know BobX is supossed to be a troll language but it bothers me to no end that the example code uses instead of the XML spirited . I believes this confirms that I suffer from OCD.
Post reply on HN