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... )
Comments 12
Reply
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
Reply
Contains a single example that's pretty typical and the most recent .y and .l files I've got that work.
Reply
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
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
Reply
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
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
Reply
Leave a comment