Lex and yacc

Source: Internet
Author: User
Lex and yacc-Linux general technology-Linux programming and kernel information. The following is a detailed description. Author: brilliant and dusty

I recently read GCC-the-Complete-Reference-fly to know that there are two interesting tools, lex and yacc, and these two tools are installed by default in fedora core 8, so I would like to take this opportunity to learn about the yacc term when I used to learn compilation principles. But I never thought about what yacc is. There are too many things to learn, it's really hard to learn.

Start with lex. Lex, also known as Lexical Analyzar, performs Lexical analysis on the source program. If you have learned how to compile, you will know the process of converting the source code from a text file to an executable binary file. The first two steps are lexical analysis and syntax analysis. Lex matches the input according to the specified mode. When a rule is matched, the corresponding action is executed.

A Lex program is divided into three sections: the first section is the global declaration of C and Lex, the second section includes the mode (C code), and the third section is the supplementary C function. For example, the third section usually contains the main () function. These segments are separated by %.

The following is a lex program for counting words.
QUOTE:
Related Article

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.