Posts

Showing posts with the label libyaml

YAML syntax processing in C with libyaml and lemon parser generator (part 2)

Image
In previous part of the blog we have created the basis of the program. In this part we will work on lemon parser grammar file "parser.y". Lemon is an application that can be installed from packages (comes almost with all Linux distributions), with Homebrew on Mac OS. Or you can build it from the sources. It is to find in Internet how to do that.  When lemon is installed, we can run command "lemon" with a path to the grammar file as an argument.  Using Makefile will much improve our build process: We can simply run "make" command in our working directory and it will generate the parser .c and .h files. Libyaml wiki has a grammar explained for events: http://pyyaml.org/wiki/LibYAML#Events This is basically the same for tokens. Let's start with a very minimal ( minimum minimorum ) YAML syntax (file minimum.yaml):   key : value If we run now our program, we will have this in output: Here, the "key" and the ...

YAML syntax processing in C with libyaml and lemon parser generator (part 1)

Image
This article continues previous blog on YAML data serialization format processing with C. I have mentioned there that libyaml perfectly fits to be used with parser generators like GNU bison, yacc or lemon. Usually, these tools are used with lexical analyser (flex, lex) that parses input sequence of bytes (text) and produces tokens for parser. In case of YAML the C library "libyaml" is do the job. Libyaml can scan YAML file or stream and produces events or tokens. In this article I will try use libyaml with lemon parser to implement YAML processing. Sure thing, bison and yacc can be used too. Let's with simple function that will use libyaml to scan file. For that I took the example from "libyaml" wiki:  http://pyyaml.org/wiki/LibYAML#ParserAPISynopsis Here what I got for the bootstrap main.c file: Note that here we use function "yaml_parser_scan" that produces tokens. To compile the scenario we can run command: # gcc main.c -...

YAML documents parsing with libyaml in C

YAML markup standard (or human-readable data serialization language as it stands in wikipedia ) is widely used these days as alternative to XML, JSON or others. Anybody who does some ruby-on-rails uses YAML configuration for database connection. It is simple, but in the same time, flexible standard which definitely should replace outdated formats like INI. YAML is supported by lots of programming languages. Check projects list at yaml.org .