yacc

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

yacc - Precedence of a rule with no operator?

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Thinking about parsing regular expressions using yacc (I'm actually using PLY), some of the rules would be like the following: expr : expr expr expr : expr '|' expr expr : expr '*' The problem is, the first rule(concatenation) must take precedence over the second rule, but not the third one. However, the concatenation rule has no operator in it. How can I specify the precedence correctly in this case? Thank you! EDIT: I modified the rules to avoid the issue, but I'm still curious what was the problem. Here is the source code: tokens = [

Where can I find standard BNF or YACC grammar for C++ language?

房东的猫 提交于 2019-12-03 02:22:23
问题 I'm trying to work on a kind of code generator to help unit-testing an legacy C/C++ blended project. I don't find any kind of independent tool can generate stub code from declaration. So I decide to build one, it shouldn't be that hard. Please, anybody can point me a standard grammar link, better described by yacc language. Hope I'm not reinventing wheel, please help me out in that case. Best Regards, Kevin 回答1: From the C++ FAQ Lite: 38.11 Is there a yacc-able C++ grammar? The primary yacc

Flex and Yacc - Cannot find - lfl?

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I'm learing Lex and yacc. I created the following lex program. %{ #include <stdio.h> %} %% [0123456789]+ printf("NUMBER\n"); [a-zA-Z][a-zA-Z0-9]* printf("WORD\n"); %% I'm trying to run it using the following commands: lex example1.l cc lex.yy.c -o example1 -ll also tried cc lex.yy.c -o example1 -lfl When I enter the second command form above, I get error: D:\workdir\flexyacc\Test3>gcc lex.yy.c -o Test -lfl C:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lfl collect2: ld returned 1 exit status I tried

YACC Rules not reduced

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is my code calc.y. I keep getting the error: yacc: 1 rule never reduced yacc: 3 reduce/reduce conflicts not really sure what this means Ive done some research in other places but I am now lost. Im guessing the rules being referred to is program and statement but even so... what does the reduce rule mean? %{ #include <stdio.h> FILE *outfile; int yyline = 1; int yycolumn = 1; %} %union{ int nw; struct{ int v; char s[1000]; }attr; } %token SEMInumber %token LPARENnumber %token <nw> ICONSTnumber %token BEGINnumber %token PROGRAMnumber

yacc shift-reduce for ambiguous lambda syntax

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm writing a grammar for a toy language in Yacc (the one packaged with Go) and I have an expected shift-reduce conflict due to the following pseudo-issue. I have to distilled the problem grammar down to the following. start: stmt_list expr: INT | IDENT | lambda | '(' expr ')' { $$ = $2 } lambda: '(' params ')' '{' stmt_list '}' params: expr | params ',' expr stmt: /* empty */ | expr stmt_list: stmt | stmt_list ';' stmt A lambda function looks something like this: map((v) { v * 2 }, collection) My parser emits: conflicts: 1 shift/reduce

What is the difference between Flex/Lex and Yacc/Bison?

我与影子孤独终老i 提交于 2019-12-03 00:37:22
问题 What is the difference between Flex & Lex and Yacc & Bison. I searched the Internet wildly and I didn't find any solid answer. Can I install pure Lex and Yacc on Ubuntu, or I can install only flex and bison. I am confused. Is Lex or Yacc still being maintained by someone? Are all of them free? If Lex is not free why do I have it installed on my Ubuntu distribution? lex --version lex 2.5.35 回答1: There are some differences between Lex and Flex, but you have to be abusing Lex to run into the

[转载]Yacc基础

匿名 (未验证) 提交于 2019-12-02 23:30:02
原文:https://www.ibm.com/developerworks/cn/linux/sdk/lex/index.html,摘录部分内容。 Yacc的定义 Yacc 代表 Yet Another Compiler Compiler。 Yacc 的 GNU 版叫做 Bison。它是一种工具,将任何一种编程语言的所有语法翻译成针对此种语言的 Yacc 语 法解析器。它用巴科斯范式(BNF, Backus Naur Form)来书写。按照惯例,Yacc 文件有 .y 后缀。   2. Yacc与Flex的配合 到目前为止我们已经分别讨论了 Lex 和 Yacc。现在让我们来看一下他们是怎样结合使用的。 yylex() yylex() yylex() 对于由 Lex 生成的 lexer 来说,要和 Yacc 结合使用,每当 Lex 中匹配一个模式时都必须返回一个标记。 因此 Lex 中匹配模式时的动作一般格式为: 1 2 {pattern} { /* do smthg*/ return TOKEN_NAME; } .y #define .lex 中的 C 声明段中包括。 让我们回到名字和年龄的文件解析例子中,看一看 Lex 和 Yacc 文件的代码。 Name.y - 语法文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Where can I find standard BNF or YACC grammar for C++ language?

点点圈 提交于 2019-12-02 15:54:18
I'm trying to work on a kind of code generator to help unit-testing an legacy C/C++ blended project. I don't find any kind of independent tool can generate stub code from declaration. So I decide to build one, it shouldn't be that hard. Please, anybody can point me a standard grammar link, better described by yacc language. Hope I'm not reinventing wheel, please help me out in that case. Best Regards, Kevin From the C++ FAQ Lite : 38.11 Is there a yacc-able C++ grammar? The primary yacc grammar you'll want is from Ed Willink. Ed believes his grammar is fully compliant with the ISO/ANSI C++

Python/YACC: Resolving a shift/reduce conflict

£可爱£侵袭症+ 提交于 2019-12-02 15:40:59
问题 I'm using PLY. Here is one of my states from parser.out : state 3 (5) course_data -> course . (6) course_data -> course . course_list_tail (3) or_phrase -> course . OR_CONJ COURSE_NUMBER (7) course_list_tail -> . , COURSE_NUMBER (8) course_list_tail -> . , COURSE_NUMBER course_list_tail ! shift/reduce conflict for OR_CONJ resolved as shift $end reduce using rule 5 (course_data -> course .) OR_CONJ shift and go to state 7 , shift and go to state 8 ! OR_CONJ [ reduce using rule 5 (course_data -