00:53:16 -!- WildHalcyon has quit (Read error: 110 (Connection timed out)).
03:46:19 -!- e-kyle has joined.
03:54:09 -!- e-kyle has quit.
04:17:25 -!- kosmikus|away has quit (bear.freenode.net irc.freenode.net).
04:18:57 -!- kosmikus|away has joined.
07:59:59 -!- clog has quit (ended).
08:00:00 -!- clog has joined.
09:25:45 -!- kosmikus|away has changed nick to kosmikus.
16:08:46 -!- fizzie has quit (Remote closed the connection).
16:08:47 -!- fizzie has joined.
16:59:51 -!- ChanServ has quit (Shutting Down).
17:08:43 -!- ChanServ has joined.
17:08:43 -!- irc.freenode.net has set channel mode: +o ChanServ.
17:35:56 -!- kosmikus has changed nick to kosmikus|away.
20:52:37 -!- mtve has left (?).
20:53:22 -!- mtve has joined.
20:58:37 -!- calamari_ has joined.
20:59:19 <calamari_> been thinking about the c parsing and ran into a difficulty
21:00:32 <calamari_> parsing of = is right to left.. i.e. a = b[c] = d is really a = (b[c] = d), not (a = b[c]) = d
21:02:01 <calamari_> is there an easy way to deal with that (I'm using something similar to recursive descent, using a stack rather than recursive calls)
21:02:21 <calamari_> in other words I'm converting to rpn
21:04:32 <mtve> usually it's a recursive parser that returns tree of operations. then you build your code by walking the tree.
21:04:52 <calamari_> right, but it builds the wrong tree
21:05:02 <mtve> it's broken then :)
21:05:07 <calamari_> it does (a = b[c]) = d, which is wrong
21:05:34 <mtve> hard to help you with seeing the code (or at least pseudocode).
21:05:36 <calamari_> right, it's broken because it assumes everything is left to right
21:06:23 <calamari_> I haven't written any code yet, still planning
21:06:35 <calamari_> I just know that it will not be right
21:07:24 <calamari_> the best I have come up with is to scan forward and add parenthesis
21:08:19 <mtve> search for some example code. the good one was kernighan and pike calculator afair.
21:08:48 <calamari_> doubtful that a calculator would involve the situation I'm describing
21:09:40 <calamari_> since in that case, the correct order is given by the person operating the calculator
21:09:42 <mtve> right, they use lex.
21:10:03 <Taaus> That really depends on the complexity of the calculator.
21:10:51 <mtve> anyway there is miriad of simple lectures about parsing, and lots of good books online.
21:11:17 <calamari_> most simple tutorials don't get into associativity of operators
21:11:41 <calamari_> the more complex ones assume use of flex & bison or such
21:12:44 <Taaus> Well, the calculator is an excellent example here. Exponentiation is a bothersome operation, associativity-wise.
21:12:47 <calamari_> so, adding the parenthesis is the best idea so far, I guess. bummer
21:13:07 <mtve> it's very easy, i guess you just havn't did it before.
21:13:39 <mtve> parsing of left and right associative operators.
21:15:37 <calamari_> perhaps you can offer the easy solution?
21:21:03 <calamari_> I'll probably just go ahead and add parenthesis.. I'll let someone add the "easy" solution later :)
21:22:26 <Taaus> This isn't entirely related, but it's a nifty way of parsing infix: http://article.gmane.org/gmane.comp.lang.lightweight/285
21:22:49 <Taaus> I'm mainly stating it so I can find it more quickly the next time :P
21:25:31 <mtve> just untested pseudocode:
21:25:38 <mtve> void read_lvl1(void) { read_lvl2(); if(token=='=') { eat_token(); read_lvl1(); op(PUSH POP=POP); } } // level 1 is right associative
21:25:38 <mtve> void read_lvl2(void) { read_lvl3(); while(token=='+') { eat_token(); read_lvl3(); op(PUSH POP+POP); } } // level 2 is left associative
21:26:58 <mtve> s/level/precedence/
21:34:34 <Taaus> What language are you writing the compiler in?
21:36:33 <calamari_> but I won't be using recursive calls
21:36:52 <Taaus> Not to preach, but why C?
21:37:09 <calamari_> so that I can compile the compiler
21:43:54 <calamari_> what I should do is stop trying to make this non-recursive thing work.. write it recursive then rescue it from recursion later
21:48:18 <calamari_> mtve: btw, thanks.. why does if make it right and while make it left?
21:48:48 <mtve> note also read_lvl1 is self recursive
21:49:37 <mtve> code looks pretty natural to me. same way as human parses such a code.
21:49:51 <mtve> such a grammar i mean.
21:50:35 <mtve> Taaus' link is interesting too.
21:51:14 <calamari_> hmm, I think I came up with a way to simulate private variables .. then I can use recursion
21:51:25 <mtve> it allows excellent things like changing operators and meaning of language on-the-fly while parsing.
21:52:07 <calamari_> that would be nifty.. because I'll want to change a[b] to *(&a+b)
21:52:17 <mtve> recursion can always be rewritten with static variables (basically the same way underlying processor works with memory)
21:52:50 <calamari_> yeah, I did that when working on the bf golf set problem
21:53:20 <calamari_> used a memory array to simulate the recursion
21:53:59 <calamari_> since all my variables are global, I didn't want to use recursion, but I think I can get around it
21:54:08 <mtve> recursion is harder for computers, its purpose is only to make life easier for a human :)
22:28:04 -!- calamari- has joined.
22:28:11 -!- calamari_ has quit (Read error: 104 (Connection reset by peer)).
22:30:41 -!- calamari has joined.
22:30:41 -!- calamari- has quit (Read error: 104 (Connection reset by peer)).
22:37:05 <calamari> thanks for your help and ideas
22:37:08 -!- calamari has quit ("Leaving").