Talk:Con-Text

From Esolang
Jump to navigation Jump to search

It's a good idea to post the full spec or an interpreter *somewhere*, even if hardly anyone's interested in the language. Chances are at least someone will. --Ihope127 23:27, 6 Sep 2006 (UTC)

Infinite lookahead?

I don't see why you would need infinite lookahead, even for a recursive descent type parser. Just make a common function for parsing ifs and whiles that decides which case it is only at the end - if I understand correctly, the two statements have identical structure otherwise. Deciding the grammatical category/token only at the end is the rule for LALR(1) style generated parsers (yacc/bison etc.) anyhow, and lookahead then generally means only past-the-end lookahead. --Ørjan 09:56, 23 Dec 2006 (UTC)

Ørjan is correct; parser-generator programs can handle such cases easily (after all, they happen in many non-esoteric languages, such as with bracketed postfix expressions). Even if you're using a weird type of parser that can't handle it naturally, just label the statement in the parse true as an 'ifwhile' and then go back and mark which one it is later. (Also, the semantics of 'if' and C-style 'while' mean that you don't need to distinguish between them until the end of the block anyway, which is how you can program 'if' in languages like brainfuck.) ais523 17:00, 23 Dec 2006 (UTC)
Thanks for the help, I was thinking about compiling the language into C++ and then using a real compiler to generate a native executable. This however requires either backtracking the output file or infinite look ahead because you wont know if a statement is an 'if' or a 'while' till you get to the end of it. Using a lower level language where if and while both translate to jumps would be easier. This is where I was getting confused. I have only written a few parsers (hand coded recusive decent with backtracking on the input file) and never used a compiler compiler. I might start working on a backtracking output file first. --Sphen lee 07:52, 30 Dec 2006 (UTC)
Ah. It requires infinite lookahead/backtracking if you compile in the same step as parsing, but that works only for the simplest languages anyhow. Instead parse into an AST, then compile that. Much more flexible. --Ørjan 08:37, 30 Dec 2006 (UTC)

Oops...

Those last two edits were mine, forgot to login (well it was set to remember me, but that was before I formatted) --Sphen lee 12:25, 3 May 2007 (UTC)