--- Log opened Mon Mar 10 00:00:14 2008 |
00:25 | <@AnnoDomini> | Finally finished that thing. Now only to complete my rounds around the tubes and I can go to sleep... and start work on the other things when I wake up. :/ |
00:48 | | ReivUni [~82d94c4d@Nightstar-29731.dsl.in-addr.zen.co.uk] has joined #Code |
00:49 | | You're now known as TheWatcher[T-2] |
00:53 | | You're now known as TheWatcher[zZzZ] |
00:56 | | AnnoDomini [AnnoDomini@83.21.28.ns-26444] has quit [Quit: ACHTUNG! ALLES LOOKENSPEEPERS! Das Internet is nicht fuer gefingerclicken und giffengrabben. Ist easy droppenpacket der routers und overloaden der backbone mit der spammen und der me-tooen. Ist nicht fuer gewerken bei das dumpkopfen. Das mausklicken sichtseeren keepen das bandwit-spewin hans in das pockets muss; relaxen und watchen das cursorblinken.] |
01:52 | | gnolam [lenin@85.8.5.ns-20483] has quit [Quit: Z?] |
02:33 | < ReivUni> | ...Okay, there's /got/ to be a class that handles parsing commandline inputs in Java somewhere, right? |
02:33 | < ReivUni> | And/or I'm overthinking this. |
02:35 | < ReivUni> | Input/Output: Your program should run from the command-line (i.e. no GUI) with the command xsort and accept the following command-line arguments: -o outputfile -- where outputfile is the name of the file into which the final, sorted data is to be stored. If this argument is omitted then results are displayed to standard output. -t tempdir -- where tempdir is the name of the directory where temporary files are created. If this ar |
02:36 | < ReivUni> | This is pretty basic stuff; and we haven't been instructed to do it by hand (We have in other parts which are the bit they're actually assessing us on) - so why am I failing utterly to figure out a straightforward method of doing it? >.> |
02:40 | | Thaqui [~Thaqui@Nightstar-123.jetstream.xtra.co.nz] has joined #code |
02:40 | | mode/#code [+o Thaqui] by ChanServ |
02:51 | < ReivUni> | ...ooookay, random syntax errors. Lovely. ?? |
02:52 | | * ReivUni throttles it, goes to class. Will have more goes later tonight. |
02:53 | | ReivUni [~82d94c4d@Nightstar-29731.dsl.in-addr.zen.co.uk] has quit [Quit: CGI:IRC (EOF)] |
04:51 | | GeekSoldier|bed [~Rob@Nightstar-9089.dip.t-dialin.net] has quit [Ping Timeout] |
05:38 | <@Reiver> | Okay, I'm doing something wrong with it. |
05:39 | <@Reiver> | Should I be trying to hold onto the /last/ (i-1) string, so that I know what to do with /this/ one? |
05:42 | <@ToxicFrog> | Generally, you look at string i to determine what to do with string i+1 |
05:42 | < Vornicus> | What is it we're doing anyway? |
05:42 | <@ToxicFrog> | One would think this would be something like Map args = Getopts.parse(argv), but java doesn't seem to have getopts |
05:47 | <@Reiver> | hrmn |
05:48 | <@Reiver> | Issue is I need to know what to do with commands that don't have an -x in front of them |
05:49 | <@Reiver> | Hence my guess that if I read an -x, I then keep that bit of information so I know what to do with the string that comes after it |
05:49 | <@Reiver> | And if I /haven't/ read an -x, then I take it as a raw command. |
05:50 | <@ToxicFrog> | The way I do it is generally something like: |
05:50 | <@ToxicFrog> | for arg in next_arg do -- where next_arg is an iterator returning the next argument from the list |
05:50 | <@ToxicFrog> | if arg == "-x" then |
05:51 | <@ToxicFrog> | handle_flag_x(next_arg()) -- if it's "-x foo" |
05:51 | <@ToxicFrog> | handle_flag_x() -- if it's meant to be just "-x" |
05:51 | <@ToxicFrog> | ... code for other flags goes here ... |
05:51 | <@ToxicFrog> | else |
05:51 | <@ToxicFrog> | handle_raw_argument(arg) |
05:51 | <@ToxicFrog> | end |
05:51 | <@ToxicFrog> | end |
05:51 | <@Reiver> | hm |
05:52 | <@ToxicFrog> | It'll look somewhat different in Java, but the principle is the same; if you get a flag that needs an additional argument, you grab the next argument (in a manner that ensures it'll be skipped by the main argument parsing loop) and handle the combination of flag+argument |
05:52 | <@ToxicFrog> | If you get a plain argument, or a flag that doesn't need one, you just handle it directly. |
05:53 | <@ToxicFrog> | This is easier since you don't need to handle constructs like "-xzy" => "-x -y -z" or "-ffoo" => "-f foo" |
05:54 | <@ToxicFrog> | And now I really do sleep |
05:54 | | * Reiver eyes that |
06:00 | <@jerith> | ToxicFrog: Java does have getopt. |
06:00 | <@jerith> | It *really* needs something like optparse, though. |
06:01 | <@Reiver> | getopt? |
06:02 | <@jerith> | The system originally written to parse options in C. |
06:03 | <@jerith> | Been ported everywhere. |
06:03 | <@Reiver> | I see |
06:03 | <@Reiver> | So if I just use that, I can save having to hand-code the blasted thing?~ |
06:03 | <@jerith> | Ruby and Python have optparse, which is /far/ superior. |
06:03 | <@jerith> | Not entirely. |
06:04 | <@jerith> | But you get a /lot/ of stuff done for you. |
06:04 | <@jerith> | Things like "-h" text generation, handling of optional and mandatory parameters, etc. |
06:05 | <@jerith> | I've got some code that uses it at work, so I can sanitise and send you an example it you want. |
06:06 | <@Reiver> | ...Is it simple enough to use? I have a total of three optional arguements, here. |
06:06 | <@jerith> | Yes. |
06:06 | <@jerith> | In fact, the docs should give you all you need. |
06:06 | <@jerith> | Do you have my IM details? |
06:07 | <@Reiver> | aye, IIRC |
06:07 | <@Reiver> | For gtalk, yes? |
06:07 | <@jerith> | Cool. I'm off to work now and I prefer to to IRC from there. |
06:07 | <@jerith> | firxen@, yes. |
06:07 | <@Reiver> | Okay. Bye! |
06:08 | <@jerith> | Well, not *right* now. Still have to pack my bag. :-) |
06:08 | <@jerith> | This /is/ Java, right? |
06:09 | <@Reiver> | Java, yes. |
06:09 | <@jerith> | Ah. Then getopt, horrible as it is, is the lesser of the available evils. |
06:10 | <@jerith> | I wonder why Java doesn't hae an optparse implementation... |
06:10 | <@jerith> | +v |
06:10 | <@jerith> | Perhaps I'll write one. |
06:12 | <@jerith> | *Now* I'm off to work. Cheers all. |
07:01 | | Vornicus is now known as Vornicus-Latens |
08:00 | | AnnoDomini [AnnoDomini@83.21.28.ns-26444] has joined #Code |
08:00 | | mode/#code [+o AnnoDomini] by ChanServ |
08:01 | | GeekSoldier|bed [~Rob@Nightstar-8928.dip.t-dialin.net] has joined #code |
08:05 | | GeekSoldier|bed is now known as GeekSoldier |
08:43 | | You're now known as TheWatcher |
09:54 | | * TheWatcher eyes XML::Simple, curses its lack of sort function option |
10:29 | | Thaqui [~Thaqui@Nightstar-123.jetstream.xtra.co.nz] has left #code [Leaving] |
11:02 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code |
11:02 | | mode/#code [+o gnolam] by ChanServ |
11:30 | | AnnoDomini [AnnoDomini@83.21.28.ns-26444] has quit [Ping Timeout] |
11:32 | | AnnoDomini [AnnoDomini@83.21.41.ns-3845] has joined #Code |
11:32 | | mode/#code [+o AnnoDomini] by ChanServ |
12:10 | | GeekSoldier is now known as GeekSoldier|store |
12:18 | | GeekSoldier|store is now known as GeekSoldier |
13:22 | <@ToxicFrog> | jerith: it does? Where |
13:22 | <@ToxicFrog> | ? |
15:07 | <@McMartin> | I suspect he means "there exists a third-party port of it" |
15:11 | | Serah [~Z@87.72.35.ns-26506] has quit [Quit: Don't try to read the quit message, that is impossible. Instead only realize the truth; "there is no quit message" and you will see it is not you who read the quit message but the quit message who reads you.] |
15:12 | <@ToxicFrog> | Oh, well, yes |
15:12 | <@ToxicFrog> | I'm assuming that since this is schoolwork you can't do that. |
15:37 | <@jerith> | Oh. |
15:37 | <@jerith> | That's silly. |
15:37 | <@jerith> | I wasn't aware that it was third-party -- I only hacked on the code someone else wrote. |
15:37 | <@McMartin> | RMS hates Sun with the fire of a thousand, well, suns. |
15:38 | <@jerith> | I can imagine. |
15:38 | | * Vornicus-Latens still doesn't get why though |
15:38 | <@McMartin> | Vorn: Originally because they weren't releasing their (and thus third-party) code under GPL |
15:39 | <@McMartin> | Now ANAICT it's that they didn't do so fast enough. |
15:40 | <@McMartin> | They also occasionally show up as bit players in MS/SCO conspiracy theories about trying to slay all open source everywhere, but I can't really blame RMS for that since it's one of those lolinterwubs things. |
15:43 | <@ToxicFrog> | What does RMS's hatred of Sun have to do with getopts? |
15:44 | <@McMartin> | ISTR getopt being a GNU project, which tends to mirror his prejudices. |
15:46 | < Vornicus-Latens> | arg, cargo cult programming |
15:46 | <@ToxicFrog> | Well, "GNU Getopt" is. |
15:47 | <@ToxicFrog> | Getopt-the-specification is POSIX, though, and there's plenty of non-GNU implementations thereof in various languages. |
15:47 | <@ToxicFrog> | And considering that Java comes with libraries for every goddamn thing under the sun, I'm very surprised it doesn't have a java.util.Getopt |
15:49 | <@McMartin> | Aha. |
15:49 | <@McMartin> | Now that you mention it, it might be hiding somewhere in Runtime or System or something. |
15:50 | | * McMartin is so used to writing basic option parsers in other langauges that his Java equivalents just do an array scan. |
15:56 | <@jerith> | import gnu.getopt.Getopt; <-- From my code. |
15:56 | <@jerith> | So there /is/ a GNU implementation for Java. |
15:57 | <@jerith> | Although I was under the somewhat vague impression that it was in the stdlib. |
16:04 | <@ToxicFrog> | None of the gnu.* stuff is part of standard Sun Java. |
16:04 | <@ToxicFrog> | It might come standard with the gcj toolchain. |
16:07 | <@jerith> | Yeah, My vague impression was mistaken in this case. |
16:42 | | Brother_Willibald [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code |
16:44 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Ping Timeout] |
16:54 | | Brother_Willibald [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Ping Timeout] |
17:01 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code |
17:01 | | mode/#code [+o gnolam] by ChanServ |
17:05 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Ping Timeout] |
17:05 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code |
17:05 | | mode/#code [+o gnolam] by ChanServ |
17:11 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Ping Timeout] |
17:14 | | You're now known as TheWatcher[afk] |
17:17 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code |
17:17 | | mode/#code [+o gnolam] by ChanServ |
17:18 | <@AnnoDomini> | Hm. |
17:18 | <@AnnoDomini> | Why is there a 1.3Gb hidden directory called System Volume Information on one of my drives? |
17:19 | <@AnnoDomini> | I'm mostly wondering why it's so large, mind. |
17:19 | < Vornicus-Latens> | SVI I believe holds bad blocks. |
17:20 | <@AnnoDomini> | Most of the other drives contain smaller versions of this directory. C: has just over 700Mb, but other than that they're only about 50-70Mb heavy. |
17:43 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Ping Timeout] |
17:47 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code |
17:47 | | mode/#code [+o gnolam] by ChanServ |
18:16 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Ping Timeout] |
18:17 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code |
18:17 | | mode/#code [+o gnolam] by ChanServ |
18:47 | | You're now known as TheWatcher |
18:59 | <@ToxicFrog> | It also contains information on system restore. |
19:06 | | Vornicus-Latens is now known as Vornicus |
19:07 | | Vornicus is now known as NSGuest-5494 |
19:07 | | NSGuest-5494 is now known as Vornicus |
19:37 | | Pi [~sysop@ServicesAdmin.Nightstar.Net] has quit [Ping Timeout] |
19:44 | <@McMartin> | ...ahahahahahaaaaaa |
19:44 | <@McMartin> | Knuth++ |
19:44 | <@McMartin> | On his list of paper publications on his official CV |
19:45 | <@McMartin> | The first entry is a silly article he sent to MAD Magazine at age 19 |
19:45 | <@McMartin> | The Potrzebie system of Weights and Measures |
--- Log closed Mon Mar 10 19:52:47 2008 |
--- Log opened Mon Mar 10 20:04:18 2008 |
20:04 | | chris_ [~chris@Nightstar-29731.dsl.in-addr.zen.co.uk] has joined #code |
20:04 | | Irssi: #code: Total of 16 nicks [8 ops, 0 halfops, 0 voices, 8 normal] |
20:04 | | You're now known as TheWatcher |
20:05 | | Irssi: Join to #code was synced in 53 secs |
20:06 | | mode/#code [+o TheWatcher] by ChanServ |
21:34 | | Pi-2 [~sysop@67.183.88.ns-4261] has joined #code |
22:14 | | Vornicus [~vorn@ServicesOp.Nightstar.Net] has quit [Ping Timeout] |
22:52 | | Molgorn [~moltare@Nightstar-29340.cable.ubr02.bath.blueyonder.co.uk] has joined #code |
22:52 | < Molgorn> | Good evening, gentlemen! |
22:52 | < EvilDarkLord> | And the rest of the meme. Hello, Molt. |
22:54 | < Molgorn> | My compiler is complaining about "implicit declaration of function `int malloc(...)'" in the tokens.h file, and I have no idea why. Any advice? |
22:56 | < EvilDarkLord> | #include <stdlib.h> |
22:56 | < Molgorn> | ...I'm a muppet |
22:57 | <@ToxicFrog> | "implicit declaration of function foo" means you're using a function without first declaring it. |
22:57 | <@ToxicFrog> | Typically, this means you've forgotten an #include. |
22:57 | | * Molgorn hangs his head in shame |
23:00 | | You're now known as TheWatcher[T-2] |
23:04 | | You're now known as TheWatcher[zZzZ] |
23:04 | < Molgorn> | yay it all compiles in the face |
23:05 | < Molgorn> | but doesn't link. never mind! hash() first. |
23:05 | | Vornicus [~vorn@Admin.Nightstar.Net] has joined #code |
23:05 | | mode/#code [+o Vornicus] by ChanServ |
23:06 | < Molgorn> | Does anyone have a link to a decent basic-making-a-C-hashing-function tutorial which'll let me hash a string into a suitable int? |
23:06 | < Molgorn> | I've looked but I keep finding .c files people tell one to include, which is Contraindicated |
23:08 | <@ToxicFrog> | The Dragon Book has a quick look, and Levitin - Algorithms has a more in depth overview |
23:09 | <@ToxicFrog> | In practice what you should probably look for is a tutorial on hash algorithms, which you can then implement in C yourself |
23:09 | < Molgorn> | Ooh, I've got the Levitin |
23:10 | <@ToxicFrog> | Page 265, if you have the same edition I do |
23:10 | < Molgorn> | Looking at it now |
23:11 | < Molgorn> | Not what I need, though |
23:11 | <@ToxicFrog> | How so? |
23:11 | <@ToxicFrog> | I don't think you're going to find "how to implement a hash specifically in C" that isn't just a simple hash library |
23:11 | < Molgorn> | I know I want to sum up the values of the characters of the strings and mod them against the hashtable size |
23:12 | <@ToxicFrog> | As a rule, this sort of thing is explained as an algorithm independent of any language |
23:12 | <@ToxicFrog> | And you are then responsible for writing the actual code that implements that algorithm. |
23:12 | < Molgorn> | What I don't know is how the blazes one takes a *char or whatever and turns it into a set of integer values for the chars in that *char |
23:12 | <@Vornicus> | That's not hard |
23:12 | <@Vornicus> | Seeing as a char is in reality a number |
23:13 | <@ToxicFrog> | And a char * is actually an array of characters |
23:13 | <@ToxicFrog> | (well, for this purpose) |
23:13 | <@ToxicFrog> | Recall that in C, strings are just arrays of characters, and arrays are just pointers to the first element. |
23:13 | < Molgorn> | So can you just iterate through from char*[0] to char*[length] and add up the chars you get? |
23:13 | <@Vornicus> | Sure, except |
23:13 | <@ToxicFrog> | replace char* with the name of the variable and yes. |
23:13 | <@ToxicFrog> | char * foo; |
23:13 | < Molgorn> | well, yes |
23:13 | <@Vornicus> | C strings are null terminated |
23:14 | <@ToxicFrog> | for (int i = 0; i < strlen(foo); ++i) { total += foo[i]; } |
23:14 | <@gnolam> | Assuming C99. |
23:14 | <@ToxicFrog> | This is not terribly efficient (it's O(n^2) due to repeated calls to strlen; a memoized version would be O(n)) but it gets the concept across. |
23:15 | < C_tiger> | Well, you can make a new variable len = strlen(foo) |
23:15 | < Molgorn> | Efficiency is the least of my concerns |
23:15 | <@ToxicFrog> | Indeed. |
23:15 | <@ToxicFrog> | So go with what makes the most sense, and worry about efficiency later, if at all. |
23:16 | <@ToxicFrog> | In this case, you can get the length of a string with strlen() (it's in <string.h>) and then you just iterate over it like an array and treat its elements like ints. |
23:18 | < C_tiger> | well, kinda... depends if you don't mind mapping 65 to a or if you want a = 1 |
23:18 | <@ToxicFrog> | As far as the table itself goes, the easiest is probably closed hashing, with linear probing and a rehash once it gets too full |
23:18 | <@ToxicFrog> | But open hashing isn't too difficult either, once you're comfortable with pointers and structs. |
23:19 | <@ToxicFrog> | C_tiger: how do you handle, say, '!' then? |
23:19 | < C_tiger> | True, I'm only kinda paying attention to what mol's trying to do :P |
23:20 | | * ToxicFrog throws C to the headcrabs~ |
23:21 | <@ToxicFrog> | I also note that if implementing the hash becomes too much of a headache, you can always swap in a prefab hash and use that to test the rest of the problem |
23:21 | < C_tiger> | Sorry, just confused... it seemed like a hashtable was the goal but summing would mean "ha" hashes like "ah" |
23:22 | <@ToxicFrog> | And then revisit it later and implement your own. |
23:23 | <@ToxicFrog> | C_tiger: yes, which is why Levitin recommends using a more sophisticated hash. |
23:23 | <@ToxicFrog> | However, ?i str[i] is easy to implement. |
23:23 | <@ToxicFrog> | Which at the moment is more important than minimizing collisions or maximizing performance. |
23:24 | < C_tiger> | Ah. |
23:25 | < Molgorn> | C: This is merely an exercise. It doesn't have to be astoundingly efficient, just robust enough to not kill itself. |
23:28 | <@ToxicFrog> | (personally, the way I'd handle this is to use a prefab hash - drop that in, finish the rest of the program, test it for correctness with a hash that I know works - then write my own hash and replace the prefab one with that) |
23:28 | <@ToxicFrog> | Which reminds me - with the lexer done, how's the parser coming? |
23:28 | | * Vornicus fiddles with a logic simulator. |
23:31 | | * C_tiger simulates illogic |
23:31 | < Molgorn> | Fairly well. Doesn't yet do anything, because the various components have no actions associated, and it doesn't link because I can't seem to work out how to #include my yy.lex.c without the linker screaming about multiple definitions |
23:31 | < Molgorn> | But it doesn't complain about my syntax, at least ¬¬ |
23:32 | < Molgorn> | From it not existing yesterday evening, this is Progress |
23:32 | <@Vornicus> | gah |
23:32 | | * Vornicus misclicks, joins the "include" channel |
23:32 | | * C_tiger points, laughs. |
23:32 | <@McMartin> | If you really don't care about performance, just use an association list and claim it's a one-bucket hash~ |
23:33 | < Molgorn> | (and if I try to just #include the yy.lex.h file that defines yylex(), the compiler explodes into 25-odd errors) |
23:33 | <@McMartin> | (Duplicate the yylex prototype in your tokens.h) |
23:34 | < Molgorn> | (instead or as well?) |
23:35 | <@McMartin> | (as well. Multiple prototypes that are 'the same' should be permitted) |
23:35 | < Molgorn> | hrm |
23:36 | <@McMartin> | Or, for that matter, have a completely separate lexer.h file that eveyrone that isn't yy.lex.c can include. |
23:36 | < Molgorn> | "tokens.h:3: parse error before `token'" |
23:36 | <@McMartin> | Oh. Right. tokens.h it is, thn. |
23:37 | <@McMartin> | You have to define the token type before you can put it in a signature. |
23:37 | <@McMartin> | Put it after the defenition of the token struct. |
23:37 | < Molgorn> | I did |
23:37 | <@McMartin> | Also, except under very special and unspeakably heinous conditions, one must never ever ever #include a .c file |
23:37 | <@McMartin> | Not if your error is on line 3 you didn't. |
23:37 | < Molgorn> | It's on line 15 as of two seconds after I pasted that line |
23:38 | <@McMartin> | Same error? |
23:38 | < Molgorn> | (And I note that, in defence of my #include yy.lex.c, that The Lecturer Made Me Do It) |
23:38 | <@McMartin> | Something's screwy with the typedef if so. |
23:38 | < Molgorn> | Same error |
23:38 | | * McMartin steeples his fingers |
23:39 | <@ToxicFrog> | To the pastebin? |
23:39 | <@McMartin> | Right, it's because in including yy.lex.c you're including tokens.h twice |
23:39 | | AnnoDomini [AnnoDomini@83.21.41.ns-3845] has quit [Quit: Why is there a jalapeno in the Aegean Sea?] |
23:39 | <@McMartin> | And typedeffing the same type twice will confuse it. |
23:39 | <@McMartin> | So, put at the top of tokens.h |
23:39 | <@McMartin> | #indef TOKENS_H_ |
23:39 | <@McMartin> | #define TOKENS_H_ |
23:39 | <@McMartin> | And at the very bottom, |
23:39 | <@McMartin> | #endif |
23:40 | <@McMartin> | That will insure that its text is only ever #included once per source file. |
23:40 | <@McMartin> | Er |
23:40 | <@McMartin> | #ifndef, not #indef. |
23:41 | <@ToxicFrog> | Molgorn: did the lecturer give any reason for including lex.yy.c? |
23:41 | | mode/#code [+v Molgorn] by ChanServ |
23:41 | <@ToxicFrog> | Because doing so is Stupid And Wrong. |
23:42 | <+Molgorn> | More or less "Because you can get away with it" |
23:42 | <+Molgorn> | tokens.h:16: parse error before `token' still, idly |
23:42 | <@McMartin> | OK, pastebin tokens.h |
23:42 | <@ToxicFrog> | Hurt the lecturer for me, plz |
23:42 | < C_tiger> | Man, I wish I knew about #code when I took my first CS class. |
23:43 | <+Molgorn> | http://rafb.net/p/g2dXiT11.html |
23:43 | <@McMartin> | token *yylex(void) |
23:43 | < C_tiger> | put #endif at the bottom, also. |
23:44 | <@McMartin> | The struct name is "struct token_struct" |
23:44 | <@McMartin> | token is a shorthand for that. |
23:44 | <@ToxicFrog> | That should be either "token *" or "struct token_struct *" |
23:44 | <@McMartin> | and the * goes after the typename, yeah. |
23:44 | <@ToxicFrog> | Also, move the #endif at the top to the bottom |
23:44 | <@ToxicFrog> | The purpose of those directives is: if TOKENS_H_ is not already defined, define it and <here's the rest of the file> |
23:44 | <@ToxicFrog> | Otherwise, skip the entire header |
23:44 | <@McMartin> | Also, new_token really shouldn't be defined in tokens.h |
23:44 | <@McMartin> | Line 22 should be part of some .c file |
23:45 | <@ToxicFrog> | So, the #ifndef at the start needs to match up with an #endif at the bottom. |
23:45 | <@McMartin> | Possibly yy.lex.c, if you define it right above your definition of main. |
23:45 | <@McMartin> | (in lexer.l, that is) |
23:45 | <@ToxicFrog> | McMartin: if it's declared in the header, he can define it wherever he likes |
23:45 | <+Molgorn> | main's defined in parser.c now |
23:45 | <+Molgorn> | and no longer in lexerl. |
23:45 | <@McMartin> | OK |
23:45 | <+Molgorn> | .l* |
23:45 | <@McMartin> | Well, it should go in some .c file. |
23:45 | <@McMartin> | It should not be in the header, or once you have two files that #include tokens.h, they won't link because the function will have been apparently defined twice. |
23:46 | <@McMartin> | As opposed to declared, which is what line 20 does. |
23:46 | <@ToxicFrog> | And even if the two definitions are the same, that is Not Allowed; you can declare something as many times as you like, as long as all the declarations agree, but you can only define it once. |
23:46 | <+Molgorn> | I note that changing struct * token yylex(void) to token yylex(void) makes the compiler cry |
23:47 | <@McMartin> | You forgot the * before yylex. |
23:49 | <+Molgorn> | So noted :) right, now it's back to the same "multiple definition of Thing in yy.lex.c and parser.c" |
23:50 | <@McMartin> | Stop #including yy.lex.c, and let the linker do its job |
23:50 | <@McMartin> | If the Lecturer *absolutely insists*, then remove yy.lex.c from the project entirely. |
23:51 | <+Molgorn> | If I don't #include yy.lex.c, the compiler explodes into 28 errors |
23:51 | <@McMartin> | Of the form? |
23:51 | <@McMartin> | And what is "Thing"? |
23:52 | <+Molgorn> | "thing" is a big list of the methods flex causes yy.lex.c to contain |
23:52 | <+Molgorn> | yyput, yyunput, yylex, yyhands, yyknees, yybumpsadaisy |
23:52 | <@McMartin> | Right, hence why #including it is a bad idea |
23:52 | <@McMartin> | Anyway, what are the 28 errors? |
23:52 | <@ToxicFrog> | The way this should work is that the compiler turns them into yy.lex.o and parser.o |
23:52 | <@ToxicFrog> | And then the linker combines them. |
23:53 | <@McMartin> | And while we're at it, it's entirely possible that the 28 errors are in fact linker errors, not compiler errors |
23:53 | <@McMartin> | Since you haven't told us in any detail what's gone wrong. |
23:53 | <+Molgorn> | Lots of "This isn't declared!" with a sprinkling of "implicit declaration"s and "syntax error"s |
23:53 | <@McMartin> | OK, so, syntax errors are problems |
23:54 | <@McMartin> | Does parser.c include tokens.h? |
23:54 | <@Vornicus> | undeclared/implicit declarations are linker errors. |
23:54 | <+Molgorn> | Ah. No, since it was #including yy.lex.c which does. |
23:54 | <@McMartin> | "implicit declaration" means you're calling a function it doesn't know about, either because you didn't declare it in that file (or one of its #includes) or because you misspelled the function name. |
23:54 | <+Molgorn> | 9 linker errors now. |
23:55 | <@McMartin> | What are the missing methods? |
23:56 | <+Molgorn> | Likewise I forgot to replace stdio |
23:56 | <+Molgorn> | 4 errors. |
23:56 | <@McMartin> | If one of the missing functions is yylex, then your dev-cpp project is misconfigured. |
23:56 | <+Molgorn> | No, there's only one left, which is yyin |
23:56 | <+Molgorn> | And that's because I was using it before for the command-line test rig |
23:57 | <@ToxicFrog> | ...including stdio wouldn't fix linker errors |
23:57 | <@McMartin> | Another way around this is to do a redeclaration. |
23:57 | <@ToxicFrog> | Unless they were preceded by a bunch of "implicit declaration of foo" errors |
23:57 | <@McMartin> | TF: It will fix implicid declaration of printf and friends. |
23:57 | <@ToxicFrog> | Well, s/errors/warnings that really should be errors/ |
23:57 | <@McMartin> | (To declare a variable, you put "extern" in front of it) |
23:57 | <@McMartin> | (So, "extern FILE *yyin;") |
23:58 | <+Molgorn> | nifty! |
23:58 | <+Molgorn> | It compiles! and links! |
23:58 | <+Molgorn> | zooomj |
23:59 | <+Molgorn> | Thanks, lads! |
23:59 | <@McMartin> | Not really. C is just unutterably stupid and needs to be told everything a million times. |
23:59 | <+Molgorn> | (of course, since it doesn't generate any output from any input, it just exits as soon as you give it anything, but that's the next step) |
23:59 | <@McMartin> | It's just good enough at what it does that nobody bothers writing a replacement. |
23:59 | <+Molgorn> | wheeeeee |
--- Log closed Tue Mar 11 00:00:24 2008 |