Syntax Parser

Sprout uses nested key-value pair low level code to store object metadata descriptions and program code. A “create table” statement:

CREATE TABLE TBL
 (
  I INT,
  T TEXT
 );

In nested key-value code is converted to:

-- +/- preceeding a key signifies nesting of the following pairs
-- ; delimiter
0A="TBL";
+0B="I";
 0B="T";

The purpose of syntax parser is to convert high level program code into key-value format. The process includes running error checks and committing to Sprout database error-free, pre-compiled source.

Example of parsing a “loop” statement:

-- three part loop statement
for (initialization, condition, afterthought)
{
  ...
}

-- example
for (i=0; i < 10; i++) loop
  {
    ...
  }

When a program is loaded the parser iterates over delimited commands. Each command is matched with its envelope containing conversion characteristics. The process is performed in a PL/pgSQL function. To process a loop statement the following key codes exist the table COMMANDS and the interpreter.

SELECT * FROM COMMANDS
;
COMMAND_HEX | DESCRIPTION
==============================
         00 | 'root'
         01 | 'variable'
         02 | 'scalar'
         03 | 'operand'
         A0 | 'for cycle'
         A1 | 'initialization'
         A2 | 'condition'
         A3 | 'afterthought'
         E0 | 'operator'

Nested key-value pair code of the ‘for … loop’ example:

// parse "for loop" command
SELECT parse("for (i=0; i < 10; i++)")
;
parse
==================
A0;                           // loop header
 +A1;                         // loop initialization
  +01=i;                      // - variable i
   +02=0;                     // - value of variable i
  --                          // two left indents
  A2;                         // loop condition
  +01=i;                      // - variable i
   03=<;                      // - less than
   02=10;                     // - value 10
  -                           // one left indent
  A3;                         // loop afterthought
  +01=i;                      // - variable i
   +E0=++;                    // - is assigned operator ++

Sprout may support various high level syntax specifications.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s