lex prefix undefined symbol yyparse - c

I am including two diferent lex parsers in my C code so to include the second one defined a Prefix on it:
%option prefix="prep"
When I integrated this one in the global proyect It compiles without errors but on execution, If I try to call prepparse (formerly yyparse) I get this error:
undefined symbol: prepparse
I have tried including an external reference (not quite sure if this is correct):
extern int prepparse(void);
And defining it in the Lex header:
#define yyparse prepparse
But I still get the same error.
Any idea of what I am doing wrong?

I think I got it. I have found I omited one information that has proben important. As I only wanted to alter some tokens and not defining a full language (it is only preparsing) I dind't define a Yacc file, so I was not actually a parser but a Lexer what I had to call. So the command is not preparse but preplex.
I stil don't have it working but I guess it is another different issue.

Related

How do I fix collect2 error while compiling an old MUD?

I'm trying to run make on an Ubuntu machine to compile a RoT MUD, but the farthest I've gotten is when I get a collect2: error: ld returned 1 exit status.
This is what comes immediately before the error in the terminal (along with a lot of other similar errors):
/usr/bin/ld: obj/wizlist.o:/home/lucas/Projects/R2b5/src/merc.h:3355: multiple definition of `bllmax'; obj/act_comm.o:/home/lucas/Projects/R2b5/src/merc.h:3355: first defined here
From what I've gathered this means that the header files have variable declarations in them, and that using static is an easy fix, however, I haven't been able to figure out where I should put that keyword in the code to fix this issue. The following is the only mention of bllmax in merc.h:
int bllmax, crbmax, crnmax, srpmax, mngmax;
Here is the program I'm trying to compile.
You need to learn the difference between declaration and definition. A declaration is telling the compiler that the symbol exists somewhere but possibly not here. A definition is telling the compiler that the symbol exists here.
The line you show (without any context) is defining the variables, which means they will be defined in each source file that includes the header file.
What it should do is to declare the variables, which can be done by making them extern:
extern int bllmax, crbmax, crnmax, srpmax, mngmax;
Then in a single source file define the variables (without extern).

VSCode not importing functions from other files in C language

I am going through a C course and got to the point where we #include "myfile.h"
Good news : VSCode finds "myfile.h" and can pull variables from it, such as int myvar=10;
Bad News : VSCode does not seem to identify function definition in the "myfile.c", so extern in myfunction() is seen but not defined.
This results in the following
int i = myfunction();
Compilation Error: undefined reference to 'myfunction';
How can I get VSCode to recognize and use "myfile.c"?
Answer found in ::
undefined reference error in VScode
Basically, I had to compile all my files at once. This required me going into the tasks.json file and modifying it from ${file} to ${workspaceFolder}\*.c
This is better explained in ::
https://code.visualstudio.com/docs/cpp/config-linux

Invoking two separate parsers from a C program

Say that the names of the parsers are parser_1 and parser_2.
parser_1:
Bison file = parser_1.y
Flex file = parser_1.l
After Compiling with gcc I get my paser in the following two files:
parser_1.tab.c and parser_1.lex.yy.c
Similary my parser_2 consitst of:
parser_2.tab.c and parser_2.lex.yy.c
I am trying to compile both the parsers together because me program needs both the parsers. I cannot replace the two parsers by one parser because the following two reasons. The grammars are completely different and the parsers are to be invoked at entirely different statges of my program.
gcc parser_1.tab.c parser_1.lex.yy.c \
parser_2.tab.c parser_2.lex.yy.c \
my_program.c -lfl
It gives me error that some functions like yylex (), yyparse () etc. have been defined multiple times, which is understandable.
My Question:
Is there some method by which I can have the two parsers in my program?
Or please give your suggestions.
To invoke use multiple parsers from a C program there are two methods:
Use multiple start symbols, if grammars are closely related.
For details see
http://www.gnu.org/software/bison/manual/html_node/Multiple-start_002dsymbols.html
Change the prefix yy for parser(s). This would remove all the name conflicts. A new prefix can be specified using the option -Dapi.prefix={prefix}.
You will need to modify the prefixes of the lexical analyser also, if you are using a separte lexical analyser. This can be achieved by using the --prefix=PREFIX flag.
For details about renaming in Bison see: http://www.gnu.org/software/bison/manual/html_node/Multiple-Parsers.html
For details about renaming in Flex see: http://westes.github.io/flex/manual/#Code_002dLevel-And-API-Options
In flex you will need to specify %option noyywrap as the very first line of the .l file. For details see: http://westes.github.io/flex/manual/Generated-Scanner.html#index-yywrap_0028_0029

Swig: Syntax error in input(3)

./theheader.h:349: Error: Syntax error in input(3).
Offending line:
string read_gdbm(GDBM_FILE dbf, string key_str, bool show_err = gbls.verbose);
Any ideas?
Typically, a syntax error in SWIG means that it can't understand the line in question (which can be annoying, because the line numbers don't follow macros such as %defines). So I suggest you check that string (should it be std::string? has it been defined?), GDBM_FILE (has it been defined? should it be in a namespace?) and maybe gbls.verbose (has it been defined?) make sense to SWIG. It may help to run swig with the -E option (be sure to redirect the stdout), find the corresponding line and search backward for each type involved. You may need to add some #includes.
Also check the previous line, to ensure you're not missing a semicolon, or something like that.
As a side note, I've run into the same issue for different reasons: I was trying to use a vector < vector < double >>. Now the ">>" character sequence mustn't be used with templates according to the C++99 standard, hence the swig error message popped up. The solution was to simply add an extra space to separate them.
I hit a similar error. I'll clarify my process, hope it can be helpful.
lib.i:
...
%begin %{
#include "header1.h"
%}
...
%include "header1.h"
header1.h:
19 typedef struct T {
...
23 } PACKED TlvHdr;
The error message just as below
./header1.h:23: Error: Syntax error in input(3).
I check the SWIG doc(http://www.swig.org/Doc1.3/SWIG.html 5.7.1) and found that the syntax error is so common, it's probably caused by a SWIG bug.
The doc recommended when encountering a syntax error to use #ifndef SWIG to omit statements that will make SWIG parser issue an error. So I changed the header1.h file, then the error disappeared.
header1.h:
#ifndef SWIG
19 typedef struct T {
...
23 } PACKED TlvHdr;
#endif
If you can't modify theheader.h file, you can make a new header file that just contains the declarations you need and replace the file from theheader.h to your new header file at %include directive
I had a similar issue and -E helped me understand that a macro definition was hidden inside an #ifndef SWIG block. I suspect that here it does not see the definition of GDBM_FILE, likely because it does not recurse.

problems with memset in Metal C

I’m trying to initialize the Metal C environment with the following code, but get the following errors on the memset line.
ERROR CCN3275 IMIJWS0.METAL.SAMPLIB(MEM):6 Unexpected text ')' encountered.
ERROR CCN3045 IMIJWS0.METAL.SAMPLIB(MEM):6 Undeclared identifier ___MEMSET.
ERROR CCN3277 IMIJWS0.METAL.SAMPLIB(MEM):6 Syntax error: possible missing ')' or ','?
CCN0793(I) Compilation failed for file //'IMIJWS0.METAL.SAMPLIB(MEM)'. Object file not created.
Below is my code
#include &lt string.h&gt
#include &lt stdlib.h&gt
#include &lt metal.h&gt
void mymtlfcn(void) {
struct __csysenv_s mysysenv;
memset ( &mysysenv, 0, sizeof ( mysysenv ) );
mysysenv.__cseversion = __CSE_VERSION_1;
mysysenv.__csesubpool = 129;
mysysenv.__cseheap31initsize = 131072;
mysysenv.__cseheap31incrsize = 8192;
mysysenv.__cseheap64initsize = 20;
mysysenv.__cseheap64incrsize = 1;
The issue was with the search order. Although I did search(/usr/metal/include) from with in my JCL I didn't proceed it with a nosearch option, so string.h was getting picked up from the standard system librarys instead of the version included with Metal C. I've pasted my optfile dataset I passed to the CPARM below for refference.
//OPTIONS DD *
SO
LIST
LONG
NOXREF
CSECT
METAL
LP64
NOSEARCH
search(/usr/include/metal/)
So, I have no idea. But some suggestions:
You might try copying/pasting this code here from this example just to make sure it works 'as expected'
Maybe try defining some of the macros here? (when I did C programming on zOS, I had to do include some weird macros in order to get stuff to work. I have no reasonable technical explanation for this.)
You could try searching for memset() using "=3.14" (from ispf.) See if any other modules use that function, and then check the headers that they include (or macros that they define - either in the C files or H files) to make it work.
Another thought: before the memset(), try doing putting a printf() in. If you get a syntax error on the same line (only for printf, rather than memset) then you can see if the problem is before line 6 - like a misplaced parenthesis.
Finally, if i recall correctly, I had to compile my individual modules, and then link them manually (unless I wrote a JCL to do this for me.) So you might have to link once to link with your other modules, and then link again against the C library. Not to be pedantic, but: you're fairly certain that you're doing all of the link passes?
I realize that's a lot of hoops to try and you've probably already read the manuals, but maybe there is something useful to try?
Also, and you probably already know this, but this site (for looking up error codes) is infinitely useful. (along with the above links for full-text-searching the manual)
Edit: this page also talks about "built-in functions" - you could try (as stated at the bottom of the page) "#undef memcpy" to use the non-built-in version?
Can you show us your compiler arguments? You need to make sure that you're not pulling in the standard C header files in addition to the metal C ones. Here's an example:
xlc -c -Wc,metal,longname,nosearch,'list(./)' -I. -I /usr/include/metal -I "//'SYS1.SIEAHDRV'" -S -qlanglvl=extended foo.c
as -mrent -mgoff -a=foo.list -o foo.o foo.s
ld -bac=1 -brent -S "//'SYS1.CSSLIB'" -o foo foo.o
Are you missing the closing brace '}' for the function? How about any missing semi-colon line terminators? When missing braces/semi-colons the z/OS C compiler throws some strange/misleading messages sometimes. I don't have it to try out, but I'm assuming Metal does as well.

Resources