Gorgon Game Engine
Gorgon::Scripting::Compilers Namespace Reference

This namespace contains compliers and any utilities related with it. More...

Classes

class  ASTCompiler
 ASTCompiler stores states for AST compiler. More...
 
class  ASTNode
 Represents a node in abstract syntax tree. More...
 
class  Base
 The base class for compilers. More...
 
class  Intermediate
 Intermediate language complier. More...
 
class  Programming
 Programming dialect compiler. More...
 

Functions

void ASTToSVG (const std::string &line, ASTNode &tree, const std::vector< std::string > &compiled={}, bool show=false)
 Converts given AST to an SVG file. More...
 
template<class ... P_>
int CheckInputFor (const std::string &input, int &ch, P_ ...args)
 Checks if the input string contains one of the given characters at current point. More...
 
Value compilevalue (ASTNode &tree, std::vector< Instruction > *list, Byte &tempind, bool generateoutput=true)
 
std::string Disassemble (const Instruction &inst)
 Disassembles the given instruction. More...
 
std::string Disassemble (const Instruction *)
 Disassembles the given instruction. More...
 
void Disassemble (InputSource &source, std::ostream &out)
 Disassembles entire input source to the given stream. More...
 
void Disassemble (Scope &scope, std::ostream &out)
 
std::string disassemblevalue (const Value &value)
 
std::string dottree (ASTNode &tree, int &ind)
 
std::string ExtractQuotes (const std::string &input, int &ch)
 Extracts a string that is in quotes. More...
 
int GetPrecedence (const std::string &op)
 Returns the precedence of the given operator. More...
 
void PrintAST (ASTNode &tree)
 Recursively prints an AST. More...
 

Variables

MappedReferenceType< std::vector< Instruction >, &ToEmptyStringinstructionlisttype ("#instructionlist", "")
 

Detailed Description

This namespace contains compliers and any utilities related with it.

Function Documentation

◆ ASTToSVG()

void ASTToSVG ( const std::string &  line,
ASTNode tree,
const std::vector< std::string > &  compiled = {},
bool  show = false 
)

Converts given AST to an SVG file.

This function requires GraphViz dot to be in path. The SVG will be saved as temp.dot.svg in the current directory.

Parameters
linethe source code line
treeto be converted
compiledparameter can be used to add disassembly to the tree
showif set, the generated SVG will be opened

References dottree(), Gorgon::OS::Open(), Gorgon::String::Replace(), and Gorgon::OS::Start().

◆ CheckInputFor()

int Gorgon::Scripting::Compilers::CheckInputFor ( const std::string &  input,
int &  ch,
P_ ...  args 
)

Checks if the input string contains one of the given characters at current point.

If it does the index of the character found is returned and index is incremented. If not, an exception is thrown

◆ compilevalue()

◆ Disassemble() [1/4]

std::string Gorgon::Scripting::Compilers::Disassemble ( const Instruction inst)

Disassembles the given instruction.

References Disassemble().

◆ Disassemble() [2/4]

◆ Disassemble() [3/4]

void Gorgon::Scripting::Compilers::Disassemble ( InputSource &  source,
std::ostream &  out 
)

Disassembles entire input source to the given stream.

◆ Disassemble() [4/4]

void Gorgon::Scripting::Compilers::Disassemble ( Scope scope,
std::ostream &  out 
)

◆ disassemblevalue()

◆ dottree()

◆ ExtractQuotes()

std::string Gorgon::Scripting::Compilers::ExtractQuotes ( const std::string &  input,
int &  ch 
)

Extracts a string that is in quotes.

This function supports both single and double quotes. Additionally, this function transforms following escape sequences \", \', \n, and \xx, where xx is an hexadecimal digit. Notice that \0 is not valid, it should be given as \00.

References CheckInputFor().

◆ GetPrecedence()

int Gorgon::Scripting::Compilers::GetPrecedence ( const std::string &  op)

Returns the precedence of the given operator.

If the given string is not an operator returns -1

◆ PrintAST()

void PrintAST ( ASTNode tree)

Variable Documentation

◆ instructionlisttype

MappedReferenceType<std::vector<Instruction>, &ToEmptyString> instructionlisttype("#instructionlist", "")