how to use yy_scan_string in lex

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; }

Yacc equivalent for Java

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.

Lex/Yacc for C#?

I’ve done a couple of small projects with GPLEX/GPPG, which are pretty straightforward reimplementations of LEX/YACC in C#. I’ve not used any of the other tools above, so I can’t really compare them, but these worked fine. GPPG can be found here and GPLEX here. That being said, I agree, a full LEX/YACC solution probably … Read more

String input to flex lexer

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): scans a NUL-terminated string` YY_BUFFER_STATE yy_scan_bytes(const char *bytes, int len): scans len bytes (including possibly NULs) starting at location bytes Note that both of these functions create, return a corresponding YY_BUFFER_STATE … Read more

How to compile LEX/YACC files on Windows?

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 … Read more

Thread-safe / reentrant bison + flex

1. Sample code A kind of explanation of how reentrancy is configured into bison and flex is provided in section 2 of this answer. Other annotations of the sample code are in section 3. 1.1 eval.l %option noinput nounput noyywrap 8bit nodefault %option yylineno %option reentrant bison-bridge bison-locations %{ #include <stdlib.h> #include <string.h> #include “eval.tab.h” … Read more

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

Parsing C++ is extremely hard because the grammar is undecidable. To quote Yossi Kreinin: Outstandingly complicated grammar “Outstandingly” should be interpreted literally, because all popular languages have context-free (or “nearly” context-free) grammars, while C++ has undecidable grammar. If you like compilers and parsers, you probably know what this means. If you’re not into this kind … Read more