yacc

bison end of file

╄→尐↘猪︶ㄣ 提交于 2019-11-27 18:00:02
问题 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

how to use yy_scan_string in lex

隐身守侯 提交于 2019-11-27 14:30:23
I want to parse a string which I give to the parser in the main function of yacc . I know that this could be done by using yy_scan_string but I don't know how to use it. I searched the web and the man pages but it is still not clear to me. Please help me. In case anyone needs the sample for a re-entrant lexer: int main(void) { yyscan_t scanner; YY_BUFFER_STATE buf; yylex_init(&scanner); buf = yy_scan_string("replace me with the string youd like to scan", scanner); yylex(scanner); yy_delete_buffer(buf, scanner); yylex_destroy(scanner); return 0; } This works for me. I have this code in the

Yacc equivalent for Java

江枫思渺然 提交于 2019-11-27 11:48:30
I'm working on a compiler design project in Java. Lexical analysis is done (using jflex) and I'm wondering which yacc-like tool would be best(most efficient, easiest to use, etc.) for doing syntactical analysis and why. kdgregory If you specifically want YACC-like behavior (table-driven), the only one I know is CUP . In the Java world, it seems that more people lean toward recursive descent parsers like ANTLR or JavaCC . And efficiency is seldom a reason to pick a parser generator. In the past, I've used ANLTR for both lexer and parser, and the JFlex homepage says it can interoperate with

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

隐身守侯 提交于 2019-11-27 11:25:13
问题 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

Integrating Bison/Flex/Yacc into XCode

£可爱£侵袭症+ 提交于 2019-11-27 11:03:19
问题 Is there a simple way for integrating Bison/Flex/Yacc into XCode? I want to write my own language to be parsed, which interacts with my ObjC objects. But the tools will only take STDIN as input, and will only produce C code, instead of ObjC. They're basically only seem useful for command-line tools, otherwise they need massive pain to override the output every time I regenerate the parser code. 回答1: In a nutshell, give your grammar files a .ym extension instead of .y. Xcode will then run

How to make YY_INPUT point to a string rather than stdin in Lex & Yacc (Solaris)

狂风中的少年 提交于 2019-11-27 08:55:42
I want my yylex() to parse a string rather than a file or standard input. How can I do it with the Lex and Yacc provided with Solaris? Redefine YY_INPUT. Here's a working example, compile and run with the commands yacc -d parser.y lex lexer.l gcc -o myparser *.c Input is read from globalInputText. You can modify this example so that global input text is whatever string you want or from any input source you want. parser.y: %{ #include <stdio.h> extern void yyerror(char* s); extern int yylex(); extern int readInputForLexer(char* buffer,int *numBytesRead,int maxBytesToRead); %} %token FUNCTION

Is it possible to have two or more Lex/Yacc parsers in the same application

断了今生、忘了曾经 提交于 2019-11-27 07:45:21
问题 I have an application where I already have a parser for one sort of grammar and I need to add a second different grammar for another purpose. Is it possible to have more than one? And if so how do you get another entry point? Thanks david allan finch 回答1: I think you can to this by using the --name-prefix option to Bison, and the --prefix option to Flex. In both cases they allow you to replace the default " yy " prefix used on the functions generated with a prefix of your own choice. 回答2: Yes

A yacc shift/reduce conflict on an unambiguous grammar

陌路散爱 提交于 2019-11-27 07:28:04
问题 A piece of code of my gramamar its driveing me crazy. I have to write a grammar that allow write functions with multiple inputs e.g. function begin a: <statments> b: <statements> end The problem with that its that is statements that are assignments like this ID = Expresion. in the following quote you can see the output produced by yacc. 0 $accept : InstanciasFuncion $end 1 InstanciasFuncion : InstanciasFuncion InstanciaFuncion 2 | InstanciaFuncion 3 InstanciaFuncion : PuntoEntrada Sentencias

Lisp grammar in yacc

徘徊边缘 提交于 2019-11-27 05:40:32
问题 I am trying to build a Lisp grammar. Easy, right? Apparently not. I present these inputs and receive errors... ( 1 1) 23 23 23 ui ui This is the grammar... %% sexpr: atom {printf("matched sexpr\n");} | list ; list: '(' members ')' {printf("matched list\n");} | '('')' {printf("matched empty list\n");} ; members: sexpr {printf("members 1\n");} | sexpr members {printf("members 2\n");} ; atom: ID {printf("ID\n");} | NUM {printf("NUM\n");} | STR {printf("STR\n");} ; %% As near as I can tell, I