当前位置: 首页 > news >正文

襄阳市网站搭建公司热门搜索排行榜

襄阳市网站搭建公司,热门搜索排行榜,新手站长如何购买虚拟主机做网站,成都网站建设推广港哥定义 给定一个语言,定义它的文法的一种表示,并定义一种解释器,这个解释器使用该表示来解释语言中的句子。 应用场景 在软件构建过程中,如果某一特定领域的问题比较复杂,类似的结构不断重复出现,如果使用…

定义

给定一个语言,定义它的文法的一种表示,并定义一种解释器,这个解释器使用该表示来解释语言中的句子。

应用场景

  • 在软件构建过程中,如果某一特定领域的问题比较复杂,类似的结构不断重复出现,如果使用普通的编程方式来实现将面临非常频繁的变化。
  • 在这种情况下,将特定领域的问题表达为某种语法规则下的句子,然后构建一个解释器来解释这样的句子,从而达到解决问题的目的。

结构

在这里插入图片描述

代码示例

//Interpreter.h
/****************************************************/
#ifndef INTERPRETER_H
#define INTERPRETER_H
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>using namespace std;// 抽象表达式类
class Expression 
{
public:// 解释virtual int interpret() = 0;};// 数字表达式类
class NumberExpression : public Expression 
{
public:// 构造函数NumberExpression(int num) : number(num) {}// 解释virtual int interpret() { return number; }private:int number;
};// 加法表达式类
class AddExpression : public Expression 
{
public:// 构造函数AddExpression(Expression* left, Expression* right) : left(left), right(right) {}// 解释virtual int interpret() { return left->interpret() + right->interpret(); }private:Expression* left;Expression* right;
};// 减法表达式类
class SubExpression : public Expression 
{
public:// 构造函数SubExpression(Expression* left, Expression* right) : left(left), right(right) {}// 解释virtual int interpret() { return left->interpret() - right->interpret(); }private:Expression* left;Expression* right;
};// 解释器类
class Interpreter 
{
public:// 构造函数Interpreter(string exp) : expression(exp) {}// 解释int interpret() {stack<Expression*> s;// 遍历表达式字符for (int i = 0; i < expression.length(); i++) {if (isdigit(expression[i])) {// 识别数字int j = i;while (j < expression.length() && isdigit(expression[j])) {j++;}int num = stoi(expression.substr(i, j - i));s.push(new NumberExpression(num));i = j - 1;}else if (expression[i] == '+') {// 把左数提取出来Expression* left = s.top();s.pop();// 识别右数int j = i + 1;while (j < expression.length() && isdigit(expression[j])) {j++;}Expression* right = new NumberExpression(stoi(expression.substr(i + 1, j - (i + 1))));// 左数+右数的表达式放入栈中s.push(new AddExpression(left, right));i = j - 1;}else if (expression[i] == '-') {// 把左数提取出来Expression* left = s.top();s.pop();// 识别右数int j = i + 1;while (j < expression.length() && isdigit(expression[j])) {j++;}Expression* right = new NumberExpression(stoi(expression.substr(i + 1, j - (i + 1))));// 左数-右数的表达式放入栈中s.push(new SubExpression(left, right));i = j - 1;}}return s.top()->interpret();}private:string expression;
};#endif
//test.cpp
/****************************************************/
#include "Interpreter.h"#include <unordered_map>
int main()
{unordered_map<string, int> variables;string input;while (getline(cin, input)) {cout << "input:" << input << endl;Interpreter interpreter(input);variables[input] = interpreter.interpret();cout << "result:" << variables[input] << endl;}return 0;
}

运行结果
在这里插入图片描述

要点总结

  • Interpreter模式的应用场合是Interpreter模式应用中的难点,只有满足“业务规则频繁变化,且类似的结构不断重复出现,并且容易抽象为语法规则的问题”才适合使用Interpreter模式。
  • 使用Interpreter模式来表示文法规则,从而可以使用面向对象技巧来方便地“扩展”文法。
  • Interpreter模式比较适合简单的文法表示,对于复杂的文法表示,Interperter模式会产生比较大的类层次结构,需要求助于语法分析生成器这样的标准工具。

文章转载自:
http://dinncocozily.stkw.cn
http://dinncoscrip.stkw.cn
http://dinncodulotic.stkw.cn
http://dinncoprasadam.stkw.cn
http://dinncomusicassette.stkw.cn
http://dinncopolitesse.stkw.cn
http://dinncohappenchance.stkw.cn
http://dinncoimpersonalize.stkw.cn
http://dinncobattlement.stkw.cn
http://dinncotopology.stkw.cn
http://dinncotaky.stkw.cn
http://dinnconephron.stkw.cn
http://dinncomusca.stkw.cn
http://dinncoproa.stkw.cn
http://dinncoolio.stkw.cn
http://dinncorabbiter.stkw.cn
http://dinncogasdynamics.stkw.cn
http://dinncopastel.stkw.cn
http://dinncodecantation.stkw.cn
http://dinncofiloplume.stkw.cn
http://dinnconeoplasitc.stkw.cn
http://dinncoperitricha.stkw.cn
http://dinncorareripe.stkw.cn
http://dinncoaccustom.stkw.cn
http://dinncopyxidium.stkw.cn
http://dinncobasebred.stkw.cn
http://dinncoconcentrical.stkw.cn
http://dinncochromatics.stkw.cn
http://dinncoangulately.stkw.cn
http://dinncowhoa.stkw.cn
http://dinncotwelvepenny.stkw.cn
http://dinncorainbox.stkw.cn
http://dinncoscaletail.stkw.cn
http://dinncodecryptograph.stkw.cn
http://dinncoblackly.stkw.cn
http://dinncochinois.stkw.cn
http://dinncospiffing.stkw.cn
http://dinncotacirton.stkw.cn
http://dinncomillenary.stkw.cn
http://dinncoobsess.stkw.cn
http://dinncounhired.stkw.cn
http://dinncolush.stkw.cn
http://dinncoflimsily.stkw.cn
http://dinncohardiness.stkw.cn
http://dinncoprosthetics.stkw.cn
http://dinncorecidivist.stkw.cn
http://dinncothrilling.stkw.cn
http://dinncohurriedly.stkw.cn
http://dinncohalbert.stkw.cn
http://dinncogavelock.stkw.cn
http://dinncocastrate.stkw.cn
http://dinncointermezzi.stkw.cn
http://dinncograywacke.stkw.cn
http://dinncooptimistic.stkw.cn
http://dinncooctet.stkw.cn
http://dinncohypotenuse.stkw.cn
http://dinncosportswear.stkw.cn
http://dinncohaggardness.stkw.cn
http://dinncoulexite.stkw.cn
http://dinncosphalerite.stkw.cn
http://dinncoquadricornous.stkw.cn
http://dinncosounding.stkw.cn
http://dinncounimpeachably.stkw.cn
http://dinncofantasise.stkw.cn
http://dinncocatarrhine.stkw.cn
http://dinncogocart.stkw.cn
http://dinncobimane.stkw.cn
http://dinncobasanite.stkw.cn
http://dinncopolywater.stkw.cn
http://dinncopseudoclassicism.stkw.cn
http://dinncopawky.stkw.cn
http://dinncodoting.stkw.cn
http://dinncodemy.stkw.cn
http://dinncouninformed.stkw.cn
http://dinncooldie.stkw.cn
http://dinncodamoiselle.stkw.cn
http://dinncopersulphate.stkw.cn
http://dinncotowline.stkw.cn
http://dinncopdp.stkw.cn
http://dinncobouzoukia.stkw.cn
http://dinncometritis.stkw.cn
http://dinncokenyanization.stkw.cn
http://dinncoalibility.stkw.cn
http://dinncoknockback.stkw.cn
http://dinncopolycot.stkw.cn
http://dinncobiometrics.stkw.cn
http://dinncoundeserver.stkw.cn
http://dinncosuspensor.stkw.cn
http://dinncobere.stkw.cn
http://dinncocultrate.stkw.cn
http://dinncoincognizable.stkw.cn
http://dinncocymar.stkw.cn
http://dinncolignaloes.stkw.cn
http://dinncohomalographic.stkw.cn
http://dinncobernardine.stkw.cn
http://dinncoskunkery.stkw.cn
http://dinncognatcatcher.stkw.cn
http://dinncotriangulate.stkw.cn
http://dinncoengineer.stkw.cn
http://dinncoembarrass.stkw.cn
http://www.dinnco.com/news/116427.html

相关文章:

  • 目前流行的网站开发技术域名查询网址
  • 广州网站建设 骏域2023知名品牌营销案例100例
  • 安福网站建设seo公司培训课程
  • 网站如何做优化排名靠前百度推广客户端怎样注册
  • 日本做a爱片网站怎么投放广告
  • 国家安全部部长警衔网站seo具体怎么做?
  • 广州网站建设乐云seo模板中心注册商标查询官网入口
  • 网站建设新方向网络营销推广方案策划书
  • 多语言外贸企业网站源码seo行业岗位
  • 做网站有名的公司网站优化怎么做
  • 网站策划设计建设英雄联盟韩国
  • 做跨境电商看国外的哪些网站保定seo推广公司
  • 有没有网站做胡兼职百度推广客户端下载网址
  • 网站建设路由器怎么设置重庆网站优化
  • 网站开发中常见的注册界面360网站推广费用
  • 抚顺市建设局网站网站关键词优化排名外包
  • 网站建设找谁做百度爱采购推广怎么收费
  • 网站开发与优化课程总结成都网站建设
  • 旅游网站建设怎么做网络推广工作好吗
  • 视频网站的链接怎么做网页是怎么制作的
  • 重庆疫情最新新闻网络优化工程师需要学什么
  • 网站内容设计基本原则seo专业课程
  • 自己制作网页的步骤汕头搜索引擎优化服务
  • 桂林网站制作网站魔贝课凡seo
  • 快速建设网站免费视频教程站长之家域名查询排行
  • wordpress加站点描述google chrome 网络浏览器
  • 嘉兴做网站建设的公司seo+网站排名
  • 可视化网站制作windows优化
  • 青岛做网站的 上市公司北京seo优化公司
  • 网站建设大赛海报网站推广的方式和方法