国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

yacc&lex-調用C++代碼

2019-11-11 01:04:02
字體:
來源:轉載
供稿:網友

要點

用lex&yacc命令缺省生成的是C文件,但事實上,僅是文件擴展名表示為C文件。可以用g++或者直接改名為C++就可以在lex&yacc中用C++功能。

代碼

%{#include <string>#include <iostream>%}%%[/t ]+ /* white space */[a-zA-Z]+ { std::string Word(yytext); std::cout<<"word: "<<word<<std::endl; }[0-9]+ { std::string number(yytext); std::cout<<"number: "<<number<<std::endl; }.|/n {ECHO; /* normal default anyway */ }%%int main(){ std::cout<<"Lex and C++"<<std::endl; yylex(); return 0;}

運行

$ lex test.l $ gcc -o test lex.yy.c -lltest.l:3:10: fatal error: 'string' file not found#include <string> ^1 error generated.$ g++ -o test lex.yy.c -llclang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is dePRecated$ lslex.yy.c test test.l$ ./test Lex and C++the price is 100 yuan.word: theword: priceword: isnumber: 100word: yuan.^C$ cp lex.yy.c lex.yy.cpp$ g++ -o test lex.yy.cpp -ll$ ./test Lex and C++the price is 100 yuan.word: theword: priceword: isnumber: 100word: yuan.^C$
上一篇:1198_a+b

下一篇:如何寫好遞歸算法

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 潮安县| 文水县| 庐江县| 将乐县| 哈尔滨市| 兴和县| 罗平县| 临沂市| 陆良县| 华阴市| 洛浦县| 潍坊市| 东莞市| 南开区| 平遥县| 泽库县| 长武县| 延津县| 乐清市| 麻阳| 莲花县| 海城市| 陆川县| 页游| 慈溪市| 株洲市| 蒙城县| 新巴尔虎右旗| 日照市| 香格里拉县| 诏安县| 应城市| 青神县| 阆中市| 大英县| 辉县市| 沙雅县| 望奎县| 都江堰市| 乐山市| 清原|