Combine Lex, YACC (FLEX, bison) and MFC!

Source: Internet
Author: User

Recently, Lex and bison have been used to write some things. It is quite convenient to combine them. After using lex and bison to complete core analysis and processing, we will surely embed these into our own projects and combine them with other functions. However, many errors may occur at this time.

Lex and bison generate C source programs by default, and both have their own syntax rules. Sometimes there are some conflicts with VC, but these problems can be solved as long as some definitions are modified.

1. yyerror () function, which can be written directly at the end of the YACC file. However, the declaration of yyerror () must be pre-declared in VC, that is, the declaration part of yyerror () must be placed in the first part of the YACC file.
2. The isatty () function didn't use MFC, so I didn't even pay attention to this stuff. The console program generated by Lex and bison ran very well, but after MFC was added, this function suddenly jumped out, it is not defined. As a result, <Io. h> Y is also included. I am not very clear about the specific reasons.
3. data exchange issues. Lex and YACC use the keyboard by default. Therefore, a new buffer must be created for Lex. Here you can create a new file as the buffer, or use the string yy_switch_to_buffer (yy_scan_string (m_stredit.getbuffer (m_stredit.getlength (); the output result can use a global string.

In this way, we can basically use Lex in MFC. Bison brings us convenience.

The above is a bit of my experience. Mistakes and misoperations are inevitable!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.