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

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

yacc&lex-調用C++代碼

2019-11-11 02:18:06
字體:
來源:轉載
供稿:網友

要點

用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$
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 红原县| 龙岩市| 泰和县| 太仓市| 阿鲁科尔沁旗| 临城县| 桓仁| 登封市| 读书| 兰西县| 珠海市| 同仁县| 阜新| 吴旗县| 金昌市| 鲁甸县| 金坛市| 饶阳县| 都匀市| 凭祥市| 平潭县| 东丽区| 老河口市| 四川省| 双鸭山市| 民权县| 区。| 南和县| 富阳市| 乐清市| 沾化县| 西和县| 鄯善县| 榆林市| 长汀县| 拉孜县| 商河县| 墨竹工卡县| 濉溪县| 田林县| 丹凤县|