Tag: bison

GCC源代码中的C语法

我正在寻找GCC源代码中的C语法,更具体地说是yacc / bisonforms的语法。

加载外部文件flex bison – yyin?

我正在写flex + bison的基本语言,用于我自己的个人研究/运行简单的脚本以获得乐趣。 它通过命令行获取用户输入,解析它,并执行所需的结果。 我想添加function加载文件。 例如,当“加载文件’somefile.src’”文件被加载并自动解析时,解析器就会切换回等待命令行输入。 我无法理解文档而且很丢失。 我不熟悉flex,bison和C作为一个整体。 我正在关注这个pdf: http : //epaperpress.com/lexandyacc/ (使用复杂的计算器作为骨架并在其上添加function)以及查看bison文档http://www.gnu.org/software /bison/manual/bison.html 。 任何意见,将不胜感激。

从flex / bison中释放strdup()中分配的字符串

我有使用strdup()复制字符串lexeme的flex代码。 %{ #include “json.tab.h” #define YY_DECL extern “C” int yylex() %} %option noyywrap %% [ \t\n]+ ; \”[a-zA-Z]+\” {yylval.sval = strdup(yytext); return STRING; } [0-9]+ {yylval.ival = atoi(yytext); return NUMBER; } . {return yytext[0];} ; %% strdup()分配内存并将输入字符串复制到其中并返回( strdup() – 它在C中做了什么? ),所以我想我需要在我不再需要它时将其释放。 从这篇文章: 什么是在BISON中调用%析构函数? ,我添加了%destructor { free($$); printf(“free”);} STRING %destructor { free($$); printf(“free”);} STRING yacc文件中的%destructor { […]

为什么这个野牛代码会产生意想不到的输出?

flex代码: 1 %option noyywrap nodefault yylineno case-insensitive 2 %{ 3 #include “stdio.h” 4 #include “tp.tab.h” 5 %} 6 7 %% 8 “{” {return ‘{‘;} 9 “}” {return ‘}’;} 10 “;” {return ‘;’;} 11 “create” {return CREATE;} 12 “cmd” {return CMD;} 13 “int” {yylval.intval = 20;return INT;} 14 [a-zA-Z]+ {yylval.strval = yytext;printf(“id:%s\n” , yylval.strval);return ID;} 15 […]

使用Bison / Yacc在%union def中包含struct

我试图将一个结构作为与Bison的联合的一部分包含在内,但是我在%union中的’struct node args’上得到一个错误: parser.y:17: error: field ‘args’ has incomplete type 代码: struct node { char * val; struct node * next; }; %} %union { char * string; struct node args; } %token CD WORD PWD EXIT %type arg_list 谁知道我做错了什么?