yacc

C11 grammar ambiguity between _Atomic type specifier and qualifier

拜拜、爱过 提交于 2019-11-29 09:35:59
I'm trying to write a lex/yacc grammar for C11 based off of N1570. Most of my grammar is copied verbatim from the informative syntax summary, but some yacc conflicts arose. I've managed to resolve all of them except for one: there seems to be some ambiguity between when '_Atomic' is used as a type specifier and when it's used as a type qualifier. In the specifier form, _Atomic is followed immediately by parentheses, so I'm assuming it has something to do with C's little-used syntax which allows declarators to be in parentheses, thus allowing parentheses to immediately follow a qualifier. But

freeing the string allocated in strdup() from flex/bison

℡╲_俬逩灬. 提交于 2019-11-29 07:29:21
I have flex code that copies a string lexeme using strdup() . %{ #include "json.tab.h" #define YY_DECL extern "C" int yylex() %} %option noyywrap %% [ \t\n]+ ; \"[a-zA-Z]+\" {yylval.sval = strdup(yytext); return STRING; } [0-9]+ {yylval.ival = atoi(yytext); return NUMBER; } . {return yytext[0];} ; %% strdup() allocates memory and copies the input string into it and return ( strdup() - what does it do in C? ), so I guess I need to free it up when I don't need it anymore. From this post: When is %destructor invoked in BISON? , I added %destructor { free($$); printf("free");} STRING in the yacc

in lex how to make yyin point to a file with the main function in yacc?

对着背影说爱祢 提交于 2019-11-29 06:31:41
I am storing the arguments passed to main in yacc in a file. Now I want the lex to read its input from this file rather than the terminal. I know I can point yyin to a file like yyin = fopen("fn","r"); but this works only when main is in lex. When I use this yyin declaration in main in yacc, it shows an error so please suggest something to overcome this problem. You probably just need to declare extern FILE * yyin; If that doesn't solve the problem, please give the error message you got. 来源: https://stackoverflow.com/questions/1796520/in-lex-how-to-make-yyin-point-to-a-file-with-the-main

How much time would it take to write a C++ compiler using flex/yacc?

人盡茶涼 提交于 2019-11-29 06:16:34
问题 How much time would it take to write a C++ compiler using lex/yacc? Where can I get started with it? 回答1: There are many parsing rules that cannot be parsed by a bison/yacc parser (for example, distinguishing between a declaration and a function call in some circumstances). Additionally sometimes the interpretation of tokens requires input from the parser, particularly in C++0x. The handling of the character sequence >> for example is crucially dependent on parsing context. Those two tools

How to create a parser(lex/yacc)?

好久不见. 提交于 2019-11-29 04:13:48
问题 I'm having the following file and which need to be parsed --TestFile Start ASDF123 Name "John" Address "#6,US" end ASDF123 The lines start with -- will be treated as comment lines. and the file starts 'Start' and ends with end . The string after Start is the UserID and then the name and address will be inside the double quots. I need to parse the file and write the parsed data into an xml file. So the resulting file will be like <ASDF123> <Name Value="John" /> <Address Value="#6,US" /> <

bison end of file

大兔子大兔子 提交于 2019-11-29 04:03:38
If I forget to put an empty line at the end of any of my files my program gets a syntax error. The problem is my grammar expects a newline to end the current line. Since a newline doesn't exist bison generates a syntax error because it does not finish the rule. How do I solve this? I tried making <<EOF>> return MY_EOF BUT when I do that lex crashes a horrible death. I guess there's code in its default EOF that I am not calling. I have no idea what functions they may be. Using EOF create the error symbol EOF is used, but is not defined as a token and has no rules You could use a flex EOF rule

C grammar in GCC source code

青春壹個敷衍的年華 提交于 2019-11-29 01:21:20
问题 I'm looking for the C grammar in GCC source code, more specifically for the grammar in the yacc/bison form. 回答1: Found the C grammar in Yacc specification in the GCC version 3.3 in the file "c-parse.y" 回答2: You will not find a C grammar yacc/bison file within the current GCC source code. It was done in the past, before the egcs fork stuff. I cannot give you the exact version and location, but i can tell you that it should be in the 2.x release The current version of GCC has its own C parser

how to install Lex and Yacc in Ubuntu? [closed]

旧巷老猫 提交于 2019-11-28 20:47:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 years ago . I am doing project in SENSE, for that i have to install Lex and Yacc. If you can help me how to install in Ubuntu. I very new to this area. So can you help me. Any website to study the basic of Lex and Yacc 回答1: Use the synaptic packet manager in order to install yacc / lex. If you are feeling more comfortable

Good parser generator (think lex/yacc or antlr) for .NET? Build time only? [closed]

本秂侑毒 提交于 2019-11-28 19:22:58
Is there a good parser generator (think lex/yacc or antlr) for .NET? Any that have a license that would not scare lawyers? Lot’s of LGPL but I am working on embedded components and some organizations are not comfortable with me taking an LGPL dependency. I've heard that Oslo may provide this functionality but I'm not sure if it's a build time dependency or also a runtime dependency. Can anyone clarify what Oslo will provide? UPDATE What I would really like is a parser generator that is a build time only dependency. It looks like ANTLR has a runtime component. I just discovered that F# ships

How exactly does R parse `->`, the right-assignment operator?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 18:30:46
So this is kind of a trivial question, but it's bugging me that I can't answer it, and perhaps the answer will teach me some more details about how R works. The title says it all: how does R parse -> , the obscure right-side assignment function? My usual tricks to dive into this failed: `->` Error: object -> not found getAnywhere("->") no object named -> was found And we can't call it directly: `->`(3,x) Error: could not find function "->" But of course, it works: (3 -> x) #assigns the value 3 to the name x # [1] 3 It appears R knows how to simply reverse the arguments, but I thought the above