如何使用C编程对此进行编码 [英] how to code this using c programming

查看:60
本文介绍了如何使用C编程对此进行编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无上下文语法(CFG)是一组用于生成字符串模式的递归重写规则(或产生式). CFG包含以下组件:
一组终端符号,它们是出现在语法生成的字符串中的字母字符.
一组非终端符号,它们是可以由非终端符号生成的终端符号模式的占位符.
一组生产,这些规则是用其他非终端或终端符号(在生产的右侧)替换(或重写)字符串中非终端符号(在生产的左侧)的规则. /> 种子,这是一个特殊的非终结符,出现在语法生成的初始字符串中.
要从CFG生成一串终端符号,我们:
以包含开始符号的字符串开头;
应用其中一个带有开始符号在左侧的产品,用开始右侧的产品替换开始符号;
重复选择字符串中非终结符的过程,并将其替换为相应产品的右侧,直到所有非终结符都被终结符替换为止.
例如,此规范:A = BD B = bB | b | Bb D = dD D = d以A作为种子表示一组单词,这些单词具有一个或多个b',后跟一个或多个d'(bd,bbd,bddd,bbbddd等).上面的生产语法包含字符串"bbd".因此,您的任务是找出给定的字符串是否可以由给定的语法组成.如果该字符串可以由给定的语法组成,则返回true,否则返回false.

A context-free grammar (CFG) is a set of recursive rewriting rules (or productions) used to generate patterns of strings. A CFG consists of the following components:
a set of terminal symbols, which are the characters of the alphabet that appear in the strings generated by the grammar.
a set of non-terminal symbols, which are placeholders for patterns of terminal symbols that can be generated by the non-terminal symbols.
a set of productions, which are rules for replacing (or rewriting) non-terminal symbols (on the left side of the production) in a string with other non-terminal or terminal symbols (on the right side of the production).
a seed, which is a special non-terminal symbol that appears in the initial string generated by the grammar.
To generate a string of terminal symbols from a CFG, we:
Begin with a string consisting of the start symbol;
Apply one of the productions with the start symbol on the left hand side, replacing the start symbol with the right hand side of the production;
Repeat the process of selecting non-terminal symbols in the string, and replacing them with the right hand side of some corresponding production, until all non-terminals have been replaced by terminal symbols.
For example, this specification: A = BD B = bB | b | Bb D = dD D = d with A as the seed represents the set of words that have one or more b''s followed by one or more d''s (bd, bbd, bddd, bbbddd, etc.). Above production grammar contains string "bbd". So your task is to find out the given string can be formed by given grammar or not. If that string can formed by the given grammar then return true otherwise false.

推荐答案

您只需要成为一个真正的开发人员来编写它即可.
真正的开发人员会很快意识到这是一项艰巨的任务,而无需了解解析技术.然后,他/她将仔细研究有关编译器构造的教科书,而不是询问给定代码的快速答案".
You just need to be a real developer to code it.
A real developer would quicky realize it is a difficult task without knowing parsing techniques. Then he/she would study carefully textbooks about compiler construction, instead of asking a ''gimme-code quick answer''.


如何在C语言中编写代码?

我不是一个非常聪明的程序员.但是,我遵循一些简单的步骤来解决问题.
步骤1:
了解问题
步骤2:
自己做几次,并形成逻辑理解.
步骤3:
以一种计算机可以理解的方式来实现我的理解.

最后一个问题使人们永不放弃的心态.

只要您不想自己解决问题,编程就不会很有趣.
How to code this in C?

I am not a very clever programmer. But I follow few simple steps to solve a problem.
Step 1:
Understanding the problem
Step 2:
Doing it by myself several time and create a Logical Understanding.
Step 3:
Implement my understanding in such a way that will be understandable by computer.

And one final issue make the mentality to never give up.

Programming is not fun as long as you don''t feel like to solve the problem by yourself.


这篇关于如何使用C编程对此进行编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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