C# 什么是解析?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1788796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is parsing?
提问by Grace
Parsing is something I come across a lot in development, but as a junior it is one of those things I assume I will get the hang of at some point, when it is needed. In my current project I've been told to find and use an HTML parser for a certain function, I have found a couple on the web.
解析是我在开发过程中经常遇到的事情,但作为一名大三学生,我认为我会在需要时掌握其中的窍门之一。在我当前的项目中,我被告知要为某个功能找到并使用 HTML 解析器,我在网上找到了几个。
But what does an HTML parser actually do? And what does it mean to parse an object?
但是 HTML 解析器实际上是做什么的?解析一个对象是什么意思?
采纳答案by Jon Skeet
Parsingusually applies to text - the act of reading text and converting it into a more useful in-memory format, "understanding" what it means to some extent. So for example, an XML parser will take the sequence of characters (or bytes) and convert them into elements, attributes etc.
解析通常适用于文本——阅读文本并将其转换为更有用的内存格式的行为,在某种程度上“理解”它的含义。例如,XML 解析器将获取字符(或字节)序列并将它们转换为元素、属性等。
In some cases (particularly compilers) there's a separation between lexical analysisand syntactic analysis, so the real "understanding" part of the parser works on a sequence of tokens (identifiers, operators etc) rather than on the raw characters.
在某些情况下(特别是编译器),词法分析和句法分析是分开的,所以解析器真正的“理解”部分是处理一系列标记(标识符、运算符等)而不是原始字符。
回答by Konamiman
You can start here: http://en.wikipedia.org/wiki/Parsing. Short excerpt:
您可以从这里开始:http: //en.wikipedia.org/wiki/Parsing。简短摘录:
Parsing or syntactic analysis is the process of analysing a string of symbols, either in natural language or in computer languages, conforming to the rules of a formal grammar. The term parsing comes from Latin pars (orationis), meaning part (of speech).
解析或句法分析是分析符合形式语法规则的自然语言或计算机语言中的符号串的过程。术语解析来自拉丁文 pars (orationis),意思是(语音的)部分。
回答by rahul
It is the process of identifying the tokens [tags, attributes] inside an HTML.
它是识别 HTML 中的标记 [标签、属性] 的过程。
回答by Adam Hopkinson
Parsing is taking a set of data and extracting the meaningful information from it. With HTML parsing, you're looking to read some html and return a structured set of tags and text
解析是获取一组数据并从中提取有意义的信息。通过 HTML 解析,您希望读取一些 html 并返回一组结构化的标签和文本
回答by Mongus Pong
In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a text, made of a sequence of tokens (for example, words), to determine its grammatical structure with respect to a given (more or less) formal grammar.
在计算机科学和语言学中,解析或更正式的句法分析是分析由一系列标记(例如,单词)组成的文本的过程,以确定其相对于给定(更多或少)正式语法。
:0)
:0)
回答by Igor Oks
Parse(computers), by Dictionary.com:
To analyze (a string of characters) in order to associate groups of characters with the syntactic units of the underlying grammar.
分析(一串字符)以便将字符组与基础语法的句法单元相关联。
回答by martsbradley
Don't attempt to write anything but a trivial parser yourself. There are good tools for this use ANTLRand bisonare two I can think of.
不要试图自己写一个简单的解析器。有用于此用途的好工具ANTLR和bison是我能想到的两个。
If you use the tools you'll be able to ask for help when you hit a problem.
如果您使用这些工具,您将能够在遇到问题时寻求帮助。
cheers, Martin.
干杯,马丁。
回答by Gajendra K Chauhan
A parser is a compiler / interpreter component that breaks data into smaller elements for easy translation into another language. A parser takes input in the form of a sequence of tokens or program instructions and usually builds a data structure in the form of a parse tree or an abstract syntax tree.
解析器是一个编译器/解释器组件,它将数据分解成更小的元素,以便于翻译成另一种语言。解析器以标记序列或程序指令的形式接受输入,通常以解析树或抽象语法树的形式构建数据结构。