Interweb tech support request

Sep 11, 2008 10:33

Dear Tubes, Please help.

So I'm playing with Yacc for the first time.  I'm learning from the Flex and Bison manuals.  I own the dragon book but I haven't cracked it open yet (which may be part of my problem).

As a first project I'm trying to build a parser for the output of a game I play.  I can't redefine the language. In fact I don't have a ( Read more... )

Leave a comment

Comments 12

boba September 11 2008, 18:24:49 UTC
I miss yacc. I used to use it a lot ( ... )

Reply

gramatan September 11 2008, 18:52:26 UTC
Lex and yacc are damn impressive tools. It's been fun getting this point.

You're right though this file is completely line oriented. I could do this line handling it with strtok a lot faster that that it's taken me to get here. In fact line handing is probably better, that first number on a line... It's the time delta in ms since the previous line.

I'm using yacc in order to learn yacc. This was the best project I could think of that could use the power of yacc and wasn't purely a learning exercise. Once I write any parser for this I can do some clever things that I've been thinking about that help Liz with her machinama.

I actually did a generation of this completely inside lex that could rewrite the file in a useful way and then undo it. I moved up to Yacc in order to parse the file a bit more completely in order to get info that I didn't get in that first lex generation of the tool.

Reply

boba September 11 2008, 18:55:18 UTC
Is there a public uri to the target files you're parsing?

Reply

gramatan September 11 2008, 19:30:26 UTC
There is now: ftp://frontiernet.net/pub/users/rreay/CoHparser.zip

Contains a single example that's pretty typical and the most recent .y and .l files I've got that work.

Reply


questions? i_am_moof September 12 2008, 01:21:29 UTC
It looks like you found your answers. I downloaded the code without reading everything, compiled it, and it seems to work.

Still got questions? I just wrote an assembler for a custom computer design. I made the syntax capable of RPN and infix expression analysis. The assembly language I created is very similar to B and not as advanced as C. If your interested, I may be able to share bits of it. I can show you on Tuesday.

Reply

Re: questions? gramatan September 12 2008, 20:35:34 UTC
Not quite, that's the code without the shift-reduce error because it doesn't associate the PARTSNAME action with the NEW (that starts a PC. I probably shouldn't have put a working version up.

I just put up the actual current version. It's not exactly the same as the initial example but it's equivalent. I also put up the code and data file that the initial example came from.

ftp://frontiernet.net/pub/users/rreay/CoHParserFails.zip

Reply

Re: questions? boba September 12 2008, 20:59:12 UTC
Granted, I'm just looking at the code, not actually running it... (but I can tell already you're using bison and not yacc ( ... )

Reply

Re: questions? boba September 12 2008, 22:02:48 UTC
Walking back from the vending machine, another thought just hit me. What I said above is incomplete.

Is HPMAX always the end of one of these funky long chain of records? More to the point, is NEW always the start of a new chain? You're going to have to reflect that in the grammar, or you'll still get shift/reduce errors.

The parser has to decide, at the end of one of these records, whether it's done or if it continues to the next line. You might make a rule that matches all the possible commands that follow in a given case, ensuring that there's no NEW or such in there. Then, the parser can read ahead (a whole fucking lot), see the NEW (or end of file), and backtrack with all the intervening records being marked together in the same pattern.

Reply


Another potential solution i_am_moof September 12 2008, 23:08:17 UTC
Since the grammer, like you already figured out, is not LALR(1) but is actually in LR(3), a possible solution is: don't force the compiler to detect the "parts" as a part of a costume_line, but rather use it as it's own command. In other words, the parser will compile your language and the new language with incorrectly placed "NUMBER NUMBER PARTSNAME" lines.

You can then check for this error manually by writing an action when you detect that somebody typed in a "part" without a directly preceding "costume_line." You can catch this easily by defining all "NUMBER NUMBER blahblahblah" lines other than "NUMBER NUMBER PARTSNAME" as a new nonterminal such as non_parts_cmd.

Or, you don't have to catch that syntax error if you don't want to. It's not likely that your going to have a dangling "NUMBER NUMBER PARTSNAME" line anyway. If you do, the results are "undefined."

Reply

Re: Another potential solution gramatan September 15 2008, 15:01:53 UTC
Yup and yup. See above.

Reply


Leave a comment

Up