yacc 解析问题

发布于 2024-10-31 19:25:41 字数 636 浏览 4 评论 0原文

我有一个使用套接字的应用程序..像 mySql 这样的客户端和服务器程序..

我将查询从客户端发送到解析器所在的服务器....

当我在服务器上收到来自客户端的查询时,我编写该查询到一个文件中,然后将 yyin 设置为该文件并调用 yyparse() .. 这就是我解析输入字符串的方式..

问题是当查询成功执行时,解析器显示“语法错误”.. 当我查看时在文件中它有一个不可读的字符...所以这意味着解析器正在尝试解析该字符,从而最终给出语法错误..

我如何从文件中删除这个字符或者如何停止解析器解析字符...

以下是解析器的输出:

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

如您所见,127.0.0.1 是文件名及其内容... 分号后面有一个神秘字符...

看到解析器解析查询(它输出“Select”,后跟“Parsing done”和“Free OK”)..但是它在第 1 行给出了这个语法错误.. .我认为这是因为该行末尾的字符...

我该如何解决这个问题...

谢谢..:)

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 character 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.. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面犯桃花 2024-11-07 19:25:41

如果您只想修复这个字符,您可以使用十六进制编辑器(例如 hexer)来编辑文件,找到一个有趣的字符,更改它,保存并重新运行解析器。也许更标准的编辑器(例如 vim)也可以很好地编辑文件,如果需要的话,修改环境肯定会更容易。

您可能希望在将查询保存到磁盘之前对其进行过滤;也许 isalnum(3)、isalpha(3)、isgraph(3) 或 isprint(3) 会是一个有用的健全性检查工具,可以在将每个字符保存到磁盘之前检查它们。这样,您可以在提供错误输入时发出日志条目,这可能帮助您弄清楚为什么客户端首先向您发送格式错误的输入。

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.

若沐 2024-11-07 19:25:41

性格是什么?总是同一个吗?它是 0x0a、0x0d 还是 0x00。如果它始终是相同的字符,您可以添加它,它是 .y 文件中已解析行的可选行结尾。

如果它总是不同,那么在将文件写入磁盘的代码中可能存在一个错误(或者然后发送应用程序发送过多的字符)。值得检查一下。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文