Tag: 野牛

野牛警告:键入非终结符号的空规则

我收到一个警告,我对Bison并不是很了解。 warning: empty rule for typed non-terminal, and no action 这是我的每个非终端角色。 我不明白的部分是,如果我不给它们一个类型,那么我得到编译错误,说明所有的$ ns都是未定义的。 这是我的野牛文件的语法部分。 %union { char *sval; } %token PLUS TIMES LPAREN RPAREN ID %type setf %% s : e { cout << GetNonConstCharStar(std::string("(e ") + $1 + ")") << endl; } e : | e PLUS t { $$ = GetNonConstCharStar(std::string("(e ") + […]

初始化gchar时程序givin错误

在我的main.h (包含在所有其他src文件中)中,我有: char* buffer; 这编译并且工作正常。 由于其他原因,我尝试初始化buffer ,两者都是 char* buffer=””; 和 char* buffer=”\0″; 现在,构建它是错误的: src/search.o:(.data+0x0): multiple definition of `buffer’ src/bib.o:(.data+0x0): first defined here src/mkbib.o:(.data+0x0): multiple definition of `buffer’ src/bib.o:(.data+0x0): first defined here src/update_file.o:(.data+0x0): multiple definition of `buffer’ src/bib.o:(.data+0x0): first defined here src/view.o:(.data+0x0): multiple definition of `buffer’ src/bib.o:(.data+0x0): first defined here src/file_util.o:(.data+0x0): multiple definition of `buffer’ src/bib.o:(.data+0x0): […]

在尝试添加可选规则时,切换/减少Bison中的冲突

我正试图解决Bison中的转移/减少冲突。 我有遵循语法规则 new_expr: T_NEW class_name_reference optional_generics_list ctor_arguments { $$ = zend_ast_create(ZEND_AST_NEW, $2, $4, $3); } | T_NEW anonymous_class { $$ = $2; } optional_generics_list: /* empty */ { $$ = NULL; } | generics_list { $$ = $1; } ctor_arguments: /* empty */ { $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); } | argument_list { $$ = $1; […]

野牛规格和优先顺序

鉴于Bison规范:%权利TOK_ADD TOK_MUL 我想知道TOK_ADD和TOK_MUL的优先顺序是什么。 如果我有Bison规格 %left TOKMUL TOKADD %left TOKDIV %left TOKSUB 我想知道TOKMUL TOKADD TOKDIV和TOKSUB的优先顺序是什么

为什么这些冲突出现在XML的以下yacc语法中

我有以下XML语法,工作正常: program : ” root ; root : ” node_list ” ; node_list : node_s | node_list node_s ; node_s : node | u_node | ID ; node : ” ; u_node :” node_list ” |” ” ; attribute_list : attributes | ; attributes : attribute | attributes attribute ; attribute : ID ASSIGNOP ‘”‘ […]

Flex,Bison和C:寻找一个非常基本的介绍

我正在寻找一个非常简短的flex和bison工作示例,附带Makefile,它使用了内置规则。 我已经尝试了几个谷歌搜索结果,这些搜索结果很乱,不会构建,或者使用C ++,这是不可接受的。 良好的在线资源和简短的示例代码表示赞赏。 额外 # Makefile example — scanner and parser. # Creates “myprogram” from “scan.l”, “parse.y”, and “myprogram.c” # LEX = flex YACC = bison -y YFLAGS = -d objects = scan.o parse.o myprogram.o myprogram: $(objects) scan.o: scan.l parse.c parse.o: parse.y myprogram.o: myprogram.c 我想要一个看起来与此类似的Makefile,附带的源文件可以做任意简单的事情。

如何解决2 + 2和2 ++ 2冲突

在较大的程序中,我给出了以下(flex / bison) 在flex中: pn [\+|\-] dig [0-9]+ exp [e|E]{dig}+ 。 。 。 “+” {printf(“+ detected\n”); return PLUS_SIGN;} {pn}?{dig}+ { printf(“digit detected – %s\n”,yytext); sscanf(yytext, “%d”, (int*)&yylval); return TYPE_INT;} 在野牛: expr: expr PLUS_SIGN expr { $$ = $1 + $3; printf(” $$=%f\n”,$$); } | TYPE_INT { $$ = (int)$1; printf(” $$=%f\n”,$$); } ; 问题是: 当我给2 […]