Tutorial

In this tutorial we will generate a lexical analyzer and parser using Soul 5.1.0 for a string that contains a list of fruit names such as

(apple, orange, banana)

The generated lexer will tokenize the input string and the parser will consume the tokens and make a structured representation of the input.

Probably the easiest and fastest way to create a new application using Soul 5.1.0 is to add it to the soul.sln solution:

Now the program should compile, so right-click the the fruits project and select Build .

Generating a lexical analyzer

First we will create tokens that the lexical analyzer will return when the fruit list is scanned:

Next we will create a lexer project file that references the token file:

Now we can create C++ code for the token declarations by running the lexer generator slg :

In this fruit list language the identifier of each fruit is also a keyword , that is: a reserved word. So next we will create a file for the keywords:

Now we can update the lexical analyzer's project file fruits.slg :

Next we will create regular expressions for fruit name identifiers and whitespace seperator characters:

Again we can update the lexer project file fruits.slg :

We will now complete the fruit list lexical analyzer by adding a lexer file fruits.lexer :

Finally we complete the lexical analyzer's project file fruits.slg :

Now the lexer generator will generate various binary and text files:

Generating a parser

First we will generate an abstract syntax tree classes for parsed fruits:

Adding parser file:

The parser file has following structure:

Now a parser project file can be created:

Now we can generate C++ source code for the parser:

Now we can add the generated files to the fruits C++ project:

We will now complete the main program:

Now we will edit the program configuration:

Now you can build the fruits project for the x64 | Debug and x64 | Release configurations.

Testing:

This completes the tutorial.