首页 > 编程知识 正文

plc零基础自学入门,钢琴入门自学教程

时间:2023-05-04 22:36:24 阅读:234420 作者:32

看了 mysql parse 着手看了看 yyparseinclude.h

#ifndef MAIN_HPP#define MAIN_HPP#include <iostream>#include <string>#include <stdio.h>using namespace std;#define YYSTYPE string#endif lex.l %{#include "include.h"#include "yacc.tab.h"extern "C"{ int yywrap(void); int yylex(void);}%}%% "abc" { yylval = yytext; return ABC; }"123" { yylval = yytext; return A123;}%%int yywrap(void){ puts("-----the file is end"); return 1;}yacc.y %{#include "include.h"extern "C"{ void yyerror(const char *s); extern int yylex(void);}%}%token ABC%token A123//%type tokens%%file: tokens { cout<<"all abc:"<<$1<<endl; };tokens: { cout<< "3"; } | tokens ABC A123 { $$ = $2; cout<<"----->"<<$2<<"---->"<<$3<<endl; } ;%%void yyerror(const char *s){ cerr<<"err:"<<s<<endl;}int main(){ const char* sFile="file.txt"; zjdxtd fp=fopen(sFile, "r"); if(fp==NULL) { printf("cannot open %sn", sFile); return -1; } extern zjdxtd yyin; yyin=fp; printf("-----begin parsing %sn", sFile); yyparse(); puts("-----end parsing"); fclose(fp); return 0;}file.txt</>

abc 123LEX=flexYACC=bisonCC=g++OBJECT=main$(OBJECT):clean lex.yy.o yacc.tab.o$(CC) lex.yy.o yacc.tab.o -o $(OBJECT)@./$(OBJECT) #编译后立刻运行lex.yy.o: lex.yy.c yacc.tab.h$(CC) -c lex.yy.cyacc.tab.o: yacc.tab.c $(CC) -c yacc.tab.cyacc.tab.c yacc.tab.h:$(YACC) -d yacc.ylex.yy.c: #lex.l$(LEX) lex.lclean:@rm -f $(OBJECT) *.o@rm -f yacc.tab.c lex.yy.c yacc.tab.h

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。