开发者

Problem with parsing in yacc

I have an application using sockets.. a client and server program like mySql..

I am sending queries from the client to the server where the parser resides....

When i receive the query from the client at the server i write that query into a file and then set yyin to that file and call yyparse().. So this is how i parse the input string..

The problem is when a query is successfully executed the parser shows "syntax error".. And when i looked at the file it had a non-readable character... So this means that parser is trying to parse that character and thus ends up giving a syntax error..

How do i remove this ch开发者_运维问答aracter from the file or just how do i stop the parser from parsing the character...

Here is what the output from the parser looks like:

----- 127.0.0.1 -----select nm from stud;�
--- end 127.0.0.1 ---
Select
Parsing done
Free    OK
1: syntax error

As you can see the 127.0.0.1 is the file name followed by its contents.... And there's the mystery character after the semicolon...

See that the parser parses the query ( it outputs "Select" followed by "Parsing done" and "Free OK" ).. but then it gives this syntax error on line 1... i think its because of that character at the end of the line...

How do i solve this problem...

Thanks.. :)


If you just want to fix this one character, you can use a hex editor such as hexer to edit the file, find the one character that is funny, change it, save and re-run your parser. Maybe a more-standard editor such as vim can edit the file well, too, it'll definitely be easier to modify the surroundings if you need to.

You might want to filter the queries before saving them to disk; perhaps isalnum(3), isalpha(3), isgraph(3), or isprint(3) would be a useful sanity checking tool to inspect every character before saving them to disk. That way you could emit log entries at the time the bad input is provided, which might help you figure out why the client was sending you poorly formed input in the first place.


What is the character? Is it always the same one? Is it a 0x0a, 0x0d or 0x00.If it is always the same char you can add it is an optional line ending for the parsed line in you .y file.

If it is always different then probably have an off by one error in the code that is writing the file to disk (or then sending app sending one too many chars). It would be worth checking that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜