bison

Is there a modern ( e.g. CLR ) replacement for bison / yacc?

北慕城南 提交于 2019-12-08 07:55:06
问题 I have just been re-working an old bit of compiler-like code written using bison. While I was doing this, I was wondering what the modern equivalent is? Is there a nice .NET ( or similar ) compiler writing framework that takes a BNF grammar and splits out a DLL that does the parsing? 回答1: I use Gardens Point GPPG and GPLEX in my own dynamic language interpreter. GPPG and GPLEX have been adopted by Microsoft as MPPG and MPLEX in the Visual Studio 200x SDK. This means that is very easy to

Bison does not appear to recognize C string literals appropriately

前提是你 提交于 2019-12-08 05:36:18
My problem is that I am trying to run a problem that I coded using a flex-bison scanner-parser. What my program is supposed to do is take user input (in my case, queries for a database system I'm designing), lex and parse, and then execute the corresponding actions. What actually happens is that my parser code is not correctly interpreting the string literals that I feed it. Here's my code: 130 insertexpr : "INSERT" expr '(' expr ')' 131 132 { 133 $$ = new QLInsert( $2, $4 ); 134 } 135 ; And my input, following the "Query: " prompt: Query: INSERT abc(5); input:1.0-5: syntax error, unexpected

Resetting the state of flex and/or bison

你说的曾经没有我的故事 提交于 2019-12-08 04:55:31
问题 As part of a toy project I've been trying to make a small modification of someone else's parser based on flex/bison. I'm really not experienced with either. You can find the original parser here. I've been trying to put together a simple function that accepts a string and returns a parse tree, so I can expose this via FFI for use in another programming language. What I have is mostly based on the main() function in the original program, my butchered version is below: TreeNode* parse_string

Integrating Flex/Bison with external program

◇◆丶佛笑我妖孽 提交于 2019-12-08 01:01:09
问题 I'm working on an intelligent agent model that requires, as input, a list of events. The events come from the output of another model and are in a (large) text file. The text file is a list of all events (including unnecessary events that I don't care about), so I've written a scanner using flex that can find the useful bits. The framework for the intelligent agent model is already written in C++. Each event is timestamped and contains a large amount of information about the event. The format

Why is yylval null?

对着背影说爱祢 提交于 2019-12-07 17:03:56
问题 I'm trying to write my first parser with Flex & Bison. When parsing numbers, I'm trying to save their values into the yylval structure. The problem is, yylval is null when the lexer reaches a number, which causes a segmentation fault. (Related point of confusion: why is it that in most Flex examples (e.g. here), yylval is a structure, rather than a pointer to a structure? I couldn't get yylval to be recognized in test.l without %option bison-bridge , and that option made yylval a pointer.

how to use `yy_scan_string(const char *str)` (generated by lex yacc ) in a separated file

烂漫一生 提交于 2019-12-07 16:53:55
问题 I want to use YY_BUFFER_STATE yy_scan_string(const char *str) and other functions like yyparse() in my main.cpp , I did things: extern "C"{ extern YY_BUFFER_STATE yy_scan_string(const char *str); } But there is a error error: YY_BUFFER_STATE' does not name a type`, then I did: extern yy_buffer_state; typedef yy_buffer_state *YY_BUFFER_STATE; extern int yyparse(); extern YY_BUFFER_STATE yy_scan_buffer(char *, size_t); But the same problem also, how to do it, thanks, really appreciate your help

Difficulties during the compilation (g++, bison, flex) with yyparse();

社会主义新天地 提交于 2019-12-07 09:35:32
问题 I have a problem with compilation of my code: Flex: %{ #include "lista4.tab.hpp" #include <stdlib.h> extern int yylex(); %} %% "=" {return EQ;} "!=" {return NE;} "<" {return LT;} ">" {return GT;} ":=" {return ASSIGN;} ";" {return SEMICOLON;} "IF" {return IF;} "THEN"{return THEN;} "END" {return END;} [_a-z]+ {yylval.text = strdup(yytext); return IDENTIFIER;} [ \t]+ [0-9]+ { yylval.var = atoi (yytext); return NUMBER; } [-+/^*'%'()] { return *yytext; } \n return RESULT; %% Bison: %{ extern "C" {

Multiple flex/bison parsers

可紊 提交于 2019-12-07 03:19:26
问题 What is the best way to handle multiple Flex/Bison parsers inside a project? I wrote a parser and now I need a second one in the same project. So far in the third section of parser1.y I inserted the main(..) method and called yyparse from there. What I want to obtain is having two different parsers ( parser1.y and parser2.y ) and be able to use them from an external function (let's assume main in main.cpp ). Which precautions should I use to export yyparse functions outside .y files and how

How can I send the yyleng of a matched string from Lex to Yacc?

我只是一个虾纸丫 提交于 2019-12-07 02:46:31
Please i am trying to pass the yyleng of a matched string from my (.l) file to the (.y) file. Here is a sample of the issue: In the Lex File: <state1>.+ { fprintf(yyout, "%d", yyleng); } In the Yacc File: /* I need to know the methodology used to receive a specific yyleng to the yacc file. Shall I use global variables? or there is a specific way for dealing with this issue? */ Thanks in advance for your help! ~ Any suggestions are highly appreciated. yyleng is a global variable; declare it in your grammar file and use it. Flex uses: typedef size_t yy_size_t; extern yy_size_t yyleng; Lex uses:

Is there a modern ( e.g. CLR ) replacement for bison / yacc?

青春壹個敷衍的年華 提交于 2019-12-07 01:11:27
I have just been re-working an old bit of compiler-like code written using bison. While I was doing this, I was wondering what the modern equivalent is? Is there a nice .NET ( or similar ) compiler writing framework that takes a BNF grammar and splits out a DLL that does the parsing? I use Gardens Point GPPG and GPLEX in my own dynamic language interpreter. GPPG and GPLEX have been adopted by Microsoft as MPPG and MPLEX in the Visual Studio 200x SDK. This means that is very easy to create a Visual Studio language extension for syntax colouring of your language. There's also ANTLR , a very