bison

How to write a bison grammar for WDI?

我的梦境 提交于 2020-01-24 15:38:06
问题 I need some help in bison grammar construction. From my another question: I'm trying to make a meta-language for writing markup code (such as xml and html) which can be directly embedded into C/C++ code. Here is a simple sample written in this language, I call it WDI (Web Development Interface): /* * Simple wdi/html sample source code */ #include <mySite> string name = "myName"; string toCapital(string str); html { head { title { mySiteTitle; } link(rel="stylesheet", href="style.css"); } body

Yacc/Bison: The pseudo-variables ($$, $1, $2,..) and how to print them using printf

女生的网名这么多〃 提交于 2020-01-23 02:16:49
问题 I have a lexical analyser written in flex that passes tokens to my parser written in bison. The following is a small part of my lexer: ID [a-z][a-z0-9]* %% rule { printf("A rule: %s\n", yytext); return RULE; } {ID} { printf( "An identifier: %s\n", yytext ); return ID; } "(" return LEFT; ")" return RIGHT; There are other bits for parsing whitespace etc too. Then part of the parser looks like this: %{ #include <stdio.h> #include <stdlib.h> #define YYSTYPE char* %} %token ID RULE %token LEFT

Yacc/Bison, minimize amount by grouping math ops

落爺英雄遲暮 提交于 2020-01-20 08:16:21
问题 I am looking at the calc source here http://epaperpress.com/lexandyacc/ I see theses lines in calc.y | expr '+' expr { $$ = opr('+', 2, $1, $3); } | expr '-' expr { $$ = opr('-', 2, $1, $3); } | expr '*' expr { $$ = opr('*', 2, $1, $3); } | expr '/' expr { $$ = opr('/', 2, $1, $3); } | expr '<' expr { $$ = opr('<', 2, $1, $3); } | expr '>' expr { $$ = opr('>', 2, $1, $3); } Is there a way to group them? so i can write something like the below instead? | expr mathOp expr { $$ = opr(mathOp, 2,

Yacc/Bison, minimize amount by grouping math ops

北城余情 提交于 2020-01-20 08:14:26
问题 I am looking at the calc source here http://epaperpress.com/lexandyacc/ I see theses lines in calc.y | expr '+' expr { $$ = opr('+', 2, $1, $3); } | expr '-' expr { $$ = opr('-', 2, $1, $3); } | expr '*' expr { $$ = opr('*', 2, $1, $3); } | expr '/' expr { $$ = opr('/', 2, $1, $3); } | expr '<' expr { $$ = opr('<', 2, $1, $3); } | expr '>' expr { $$ = opr('>', 2, $1, $3); } Is there a way to group them? so i can write something like the below instead? | expr mathOp expr { $$ = opr(mathOp, 2,

Flex and Bison: Beginning a sentence with a specific keyword

给你一囗甜甜゛ 提交于 2020-01-17 04:59:32
问题 I am working on a program using Flex and Bison. My task can be done using only Flex(using start conditions etc.), but I have understood that using Bison might make my life easier. My task is to design a program which recognizes a programming language declaration part. Its syntax and logic can be understood through my code below. My problem is that I want my program to recognize as an acceptable declaration part every part of code which begins only with the " var " keyword! Until now, I have

Circular dependency resolution with bison generated file

限于喜欢 提交于 2020-01-16 12:18:35
问题 I have this code block in bison's yacc file. This is the code from the flex/bison code for Flex & Bison book. The yacc code can be downloaded from https://github.com/GrooveStomp/Flex-Bison/blob/master/samples/purecalc.y %{ # include "purecalc.lex.h" # include "purecalc.h" #define YYLEX_PARAM pp->scaninfo %} The issue is that I have a compilation error(Circular dependency resolution with bison generated file); they are circular dependent as purecalc.lex.h depends on pcdata which is in purecalc

Circular dependency resolution with bison generated file

空扰寡人 提交于 2020-01-16 12:09:04
问题 I have this code block in bison's yacc file. This is the code from the flex/bison code for Flex & Bison book. The yacc code can be downloaded from https://github.com/GrooveStomp/Flex-Bison/blob/master/samples/purecalc.y %{ # include "purecalc.lex.h" # include "purecalc.h" #define YYLEX_PARAM pp->scaninfo %} The issue is that I have a compilation error(Circular dependency resolution with bison generated file); they are circular dependent as purecalc.lex.h depends on pcdata which is in purecalc

Syntax analyser to show success using flex and bison

我只是一个虾纸丫 提交于 2020-01-16 02:52:51
问题 I am trying to make a syntax analyzer that will recognize a valid statement and will print success upon doing so. However, after making the lex and yacc files, I keep getting errors in my yacc file which says: In function 'yyparse'fofo.y: In function 'yyparse': fofo.y:13:5: error: stray '\223' in program fofo.y:13:5: error: stray '\' in program fofo.y:13:16: error: 'n' undeclared (first use in this function) fofo.y:13:16: note: each undeclared identifier is reported only once for each

Can Bison parse UTF-8 characters?

瘦欲@ 提交于 2020-01-12 07:24:28
问题 I'm trying to make a Bison parser to handle UTF-8 characters. I don't want the parser to actually interpret the Unicode character values, but I want it to parse the UTF-8 string as a sequence of bytes. Right now, Bison generates the following code which is problematic: if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } The problem is that many bytes of the UTF-8 string will have a negative value, and Bison interprets negative values as an EOF,

bison.exe cannot find file m4sugar.m4 which is required by an MSBuild in VS2010

左心房为你撑大大i 提交于 2020-01-11 10:40:08
问题 I am trying to compile QGIS in Visual Studio. I used OSGeo4W to download the packages, added Flex.exe and Bison.exe to my environment path. Downloaded QGIS Release 2.0, and launched a CMake-GUI with the option "Visual Studio 10". Then I configured my paths using the GUI tool. Then I hit configure and generate, and it worked. I looked in my directory and there were Visual Studio Solution files available for me. Then I hit "Build All" and I got the following output in the "Output Window"