bison

Pass STL containers from Flex to Bison

老子叫甜甜 提交于 2021-02-10 19:01:22
问题 I'm writing a scanner/parser combination using Flex and Bison, if possible I would like to avoid using C++ specific features of both programs but nevertheless I need to access a C++ library from the source file generated by Bison. At the moment I'm compiling the source file generated by Flex as a C program. One thing I thought I might be able to do is to declare STL type members inside Bison's %union statement, e.g.: %union { std::string str; }; I quickly realized that this cannot work

Pass STL containers from Flex to Bison

别等时光非礼了梦想. 提交于 2021-02-10 18:52:22
问题 I'm writing a scanner/parser combination using Flex and Bison, if possible I would like to avoid using C++ specific features of both programs but nevertheless I need to access a C++ library from the source file generated by Bison. At the moment I'm compiling the source file generated by Flex as a C program. One thing I thought I might be able to do is to declare STL type members inside Bison's %union statement, e.g.: %union { std::string str; }; I quickly realized that this cannot work

Shift Reduce Conflict for arithmetic expressions in yacc

别来无恙 提交于 2021-02-08 08:30:40
问题 This grammar has given me conflict despite specifying precedence of operators. Even in the Dragon book it's been resolved in such a way(the way implemented as first 7 lines below) but it still gets conflict! Below is the code implemented in yacc %right THEN_KW %right ELSE_KW %left XOR_KW OR_KW %right '=' %left AND_KW ALSO_KW %left EQ_KW LT_KW GT_KW LE_KW GE_KW %left PLUS_KW MINUS_KW %left MULT_KW DIV_KW MOD_KW %right NOT_KW arthlogicexpr -> operand | arthlogicexpr arthop arthlogicexpr arthop

Flex RegEx not getting matched?

可紊 提交于 2021-02-08 08:21:02
问题 I've been working with Flex/Bison for about 6 hours now, and here is the first problem I don't seam to be able to solve: I have the following file... state state1: { 1-3: 255 4: 255 } ...which I pass to my flex/bison program using cat and |. The flex file contains this line: \bstate\b { return STATE; } and further down this one: .* { fprintf(stderr, "Lexer error on line %d: \"%s\"\n", linenum, yytext); exit(-1); } One should think that \bstate\b should get matched in the file, but it doesn't.

Flex RegEx not getting matched?

ぃ、小莉子 提交于 2021-02-08 08:19:15
问题 I've been working with Flex/Bison for about 6 hours now, and here is the first problem I don't seam to be able to solve: I have the following file... state state1: { 1-3: 255 4: 255 } ...which I pass to my flex/bison program using cat and |. The flex file contains this line: \bstate\b { return STATE; } and further down this one: .* { fprintf(stderr, "Lexer error on line %d: \"%s\"\n", linenum, yytext); exit(-1); } One should think that \bstate\b should get matched in the file, but it doesn't.

Need help identifying cause of “type clash on default action”

折月煮酒 提交于 2021-02-08 04:41:06
问题 I've been working a school assignment and am having difficulty figuring out which issue is causing the multiple warnings below "type clash on default action." Any help would be greatly appreciated. Warnings received: parser.y:62.9-23: warning: type clash on default action: <value> != <> parser.y:71.9-16: warning: type clash on default action: <value> != <> parser.y:82.5-23: warning: type clash on default action: <value> != <iden> parser.y:83.5-27: warning: type clash on default action: <value

Troubles using Bison's recursive rules, and storing values using it

旧巷老猫 提交于 2021-01-29 20:02:40
问题 I am trying to make a flex+bison scanner and parser for Newick file format trees in order to do operations on them. The implemented grammar an explanation is based on a simplification of (labels and lengths are always of the same type, returned by flex) this example. This is esentially a parser for a file format which represents a tree with a series of (recursive) subtrees and/or leaves. The main tree will always end on ; and said tree and all subtrees within will contain a series of nodes

How to parse new line in Scala grammar with flex/bison?

∥☆過路亽.° 提交于 2021-01-29 14:15:52
问题 I want to parse Scala grammar with flex and bison. But I don't know how to parse the newline token in Scala grammar. If I parse newline as a token T_NL , Here's the Toy.l for example: ... [a-zA-Z_][a-zA-Z0-9_]* { yylval->literal = strdup(yy_text); return T_ID; } \n { yylval->token = T_LN; return T_LN; } [ \t\v\f\r] { /* skip whitespaces */ } ... And here's the Toy.y for example: function_def: 'def' T_ID '(' argument_list ')' return_expression '=' expression T_NL ; argument_list: argument |

yyllocp->first_line returns uninitialized value in second iteration of a reEntrant Bison parser

痴心易碎 提交于 2021-01-29 14:02:23
问题 I have a reEntrant parser which takes input from a string and has a structure to maintain context. A function is called with different input strings to be parsed. Relevant code of that function is: void parseMyString(inputToBeParsed) { //LEXICAL COMPONENT - INITIATE LEX PROCESSING yyscan_t scanner; YY_BUFFER_STATE buffer; yylex_init_extra(&parseSupportStruct, &scanner ); //yylex_init(&scanner); buffer = yy_scan_buffer(inputToBeParsed, i+2, scanner); if (buffer == NULL) { strcpy(errorStrings,

How to reduce parser stack or 'unshift' the current token depending on what follows?

江枫思渺然 提交于 2021-01-28 17:43:30
问题 Given the following language described as: formally: (identifier operator identifier+)* in plain English: zero or more operations written as an identifier (the lvalue), then an operator, then one or more identifiers (the rvalue) An example of a sequence of operations in that language would be, given the arbitrary operator @ : A @ B C X @ Y Whitespace is not significant and it may also be written more clearly as: A @ B C X @ Y How would you parse this with a yacc-like LALR parser ? What I