用Lex(flex)和yacc(bison)写的简单计算器

【自研Fe编译器】三、(变量声明+栈分配)基于Flex + Yacc开发的高级语言编译器 Fe语言是一种语法类似C的高级语言,由于笔者将重点放在编译器的语义分析和代码优化上,因此目前阶段语法和C不会有什么不同。该编译器会生成Koopa IR,并基于Koopa IR生成目标汇编代码(RISC-V)。 阅读详情

Lex文件如下:
 %{
#include "cal.tab.h"
%}
%option noyywrap
integer      [0-9]+
dreal        ([0-9]*"."[0-9]+)
ereal        ([0-9]*"."[0-9]+[EedD][+-]?[0-9]+)
real         {dreal}|{ereal}
nl           /n
plus         "+"
minus        "-"
times        "*"
divide       "/"
lp           "("
rp           ")"
module       "%"
power        "^"
%%
[ /t]        ;  /*skip any blanks */
{integer}    { sscanf(yytext, "%d", &yylval.integer);
               return INTEGER;
             }
{real}       { sscanf(yytext, "%lf", &yylval.real);/*yylval = atof(yytext);  it doesn't work under MSVSC*/
               return REAL;
              }

{plus}       { return PLUS;}
{minus}      { return MINUS;}
{times}      { return TIMES;}
{divide}     { return DIVIDE;}
{module}     { return MODULE;}
{power}      { return POWER;}
{lp}         { return LP;}
{rp}         { return RP;}

{nl}         { return NL;}
.            { return yytext[0];}

%%
以上是Lex文件的代码(cal.l),lex是用来得到token。

Lex与Yacc学习(六)之lex & yacc (简单计算器程序) 运行 词法分析程序ch3-01.l %{ #include "ch3-01.tab.h" extern int yylval; %} %% [0-9]+ { yylval = atoi(yytext); return NUMBER; } [ \t] ; /* ignore white space */ \n return 0; /* logical EOF */ . return yytext[0 阅读详情

相关推荐

tinyC-compiler:使用flex,yacc和gnu汇编器制作的精简C编译器

tinyC编译器 使用flex,yacc和gnu汇编器制作的精简C编译器。 支持常见的C函数,例如int,char和string数据类型的变量声明和赋值,循环,算术运算,函数调用,数组和变量作用域。 使用tinyC进行编译 允许文件执行 chmod +x compile.sh chmod +x test.sh 编译 ./compile.sh filename.c 跑步 ./filename.out 运行测试文件 要运行测试文件夹中提供的所有测试文件, ./test.sh

flex 和bison linux 下的软件

flex 和bison linux 下的软件,到2012年4月最新的版本,在linux操作系统下使用,词法和语法分析程序

基于Flex&Bison;的网页可编程计算器

课程设计,附实验报告。使用Flex&Bison;生成的DLL文件用作计算器后端,使用Flask框架和HTML CSS做前端。

基于Flex与Bison实现的网页版可编程计算器

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在IT领域,打造网页可编程计算器是开发者常做的实践项目,能增进其对Web开发和解析器技术的掌握。本项目以“基于Flex&Bison的网页可编程计算器”为主题,借助Flex与Bison实现计算器后端逻辑,再用Flask框架搭配HTML、CSS完成前端设计,为用户提供良好交互界面。 Flex是功能强大的词法分析器生成器,可把正则表达式转为C代码,生成能识别特定模式的词法分析器。在本项目里,fb3-3.l文件作为Flex输入文件,内含正则表达式,用于识别计算器输入的数字、运算符等符号。编译后生成的.c文件,像fb3-3.lex.c和fb3-3.lex.obj,是词法分析器的实现,其作用是把用户输入转为可处理的标记。Bison是语法分析器生成器,依据Yacc语法定义文件生成解析器。虽fb3-3.y文件未在文件列表中,但它是Bison项目常见部分,描述计算器语法规则,而fb3-3.tab.c、fb3-3.tab.h和fb3-3.tab.exe是Bison生成的解析器相关代码与可执行文件,能将Flex产生的标记转为解析树,执行计算逻辑并返回结果。 后端计算逻辑完成后,需前端展示和接收用户输入。本项目采用Python的Flask框架,它是个轻量级Web服务器和应用框架,提供简洁API,方便开发者构建动态网页。前端界面主要由HTML和CSS构建,可能有简单表单供用户输入计算表达式,以及结果显示区域。虽具体HTML和CSS代码未在列表里,但实际项目中它们会与Flask结合,构成完整交互系统。 实验报告文档(实验报告.docx)一般会详尽记录项目过程、遇到的问题及解决方案,还有项目实现的功能和性能评估,是项目总结的重要部分,有助于理解项目整体设计思路和技术实现。此项目涉及编译原理的词法分析和语法分析,We

联想服务器ThinkSystemRAID阵列设置教程

关注我不迷路,全是干货! 以联想ThinkSystemSR530为例子进行示范。 开机点按【F1】 点击——【UEFI设置】 依次点击——【系统设置】——【存储】 点击——【RAID卡】 PS:本次服务器配置的是730-8i 阵列卡,按实际情况选中需要设置的阵列卡即可。 点击——【Main Menu】 点击——【Configuration Management】 点击——【Create Virtual Drive】 点击——【Select RAID Leve..

littlelotusK的博客 2万+

Understand-Anything:AI驱动的代码知识图谱,实现项目全局洞察与高效导航

在软件开发中,理解复杂代码库的结构和依赖关系是提升开发效率的关键。传统代码阅读方式往往陷入局部视角,难以快速把握系统全貌。知识图谱技术通过将代码实体(如文件、类、函数)及其关系(调用、继承、依赖)可视化,为代码理解提供了全局视角。这项技术的核心价值在于将静态代码转化为动态、可交互的认知地图,极大降低了系统学习与维护成本。在实际工程中,它广泛应用于新成员快速入职、遗留系统梳理、架构影响分析等场景。本文介绍的Understand-Anything工具,正是基于这一理念,通过多智能体分析管道,自动构建代码的结构图

weixin_42615290的博客 882

YOLOv8中间特征层可视化

在通过观察这些特征,可以清楚地看到模型如何逐步将输入图像转化为有意义的表示。

weixin_45314480的博客 6890

KTransformers安装笔记 利用docker安装KTransformers

KTransformers安装笔记 利用docker安装KTransformers

guoqingru0311的博客 1562

变压器耦合放大器(低频应用+高频应用)

变压器耦合放大器(低频应用+高频应用)

m0_54943120的博客 2275

【任何电机可使用的七段式s曲线-----包括matlab代码和simulink仿真】

S形加加速(T1)→>匀加速(T2)→减加速(T3)→>匀速(T4 )>加减速(T5)>匀减速(T6)-→>减减速(T7)

weixin_44312889的博客 6309

无限泛化!AI背景文字识别,腾讯文字六宫格

本文介绍了生成大规模文字验证码数据集的方法,通过使用上百种字体和2万+字库,结合随机背景和数十种图像增强技术,生成了2000万+的多样化样本。该方法采用二阶段训练策略,确保模型对字体、形态、形变等具有强泛化能力,可适配腾讯、咸鱼等多种平台的文字验证码识别,包括生僻字和复杂形变情况。生成的模型在多种验证码场景下表现优异,但强调该方法仅用于技术研究,严禁非法用途。

码王吴彦祖的博客 563

【CAD】【手把手带你写一个DXF&JAVA解析框架】02——整理DXF元数据实体类,涵盖重要属性与对照组码

本文系统梳理了DXF文件解析中的核心元数据类,重点分析了Tables段(图层、块记录)、Blocks段和Entities段的关键数据结构。通过详细的组码说明和对照代码实现,阐述了图层定义(DXFLayer)、块记录(DXFBlockRecord)、应用程序标识(DXFAppId)等表对象的属性构成;同时解析了直线(DXFLine)、多段线(DXFLwPolyLine)、圆弧(DXFArc)、文字(DXFText)等实体类的几何特征与属性定义。文章还构建了顶点(Vertex)、基类(DXFEntity、DXF

Wonder ZH 268

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: DirectX 8开发人员常见问题
下一篇: 为flex提供多输入缓冲!Multiple input buffers
chenbuaa
博客等级 码龄25年 6粉丝 34原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值