Skip to content
clemahieu edited this page Jan 24, 2013 · 12 revisions

Audience

This page is intended for language developers looking to extend mu's parsing engine. The reader will need a full understanding of formal grammars and parsing topics.

Summary

The purpose of the parser is to convert the sequence of tokens from the Lexing Engine in to an abstract syntax tree of nodes to be passed to an Analysis Engine

The primary goals of the parser are:

  • Efficiency - Parsing of a sequence of tokens is a serial task, the less time spent parsing the better
  • Extensibility - Extensions to the grammar for any purpose should be easy and efficient with minimal restrictions

Parser extensibility

The parser is extended for the purpose of creating keywords or key-prefixes out of identifiers. Extensions are associated with either complete identifiers, a non-covering extension, or identifiers with a specific prefix, a covering extension. For efficiency reasons, only complete identifiers or identifier prefixes can be used to extend the parsing grammar. Extensions are able to inspect the tokens following itself for special meaning.

Covering extensions

Covering extensions are associated with an identifier prefix and when an identifier is found with this prefix, the identifier contents after the prefix is given to the extension. Take for instance the hypothetical covering extension with a prefix 'int' which uses the trailing characters to specify a bit-width and yields an integer type node.

The following identifiers would be processed by the extension:
int32 -- Receives '32'
int16 -- Receives '16'
int -- Receives '' Extension would signal an error, no bit width specified
int% -- Receives '%' Extension would signal an error, unable to parse bit width

Non-covering extensions

Non-covering extensions are associated with a whole identifier, when this identifier is found, the extension is called. Take for instance the hypothetical non-covering extension 'double' that yields a 64-bit double type node.

The extension would be called when encountering the following identifier:
double

The extension would not be called when encountering the following identifiers:
double_variable
double64

Clone this wiki locally