bison

How can I rewrite the programs, so that I don't have to call `flex` but only call `bison` and `cc`?

做~自己de王妃 提交于 2019-12-11 23:23:48
问题 I already have a calculator program based on bison and flex which takes input from command line arguments. Now how can I rewrite the programs, so that I don't have to call flex but only call bison and cc during building process? (Achieve something similar to https://unix.stackexchange.com/questions/499190/where-is-the-official-documentation-debian-package-iproute-doc#comment919875_499225). $ ./fb1-5 '1+3' = 4 Makefile: fb1-5: fb1-5.l fb1-5.y bison -d fb1-5.y flex fb1-5.l cc -o $@ fb1-5.tab.c

Reduce order in Bison

安稳与你 提交于 2019-12-11 20:15:30
问题 I am writing a compiler using Bison and I am trying to use the same function with while and repeat loops. I need the parser to reduce " condition " before " statements_off ". ¿Can I specify the reduction order? Here is the code for the loops: loop_stmt: WHILE line condition DO ENDL line statements_off DONE { $$ = process_while($<elem>3, $<elem>7, $<ival>2, $<ival>6); } | REPEAT ENDL line statements_off UNTIL line condition { $$ = process_not($<elem>7); $$ = process_while($$, $<elem>4, $<ival

program givin error when gchar is initialized

孤人 提交于 2019-12-11 19:33:11
问题 in my main.h (which is included in all other src file), I have: char* buffer; This compiles and workes fine. For some other reason, I tried to initialize buffer , both as char* buffer=""; and char* buffer="\0"; Now, building it is giving error: 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

Multiple attributes in bison

徘徊边缘 提交于 2019-12-11 18:21:58
问题 I am doing semantic analysis in bison and i want to use multiple attribute associated with a token. A related part of my code is: %union semrec { int Type; char *id; } %start prog %token <id> tIDENT Here, i can only use the "id" attribute witht the tIDENT token. I also want to associate the "Type" attribute with tIDENT token. To do this, i tried the following: %token <id> tIDENT %token <Type> tIDENT But it gives me a redeclaration warning for token tIDENT. I also tried the following: %token

How to handle multiple rules for one token with PLY

不打扰是莪最后的温柔 提交于 2019-12-11 16:47:49
问题 I'm working with a jison file and converting it to a parser generator using the lex module from python PLY. I've noticed that in this jison file, certain tokens have multiple rules associated with them. For example, for the token CONTENT , the file specifies the following three rules: [^\x00]*?/("{{") { if(yytext.slice(-2) === "\\\\") { strip(0,1); this.begin("mu"); } else if(yytext.slice(-1) === "\\") { strip(0,1); this.begin("emu"); } else { this.begin("mu"); } if(yytext) return 'CONTENT';

Remove default YY_DECL from Flex output

心已入冬 提交于 2019-12-11 15:38:04
问题 I was able to sidestep this problem when manually setting up the order in which header files are read by the compiler. In this case, I'm able to spoof the default "pearl" with the correct definition, but when I have no control of the order in which headers are included, this... genius of engineering surfaces: /* Default declaration of generated scanner - a define so the user can * easily add parameters. */ #ifndef YY_DECL #define YY_DECL_IS_OURS 1 /* %if-c-only Standard (non-C++) definition *

Bison: strange shift-reduce conflict

自古美人都是妖i 提交于 2019-12-11 14:40:32
问题 I try to implement a function call in a custom grammar (plus a similar array-access operator): expression : ....OTHER EXPRESSION RULES.... | expression PARENTHESIS_OPEN expressions PARENTHESIS_CLOSE { } %prec DOT | expression SQUARE_OPEN expressions SQUARE_CLOSE { } %prec DOT ; Here is my all my operator precedences: %right ASSIGN ASSIGN_MOD ASSIGN_XOR ASSIGN_AND ASSIGN_STAR ASSIGN_MINUS ASSIGN_PLUS ASSIGN_OR ASSIGN_DIV ASSIGN_LSHIFT ASSIGN_RSHIFT %right QUESTION COLON %left OR %left AND

How to reference lex or parse parameters in flex rules?

倖福魔咒の 提交于 2019-12-11 12:56:18
问题 I know I can declare %parse-param {struct my_st *arg} in a .y file. And so yyparse() is changed to be yyparse(struct my_st *arg) . But how do I reference the argument in the flex rules? For example: [0-9]+ { do_work(arg); return NUMBER; } I want to make a reentrant parser, so I need to do this. Please help me, thanks! 回答1: You need to pass the argument through to yylex . That requires a modification of both the bison parser description, so that the parser calls yylex with the desired

Bison Reduce/Reduce Conflict with Casting and Expression Parentheses

余生颓废 提交于 2019-12-11 10:25:13
问题 I'm building a grammar in bison, and I've narrowed down my last reduce/reduce error to the following test-case: %{ #include <stdio.h> #include <string.h> extern yydebug; void yyerror(const char *str) { fprintf(stderr, "Error: %s\n", str); } main() { yydebug = 1; yyparse(); } %} %right '=' %precedence CAST %left '(' %token AUTO BOOL BYTE DOUBLE FLOAT INT LONG SHORT SIGNED STRING UNSIGNED VOID %token IDENTIFIER %start file %debug %% file : %empty | statement file ; statement : expression ';' ;

Bison: where is the last $$ value stored in pure-push parser?

懵懂的女人 提交于 2019-12-11 10:18:05
问题 I wrote a parser definition, which interfaces with python as an extension. I declared the following options, so that Bison generates a reentrant push parser: %define api.pure full %define api.push-pull push In order to pass semantic values to python through it's C API, I declared the YYSTYPE to be PyObject* as follows: %define api.value.type {PyObject*} Now, the last ("accepting") rule has the following action: full : declarations data { $$ = Py_BuildValue("(s, O, O)", "full", $1, $2); } ;