Finite State Machine parsing configuration file

Source: Internet
Author: User

Finite State Machine is a powerful tool for text processing. The theory of finite state machine is complicated, but in actual text processing applications,

You only need to understand the finite state machine model and understand the state transfer relationship to quickly write the program.

 

Such as parsing the network configuration file (similar to the format of the/etc/sysconfig/network-scripts/ifcfg-eth0 file)

The format is as follows: (the behavior comment line starts with #. Valid configuration characters include numbers, letters, and periods)

 

# This is a net work Config File

Ipaddr = 192.168.1.71

Netmask = 255.255.255.0

Gateway = 192.168.1.1

 

We can define four states:

1. Initial status

2. Key status. This status is displayed when the configuration key is read.

3. Value status. This status is displayed when the configuration value is read.

4. delim status, that is, the delimiter between key and Value

 

The status transition diagram is as follows: (for parsing configuration files such as XML and ini, the status transition diagram is much more complex)

 

 

The specific implementation is as follows: (c)

 

Parse_config.rar

 

Parse_ini.rar (INI file parser)

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.