1
votes

I am trying to build config file parser (c++ application)from scratch using tools like lex and yacc. The parser will be able to parse files like

# Sub group example
petName = Tommy
Owner = {
   pet = "%petName%"
}

Is there any step by step guide/link to articles on how to achieve this using tools like lex and yacc? The idea is I will write a class say Config (c++) with methods like getConfig(string propName). If I invoke like config.getConfig(Owner.pet), it will return me Tommy.

1
You might want to consider using a JSON library which has a similar format to what you are showing, you will just need to adapt the format of the file a bit.David Rodríguez - dribeas
What David said. Or you might consider Boost.Spirit instead of lex & yacc.Fred Larson

1 Answers

1
votes

Boost Property Tree

It was designed for configuration files. It does reading, writing in the following formats:

  • INI
  • INFO
  • XML
  • JSON

Here is the five minute tutorial page which should give you a good idea: