Skip to main content

module Grammar

rascal-0.34.0

A simple but effective internal format for the representation of context-free grammars.

Usage

import Grammar;

Dependencies

extend ParseTree;

data Grammar

The Grammar datatype

data Grammar  
= \grammar(set[Symbol] starts, map[Symbol sort, Production def] rules)
;

Grammar is the internal representation (AST) of syntax definitions used in Rascal. A grammar is a set of productions and set of start symbols. The productions are stored in a map for efficient access.

data GrammarModule

data GrammarModule  
= \module(str name, set[str] imports, set[str] extends, Grammar grammar)
;

data GrammarDefinition

data GrammarDefinition  
= \definition(str main, map[str name, GrammarModule \mod] modules)
;

function grammar

Grammar grammar(set[Symbol] starts, set[Production] prods)

Grammar grammar(type[&T <: Tree] sym)

data Item

An item is an index into the symbol list of a production rule.

data Item  
= item(Production production, int index)
;

function compose

Compose two grammars.

Grammar compose(Grammar g1, Grammar g2)

Compose two grammars by adding the rules of g2 to the rules of g1. The start symbols of g1 will be the start symbols of the resulting grammar.

function extends

rel[str, str] extends(GrammarDefinition def)

function imports

rel[str,str] imports(GrammarDefinition def)