是csv格式常规语法还是上下文无关文法? [英] Is csv format regular grammar or context-free grammar?

查看:150
本文介绍了是csv格式常规语法还是上下文无关文法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个csv解析器。 csv格式的定义由 RFC4180 (由ABNF定义)给出。所以csv的定义绝对是一个没有contex的语法。但是,我想知道csv是否是正规语法?所以我可以解析它只用一个有限状态机。

I am currently writing a csv parser. The definition of csv format is given by RFC4180 which is defined by ABNF. So the definition of csv is absolutely a contex-free grammar. However, I would like to know if csv is regular grammar? So that I could parse it with just a finite state machine. Furthermore, if it is exactly a regular grammar and can be parsed by finite state machine, does that mean it can be also parsed by regular expression?

推荐答案

这个问题没有明确的答案,因为CSV是一个非常宽松的格式。在我观察到的CSV阅读器中,上下文和常规语法都保持。例如,一些读者如果在一个封闭值的结尾之后有逗号,则会抛出异常。

There is no definite answer to this question because CSV is a very loose format. Among the CSV readers that I have observed both context-free and regular grammars are maintained. For example some readers would throw an exception if anything but a comma follows after the end of an enclosed value.

这篇关于是csv格式常规语法还是上下文无关文法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆