winflexbison icon indicating copy to clipboard operation
winflexbison copied to clipboard

Encoding of lexical file and it generates flex.cpp file

Open Wzshun opened this issue 5 years ago • 4 comments

In the past, I can write UTF-8 char in my lexical file and it work well. But, after some days, maybe I change visual studio generate .cpp encoding, the VS template file? I can't remember exactly. The VS warning flex.cpp file contains a character that cannot be represented in the current code page (936). ( Chinese GB2312 ) , and compile fail, output mystery error.

So, how can I use UTF-8 char in lexical file? or how to set VS settings properly? Now I only use them in comment, so i can change them to english, and it work well, but maybe I will need to recognize them in the future.

I use flex/bison 2.4.6/2.5.6 and vs 2013. Sorry for my poor English.

Wzshun avatar Feb 13 '19 04:02 Wzshun

Sorry I don't know how to use UTF-8 input for flex. Try to google this problem.

lexxmark avatar Feb 14 '19 06:02 lexxmark

This discussion may help you

lexxmark avatar Feb 20 '19 05:02 lexxmark

This discussion may help you

I have checked it, but I means that the problem maybe in my Visual Studio 2013 settings which i don't know what will impact on Flex output.

Wzshun avatar Feb 20 '19 06:02 Wzshun

There are 2 ways to make Visual C++ treat source code as UTF-8:

  1. add argument /source-charset:utf-8 in the command line (the "command-line" settings in the project)
  2. add BOM to the source (.cpp) file

If you want to use utf-8 in both execution charset and source charset, you can add argument /utf-8 in the compiler command line.

taoyouh avatar Dec 27 '22 03:12 taoyouh