Goldie Homepage

Documentation (v0.3)
Goldie -> Documentation (v0.3) -> API Reference -> class Language

class Language

module goldie.lang

This class corresponds to a loaded CGT file. This is used for dynamic-style.

readonly property string filename
The path and name of the CGT file this Language was loaded from.
readonly property string name
readonly property string ver
readonly property string author
readonly property string about
readonly property bool caseSensitive
Meta-data about the language from the CGT file. See GOLD's CGT documentation for more information.
readonly property Symbol[] symbolTable
readonly property CharSet[] charSetTable
readonly property Rule[] ruleTable
readonly property DFAState[] dfaTable
readonly property LALRState[] lalrTable

readonly property int startSymbolIndex
readonly property int initialDFAState
readonly property int initialLALRState

readonly property int eofSymbolIndex
readonly property int errorSymbolIndex

The actual language-defining information in the CGT file. See GOLD's CGT documentation for more information.

Note: Since D1 doesn't support immutability, the table properties return a DUPLICATE of the actual table to prevent any changes. These tables can be large, so if you access a table more than once, it is highly recommended that you cache the table once and only use the cached table. This quirk will be fixed when Goldie moves to D2.

readonly property string[] uniqueSymbolNames
Returns an array of all valid symbol names. If multiple Symbols exist with the same name, the name is only included in the array once.
readonly property Symbol eofSymbol
Returns the Symbol for end-of-file.
readonly property Symbol errorSymbol
Returns the Symbol for error.
Parser parseFileX(string filename)

Loads a file, lexes and parses it with a new Lexer and a new Parser, and returns the Parser which can then be used to obtain the parsing (and lexing) results or can be reused to parse something else.

Throws a ParseException if the source contains an error.

Parser parseCodeX(string source, string filename="")

Creates a new Parser and a new Lexer, uses them to lex and parse "source", and returns the Parser which can then be used to obtain the parsing (and lexing) results or can be reused to parse something else.

Throws a ParseException if the source contains an error.

The filename from which the source originated can be provided so the error messages upon any parsing or lexing errors can report the filename.

Parser parseTokensX(Token[] tokens, string filename="", Lexer lexerUsed=null)

Usually just called by the other parse functions.

Creates a new Parser, uses it to parse an already-lexed array of Tokens, and returns the Parser which can then be used to obtain the parsing results or can be reused to parse something else.

Throws a ParseException if the source contains an error.

The filename from which the source originated can be provided so the error messages upon any parsing errors can report the filename.

The Lexer that was used can be provided so that the Parser returned can provide access to the lexing results.

Lexer lexFileX(string filename)

Usually just called by the parse functions.

Loads a file, lexes it with a new Lexer, and returns the Lexer which can then be used to obtain the lexing results or can be reused to lex something else.

Throws a LexException if the source contains an error.

Lexer lexCodeX(string source, string filename="")

Usually just called by the parse functions.

Creates a new Lexer, uses it to lex "source", and returns the Lexer which can then be used to obtain the lexing results or can be reused to lex something else.

Throws a LexException if the source contains an error.

The filename from which the source originated can be provided so the error messages upon any lexing errors can report the filename.

Symbol[] symbolsByName(string name)

Returns an array of all Symbols with the name "name".

Note that GOLD allows multiple symbols with the same name as long as each symbol is of a different symbol type.

SymbolType[] symbolTypesByName(string name)
Just like symbolsByName except this only returns the SymbolTypes of each symbol, rather than the Symbols themselves.
string symbolTypesStrByName(string name)
Like symbolTypesByName, but returns a human-readable list in string form.
int ruleIdOf(string parentSymbol, string[] subSymbols...)

Returns an index into ruleTable given the name of the reduction symbol and the names of the symbols being reduced.

For example, if your grammar has a rule like this:

<Add Exp> ::= <Add Exp> '+' <Mult Exp>

Then you can retrieve the corresponding ""Rule"" like this:

myLang.ruleTable[ myLang.ruleIdOf("<Add Exp>", "<Add Exp>", "+", "<Mult Exp>") ]

Throws if such a rule doesn't exist or if any of the given symbol names are ambiguous (ie, if more than one symbol exists with the given name).

Note: This is just a quick-n-dirty implementation at the moment. It works, but it probably runs slow.

bool isSymbolNameValid(string name)
Returns true if AT LEAST one Symbol exists with the given name.
bool isSymbolNameAmbiguous(string name)

Returns true if MORE THAN one Symbol exists with the given name.

Note that GOLD allows multiple symbols with the same name as long as each symbol is of a different symbol type.

module {user-specified package}.lang

{languageName} = Name of static-style language

This is the static-style counterpart to Language, and is generated by the StaticLang tool.

If the name of a language is foo (for example), then the name of this class will be Language_foo.

All of the Language members are available, but alternate versions are added.

static const string staticName
static const string staticVer
static const string staticAuthor
static const string staticAbout
static const bool staticCaseSensitive

static const Symbol[] staticSymbolTable
static const CharSet[] staticCharSetTable
static const Rule[] staticRuleTable
static const DFAState[] staticDFATable
static const LALRState[] staticLALRTable

static const int staticStartSymbolIndex
static const int staticInitialDFAState
static const int staticInitialLALRState
static const int staticEofSymbolIndex
static const int staticErrorSymbolIndex

static string[] staticUniqueSymbolNameArray
static readonly property string[] staticUniqueSymbolNames
static readonly property Symbol staticEofSymbol
static readonly property Symbol staticErrorSymbol

static bool staticIsSymbolNameValid(string name)
static bool staticIsSymbolNameAmbiguous(string name)
Compile-time counterparts to the corresponding Language members.
Parser_{languageName} parseFile(string filename)
Parser_{languageName} parseCode(string source, string filename="")
Parser_{languageName} parseTokens(Token[] tokens, string filename="", Lexer lexerUsed=null)
Lexer_{languageName} lexFile(string filename)
Lexer_{languageName} lexCode(string source, string filename="")

Type-safe static-style counterparts to the respective "X"-suffixed lex and parse functions in Language.

module {user-specified package}.lang

Language_{languageName} language_{languageName}

A pre-instantiated instance of a Language_{languageName}, generated by StaticLang and only created for static-style languages.

For example, if the name of a language is foo, then the declaration of this will be:

Language_foo language_foo;