How to successfully Compile lab1_example_solution1?中山大学软件工程学院编译原理实验1,南京大学编译原理实验,c-- (In English)

目录

To make this code.

Compilation Steps:

Testing the Parser:

Expected Outcome

Explanation in detail

Why can you omit -ly?

What is the result of omitting -ly?


To make this code.

Compilation Steps:
  1. Open your Makefile and locate the following line:

$(CC) -o parser $(filter-out $(LFO),$(OBJS)) -lfl -ly

Replace it with:

$(CC) -o parser $(filter-out $(LFO),$(OBJS)) -lfl
  1. Save the changes and run the make command in your terminal.

UPDATE:It would be a better choice to install the correct libraty function.

sudo apt-get install libbison-dev

Testing the Parser:

To test the parser, you'll need to specify a real file name in place of "self_test" in the following command:

./parser ../Test/self_test.cmm

For example, to test with a file named 2.cmm, you would run:

./parser ../Test/2.cmm

Expected Outcome

If everything is set up correctly, you should see successful output indicating that the parser has processed the input file without any issues.

Explanation in detail

The syntax.tab.c file is generated by Bison and is part of the parser for your language or data format. This file typically includes all the necessary code to parse the input according to the grammar defined in .y file. Therefore, it's often self-contained and doesn't require linking against an external yacc or Bison library (liby.a or liby.so).

Why can you omit -ly?

The -ly flag is used to link against the yacc library, which is often not necessary when you're using Bison, especially if you're not using any yacc-specific libraries or features. The Bison-generated code is usually self-contained, meaning it includes everything it needs to function. Therefore, you can often omit the -ly flag without any issues.

What is the result of omitting -ly?

If you omit -ly and your code doesn't depend on any external yacc or Bison libraries, then your program should compile and run just fine. You won't notice any difference in functionality; the parser should work as expected.

If your code does depend on some features provided by the yacc library, then omitting -ly would result in linker errors. However, given that you're already encountering linker errors complaining about not finding -ly, and you're using Bison, it's likely safe to try omitting it.

猜你喜欢

转载自blog.csdn.net/weixin_64123373/article/details/133379846