yacc

A yacc shift/reduce conflict on an unambiguous grammar

大憨熊 提交于 2019-11-28 13:02:37
A piece of code of my gramamar its driveing me crazy. I have to write a grammar that allow write functions with multiple inputs e.g. function begin a: <statments> b: <statements> end The problem with that its that is statements that are assignments like this ID = Expresion. in the following quote you can see the output produced by yacc. 0 $accept : InstanciasFuncion $end 1 InstanciasFuncion : InstanciasFuncion InstanciaFuncion 2 | InstanciaFuncion 3 InstanciaFuncion : PuntoEntrada Sentencias 4 PuntoEntrada : ID ':' 5 Sentencias : Sentencias Sentencia 6 | Sentencia 7 Sentencia : ID '=' ID State

SQL lex yacc grammar

谁说胖子不能爱 提交于 2019-11-28 08:48:29
All, Developing a validating application for embedded sql i'll use ansi c or c++ as developement language Where do i get an sql grammar for lex and yacc? Aymanadou hi there is a solution in google projects yaxx: yac file : lex file enjoy Umair There is book named "flex & bison" by John Levine (Author). in this book there is a complete chapter for sql parser. you can download this book for free here 来源: https://stackoverflow.com/questions/8656926/sql-lex-yacc-grammar

how to parse from a string rather than a file [duplicate]

孤人 提交于 2019-11-28 06:45:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to make YY_INPUT point to a string rather than stdin in Lex & Yacc (Solaris) i want to parse from a string rather than a file. i know that v can use yy_scan_string fn to do it.but for me it's not working properly so pls help me 回答1: I fought through this problem myself very recently. The flex documentation on the subject leaves a bit to be desired. I see two things right off the bat that might be tripping

Lisp grammar in yacc

 ̄綄美尐妖づ 提交于 2019-11-28 06:24:56
I am trying to build a Lisp grammar. Easy, right? Apparently not. I present these inputs and receive errors... ( 1 1) 23 23 23 ui ui This is the grammar... %% sexpr: atom {printf("matched sexpr\n");} | list ; list: '(' members ')' {printf("matched list\n");} | '('')' {printf("matched empty list\n");} ; members: sexpr {printf("members 1\n");} | sexpr members {printf("members 2\n");} ; atom: ID {printf("ID\n");} | NUM {printf("NUM\n");} | STR {printf("STR\n");} ; %% As near as I can tell, I need a single non-terminal defined as a program, upon which the whole parse tree can hang. But I tried it

Bison shift/reduce conflict - tiger compiler

半世苍凉 提交于 2019-11-28 05:02:17
问题 I have written a yacc file according to Tiger Book(appendix A, Tiger manual). But there are still some shift/reduce conflicts. I do not know how to resolve these conflicts. % yacc --version bison (GNU Bison) 3.0.2 You can use this cmd to reproduce the problem: % yacc -dvt tiger.y tiger.y: warning: 37 shift/reduce conflicts [-Wconflicts-sr] % cat tiger.y : %{ #include <stdio.h> //#include "util.h" //#include "errormsg.h" int yylex(void); /* function prototype */ void yyerror(char *s) { EM

C11 grammar ambiguity between _Atomic type specifier and qualifier

故事扮演 提交于 2019-11-28 03:02:27
问题 I'm trying to write a lex/yacc grammar for C11 based off of N1570. Most of my grammar is copied verbatim from the informative syntax summary, but some yacc conflicts arose. I've managed to resolve all of them except for one: there seems to be some ambiguity between when '_Atomic' is used as a type specifier and when it's used as a type qualifier. In the specifier form, _Atomic is followed immediately by parentheses, so I'm assuming it has something to do with C's little-used syntax which

Advantages of Antlr (versus say, lex/yacc/bison) [closed]

你说的曾经没有我的故事 提交于 2019-11-28 02:35:11
I've used lex and yacc (more usually bison) in the past for various projects, usually translators (such as a subset of EDIF streamed into an EDA app). Additionally, I've had to support code based on lex/yacc grammars dating back decades. So I know my way around the tools, though I'm no expert. I've seen positive comments about Antlr in various fora in the past, and I'm curious as to what I may be missing. So if you've used both, please tell me what's better or more advanced in Antlr. My current constraints are that I work in a C++ shop, and any product we ship will not include Java, so the

freeing the string allocated in strdup() from flex/bison

时间秒杀一切 提交于 2019-11-28 00:49:51
问题 I have flex code that copies a string lexeme using strdup() . %{ #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() allocates memory and copies the input string into it and return (strdup() - what does it do in C?), so I guess I need to free it up when I don't need it anymore. From this post:When is

Include struct in the %union def with Bison/Yacc

笑着哭i 提交于 2019-11-27 20:37:19
I am trying to include a struct as part of the union with Bison, but I get an error on the 'struct node args' in %union: parser.y:17: error: field ‘args’ has incomplete type The Code: struct node { char * val; struct node * next; }; %} %union { char * string; struct node args; } %token <string> CD WORD PWD EXIT %type <args> arg_list Anyone know what I am doing wrong? Even better, use the %code directive with the "requires" option, i.e.: %code requires { struct node { char * val; struct node * next; }; } %union { char * string; struct node args; } This will include the code in the "requires"

Lex and Yacc in PHP [closed]

泪湿孤枕 提交于 2019-11-27 19:01:51
Is there an implementation of Lex and Yacc in PHP? If not, can anyone suggest a lexical analyser and parser generator (ie, anything like Lex and Yacc) that will create PHP code. I'm not too worried about the performance of the resulting parser. I am sick of using regex to parse things that really shouldn't be parsed with regex... There's JLexPHP: https://github.com/wez/JLexPHP/blob/master/jlex.php I've not used it, but there's this: http://pear.php.net/package/PHP_ParserGenerator , which creates a PHP Parser from a Lemon grammar. The project seems to be inactive though. I also found this