bison

Bison reduce/reduce, shift/reduce conflicts

痞子三分冷 提交于 2019-12-24 08:28:09
问题 Hey guys I'm having trouble with some bison code... After compiling this chunk of code, i get 58 shift/reduce and 40 reduce/reduce conflicts... Any tips on how to constrain them, or point me to a good guide on how to do it? Thanks in advance!! (Everything that starts with T_, like T_get are tokens defined above this code) start:T_get G |T_head G |T_post G ; G:url canon ; url: T_http T_dslash T_host T_abs_path ; canon:GH canon|RH canon|EH canon|MB ; GH:T_con T_akt T_seq GH|T_date T_akt D GH|T

How to write a working cmake file for flex & bison?

ⅰ亾dé卋堺 提交于 2019-12-24 07:27:44
问题 I am writing a small parser, but have problems of using cmake. My purpose is: flex F.l => F.cc, bison B.y => B.cc, my_program.cc + F.cc + B.cc => library My first attempt: FIND_PACKAGE(FLEX REQUIRED) if (FLEX_FOUND) ADD_CUSTOM_TARGET( flex_target COMMAND ${FLEX_EXECUTABLE} --header-file=${CMAKE_CURRENT_SOURCE_DIR}/F.h --outfile=${CMAKE_CURRENT_SOURCE_DIR}/F.cc ${CMAKE_CURRENT_SOURCE_DIR}/F.l COMMENT "Generating F.cc" ) endif(FLEX_FOUND) FIND_PACKAGE(BISON REQUIRED) if (BISON_FOUND) ADD_CUSTOM

Undefined reference error even though the functions are present

老子叫甜甜 提交于 2019-12-24 01:55:08
问题 Although "Undefined Reference error" questions have been asked several times, I couldn't find solution to my problem. I am trying to get flex and bison to work in a Qt app. I am facing problem in linking only. These are the relevant files- 1) icd.l - Lex specification - It generates iclexer.c and contains definition of functions- void yyerror(char const *s){...} void* setUpBuffer(char const* text){...} void tearDownBuffer(void* buffer){...} int nextToken(){...} 2) iclexer.h #ifndef ICLEXER_H

Undefined reference error even though the functions are present

∥☆過路亽.° 提交于 2019-12-24 01:55:07
问题 Although "Undefined Reference error" questions have been asked several times, I couldn't find solution to my problem. I am trying to get flex and bison to work in a Qt app. I am facing problem in linking only. These are the relevant files- 1) icd.l - Lex specification - It generates iclexer.c and contains definition of functions- void yyerror(char const *s){...} void* setUpBuffer(char const* text){...} void tearDownBuffer(void* buffer){...} int nextToken(){...} 2) iclexer.h #ifndef ICLEXER_H

Jison: Reduce Conflict where actually no conflict is

我的梦境 提交于 2019-12-24 00:57:02
问题 I'm trying to generate a small JavaScript parser which also includes typed variables for a small project. Luckily, jison already provides a jscore.js which I just adjusted to fit my needs. After adding types I ran into a reduce conflict. I minimized to problem to this minimum JISON: Jison: %start SourceElements %% // This is up to become more complex soon Type : VAR | IDENT ; // Can be a list of statements SourceElements : Statement | SourceElements Statement ; // Either be a declaration or

Bison specification and precedence order

大兔子大兔子 提交于 2019-12-23 20:38:29
问题 Given Bison Specification: %right TOK_ADD TOK_MUL I was wondering what would be the precedence order of TOK_ADD and TOK_MUL. Also in case i had Bison specification %left TOKMUL TOKADD %left TOKDIV %left TOKSUB I was wondering what would the precedence order of TOKMUL TOKADD TOKDIV and TOKSUB be 回答1: bison/yacc precedence order is lowest to highest -- the tokens on the first line listed have the lowest precedence while those on the last have the highest. Multiple tokens on the same line (

学习编写编译器[关闭]

谁说胖子不能爱 提交于 2019-12-23 19:45:30
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 首选语言 :C / C ++,Java和Ruby。 我正在寻找一些有用的书籍/教程,以了解如何仅出于教育目的编写自己的编译器。 我最熟悉C / C ++,Java和Ruby,因此我更喜欢涉及这三种资源之一的资源,但是任何好的资源都是可以接受的。 #1楼 这是一个广阔的主题。 不要小看这一点。 并且不要低估我的观点,不要低估它。 我听说《 龙书》 是一个(“?”)学习的起点。 :)善于搜索,最终将成为您的生活。 构建自己的编程语言绝对是一个好练习! 但是要知道,最终它永远不会用于任何实际目的。 例外情况很少, 而且 相差 很 远。 #2楼 您可能想要研究Lex / Yacc(或Flex / Bison,无论您想称呼它们如何)。 Flex是一个词法分析器,它将分析和识别您语言的语义成分(“令牌”),而Bison将用于定义解析每个令牌时发生的情况。 对于可以编译为C的编译器或动态运行指令,这可能是但绝对不限于打印C代码。 该常见问题解答 应为您提供帮助, 本教程 看起来非常有用。 #3楼 我认为这是一个非常模糊的问题。 只是因为涉及的话题很深。 但是,编译器可以分解为两个独立的部分。 上半部分和下半部分。 上半部通常采用源语言并将其转换为中间表示,下半部负责平台特定的代码生成。 尽管如此

How do I generate different yyparse functions from lex/yacc for use in the same program?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 18:55:42
问题 I want to generate two separate parsing functions from lex/yacc. Normally yacc gives you a function yyparse() that you can call when you need to do some parsing, but I need to have several different yyparses each associated with different lexers and grammars. The man page seems to suggest the -p (prefix) flag, but this didn't work for me. I got errors from gcc that indicated that yylval was not properly being relabeled (i.e. it claims that several different tokens are not defined). Does

Unit test of flex bison scanner parse, how to drive the test case

纵饮孤独 提交于 2019-12-23 12:24:12
问题 I have a question about how to "drive" a flex bison based parser scanner in a unit test. The final solution will be a command parser available or telnet to a target board. I have a fully working flex bison implementation using stdin. Right now my focus is on getting a unit test running for the command parser. I would like to be able to provide a "const string" to the parser (a command) and then test that the corresponding command is invoked in the application (in a application stub). I do not

How can I send the yyleng of a matched string from Lex to Yacc?

纵饮孤独 提交于 2019-12-23 03:09:10
问题 Please i am trying to pass the yyleng of a matched string from my (.l) file to the (.y) file. Here is a sample of the issue: In the Lex File: <state1>.+ { fprintf(yyout, "%d", yyleng); } In the Yacc File: /* I need to know the methodology used to receive a specific yyleng to the yacc file. Shall I use global variables? or there is a specific way for dealing with this issue? */ Thanks in advance for your help! ~ Any suggestions are highly appreciated. 回答1: yyleng is a global variable; declare