yacc

Is there a Sublime Text Syntax for Flex and Bison?

我的梦境 提交于 2019-12-04 00:50:55
I'm looking for a syntax in Sublime Text that highlights my Flex and Bison files (or lex/yacc) in a way that makes them readable... Sublime Text automatically chooses Lisp for Flex files, but that doesn't do the trick all that well. Any suggestions to try another syntax? Or is there a plugin somewhere that's useful (haven't found anything so far)?. I haven't found one built specifically for Sublime, but I've found one for TextMate, which Sublime is compatible with. Therefore, for Flex highlight, all you need to do is git clone the TextMate's syntax files to your Packages folder. Regarding

“make: yacc: Command not found” after installing Bison

China☆狼群 提交于 2019-12-04 00:39:12
While running a makefile in gcc 4.1.2 (linux 5), I got the following error make: yacc: Command not found By googling, I came to know that this error can be rectified by installing Bison-GNU parser generator. But even after installing Bison, I get the same error. How can this error be solved? From the looks of things, your makefile is expecting a yacc executable to be available and either it's not, or it's not on your path. Since bison is supposed to be compatible with yacc so the first thing I would try would be: alias yacc="bison" and try again. On my setup, /usr/bin/yacc is simply a script

Why does this simple grammar have a shift/reduce conflict?

房东的猫 提交于 2019-12-03 20:26:01
%token <token> PLUS MINUS INT %left PLUS MINUS THIS WORKS: exp : exp PLUS exp; exp : exp MINUS exp; exp : INT; THIS HAS 2 SHIFT/REDUCE CONFLICTS: exp : exp binaryop exp; exp : INT; binaryop: PLUS | MINUS ; WHY? This is because the second is in fact ambiguous. So is the first grammar, but you resolved the ambiguity by adding %left . This %left does not work in the second grammar, because associativity and precedence are not inherited from rule to rule. I.e. the binaryop nonterminal does not inherit any such thing even though it produces PLUS and MINUS . Associativity and predecence are

How to find shift/reduce conflict in this yacc file?

喜夏-厌秋 提交于 2019-12-03 18:28:13
问题 When I try to use yacc on the following file I get the error conflicts: 1 shift/reduce How can I find and fix the conflict? /* C-Minus BNF Grammar */ %token ELSE %token IF %token INT %token RETURN %token VOID %token WHILE %token ID %token NUM %token LTE %token GTE %token EQUAL %token NOTEQUAL %% program : declaration_list ; declaration_list : declaration_list declaration | declaration ; declaration : var_declaration | fun_declaration ; var_declaration : type_specifier ID ';' | type_specifier

Assigning multiple data types to a non-terminal in yacc

99封情书 提交于 2019-12-03 17:07:21
I'm working on a project for class in which we have to build a parser. We're currently in the stage of building the parser in yacc. The thing currently confusing me is I've read that you need to assign a type to each nonterminal. In some cases though I'll have Something like: ... %union { Type dataType; int integerConstant; bool boolConstant; char *stringConstant; double doubleConstant; char identifier[MaxIdentLen+1]; // +1 for terminating null Decl *decl; List<Decl*> *declList; } %token <identifier> T_Identifier %token <stringConstant> T_StringConstant %token <integerConstant> T_IntConstant

How to use yylval with strings in yacc

拥有回忆 提交于 2019-12-03 16:07:35
I want to pass the actual string of a token. If I have a token called ID, then I want my yacc file to actually know what ID is called. I thing I have to pass a string using yylval to the yacc file from the flex file. How do I do that? See the Flex manual section on Interfacing with YACC . 15 Interfacing with Yacc One of the main uses of flex is as a companion to the yacc parser-generator. yacc parsers expect to call a routine named yylex() to find the next input token. The routine is supposed to return the type of the next token as well as putting any associated value in the global yylval. To

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

%left and %right in yacc

随声附和 提交于 2019-12-03 13:49:01
{% #include<stdio.h> #include<stdlib.h> %} %token ID NUM IF THEN LE GE EQ NE OR AND ELSE %right '=' %left AND OR %left '<' '>' LE GE EQ NE %left '+''-' %left '*''/' %right UMINUS %left '!' %% Mentioned Above is a part in the yacc program for a simple IF ELSE program.... i m just a beginner and don't understand what do we mean by %right and %left terms...... plz help me on this occasion... %left and %right specify the associativity of an operator. The associativity of an operation determines which of two operations of the same precedence level is carried out first. Suppose we have the grammar

[翻译] ply文档

风流意气都作罢 提交于 2019-12-03 13:02:07
1. 前言与要求   这篇文档提供了ply的lexing与parsing总体说明。鉴于解析的内在复杂性(Given the intrinsic complexity of parsing),我强烈推荐你在开始你ply的大型项目之前应该阅读(或至少略读)整篇文档。 Ply3.5 兼容 python2 与 python3. 如果你正在使用python2,你必须使用python2.6或更新的。 2. 介绍   PLY是一款非常受欢迎的编译器构造工具lex与yacc的纯PYTHON版本。PLY的主要目标是忠诚于(stay farily faithful)传统的lex/yacc工具的工作方式。这支持LALR(1)分析,也支持额外的输入验证、错误输出以及诊断。因此,如果你已经使用了yacc在另外的编程语言,你应该可以相对容易的使用PLY。   早期版本的PLY被开发出来支持我2001年在芝加哥大学编译原理入门课程。因为PLY最初开发作为一个构造工具,你发现它对语法与符号规范相当的挑剔(picky)。部分地,这增加了用于捕捉新手容易造成的常见的编程错误的程序。当然,高级的使用者当在用于构建真正的编程语言的复杂的语法规则时的,也会发现一部分非常有用的细节。应该注意的是PLY不提供太多花里胡哨的方法(the way of bells and whistles)(比如自动构造语法抽象树,树的遍历等)

Are GCC and Clang parsers really handwritten?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: It seems that GCC and LLVM-Clang are using handwritten recursive descent parsers , and not machine generated, Bison-Flex based, bottom up parsing. Could someone here please confirm that this is the case? And if so, why do mainstream compiler frameworks use handwritten parsers? Update : interesting blog on this topic here 回答1: Yes: GCC used a yacc (bison) parser once upon a time, but it was replaced with a hand-written recursive descent parser at some point in the 3.x series: see http://gcc.gnu.org/wiki/New_C_Parser for links to