bison

bison/yacc - limits of precedence settings

不打扰是莪最后的温柔 提交于 2019-11-30 09:55:31
问题 So I've been trying to parse a haskell-like language grammar with bison. I'll omit the standard problems with grammars and unary minus (like, what is (-5) from -5 and \x->x-5 or if a-b is a-(b) or apply a (-b) which itself can still be apply a \x->x-b , haha.) and go straight to the thing that suprised me. To simplify the whole thing to the point where it matters, consider following situation: expression: '(' expression ')' | expression expression /* lambda application */ | '\\' IDENTIFIER "-

how to escape flex keyword

做~自己de王妃 提交于 2019-11-30 09:55:23
问题 I am using Flex & bison on Linux. I have have the following set up: // tokens CREATE { return token::CREATE;} SCHEMA { return token::SCHEMA; } RECORD { return token::RECORD;} [_a-zA-Z0-9][_a-zA-Z0-9]* { yylval->strval = strdup(yytext); return TOKEN::NAME;} ... // rules CREATE SCHEMA NAME ... CREATE RECORD NAME ... ... Everything worked just fine. But if users enter: "create schema record ..." (where 'record' is the name of the schema to be created), Flex will report an error since it matches

REPL for interpreter using Flex/Bison

对着背影说爱祢 提交于 2019-11-30 09:15:00
I've written an interpreter for a C-like language, using Flex and Bison for the scanner/parser. It's working fine when executing full program files. Now I'm trying implement a REPL in the interpreter for interactive use. I want it to work like the command line interpreters in Ruby or ML: Show a prompt Accept one or more statements on the line If the expression is incomplete display a continuation prompt allow the user to continue entering lines When the line ends with a complete expression echo the result of evaluating the last expression show the main prompt My grammar starts with a top_level

Developing a simple parser

别来无恙 提交于 2019-11-30 07:19:28
问题 My day job includes working to develop a Pascal-like compiler. I've been working all along on optimizations and code generation. I would also like to start learning to build a simple parser for the same language. I'm however, not really sure how to go about this. Flex and Bison seem to be the choice. But, isn't it possible to write a parser using C++ or C#? I'm a bit creepy with C. Yacc++ supports C#, but it's a licensed one. I'm looking for all the help that I can find in this regard.

How much time would it take to write a C++ compiler using flex/yacc?

旧巷老猫 提交于 2019-11-30 06:38:34
How much time would it take to write a C++ compiler using lex/yacc? Where can I get started with it? There are many parsing rules that cannot be parsed by a bison/yacc parser (for example, distinguishing between a declaration and a function call in some circumstances). Additionally sometimes the interpretation of tokens requires input from the parser, particularly in C++0x. The handling of the character sequence >> for example is crucially dependent on parsing context. Those two tools are very poor choices for parsing C++ and you would have to put in a lot of special cases that escaped the

Simple Flex/Bison C++

拥有回忆 提交于 2019-11-30 05:04:11
I already looked for my answer but I didn't get any quick response for a simple example. I want to compile a flex/bison scanner+parser using g++ just because I want to use C++ classes to create AST and similar things. Searching over internet I've found some exploits, all saying that the only needed thing is to declare some function prototypes using extern "C" in lex file. So my shady.y file is %{ #include <stdio.h> #include "opcodes.h" #include "utils.h" void yyerror(const char *s) { fprintf(stderr, "error: %s\n", s); } int counter = 0; extern "C" { int yyparse(void); int yylex(void); int

C grammar in GCC source code

℡╲_俬逩灬. 提交于 2019-11-30 03:51:10
I'm looking for the C grammar in GCC source code, more specifically for the grammar in the yacc/bison form. Found the C grammar in Yacc specification in the GCC version 3.3 in the file "c-parse.y" You will not find a C grammar yacc/bison file within the current GCC source code. It was done in the past, before the egcs fork stuff. I cannot give you the exact version and location, but i can tell you that it should be in the 2.x release The current version of GCC has its own C parser GCC of version 4.3 did not contain explicitly written C grammar. Parsing and semantical analysis were performed

How does flex support bison-location exactly?

白昼怎懂夜的黑 提交于 2019-11-30 00:16:08
I'm trying to use flex and bison to create a filter, because I want get certain grammar elements from a complex language. My plan is to use flex + bison to recognise the grammar, and dump out the location of elements of interest. (Then use a script to grab text according the locations dumped.) I found flex can support a bison feature called bison-locations, but how it works in exactly. I tried the example in flex document, it seems the yylloc is not set automatically by flex, I always get (1,0)-(1,0) . Could flex calculate each token's location automatically? If not, what interface function is

Parsing SPARQL queries

谁都会走 提交于 2019-11-29 22:02:10
问题 I need to test for a certain structural property of a couple million SPARQL queries, and for that I need the structure of the WHERE statement. I'm currently trying to use fyzz to do this, but unfortunately its documentation is not very useful. Parsing queries is easy, the problem is that i haven't been able to recover the structure of the statement. For example: >>> from fyzz import parse >>> a=parse("SELECT * WHERE {?x a ?y . {?x a ?z}}") >>> b=parse("SELECT * WHERE {?x a ?y OPTIONAL {?x a

bison only reads one line [closed]

蹲街弑〆低调 提交于 2019-11-29 18:25:37
I'm doing a simple calculator with flex and bison but it only reads the first line of the input file. this is my bison code: %{ #include <stdio.h> #include <stdlib.h> #include <math.h> #include "symtab.h" extern int yylex(void); extern char *yytext; extern int num_linea; extern FILE *yyin; void yyerror(char *s); %} %union{ struct{ char *lexema; int lenght; int line; }ident; } %union{ struct{ int integer; float real; char *string; int type; }num; } %union{ int num_int; } %union{ float num_float; } %token <ident> IDENT %token <num> LIT_INT %token <num> LIT_FLOAT %token <num> CADENA %token