yacc

String input to flex lexer

一笑奈何 提交于 2019-11-27 03:47:34
I want to create a read-eval-print loop using flex/bison parser. Trouble is, the flex generated lexer wants input of type FILE* and i would like it to be char*. Is there anyway to do this? One suggestion has been to create a pipe, feed it the string and open the file descriptor and send to the lexer. This is fairly simple but it feels convoluted and not very platform independent. Is there a better way? The following routines are available for setting up input buffers for scanning in-memory strings instead of files (as yy_create_buffer does): YY_BUFFER_STATE yy_scan_string(const char *str) :

How to compile LEX/YACC files on Windows?

谁都会走 提交于 2019-11-26 23:40:41
I'm having Lex and YACC files to parse my files ( .l file and .y file). How to compile those files and how to make equivalent .c file for them in windows platform? As for today (2011-04-05, updated 2017-11-29) you will need the lastest versions of: flex-2.5.4a-1.exe bison-2.4.1-setup.exe After that, do a full install in a directory of your preference without spaces in the name . I suggest C:\GnuWin32 . Do not install it in the default (C:\Program Files (x86)\GnuWin32) because bison has problems with spaces in directory names, not to say parenthesis. Also, consider installing Dev-CPP in the

Include struct in the %union def with Bison/Yacc

夙愿已清 提交于 2019-11-26 22:53:58
问题 I am trying to include a struct as part of the union with Bison, but I get an error on the 'struct node args' in %union: parser.y:17: error: field ‘args’ has incomplete type The Code: struct node { char * val; struct node * next; }; %} %union { char * string; struct node args; } %token <string> CD WORD PWD EXIT %type <args> arg_list Anyone know what I am doing wrong? 回答1: Even better, use the %code directive with the "requires" option, i.e.: %code requires { struct node { char * val; struct

Good tools for creating a C/C++ parser/analyzer [closed]

旧街凉风 提交于 2019-11-26 18:14:51
What are some good tools for getting a quick start for parsing and analyzing C/C++ code? In particular, I'm looking for open source tools that handle the C/C++ preprocessor and language. Preferably, these tools would use lex/yacc (or flex/bison) for the grammar, and not be too complicated. They should handle the latest ANSI C/C++ definitions. Here's what I've found so far, but haven't looked at them in detail (thoughts?): CScope - Old-school C analyzer. Doesn't seem to do a full parse, though. Described as a glorified 'grep' for finding C functions. GCC - Everybody's favorite open source

how to use yy_scan_string in lex

余生长醉 提交于 2019-11-26 16:46:33
问题 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. 回答1: 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

Yacc equivalent for Java

坚强是说给别人听的谎言 提交于 2019-11-26 15:46:23
问题 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. 回答1: 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. 回答2: In the past,

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

前提是你 提交于 2019-11-26 14:22:44
问题 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? 回答1: 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

Good tools for creating a C/C++ parser/analyzer [closed]

天大地大妈咪最大 提交于 2019-11-26 12:15:42
问题 What are some good tools for getting a quick start for parsing and analyzing C/C++ code? In particular, I\'m looking for open source tools that handle the C/C++ preprocessor and language. Preferably, these tools would use lex/yacc (or flex/bison) for the grammar, and not be too complicated. They should handle the latest ANSI C/C++ definitions. Here\'s what I\'ve found so far, but haven\'t looked at them in detail (thoughts?): CScope - Old-school C analyzer. Doesn\'t seem to do a full parse,

String input to flex lexer

故事扮演 提交于 2019-11-26 09:35:27
问题 I want to create a read-eval-print loop using flex/bison parser. Trouble is, the flex generated lexer wants input of type FILE* and i would like it to be char*. Is there anyway to do this? One suggestion has been to create a pipe, feed it the string and open the file descriptor and send to the lexer. This is fairly simple but it feels convoluted and not very platform independent. Is there a better way? 回答1: The following routines are available for setting up input buffers for scanning in

How to compile LEX/YACC files on Windows?

廉价感情. 提交于 2019-11-26 08:48:27
问题 I\'m having Lex and YACC files to parse my files ( .l file and .y file). How to compile those files and how to make equivalent .c file for them in windows platform? 回答1: As for today (2011-04-05, updated 2017-11-29) you will need the lastest versions of: flex-2.5.4a-1.exe bison-2.4.1-setup.exe After that, do a full install in a directory of your preference without spaces in the name . I suggest C:\GnuWin32 . Do not install it in the default (C:\Program Files (x86)\GnuWin32) because bison has