2
votes

I'm trying to write a native Node.js parser using Flex/Bison. There are three parts to the addon: the lexer, the parser, and the node/v8 interface. The lexer and the parser were working well in the beginning (I used g++ to compile the lexer/parser and included the necessary lexer functions like this: http://tldp.org/HOWTO/Lex-YACC-HOWTO-5.html). When I added the node/v8 section into the mix, I ended up getting a missing symbol error for a function defined in the lexer code.

Here's an overview of the file structure:

File A: Lexer file, automatically generated by flex from the lexer rules I wrote.

File B: The parser file, includes the extern "C" { [lexer functions] } and 
        a function called parse(std::string). parse() calls some yy_functions, 
        which are defined in the lexer, and returns a c++ data structure 
        representing the parsed data.

File C: This is the node/v8 part. There is a header file with the prototype for 
        B's parse() function. When JS calls a certain function, the data is 
        converted to a c++ string and passed to the parse() function in File B.

When I run a simple test to parse a JS string, I get an error saying

node: symbol lookup error: /home/monty/projects/flex_bison/GetObj_Request_Parser/build/default/GetObjParser.node: undefined symbol: yy_scan_string

Note: I'm using node-waf to build the addon and I've renamed the files generated by flex and bison from [FILE].c to [FILE].cc so that the build script picks them up.

If you would like to see some code, you can find it all here: https://github.com/IDX-io/GetObj_Request_Parser (look in the src/buildstuffs dir).

File A = src/buildstuffs/lex.yy.c[c]
File B = src/buildstuffs/geto.tab.c[c]
File C = src/buildstuffs/GetObjParser.cc
Test = test.js

Thanks!

[EDIT] Instead of using two different compilers and messing around with the node-waf build script (my solution), one could probably use flex++ and bison++ to generate C++.

2
Is the Makefile missing from your git tree?sarnold
I don't think this should have been tagged w/ Adobe Flex; but rather gnu-flex. I retagged it.JeffryHouser
@sarnold, the Makefile is wscript in the root directory. @flextras, thanks for the retagBen Montgomery
@www, pity the [flex] tag goes to the much newer project, by all rights it ought to be [adobeflex] :) but thanks for retagging, the overlap bugged me to no end.sarnold

2 Answers

1
votes

renaming the files to .cc will generally cause default make rules to build using c++ instead of c. That could mean that the linkage is wrong on the functions in the lex.yy.c file. I think you need to figure out another way to make the node build system recognize your .c files and build them properly with as c, not c++

1
votes

Get rid of the extern "C" at the top of your geto.y file. The flex functions aren't being exported with C-linkage.