bison

Parsing optional semicolon at statement end

守給你的承諾、 提交于 2019-12-04 02:57:43
I was writing a parser to parse C-like grammars. First, it could now parse code like: a = 1; b = 2; Now I want to make the semicolon at the end of line optional. The original YACC rule was: stmt: expr ';' { ... } Where the new line is processed by the lexer that written by myself(the code are simplified): rule(/\r\n|\r|\n/) { increase_lineno(); return :PASS } the instruction :PASS here is equivalent to return nothing in LEX, which drop current matched text and skip to the next rule, just like what is usually done with whitespaces. Because of this, I can't just simply change my YACC rule into:

Lex/Flex - Scanning for the EOF character

僤鯓⒐⒋嵵緔 提交于 2019-12-04 02:56:16
问题 Other people have had the following problem that I am having but I can't find anyone that has reported a solution.. getting Flex to spot the EOF (end of file). I need Flex to find EOF and return a token indicating that it has found it so it can tell Yacc/Bison that it has reached the end of an input source file and can report a successful parse. Note that this question is not the same as this one because this is about Lex/Flex. Any help would be awesome. Thank you. 回答1: Flex has <<EOF>>

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

Flex / Lex Encoding Strings with Escaped Characters

浪子不回头ぞ 提交于 2019-12-03 21:43:03
问题 I'll refer to this question for some of the background: Regular expression for a string literal in flex/lex The problem I am having is handling the input with escaped characters in my lexer and I think it may be an issue to do with the encoding of the string, but I'm not sure. Here's is how I am handling string literals in my lexer: \"(\\.|[^\\"])*\" { char* text1 = strndup(yytext + 1, strlen(yytext) - 2); char* text2 = "text\n"; printf("value = <%s> <%x>\n", text1, text1); printf("value = <

Bison - how to print a parse tree

∥☆過路亽.° 提交于 2019-12-03 21:41:04
Hi I'm working on a small bison to learn how it works. The bison is supposed to parse a sentence. The sentence is made of expressions and expressions are made of words. Following is my code: %{ #include <stdio.h> #include <string.h> void yyerror(const char *str) { fprintf(stderr,"error: %s\n",str); } int yywrap() { return 1; } main() { yyparse(); } %} %token ASSIGN RANGE OR AND WHITESPACE QUOTE LPAREN RPAREN NOT GREATER LESS %union { int number; char *string; } %token <number> VALUE %token <string> WORD %type <string> term %type <string> expression %% query: /* empty */ | query expression {

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

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

using qt : How To Build a Gui OnTop Of a Console Application?

家住魔仙堡 提交于 2019-12-03 16:11:24
i have a console application that generated from bison (a parser) and i want to build a simple gui for it so i can send input from this gui to the console and get output from the console into the gui . i tried to do that using java process class but it doesnt work for me , please help me to do that using qt . Etienne Savard It depends on the complexity of the data you want to feed in/out of your console application. Low complexity Use some command switches that you pass from your Qt GUI to your console application. Look at the QProcess class documentation . High complexity I would go with an

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