[Compilation principle] (1) FLEX+BOSIN environment construction (VS Code version)

foreword

In fact, it was just to participate in the competition, and I didn't learn the principles of compilation at all, but I still have to bite the bullet, there is no way. But since I have to learn, at least I have to record some things for everyone to take a look at, otherwise, if I don’t win the prize in the end and have nothing, wouldn’t it be a loss.

Why use VS Code?

It's not that I want to use VS Code, but that VS is too big for me. And in fact, after using it too much, you will find that everything is based on the command line, so in the end I chose VS Code, which is a really lightweight editor. But unfortunately, there is no corresponding tutorial on the Internet. This is adapted from the tutorial on using Flex+Bison on Code Blocks. There may be something wrong, and I hope everyone can point it out.

Preparation

My environment here is Windows, and the Flex and Bison environments of the corresponding Linux system are easy to configure. This suggestion is direct to Baidu.
First of all, we give the download URL: click to download .
After downloading, we can get win_flex_bison-latestthe folder. At this time, we can add this folder to the environment variable or put it under the directory we want to use.
Of course, I put it under my own directory here (this is related to subsequent VS Code configuration issues, so please pay attention).

VS Code file configuration

First of all, I will post my configuration for everyone to see.

{
    
    
	// See https://go.microsoft.com/fwlink/?LinkId=733558
	// for the documentation about the tasks.json format
	"version": "2.0.0",
	"tasks": [
		//Flex编译命令
		{
    
    
			"label": "flex Complier",
			"command": "win_flex_bison-latest\\win_flex.exe",
			"args": [
				"-o",
				"${fileBasenameNoExtension}.flex.cpp",
				"--wincompat",
				"${file}"
			], // 编译命令参数
			"problemMatcher": {
    
    
				"owner": "l",
				"fileLocation": [
					"relative",
					"${workspaceRoot}"
				],
				"pattern": {
    
    
					"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
					"file": 1,
					"line": 2,
					"column": 3,
					"severity": 4,
					"message": 5
				}
			}
		},
		//Bison编译命令
		{
    
    
			"label": "bison Complier",
			"command": "win_flex_bison-latest\\win_bison.exe",
			"args": [
				"--output=${fileBasenameNoExtension}.tab.cpp",
				"--defines=${fileBasenameNoExtension}.tab.h",
				"${file}"
			], 
			"problemMatcher": {
    
    
				"owner": "y",
				"fileLocation": [
					"relative",
					"${workspaceRoot}"
				],
				"pattern": {
    
    
					"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
					"file": 1,
					"line": 2,
					"column": 3,
					"severity": 4,
					"message": 5
				}
			}
		}
	]
}

You can see "command": "win_flex_bison-latest\\win_bison.exe",the directory problem corresponding to the two commands in the above. If you choose to configure the environment variable in [Preparation], it is obviously solved by a direct sum, but I did not configure the environment variable here win_bison.exe. win_flex.exeMy current directory arrangement is as follows:
directory arrangement
So it is not difficult to understand why what I wrote here is "command": "win_flex_bison-latest\\win_bison.exe",right.

Compile and run

In VS Code, press to Ctrl + Shift + Pcall out the task menu, enter Run Task, select Flex Complieror Bison Complier(select the corresponding task for the corresponding file), and the corresponding Cpp can be generated. At this time, compile or h header file. At this time, everyone should know what to do!

Guess you like

Origin blog.csdn.net/qq_19577209/article/details/107229609