bison

LR(k) to LR(1) grammar conversion

北战南征 提交于 2019-12-14 03:50:43
问题 I am confused by the following quote from Wikipedia: In other words, if a language was reasonable enough to allow an efficient one-pass parser, it could be described by an LR(k) grammar. And that grammar could always be mechanically transformed into an equivalent (but larger) LR(1) grammar. So an LR(1) parsing method was, in theory, powerful enough to handle any reasonable language. In practice, the natural grammars for many programming languages are close to being LR(1).[citation needed]

LEX -YACC parser for infix-to-prefix translation

本小妞迷上赌 提交于 2019-12-14 03:34:08
问题 Translation schemes: expr -> {print("+")} expr + term | {print("-")} expr - term | term term -> {print("*")} term * factor | {print("/")} term / factor | factor factor -> digit {print(digit)} | (expr) Above grammar will print the expression in prefix form. For this grammar it is not possible to write the parser. how could we write the lex and yacc program to convert infix to prefix. I follow this lex and yacc program to convert infix to prefix but not getting proper output. Any idea how to

Flex++ Bisonc++ parser

不羁岁月 提交于 2019-12-14 00:22:14
问题 I'm trying to use flex and bison in my project to generate a parser code for a file structure. Main programming language is C++ and project is on an OO design mainly running in parallel. I heard that flex and bison generated parsers are C codes and they're not reenterant. Googling, I found flex++ and bisonc++ . Unfortunately there is no simple tutorial to get started. Most examples are based on bison/flex . Some people somehow integrated bison/flex parsers in their C++ code. They supposed to

How to list lex/yacc or flex/bison patterns?

久未见 提交于 2019-12-13 23:56:41
问题 I would like to extract all patterns from a flex/bison file to look at them altogether. I am not interested in the rules applying to the patterns for now. Surely someone has written a flex/bison file for this already? :) 回答1: If you give it the -v command-line option, bison will output a nicely formatted version of the grammar (and all the states) to a file with extension .output . You can specify the precise file name to write to with --report-file=PATH and a list of things to report on with

Why my rules of bison don't work

余生颓废 提交于 2019-12-13 18:41:26
问题 Every time I run my parser, it will appear "syntax error in line 1 near <>" (Because there is a subroutine yyerror(char *s)). I think that's because there is something wrong with my rules in bison. The file (c17.isc) I want to parse. *c17 iscas example (to test conversion program only) *--------------------------------------------------- * * * total number of lines in the netlist .............. 17 * simplistically reduced equivalent fault set size = 22 * lines from primary input gates .......

Distinguishing identifiers from common strings

风格不统一 提交于 2019-12-13 04:49:39
问题 I want to write a parser using Bison/Yacc + Lex which can parse statements like: VARIABLE_ID = 'STRING' where: ID [a-zA-Z_][a-zA-Z0-9_]* and: STRING [a-zA-Z0-9_]+ So, var1 = '123abc' is a valid statement while 1var = '123abc' isn't. Therefore, a VARIABLE_ID is a STRING but a STRING not always is a VARIABLE_ID . What I would like to know is if the only way to distinguish between the two is writing a checking procedure at a higher level (i.e. inside Bison code) or if I can work it out in the

Is there working example of flex + bison with input from string, not file?

被刻印的时光 ゝ 提交于 2019-12-13 04:46:30
问题 Is there working example of flex + bison (bison is necessary) with input from string, not file? I have tried to use YY_BUFFER_STATE ... functions instead of yyin and got error "flex scanner push-back overflow". Flex changes InputString[1] to 0. Several other answers on SO are of little help - actual code will be much more useful. 回答1: The way to scan memory region is described in the Flex manual. Flex modifies the buffer given by yy_scan_buffer . If you need to avoid to be modified, yy_scan

How can I force Bison to shift to resolve a conflict?

冷暖自知 提交于 2019-12-13 04:45:52
问题 I'm building this grammar for a simple programming language (already solved previous ambiguity issues: Can't figure out why Bison is throwing "Rules useless in parser due to conflicts"). This is my complete grammar: http://pastebin.com/yBHLSP0z And this is the output file from Bison: http://pastebin.com/eAma3gWy (sorry, they're in Spanish, but I think they're pretty self-explanatory) The thing is, I'm still getting one shift/reduce error at state 107 (I'm translating it): state 107 31 factor:

Bison/Flex, reduce/reduce, identifier in different production

隐身守侯 提交于 2019-12-13 04:43:28
问题 I am doing a parser in bison/flex. This is part of my code: I want to implement the assignment production, so the identifier can be both boolean_expr or expr, its type will be checked by a symbol table. So it allows something like: int a = 1; boolean b = true; if(b) ... However, it is reduce/reduce if I include identifier in both term and boolean_expr, any solution to solve this problem? 回答1: Essentially, what you are trying to do is to inject semantic rules (type information) into your

This switch statement is working with one Case how to make it multiple case Bison

北城以北 提交于 2019-12-13 04:35:02
问题 This switch statement is working with one Case how to make it multiple case S: Statement {printf("ACCEPTED");} Statement:SWITCH BRO ID BRC CBO E CBC E: A | A C A: A B | CASE DIGIT D B: BREAK SEMI C : DEFAULT D B D : COLON ID SEMI ; This is an issue i want to make grammar accepted with multiple cases 回答1: Your grammar is terrible, and does not account for repetition of the CASE. You need to discover how to express lists of things. The general pattern is like: item: .... items: item | item ';'