Goldie: struct Symbol

Goldie
Parsing System (v0.9)
Goldie Home (v0.9)
Getting Started

- Requirements
- Download / Install
- Never Used a Parsing Tool?
- Goldie Overview
- Beginner's Tutorial
- Grammar Definition Language
- Contact / Support
  - Message Board
  - Issue Tracking

Goldie's Tools

- AlterCGT
- DumpCGT
- GenDocs
  - Template Format
- GRMC: Grammar Compiler
- JsonViewer
  - Parse Tree Mode
- Parse
- StaticLang
- Other Tools

GoldieLib Overview

- Static And Dynamic Styles
- Ambiguous Symbols

GoldieLib Reference

- Base
- Exception
- class Language
- class Lexer
- class Parser
- struct Symbol
- class Token
- Ver

GoldieLib Sample Apps

- Calculator Static
- Calculator Dynamic
- Sample Generic Parse

CGT File Format
FAQ
Change Log
If You Use Git Master
Future Work
Developers

- Scripts for Developers
- Library Source and StaticLang

Goldie Home (v0.9) -> GoldieLib Reference -> struct Symbol

# struct Symbol

- enum SymbolType
- struct Symbol
- Module-Level Members

See also the explanation of Tokens vs Symbols.

module goldie.base

enum SymbolType
NonTerminal
Terminal
Whitespace
EOF
CommentStart
CommentEnd
CommentLine
Error

EOF and Error symbols (there is exactly one of each in every language) are automatically created when a grammar is compiled. A Whitespace symbol is automatically defined if the grammar doesn't already define one.

Symbols of the other SymbolType values are defined by a grammar.

All SymbolType values except for NonTerminal are technically considered to be terminals (and tokens of these symbols are created by the Lexer instead of the Parser), although the actual SymbolType.Terminal value is only used for "normal" terminals (ie., ones that don't match any of the other SymbolType values).

module goldie.base

struct Symbol
string name

The name of the symbol, as defined in a language's grammar. For nonterminals, this includes the surrounding < and >.

For example, in a grammar, <If Statement> ::= 'if' would define a nonterminal symbol with a name of <If Statement>.

SymbolType type
The type of symbol.
int id
The ID of the symbol. This is an index into Language.symbolTable.
string toString()
The result of this is valid D code representing a struct literal. For example:
auto sym = Symbol("foo", SymbolType.Terminal, 7); assert(sym.toString() == `Symbol("foo",SymbolType.Terminal,7)`);

module goldie.base

Module-Level Members
string symbolTypeToString(SymbolType type)
Example:
string str = symbolTypeToString(SymbolType.NonTerminal); assert(str == "NonTerminal");
string fullSymbolTypeToString(SymbolType type)
Example:
string str = fullSymbolTypeToString(SymbolType.NonTerminal); assert(str == "SymbolType.NonTerminal");
string symbolTypesToString(SymbolType[] types)
Example:
auto symTypes = [SymbolType.Terminal, SymbolType.NonTerminal, SymbolType.Terminal]; string str = symbolTypesToString(symTypes); assert(str == "Terminal, NonTerminal, Terminal");
string[] symbolTypesToStrings(SymbolType[] types)
Example:
auto symTypes = [SymbolType.Terminal, SymbolType.NonTerminal, SymbolType.Terminal]; auto strings = symbolTypesToStrings(symTypes); assert(strings.length == 3); assert(strings[0] == "Terminal"); assert(strings[1] == "NonTerminal"); assert(strings[2] == "Terminal");