bison

Creating a small programming language for beginners

我的未来我决定 提交于 2019-12-03 14:41:25
问题 I would like to create my own programming language. Maybe not exactly a programming language from scratch but maybe base it on another language. I've heard of Yacc. So, I installed Flex and Bison. But I do not understand how to make a compiler with it. I have made the Hello world project in it, but how would I make a compiler in it? Are there any easy ways of creating a small programming language, I have heard of translating a language as in taking, e.g., Write() and making the computer

Undefined reference to yyparse (flex & bison)

放肆的年华 提交于 2019-12-03 13:42:29
问题 I'm attempting to learn some flex/bison, and I'm reading Flex & Bison by John Levine (O'Reilly). There is an example that I need to get running, however I can't get it to run as I get the following error: /tmp/ccKZcRYB.o: In function `yylex': fb3-1.lex.c:(.text+0x2bd): undefined reference to `yylval' /tmp/cclBqnOk.o: In function `main': fb3-1funcs.c:(.text+0x420): undefined reference to `yyparse' collect2: ld returned 1 exit status I've got four source files: fb3-1.h : /* * Declarations for

Can Bison parse UTF-8 characters?

谁都会走 提交于 2019-12-03 12:48:05
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, and stops. Is there a way around this? bison yes, flex no. The one time I needed a bison parser to work

unistd.h related difficulty when compiling bison & flex program under vc++

99封情书 提交于 2019-12-03 09:37:13
I'm using bison & flex (downloaded via cygwin) with vc++. When I compile the program I got an error: ...: fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory The corresponding code in the flex-generated file is: #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way * down here because we want the user's section 1 to have been scanned first. * The user has a chance to override it with an option. */ /* %if-c-only */ #include <unistd.h> /* %endif */ /* %if-c++-only */ /* %endif */ #endif If I define YY_NO_UNISTD_H in the flex

Flex, Bison, and C: Looking for a very basic introduction

大兔子大兔子 提交于 2019-12-03 09:36:36
问题 I am looking for a very short working example of flex and bison with an accompanying Makefile which makes use of the builtin rules. I've tried several google results that were messy, wouldn't build, or were in C++ which isn't acceptable. Good online resources and short sample code is appreciated. ADDITIONAL # Makefile example -- scanner and parser. # Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c" # LEX = flex YACC = bison -y YFLAGS = -d objects = scan.o parse.o myprogram.o

Trouble building gcc 4.6: undefined reference to `yylex'

本秂侑毒 提交于 2019-12-03 06:36:19
问题 I'm trying to build gcc 4.6, but I'm getting some linker errors that look like it means bison or flex isn't getting linked to. When the makefile issues this command: gcc -g -fkeep-inline-functions -DIN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Wold-style-definition -Wc++-compat -fno-common -DHAVE_CONFIG_H -DGENERATOR_FILE -o build/gengtype \ build/gengtype

Writing compilers … what's right and what's wrong? [closed]

丶灬走出姿态 提交于 2019-12-03 05:09:10
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Okay, in my quest to figure out the necessary stuff to write a compiler, I've reached a bit of a roadblock. It seems that every

Creating a small programming language for beginners

不想你离开。 提交于 2019-12-03 04:47:09
I would like to create my own programming language. Maybe not exactly a programming language from scratch but maybe base it on another language. I've heard of Yacc. So, I installed Flex and Bison. But I do not understand how to make a compiler with it. I have made the Hello world project in it, but how would I make a compiler in it? Are there any easy ways of creating a small programming language, I have heard of translating a language as in taking, e.g., Write() and making the computer understand it as Print() . Is this be possible?. My take on this is that the simpler approach is not to mess

How to solve Bison warning “… has no declared type”

本秂侑毒 提交于 2019-12-03 04:11:57
Running Bison on this file: %{ #include <iostream> int yylex(); void yyerror(const char*); %} %union { char name[100]; int val; } %token NUM ID %right '=' %left '+' '-' %left '*' %% exp : NUM {$$.val = $1.val;} | ID {$$.val = vars[$1.name];} | exp '+' exp {$$.val = $1.val + $3.val;} | ID '=' exp {$$.val = vars[$1.name] = $3.val;} ; %% Leads to warnings of the kind of: warning: $$ of 'exp' has no declared type. What does it mean and how do I solve it? Asaf R The union (%union) defined is not intended to be used directly. Rather, you need to tell Bison which member of the union is used by which

Undefined reference to yyparse (flex & bison)

与世无争的帅哥 提交于 2019-12-03 03:38:22
I'm attempting to learn some flex/bison, and I'm reading Flex & Bison by John Levine (O'Reilly). There is an example that I need to get running, however I can't get it to run as I get the following error: /tmp/ccKZcRYB.o: In function `yylex': fb3-1.lex.c:(.text+0x2bd): undefined reference to `yylval' /tmp/cclBqnOk.o: In function `main': fb3-1funcs.c:(.text+0x420): undefined reference to `yyparse' collect2: ld returned 1 exit status I've got four source files: fb3-1.h : /* * Declarations for calculator fb3-1 */ /* Interface to the lexer */ extern int yylineno; /* from lexer */ void yyerror(char