Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
Aseba::Compiler Class Reference

Aseba Event Scripting Language compiler. More...

#include <compiler.h>

List of all members.

Classes

struct  SubroutineDescriptor
 Description of a subroutine. More...
struct  Token
 A token is a parsed element of inputs. More...

Public Types

typedef std::map< std::wstring,
int > 
ConstantsMap
 Lookup table for constant name => value.
typedef std::map< std::wstring,
unsigned > 
EventsMap
 Lookup table for event name => id.
typedef std::map< std::wstring,
unsigned > 
FunctionsMap
 Lookup table for functions (name => id in target description)
typedef std::set< unsigned > ImplementedEvents
 Lookup table to keep track of implemented events.
typedef std::map< std::wstring,
unsigned > 
SubroutineReverseTable
 Reverse Lookup table for subroutines name => id.
typedef std::vector
< SubroutineDescriptor
SubroutineTable
 Lookup table for subroutines id => (name, address, line)
typedef std::map< std::wstring,
std::pair< unsigned, unsigned > > 
VariablesMap
 Lookup table for variables name => (pos, size))

Public Member Functions

bool compile (std::wistream &source, BytecodeVector &bytecode, unsigned &allocatedVariablesCount, Error &errorDescription, std::wostream *dump=0)
 Compiler ()
 Constructor. You must setup a description using setTargetDescription() before any call to compile().
const TargetDescriptiongetTargetDescription () const
const VariablesMapgetVariablesMap () const
void setCommonDefinitions (const CommonDefinitions *definitions)
 Set the common definitions, such as events or some constants.
void setTargetDescription (const TargetDescription *description)
 Set the description of the target as returned by the microcontroller. You must call this function before any call to compile().
void setTranslateCallback (ErrorMessages::ErrorCallback newCB)

Static Public Member Functions

static std::wstring translate (ErrorCode error)

Protected Member Functions

void allocateTemporaryMemory (const SourcePos varPos, const unsigned size, unsigned &varAddr)
AssignmentNodeallocateTemporaryVariable (const SourcePos varPos, Node *rValue)
void buildMaps ()
 Build variables and functions maps.
bool constantExists (const std::wstring &name) const
 Return true if a constant of a given name exists.
void disassemble (BytecodeVector &bytecode, const PreLinkBytecode &preLinkBytecode, std::wostream &dump) const
 Disassemble a microcontroller bytecode and dump it.
void dumpTokens (std::wostream &dest) const
 Debug print of tokens.
std::wstring eventName (unsigned eventId) const
 Return the name of an event given its identifier.
void expect (const Token::Type &type) const
 Check if next token is of type, produce an exception otherwise.
int expectAbsoluteInt16Literal (bool negative) const
 Check if next token is the absolute part of a 16 bits signed integer literal. If so, return it, if not, throw an exception.
unsigned expectAnyEventId () const
 Check if next token is a known local or global event identifier.
int expectConstant () const
 Check if next toxen is a valid 16 bits signed integer constant.
int expectConstantExpression (SourcePos pos, Node *tree)
unsigned expectGlobalEventId () const
 Check if next token is a known global event identifier.
int expectInt16LiteralOrConstant ()
 Check and return either a 16 bits signed integer or the value of a valid constant.
template<int length>
void expectOneOf (const Token::Type types[length]) const
 Check if next token is of one of the following types, produce an exception otherwise.
unsigned expectPositiveConstant () const
 Check if next toxen is a valid positive part of a 16 bits signed integer constant.
unsigned expectPositiveInt16Literal () const
 Check if next token is the positive part of a 16 bits signed integer literal. If so, return it, if not, throw an exception.
unsigned expectPositiveInt16LiteralOrConstant () const
 Check and return either the positive part of a 16 bits signed integer or the value of a valid constant.
unsigned expectUInt12Literal () const
 Check if next token is an unsigned 12 bits integer literal. If so, return it, if not, throw an exception.
unsigned expectUInt16Literal () const
 Check if next token is an unsigned 16 bits integer literal. If so, return it, if not, throw an exception.
EventsMap::const_iterator findAnyEvent (const std::wstring &name, const SourcePos &pos) const
ConstantsMap::const_iterator findConstant (const std::wstring &name, const SourcePos &pos) const
 Look for a constant of a given name, and if found, return an iterator; if not, return an exception.
FunctionsMap::const_iterator findFunction (const std::wstring &name, const SourcePos &pos) const
 Look for a function of a given name, and if found, return an iterator; if not, return an exception.
EventsMap::const_iterator findGlobalEvent (const std::wstring &name, const SourcePos &pos) const
 Look for a global event of a given name, and if found, return an iterator; if not, return an exception.
SubroutineReverseTable::const_iterator findSubroutine (const std::wstring &name, const SourcePos &pos) const
 Look for a subroutine of a given name, and if found, return an iterator; if not, return an exception.
VariablesMap::const_iterator findVariable (const std::wstring &name, const SourcePos &pos) const
 Look for a variable of a given name, and if found, return an iterator; if not, return an exception.
void freeTemporaryMemory ()
wchar_t getNextCharacter (std::wistream &source, SourcePos &pos)
void internalCompilerError () const
 There is a bug in the compiler, ask for a bug report.
template<int length>
bool isOneOf (const Token::Type types[length]) const
 Return true if next token is of the following types.
bool link (const PreLinkBytecode &preLinkBytecode, BytecodeVector &bytecode)
 Create the final bytecode for a microcontroller.
NodeparseAddExpression ()
 Parse "add_expression" grammar element.
NodeparseAnd ()
 Parse "and" grammar element.
NodeparseAssignment ()
 Parse "assignment" grammar element.
NodeparseBinaryAndExpression ()
 Parse "binary and" grammar element.
NodeparseBinaryOrExpression ()
 Parse "binary or" grammar element.
NodeparseBinaryXorExpression ()
 Parse "binary xor" grammar element.
NodeparseBlockStatement ()
 Parse "block statement" grammar element.
NodeparseCallSub ()
 Parse "subcall" grammar element, call of subroutine.
NodeparseCondition ()
 Parse "condition" grammar element.
NodeparseConstantAndVariable ()
NodeparseEmit ()
 Parse "event" grammar element.
NodeparseFor ()
 Parse "for" grammar element.
NodeparseFunctionCall ()
 Parse "function_call" grammar element.
NodeparseIfWhen (bool edgeSensitive)
 Parse "if" grammar element.
NodeparseMultExpression ()
 Parse "mult_expression" grammar element.
NodeparseNot ()
 Parse "not" grammar element.
NodeparseOnEvent ()
 Parse "onevent" grammar element.
NodeparseOr ()
 Parse "or" grammar element.
NodeparseProgram ()
 Parse "program" grammar element.
NodeparseReturn ()
 Parse "return statement" grammar element.
NodeparseShiftExpression ()
 Parse "shift_expression" grammar element.
NodeparseStatement ()
 Parse "statement" grammar element.
NodeparseSubDecl ()
 Parse "sub" grammar element, declaration of subroutine.
TupleVectorNodeparseTupleVector (bool compatibility=false)
 Parse "[ .... ]" grammar element.
NodeparseUnaryExpression ()
 Parse "unary_expression" grammar element.
NodeparseVarDef ()
 Parse "var def" grammar element.
AssignmentNodeparseVarDefInit (MemoryVectorNode *lValue)
MemoryVectorNodeparseVariable ()
unsigned parseVariableDefSize ()
NodeparseWhile ()
 Parse "while" grammar element.
bool testNextCharacter (std::wistream &source, SourcePos &pos, wchar_t test, Token::Type tokenIfTrue)
void tokenize (std::wistream &source)
NodetryParsingConstantExpression (SourcePos pos, int &constantResult)
bool verifyStackCalls (PreLinkBytecode &preLinkBytecode)
 Verify that no call path can create a stack overflow.

Protected Attributes

EventsMap allEventsMap
 all-events map
const CommonDefinitionscommonDefinitions
 common definitions, such as events or some constants
ConstantsMap constantsMap
 constants map
unsigned endVariableIndex
 (endMemory - endVariableIndex) is pointing to the first free variable at the end
unsigned freeVariableIndex
 index pointing to the first free variable
FunctionsMap functionsMap
 functions lookup
EventsMap globalEventsMap
 global-events map
ImplementedEvents implementedEvents
 list of implemented events
SubroutineReverseTable subroutineReverseTable
 subroutine reverse lookup
SubroutineTable subroutineTable
 subroutine lookup
const TargetDescriptiontargetDescription
 description of the target VM
std::deque< Tokentokens
 parsed tokens
ErrorMessages translator
VariablesMap variablesMap
 variables lookup

Detailed Description

Aseba Event Scripting Language compiler.

Definition at line 250 of file compiler.h.


Member Typedef Documentation

typedef std::map<std::wstring, int> Aseba::Compiler::ConstantsMap

Lookup table for constant name => value.

Definition at line 356 of file compiler.h.

typedef std::map<std::wstring, unsigned> Aseba::Compiler::EventsMap

Lookup table for event name => id.

Definition at line 358 of file compiler.h.

typedef std::map<std::wstring, unsigned> Aseba::Compiler::FunctionsMap

Lookup table for functions (name => id in target description)

Definition at line 339 of file compiler.h.

Lookup table to keep track of implemented events.

Definition at line 354 of file compiler.h.

typedef std::map<std::wstring, unsigned> Aseba::Compiler::SubroutineReverseTable

Reverse Lookup table for subroutines name => id.

Definition at line 352 of file compiler.h.

Lookup table for subroutines id => (name, address, line)

Definition at line 350 of file compiler.h.

typedef std::map<std::wstring, std::pair<unsigned, unsigned> > Aseba::Compiler::VariablesMap

Lookup table for variables name => (pos, size))

Definition at line 337 of file compiler.h.


Member Function Documentation

void Aseba::Compiler::allocateTemporaryMemory ( const SourcePos  varPos,
const unsigned  size,
unsigned &  varAddr 
) [protected]

Definition at line 237 of file parser.cpp.

AssignmentNode * Aseba::Compiler::allocateTemporaryVariable ( const SourcePos  varPos,
Node rValue 
) [protected]

Definition at line 249 of file parser.cpp.

void Aseba::Compiler::dumpTokens ( std::wostream &  dest) const [protected]

Debug print of tokens.

Definition at line 469 of file lexer.cpp.

std::wstring Aseba::Compiler::eventName ( unsigned  eventId) const [protected]

Return the name of an event given its identifier.

Definition at line 188 of file parser.cpp.

void Aseba::Compiler::expect ( const Token::Type type) const [protected]

Check if next token is of type, produce an exception otherwise.

Definition at line 44 of file parser.cpp.

int Aseba::Compiler::expectAbsoluteInt16Literal ( bool  negative) const [protected]

Check if next token is the absolute part of a 16 bits signed integer literal. If so, return it, if not, throw an exception.

Definition at line 87 of file parser.cpp.

unsigned Aseba::Compiler::expectAnyEventId ( ) const [protected]

Check if next token is a known local or global event identifier.

Definition at line 174 of file parser.cpp.

int Aseba::Compiler::expectConstant ( ) const [protected]

Check if next toxen is a valid 16 bits signed integer constant.

Definition at line 118 of file parser.cpp.

int Aseba::Compiler::expectConstantExpression ( SourcePos  pos,
Node tree 
) [protected]

This is a generalization of expectPositiveInt16LiteralOrConstant() Try to reduce the expression into a single figure, if not raise an exception The tree pointed by "tree" is deleted during execution, not safe to use it after

Definition at line 1217 of file parser.cpp.

unsigned Aseba::Compiler::expectGlobalEventId ( ) const [protected]

Check if next token is a known global event identifier.

Definition at line 160 of file parser.cpp.

Check and return either a 16 bits signed integer or the value of a valid constant.

Definition at line 144 of file parser.cpp.

template<int length>
void Aseba::Compiler::expectOneOf ( const Token::Type  types[length]) const [protected]

Check if next token is of one of the following types, produce an exception otherwise.

Definition at line 216 of file parser.cpp.

unsigned Aseba::Compiler::expectPositiveConstant ( ) const [protected]

Check if next toxen is a valid positive part of a 16 bits signed integer constant.

Definition at line 101 of file parser.cpp.

unsigned Aseba::Compiler::expectPositiveInt16Literal ( ) const [protected]

Check if next token is the positive part of a 16 bits signed integer literal. If so, return it, if not, throw an exception.

Definition at line 76 of file parser.cpp.

Check and return either the positive part of a 16 bits signed integer or the value of a valid constant.

Definition at line 135 of file parser.cpp.

unsigned Aseba::Compiler::expectUInt12Literal ( ) const [protected]

Check if next token is an unsigned 12 bits integer literal. If so, return it, if not, throw an exception.

Definition at line 54 of file parser.cpp.

unsigned Aseba::Compiler::expectUInt16Literal ( ) const [protected]

Check if next token is an unsigned 16 bits integer literal. If so, return it, if not, throw an exception.

Definition at line 65 of file parser.cpp.

Definition at line 232 of file parser.cpp.

wchar_t Aseba::Compiler::getNextCharacter ( std::wistream &  source,
SourcePos pos 
) [protected]

Definition at line 450 of file lexer.cpp.

Definition at line 363 of file compiler.h.

Definition at line 364 of file compiler.h.

void Aseba::Compiler::internalCompilerError ( ) const [protected]

There is a bug in the compiler, ask for a bug report.

Definition at line 38 of file parser.cpp.

template<int length>
bool Aseba::Compiler::isOneOf ( const Token::Type  types[length]) const [protected]

Return true if next token is of the following types.

Definition at line 204 of file parser.cpp.

Parse "add_expression" grammar element.

Definition at line 924 of file parser.cpp.

Node * Aseba::Compiler::parseAnd ( ) [protected]

Parse "and" grammar element.

Definition at line 767 of file parser.cpp.

Parse "assignment" grammar element.

Definition at line 418 of file parser.cpp.

Parse "binary and" grammar element.

Definition at line 889 of file parser.cpp.

Parse "binary or" grammar element.

Definition at line 857 of file parser.cpp.

Parse "binary xor" grammar element.

Definition at line 873 of file parser.cpp.

Parse "block statement" grammar element.

Definition at line 304 of file parser.cpp.

Parse "subcall" grammar element, call of subroutine.

Definition at line 735 of file parser.cpp.

Parse "condition" grammar element.

Definition at line 826 of file parser.cpp.

Definition at line 1079 of file parser.cpp.

Node * Aseba::Compiler::parseEmit ( ) [protected]

Parse "event" grammar element.

Definition at line 672 of file parser.cpp.

Node * Aseba::Compiler::parseFor ( ) [protected]

Parse "for" grammar element.

Definition at line 539 of file parser.cpp.

Parse "function_call" grammar element.

Definition at line 1266 of file parser.cpp.

Node * Aseba::Compiler::parseIfWhen ( bool  edgeSensitive) [protected]

Parse "if" grammar element.

Definition at line 476 of file parser.cpp.

Parse "mult_expression" grammar element.

Definition at line 943 of file parser.cpp.

Node * Aseba::Compiler::parseNot ( ) [protected]

Parse "not" grammar element.

Definition at line 783 of file parser.cpp.

Parse "onevent" grammar element.

Definition at line 656 of file parser.cpp.

Node * Aseba::Compiler::parseOr ( ) [protected]

Parse "or" grammar element.

Definition at line 751 of file parser.cpp.

Parse "program" grammar element.

Definition at line 266 of file parser.cpp.

Parse "return statement" grammar element.

Definition at line 321 of file parser.cpp.

Parse "shift_expression" grammar element.

Definition at line 905 of file parser.cpp.

Parse "statement" grammar element.

Definition at line 289 of file parser.cpp.

Parse "sub" grammar element, declaration of subroutine.

Definition at line 713 of file parser.cpp.

TupleVectorNode * Aseba::Compiler::parseTupleVector ( bool  compatibility = false) [protected]

Parse "[ .... ]" grammar element.

Definition at line 1027 of file parser.cpp.

Parse "unary_expression" grammar element.

Definition at line 962 of file parser.cpp.

Parse "var def" grammar element.

Definition at line 329 of file parser.cpp.

Definition at line 386 of file parser.cpp.

Definition at line 1096 of file parser.cpp.

unsigned Aseba::Compiler::parseVariableDefSize ( ) [protected]

Definition at line 1160 of file parser.cpp.

Node * Aseba::Compiler::parseWhile ( ) [protected]

Parse "while" grammar element.

Definition at line 631 of file parser.cpp.

Definition at line 367 of file compiler.h.

bool Aseba::Compiler::testNextCharacter ( std::wistream &  source,
SourcePos pos,
wchar_t  test,
Token::Type  tokenIfTrue 
) [protected]

Definition at line 457 of file lexer.cpp.

void Aseba::Compiler::tokenize ( std::wistream &  source) [protected]

Parse source and build tokens vector

Parameters:
sourcesource code

Definition at line 144 of file lexer.cpp.

static std::wstring Aseba::Compiler::translate ( ErrorCode  error) [inline, static]

Definition at line 368 of file compiler.h.

Node * Aseba::Compiler::tryParsingConstantExpression ( SourcePos  pos,
int &  constantResult 
) [protected]

Use parseBinaryOrExpression() and try to reduce the result into an integer If successful, return NULL and the integer in constantResult If unsuccessful, return the parsed tree (constantResult useless in this case)

Definition at line 1197 of file parser.cpp.


Member Data Documentation

all-events map

Definition at line 458 of file compiler.h.

common definitions, such as events or some constants

Definition at line 464 of file compiler.h.

constants map

Definition at line 456 of file compiler.h.

unsigned Aseba::Compiler::endVariableIndex [protected]

(endMemory - endVariableIndex) is pointing to the first free variable at the end

Definition at line 462 of file compiler.h.

unsigned Aseba::Compiler::freeVariableIndex [protected]

index pointing to the first free variable

Definition at line 461 of file compiler.h.

functions lookup

Definition at line 455 of file compiler.h.

global-events map

Definition at line 457 of file compiler.h.

list of implemented events

Definition at line 454 of file compiler.h.

subroutine reverse lookup

Definition at line 460 of file compiler.h.

subroutine lookup

Definition at line 459 of file compiler.h.

description of the target VM

Definition at line 463 of file compiler.h.

std::deque<Token> Aseba::Compiler::tokens [protected]

parsed tokens

Definition at line 452 of file compiler.h.

Definition at line 466 of file compiler.h.

variables lookup

Definition at line 453 of file compiler.h.


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


aseba
Author(s): Stéphane Magnenat
autogenerated on Thu Jan 2 2014 11:17:17