Flex&Bison Tips(2010-08-26)如何改善 flex & bison 在VC下的编辑环境

编译原理 - 在 Windows 平台下使用 Flex 和 Bison 实验要求: 参考范例程序, 用 Flex 和 Bison 实现一个功能更为强大的计算器,包含以下运算: a) 加、减、乘、除运算 b) 乘方、开方运算 c) 位运算– 与 & 、或 |、非 ~... d) 阶乘运算 !  源代码: calc.lex: %{ /* * 一个简单计算器的Lex词法文件 */ #include 阅读详情

我在VC下安装VC助手(VisualAssistX), 让它可以高亮显示C/C++语法,同时支持快捷跳转、自动联想、简单重构等功能。

1. 将flex的输入文件命名为后缀 .cpp, 但是将这个.cpp文件从工程编译中排除,这样既可以方便在flex输入文件中写C/C++代码。同时编译也不会报错。

 

2. 如果要让flex生成的头文件和源文件具有自己的名字,也很简单,在flex的输入文件中使用如下选项就可自己指定想要的文件名:

通过以上设置则flex生成的源文件为 Lexer.cpp,头文件名为 Lexer.h

 

同理,我们对bison也进行一些设置

3. 将bison的输入文件命名为后缀 .cpp,但是将这个.cpp文件从工程编译中排除,这样既可以方便在flex输入文件中写C/C++代码。同时编译也不会报错。

4. 如果要让bison生成的头文件和源文件具有自己的名字,也很简单,在bison的输入文件中使用如下选项就可自己指定想要的文件名:

通过以上设置则bison生成的源文件为 Parser.tab.cpp,头文件名为 Parser.h。 注意源文件名代码.tab, 这个是去不掉的,不过没有关系,因为不会有文件去包含一个cpp文件吧。

 

上一个截图,这样我们的flex、bison输入文件都可当做C/C++文件来编辑了,同时拥有快捷跳转、自动联想补齐、简单重构等功能了。

再也不用为记不住类型定义而苦恼了。

可以看到工程中 flex和bison的输入文件 Lex.cpp和 Parser.cpp虽然加到工程中了,但是不参与编译。这是因为我们通过以下操作:

 右键源文件 > 属性 > 配置属性 > 常规 > 从生成中排除 > 选择“是”

就可以让一个文件不参与编译了。

顺带提一句,同样的设置也可以在source insight中实施。如果你足够高手,甚至可以通过自定义的脚步连 $$, $1, 这样bison特有的标记都可以识别出来。

 

flex与Bison小手册,包含一个编译器的实现源代码 flex与Bison小手册,包含一个编译器的实现源代码,价值很高。英文版,但很容易阅读,很推荐。供大家享用 立即下载

相关推荐

使用Flex和Bison进行编译器构造Compiler Construction using Flex and Bison

使用诸如Flex和Bison之类的编译器编译器进行编译的指南。 使用这两种工具,您可以专注于编译器的概念,而无需从头开始构建编译器。

flex、bison代码在visual studio 编译

在cygwin下自己写了个汇编器,使用flex和bison分别做词法和和语法分析。在cygwin下可以运行,但是汇编器要作为整个功能的一部分,就不得不把它封装起来,给外部提供接口。下边大概讲一下移植的过程及遇到的问题。在vc下新建win32控制台应用程序,如果你的bison源代码中包含main函数建一个空工程就行了;要在Windows下对flex和bison源码(assembler.

wangpf2008的专栏 2977

bison&flex编译组件bfwizard-1.6

bison&flex开发组件,主要配合Visual C++ 6.0使用,自动配置VC6.0,省去手工配置VC6.0的繁琐步骤。

词法分析生成器flex的选项

flex的选项影响最终生成的词法分析器的属性和行为。这些选项可以在运行flex命令时在终端输入,也可以在.l文件中使用%option指定。 option的主要分类: Options for Specifying Filenames Options Affecting Scanner Behavior Code-Level And API Options Options for Scann

sever2012的专栏 9724

在VisualC++集成开发环境下应用flex和bison开发编译

flex和bison是两种非常重要的、功能强大的语言工具。熟练掌握f1ex和bison可 以很方便地创建某种应用开发所需语言的编译器。本文介绍了在windows操作系统中,应用Visua1 C++集成开发环境和语言工具f1ex、bison开发编译器的基本方法,并设计了一个应用实例。

VC+bison+flex写的验证上下文无关文法表达正规式的正确性

用上下文无关文法表示正规式 用VC+BISON+FLEX写的一个小例子 已经配好可直接运行

c语言void calc(),bison(yacc)中关于calc的一个C++版实现

bison中一个calc的C++版实现,区别于传统的C语言实现,我这边整理了一个可编译的版本用以参考calc++-driver.h#ifndef CALCXX_DRIVER_HH# define CALCXX_DRIVER_HH# include # include # include "calc++-parser.h"// Tell Flex the lexer's prototype ...#...

weixin_42640676的博客 569

python123题目——判断火车票座位B(异常)

类型:流程控制。

m0_62488776的博客 3569

Flex和Bison

Flex和Bison是Linux和Unix环境下强大的工具,分别用于生成词法分析器和语法分析器。它们在编译器设计、文本处理等领域有着广泛的应用。Flex通过正则表达式进行词法分析,而Bison则通过上下文无关文法进行语法分析。两者通常一起使用,以构建完整的编译或解析过程。

wy749929317的博客 1140

10分钟快速搭建OpenClaw(基于Windows+飞书)

OpenClaw 是一款功能强大的 AI 智能体工具,能够帮助用户管理邮件、日历等日常事务。本文详细介绍了在 Windows11 系统上安装和配置 OpenClaw 的完整步骤,包括 Node.js 环境搭建、Git 安装、OpenClaw 部署以及飞书机器人创建与对接。通过简单的命令行操作和可视化界面配置,用户可以快速完成 AI 助手部署,实现智能办公自动化。文中还提供了飞书机器人权限设置等关键环节的图文指引,帮助用户轻松完成系统集成。

Hello, New World! 2927

别再手动配IP了!用NI-USRP Configuration Utility快速搞定USRP 2954与LabVIEW连接

本文详细介绍了如何使用NI-USRP Configuration Utility快速配置USRP 2954与LabVIEW的连接,解决传统手动IP配置的繁琐问题。通过图形化工具自动完成设备发现、IP设置和连接验证,大幅提升软件无线电实验效率,特别适合信号收发应用场景。

weixin_27102543的博客 292

可用于Win32平台的flex/bison

虽然flex/bison是Linux世界的东东,有些情况下却需要在Windows上使用它们,自己用MinGW编译flex和bison又没那个能力,只好找一些第三方的port,好在终于让我找到了一个,虽然比较老,但是用于学习编译原理还是够了:) 可以到这个网址下载flex和Bison的win32版本:     http://www.monmouth.com/~wstreett/lex-yac

失忆今生 901

暗黑破坏神2重制版 mod制作教程(一)

暗黑2重制版mod修改教程

hhhh2312的博客 7453

编译原理实验-FLEX+BISON+DEV C++完美解决方案

某高校注明实验——flex+bison的dev c++环境下的完美使用解决方案

DavenDW 8343

AI Agent开发第84课-paddleocr-vl全网唯一最全本地化布署教程

本文详解 PaddleOCR-VL 本地化布署全过程,指出为何在真实生产环境中 PaddleOCR-VL 更稳定、更易部署、更贴近工程落地。同时还会详细比较与 DeepSeek-OCR 的核心差异,为全网独家介绍paddleocr-vl的本地部署实战指南。

打造全国最全的AI Agent开发知识领域的博客 5966

高效计算斐波那契数列的C++实现及源码

斐波那契数列是一个非常经典的数学问题,通常递归方式计算斐波那契数列的时候会有很大的时间复杂度问题。首先,我们需要了解斐波那契数列的定义:斐波那契数列是指前两个数都为1,从第三个开始每个数都等于它前面两个数之和。因此,斐波那契数列的前几项为:1、1、2、3、5、8、13、21……在这个代码中,我们首先判断n是否特殊情况(即n等于0、1、2),然后通过循环计算得出对应的斐波那契数列值。通过这个例子,我们可以发现使用C++语言实现高效斐波那契数列计算的代码简单、易懂,并且时间复杂度相比递归方式有了很大的提升。

TechInk的博客 547

3.05 flex和bison进阶,产生C++语法分析器

bison C++版本的语法分析器都是可重入的,所以bison为语法分析器创建了一个类。在使用可重入的语法分析器时,程序员可以创建他所需要数量的实例,然后传入在另一个类中保存的每个实例的应用数据。点击查看这篇文章,其中包含有关可重入语法分析器的信息。 每次创建C++ 版本的语法分析器时,bison会创建四个头文件:location.hh和position.hh用来定义位置结构,stack.hh定义内部语法分析器堆栈,以及一个定义语法分析器自生的头文件。前三个头文件内容并不会变化,最后一个头文件则包含该语法分

ronnie88597的博客 6732

30天入门 SAP BTP 开发系列之八:动手在 SAP BTP 上开发第一个 ABAP 透明表

ABAP Cloud 环境下创建透明表的方法与数据迁移实践 本文介绍了在 SAP BTP ABAP 环境中创建透明表并迁移数据的完整流程。与传统的 SE11 事务码不同,ABAP Cloud 需通过 ABAP Development Tool 创建数据库表,使用代码定义表结构。作者详细演示了如何: 在开发包中创建名为 Z优快云_TRAVEL 的透明表 使用 ABAP 代码定义表字段和约束 通过 ABAP 类实现数据从标准表/DMO/TRAVEL 到新建表的迁移 验证数据迁移结果 文中还提供了相关技术概念的

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1785

flex与bison编译

flex与bison编译 1,flex编译生成头文件和源文件 [sbinhuang@fengyi test]$ flex --header-file=flex_calculator.hpp -o flex_calculator.cpp --c++ calculator_example.l 其中, –header-file 指定生成头文件名 -o 指定生成源文件名 –c++ 指定生成c++代码,c代码则无需指定; 最后指定flex源文件 注意: --c++ 选项存在bug,生成的fl

qq_43352441的博客 2578

【C++】ROS:ROS1环境配置与基础示例

ROS1环境配置与基础示例

DevFrank的博客 2104

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

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

bison(yacc)中关于calc的一个C++版实现

bison中一个calc的C++版实现,区别于传统的C语言实现,我这边整理了一个可编译的版本用以参考 calc++-driver.h #ifndef CALCXX_DRIVER_HH # define CALCXX_DRIVER_HH # include # include # include "calc++-parser.h" // Tell Flex the lexer's pr

信箱神、得引擎 4021

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

VC++ 项目中使用 FLEX

1, http://hi.baidu.com/qinpc/blog/item/58253df3f9a04654352acc36.html 复杂的界面有多层窗口组成,当windows在窗口改变大小的时候是先重画父窗口,然后重画子窗口,子父窗口重画的过程一般无法在一个刷新周期内完成,所以会呈现闪烁。我们知道父窗口上被子窗口挡住的部分其实没必要重画的。   解决方法:给窗口加个风格 WS_CL...

weixin_33750452的博客 358

深度学习工具包 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")

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

编译原理_计算器_flex、bison实现(详细辅助理解)

@[toc](编译原理_计算器_flex、bison实现_(从零开始)) **目标**:参考范例程序, 用 Flex 和 Bison 实现一个功能更为强大的计算器,包含以下运算: a) 加、减、乘、除运算 b) 乘方、开方运算 c) 位运算 – 与 & 、或 |、非 ~... d) 阶乘运算 ! e)sin cos tan

石灰粉 2万+

在windows下安装flex和bison

这两天为了项目而要学习一下编译原理中要用到得两个工具,flex和bison。这两个软件是可以在windows下运行和编译得,之前也在网上查了不少资料,终于昨天下载了下来。今天来安装,装完了不知道要怎么运行,于是又上网查找了很多资料,才发现这两个工具都是命令行软件,要运行就得在MS-DOS环境下输入命令。搞了很久终于弄好了,现在把安装过程记录一下。    下载得网址: http://gnuwi

sk_Overlord_knife的博客 1万+
上一篇: windows 下 flex 命令行批处理文件
下一篇: Flex&Bison Tips(2010-08-27) 如何在VC中更好的断点调试flex&bison词法和语法分析器
MPForwd
博客等级 码龄20年 7粉丝 20原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值