Mercury.Formats library  1.0
The library provides format parsers for the Mercury library components.
 All Classes Namespaces Files Functions Properties
Public Member Functions | List of all members
Mercury.Formats.Basic.GrammarParser Class Reference

Parses a grammar from a StreamReader. Grammar is expected in the format More...

Inheritance diagram for Mercury.Formats.Basic.GrammarParser:

Public Member Functions

 GrammarParser (StreamReader reader)
 Creates a parser that will parse grammar from provided StreamReader instance. More...
 
 GrammarParser (string filename)
 Initializes a new instance of the GrammarParser class. More...
 
GrammarBuilder GetBuilder ()
 Parses the file provided by the constructor's argument and returns the builder. More...
 
void Dispose ()
 

Detailed Description

Parses a grammar from a StreamReader. Grammar is expected in the format

       # comment            
       [root    Root]       
       [epsilon e   ]
       LHS -> RHS0 [| RHS1]*
          [|? RHS2        ] 
    


where LHS -> RHS is complaint to the conditions of class Mercury.Syntax.Rule and symbols of RHS are delimited by space.

Escape characters:
", \', |, \, [space]

Aggregated rules are rules of the form LHS -> RHS1 | RHS2; the notation is equivalent to LHS -> RHS1 and LHS -> RHS2. They can take more than one line. The next line can (but is not required to) start with RHS sparator '|'.

Grammar header (lines before first rule) can specify Root symbol and epsilon symbol in format
root Root
epsilon e
then the Root will be used as Root Nonterminal and e will be used as epsilon symbol. If those lines are missing, symbols from Mercury.Defaults will be used.

Example Grammar:

    # Expression language
    # i.e. (1 + (5 / 3))
    # Header
    root Expr
    # Rules
    Expr -> (Expr @Op Expr) | @Number
    @Op  -> + | - | * | /                                      
    

Definition at line 59 of file GrammarParser.cs.

Constructor & Destructor Documentation

Mercury.Formats.Basic.GrammarParser.GrammarParser ( StreamReader  reader)

Creates a parser that will parse grammar from provided StreamReader instance.

Parameters
readerThe source reader
Exceptions
System.ArgumentNullExceptionWhen provided stream is null

Definition at line 79 of file GrammarParser.cs.

Mercury.Formats.Basic.GrammarParser.GrammarParser ( string  filename)

Initializes a new instance of the GrammarParser class.

Parameters
filenameThe file name.

Definition at line 90 of file GrammarParser.cs.

Member Function Documentation

void Mercury.Formats.Basic.GrammarParser.Dispose ( )

Definition at line 210 of file GrammarParser.cs.

GrammarBuilder Mercury.Formats.Basic.GrammarParser.GetBuilder ( )

Parses the file provided by the constructor's argument and returns the builder.

Returns
The grammar builder.
Exceptions
System.FormatException

Definition at line 188 of file GrammarParser.cs.


The documentation for this class was generated from the following file: