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

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

yacc&lex-調用C++代碼

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

要點

用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$
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 资溪县| 文化| 芜湖市| 司法| 霍邱县| 吴江市| 巴东县| 定襄县| 剑川县| 石泉县| 温宿县| 彭阳县| 土默特左旗| 苍溪县| 信阳市| 新沂市| 红桥区| 遵义县| 晋中市| 邵东县| 乐业县| 剑川县| 湖南省| 封丘县| 金阳县| 资兴市| 河源市| 大英县| 永丰县| 衡阳县| 门源| 奈曼旗| 紫金县| 大同县| 贡觉县| 唐海县| 高碑店市| 兴宁市| 屯昌县| 团风县| 色达县|