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

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

yacc&lex-調用C++代碼

2019-11-11 00:09:16
字體:
來源:轉載
供稿:網友

要點

用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$
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉善县| 始兴县| 田东县| 鄂州市| 新兴县| 屏东县| 瑞金市| 祁门县| 石门县| 远安县| 平阴县| 田林县| 高尔夫| 顺昌县| 麻江县| 白沙| 镇平县| 常宁市| 德江县| 高邑县| 隆安县| 麻江县| 涪陵区| 莆田市| 乐昌市| 金寨县| 出国| 凤台县| 威海市| 沭阳县| 丰台区| 池州市| 民和| 辽宁省| 高青县| 静海县| 米易县| 时尚| 江西省| 鞍山市| 富川|