yacc

Thread-safe / reentrant bison + flex

喜欢而已 提交于 2019-12-01 12:32:48
问题 I would really prefer a working example to any explanation. Whatever I read so far on Bison's documentation site contradicts whatever Flex says. One says to declare yylex as int yylex (yyscan_t yyscanner); another one wants it to be: int yylex(YYSTYPE *lvalp, YYLTYPE *llocp); What I really need is the location information. I'm not sure as of yet if I need YYSTYPE (I don't have a use for this information right now, but maybe in the future I will). Unrelated to the above, and as a bonus, I'd be

yacc - Precedence of a rule with no operator?

扶醉桌前 提交于 2019-12-01 12:03:09
Thinking about parsing regular expressions using yacc (I'm actually using PLY), some of the rules would be like the following: expr : expr expr expr : expr '|' expr expr : expr '*' The problem is, the first rule(concatenation) must take precedence over the second rule, but not the third one. However, the concatenation rule has no operator in it. How can I specify the precedence correctly in this case? Thank you! EDIT: I modified the rules to avoid the issue, but I'm still curious what was the problem. Here is the source code: tokens = ['PLEFT', 'PRIGHT', 'BAR', 'ASTERISK', 'NORMAL'] t_PLEFT =

Where can I find a yacc grammar for ECMAscript/Actionscript/Javascript [closed]

回眸只為那壹抹淺笑 提交于 2019-12-01 08:04:53
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . My compilers class requires us to find a yacc grammar for one of these languages and combine it with the tokenizer we wrote. Presumably this is something easy to Google but I can't find it and my classmates are

How to get the AST from YACC?

*爱你&永不变心* 提交于 2019-12-01 04:45:50
I know how to make YACC generate an AST, but how do you actaully get it? I mean, how do you actaully get the value of the root node from YACC? Yacc only gives you back one node at a time, and it's always something that you just gave yacc at some earlier time, i.e., whatever you wanted to return from a reduced production or whatever you wanted to return from a terminal symbol. (Sorry, you said you knew that, but some people reading this might not.) So, take whatever you woud have returned from the root or top rule, and save it (in your attached C reduction code) any way you like. What Yacc

How to get the AST from YACC?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 03:28:37
问题 I know how to make YACC generate an AST, but how do you actaully get it? I mean, how do you actaully get the value of the root node from YACC? 回答1: Yacc only gives you back one node at a time, and it's always something that you just gave yacc at some earlier time, i.e., whatever you wanted to return from a reduced production or whatever you wanted to return from a terminal symbol. (Sorry, you said you knew that, but some people reading this might not.) So, take whatever you woud have returned

verbose error with ocamlyacc

落花浮王杯 提交于 2019-12-01 00:23:57
In bison, it is sufficient to add %verbose-error to the file to make the parser errors more verbose. Is there any way to gain similar functionality with ocamlyacc? Here is the answer for a similar question, but I could not make anything out of it. This is how I call the lexer and parser functions: let rec foo () = try let line = input_line stdin in (try let _ = (Parser.latexstatement lexer_token_safe (Lexing.from_string line)) in print_string ("SUCCESS\n") with LexerException s -> print_string ("$L" ^ line ^ "\n") | Parsing.Parse_error -> print_string ("$P" ^ line ^ "\n") | _ -> print_string (

How to build an Array with Bison/Yacc and a Recursive Rule

不问归期 提交于 2019-11-30 16:08:19
With Bison, I figured out how to get everything into one long string as follows: arg_list: WORD arg_list { strcat( $1, "IFS" ); $$ = strcat($1, $2); } | WORD ; and: WORD arg_list { printf("%s, %s\n", $1, $2); } But the problem is that I will then have to split up $2 in the second rule again to parse it. Is there a way to populate an array instead of just using concatenation? Am I going about this the wrong way? If I need to build something like a linked list that could make sense, just not sure what would be the proper way to bind to arg_list, and then clean up the memory. If you have an array

Generating a compiler from lex and yacc grammar

南楼画角 提交于 2019-11-30 14:01:16
I'm trying to generate a compiler so I can pass him a .c file after. I've downloaded both YACC and LEX grammars from http://www.quut.com/c/ANSI-C-grammar-y.html and named them clexyacc.l and clexyacc.y When generating it on terminal I did : yacc -d clexyacc.y lex clexyacc.l All went fine. When I move on to the last part I get a few errors. The last part is : cc lex.yy.c y.tab.c -oclexyacc.exe But I get these errors : y.tab.c:2261:16: warning: implicit declaration of function 'yylex' is invalid in C99 [-Wimplicit-function-declaration] yychar = YYLEX; ^ y.tab.c:1617:16: note: expanded from macro

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

笑着哭i 提交于 2019-11-30 08:26:27
问题 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. 回答1: You probably just need to declare extern FILE * yyin; If that doesn't solve the problem, please give the error message you got.

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

旧巷老猫 提交于 2019-11-30 06:38:34
How much time would it take to write a C++ compiler using lex/yacc? Where can I get started with it? 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 are very poor choices for parsing C++ and you would have to put in a lot of special cases that escaped the