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

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

yacc&lex-調用C++代碼

2019-11-11 00:32:04
字體:
來源:轉載
供稿:網友

要點

用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$
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丁青县| 龙门县| 固阳县| 舒城县| 南康市| 内丘县| 石狮市| 溧水县| 习水县| 太原市| 上饶县| 明水县| 甘谷县| 福海县| 繁昌县| 天门市| 灵寿县| 田东县| 格尔木市| 义马市| 奈曼旗| 洞头县| 禄丰县| 桃源县| 龙游县| 无棣县| 巴彦淖尔市| 凌云县| 会同县| 双江| 昆山市| 天峻县| 博客| 文成县| 武隆县| 甘泉县| 塘沽区| 交口县| 仲巴县| 临西县| 修水县|