Parser Class Reference

#include <parser.h>

Collaboration diagram for Parser:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Parser (Microbe *mb)
 ~Parser ()
void mistake (Microbe::MistakeType type, const QString &context=0)
ParsercreateChildParser ()
CodeparseWithChild (const SourceLineList &lines)
Codeparse (const SourceLineList &lines)
SourceLineList getBracedCode (SourceLineList::const_iterator *it, SourceLineList::const_iterator end)
ExprType getExpressionType (const QString &expression)
bool processAssignment (const QString &line)
void compileConditionalExpression (const QString &expression, Code *ifCode, Code *elseCode) const
QString processConstant (const QString &expression, bool *isConstant, bool suppressNumberTooBig=false) const

Static Public Member Functions

static bool isLiteral (const QString &text)
static int literalToInt (const QString &literal, bool *ok=0)
static int doArithmetic (int lvalue, int rvalue, Expression::Operation op)

Detailed Description

Author:
Daniel Clarke

David Saxton

Definition at line 194 of file parser.h.


Member Function Documentation

void Parser::mistake ( Microbe::MistakeType  type,
const QString &  context = 0 
)

Report a compile error to Microbe; the current source line will be sent. Context is extra information to be inserted into the error message, only applicable to some errors (such as a use of a reserved keyword).

Definition at line 723 of file parser.cpp.

References Microbe::compileError().

Referenced by parse(), and processAssignment().

Parser * Parser::createChildParser (  ) 

Creates a new instance of the parser class with all state information (class members) copied from this instance of the class. Don't forget to delete it when you are done!

Definition at line 145 of file parser.cpp.

References Parser().

Referenced by parseWithChild().

Code * Parser::parseWithChild ( const SourceLineList &  lines  ) 

Creates a child class and uses it to parse recursively.

Definition at line 153 of file parser.cpp.

References createChildParser(), and parse().

Code * Parser::parse ( const SourceLineList &  lines  ) 

This is the actual parsing function, make sure to use parseUsingChild instead (???)

TODO sanity check label name and then do error like "Bad label"

Definition at line 161 of file parser.cpp.

References Code::append(), Field::compulsory(), getBracedCode(), Field::key(), Microbe::makePic(), mistake(), processAssignment(), Microbe::resetDest(), PIC14::setCode(), PIC14::setParser(), PIC14::Slabel(), Field::string(), Statement::text(), SourceLine::text(), and Field::type().

Referenced by Microbe::compile(), and parseWithChild().

SourceLineList Parser::getBracedCode ( SourceLineList::const_iterator *  it,
SourceLineList::const_iterator  end 
)

Returns the lines between the braces, excluding the braces, e.g. defproc name { more code some more code } returns ("more code","some more code"). Note that Microbe has already put the braces on separate lines for us.

Parameters:
it is the iterator at the position of the first brace, this function will return with it pointing at the matching closing brace.
end is the iterator pointing to the end of the source line list, so that we don't search past it.
Returns:
The braced code (excluding the braces).

Definition at line 514 of file parser.cpp.

Referenced by parse().

ExprType Parser::getExpressionType ( const QString &  expression  ) 

Returns expression type. 0 = directly usable number (literal). 1 = variable. 2 = expression that needs evaluating.

bool Parser::isLiteral ( const QString &  text  )  [static]

Examines the text to see if it looks like a literal, i.e. of the form "321890","021348","0x3C","b'0100110'","0101001b","h'43A'", or "2Ah". Everything else is considered non-literal.

See also:
literalToInt.

Definition at line 793 of file parser.cpp.

References literalToInt().

int Parser::literalToInt ( const QString &  literal,
bool *  ok = 0 
) [static]

Tries to convert the given literal string into a integer. If it fails, i.e. it is not any recognised literal, then it returns -1 and sets *ok to false. Else, *ok is set to true and the literal value is returned.

See also:
isLiteral

Definition at line 812 of file parser.cpp.

Referenced by isLiteral().

int Parser::doArithmetic ( int  lvalue,
int  rvalue,
Expression::Operation  op 
) [static]

Does the specified operation on the given numbers and returns the result.

Definition at line 762 of file parser.cpp.

Referenced by BTreeBase::pruneTree().

bool Parser::processAssignment ( const QString &  line  ) 

Returns:
whether it was an assignment (which might not have been in the proper form).

Definition at line 430 of file parser.cpp.

References Microbe::addVariable(), Microbe::alias(), PIC14::isValidPort(), PIC14::isValidTris(), Microbe::isValidVariableName(), mistake(), Variable::name(), PIC14::saveResultToVar(), PIC14::Ssetlh(), PIC14::SsevenSegment(), PIC14::Stristate(), Statement::tokenise(), PIC14::toPortPin(), Variable::type(), and Microbe::variable().

Referenced by parse().

void Parser::compileConditionalExpression ( const QString &  expression,
Code ifCode,
Code elseCode 
) const

Definition at line 842 of file parser.cpp.

Referenced by PIC14::Sfor(), PIC14::Sif(), PIC14::Srepeat(), and PIC14::Swhile().


The documentation for this class was generated from the following files:
Generated on Tue May 8 17:05:51 2007 for KTechLab by  doxygen 1.5.1