BenchCookie  0.0.1
A simple, intuitive open source language.
Command Class Reference

#include <command.h>

Public Types

enum  cmd_type {
  READ_STRING, READ_INT, PRINT, PRINT_STR,
  PRINT_NUM, INTGETS, EXPR, DECL_INT,
  DECL_DOUBLE, DECL_STRING, DECL_BOOL, STRINGGETS,
  PRINT_BOOL, BEGIN_IF, END_IF, BEGIN_FOR,
  END_FOR, PTRGETS, ENDFUNC, NOPRINT,
  READ_LINE
}
 
enum  exp_type {
  ADD, SUB, MUL, DIV,
  MOD, AN_INT, VAR, ASIGN,
  RESULT, LOGOR, LOGXOR, LOGAND,
  BITOR, BITXOR, NEQ, BITAND,
  EQ, GT, GEQ, LT,
  LEQ, SHIFTR, SHIFTL, LOGNOT,
  COMP, UPLUS, UMINUS, PTRDEREF,
  LITERAL
}
 
enum  var_type {
  HINT, DINT, HDOUBLE, HFLOAT,
  HBOOL, LSTRING, DSTRING, HCHAR,
  DCHAR
}
 

Public Member Functions

 Command ()
 
void addPrintInt (char *arg)
 Add a command to print a number. More...
 
void addPrintString (char *arg)
 Add a string to be printed. More...
 
void addPrintLiteral (char *arg)
 Add a literal to be printed. More...
 
void addToArgList (char *, char *)
 Adds a variable to a function's argument list. More...
 
void addLiteral (char *arg)
 Add a literal to be printed. More...
 
void addToReturnList (char *)
 Add a variable to the current function's return list. More...
 
void addReadInt (char *arg)
 Add a command to read an integer. More...
 
void addReadString (char *arg)
 Add a read string command. More...
 
void addReadLine (char *arg)
 Add a read-line command. More...
 
void declDouble (char *arg)
 
void declString (char *arg)
 Declare a string variable. More...
 
void declBool (char *arg)
 
void declInt (char *arg)
 Declare an integer variable. More...
 
void declPointer (char *dom, char *cod)
 Declare a pointer. More...
 
void addIntAssignment (char *arg)
 Add int assignment command. More...
 
void addToExpressionStack (char *arg)
 Add to expression stack. More...
 
void markFunctionEnding ()
 
void markEndOfExpression ()
 Mark the end of an expression. More...
 
void markForLoop (char *arg)
 Mark the beginning of a for loop. More...
 
void markEndFor ()
 Mark the end of a for loop. More...
 
void startFunctionBody (char *arg)
 Start a function's body. More...
 
void markEndOfFunction ()
 Mark the end of a function. More...
 
void setFunctionName (char *arg)
 Set the current function's name. More...
 
void setFilename (const std::string &_filename)
 
void setCFunc (const bool &_is_c_callable)
 
void writeAssembly ()
 
void startIfBlock ()
 Mark the beginning of an if block. More...
 
void endIfBlock ()
 Mark the end of an if block. More...
 
const bool & isCCallable ()
 
void exitWithBug ()
 

Static Public Attributes

static std::string current_string
 
static Command cmd
 
static ssize_t line_num = 0
 

Detailed Description

Definition at line 55 of file command.h.

Member Enumeration Documentation

Enumerator
READ_STRING 
READ_INT 
PRINT 
PRINT_STR 
PRINT_NUM 
INTGETS 
EXPR 
DECL_INT 
DECL_DOUBLE 
DECL_STRING 
DECL_BOOL 
STRINGGETS 
PRINT_BOOL 
BEGIN_IF 
END_IF 
BEGIN_FOR 
END_FOR 
PTRGETS 
ENDFUNC 
NOPRINT 
READ_LINE 

Definition at line 60 of file command.h.

Enumerator
ADD 
SUB 
MUL 
DIV 
MOD 
AN_INT 
VAR 
ASIGN 
RESULT 
LOGOR 
LOGXOR 
LOGAND 
BITOR 
BITXOR 
NEQ 
BITAND 
EQ 
GT 
GEQ 
LT 
LEQ 
SHIFTR 
SHIFTL 
LOGNOT 
COMP 
UPLUS 
UMINUS 
PTRDEREF 
LITERAL 

Definition at line 65 of file command.h.

Enumerator
HINT 
DINT 
HDOUBLE 
HFLOAT 
HBOOL 
LSTRING 
DSTRING 
HCHAR 
DCHAR 

Definition at line 69 of file command.h.

Constructor & Destructor Documentation

Command::Command ( )
inline

Definition at line 58 of file command.h.

Member Function Documentation

void Command::addIntAssignment ( char *  varname)

Add int assignment command.

The command evaluates the top of the expression stack, then puts the result in the variable varname.

Parameters
varnameName of the variable.

Definition at line 340 of file command.cc.

void Command::addLiteral ( char *  arg)

Add a literal to be printed.

This differs from addPrintLiteral in that this literal is not to be printed. This adds a literal for expressions, such as x <– op = "+" ?.

Parameters
argString to be printed

Definition at line 56 of file command.cc.

void Command::addPrintInt ( char *  _int)

Add a command to print a number.

Benchcookie Compiler

This file sets up the compiler to generate the machine code. The contents of this file are architecture independent. This function adds the requested variable name to the vector holding all printed integers and informs the execution order vector that it should print this integer.

Parameters
_intVariable name to be printed.

Definition at line 18 of file command.cc.

void Command::addPrintLiteral ( char *  arg)

Add a literal to be printed.

Parameters
argVariable name to be printed.

Definition at line 41 of file command.cc.

void Command::addPrintString ( char *  arg)

Add a string to be printed.

Parameters
argVariable name to be printed.
See also
addPrintInt

Definition at line 30 of file command.cc.

void Command::addReadInt ( char *  arg)

Add a command to read an integer.

Parameters
argVariable to store the read integer.

Definition at line 67 of file command.cc.

void Command::addReadLine ( char *  arg)

Add a read-line command.

Parameters
argVariable to store the read line.

Definition at line 78 of file command.cc.

void Command::addReadString ( char *  arg)

Add a read string command.

Parameters
argThe variable in which to store the string.

Definition at line 326 of file command.cc.

void Command::addToArgList ( char *  type,
char *  name 
)

Adds a variable to a function's argument list.

This is currently just used for C Functions.

Parameters
typetypename
namename of the parameter.

Definition at line 92 of file command.cc.

void Command::addToExpressionStack ( char *  arg)

Add to expression stack.

Parameters
argComponent to add to expression.

Definition at line 258 of file command.cc.

void Command::addToReturnList ( char *  arg)

Add a variable to the current function's return list.

Parameters
argThe variable to return.

Definition at line 240 of file command.cc.

void Command::declBool ( char *  arg)
void Command::declDouble ( char *  arg)
void Command::declInt ( char *  arg)

Declare an integer variable.

Parameters
argName of the variable.

Definition at line 125 of file command.cc.

void Command::declPointer ( char *  dom,
char *  cod 
)

Declare a pointer.

The pointer will be pointed to cod and stored in the variable dom.

Parameters
domVariable holding the pointer.
codVariable to which we are pointing.

Definition at line 153 of file command.cc.

void Command::declString ( char *  arg)

Declare a string variable.

Parameters
argName of the variable.

Definition at line 137 of file command.cc.

void Command::endIfBlock ( )

Mark the end of an if block.

Definition at line 212 of file command.cc.

void Command::exitWithBug ( )
inline

Definition at line 118 of file command.h.

const bool& Command::isCCallable ( )
inline

Definition at line 112 of file command.h.

void Command::markEndFor ( )

Mark the end of a for loop.

Definition at line 228 of file command.cc.

void Command::markEndOfExpression ( )

Mark the end of an expression.

This function marks the end of the expression and clears the currentExpression stack. We clear this because it will be used in setting up the next expression evaluation. Before clearing, the expression is added to the list of all evals.

Definition at line 114 of file command.cc.

void Command::markEndOfFunction ( )

Mark the end of a function.

Definition at line 233 of file command.cc.

void Command::markForLoop ( char *  arg)

Mark the beginning of a for loop.

Parameters
argVariable upon which this loop depends.

Definition at line 219 of file command.cc.

void Command::markFunctionEnding ( )
void Command::setCFunc ( const bool &  _is_c_callable)
inline

Definition at line 104 of file command.h.

void Command::setFilename ( const std::string &  _filename)
inline

Definition at line 101 of file command.h.

void Command::setFunctionName ( char *  arg)

Set the current function's name.

Parameters
argName of the function.

Definition at line 250 of file command.cc.

void Command::startFunctionBody ( char *  arg)

Start a function's body.

Todo:
This is still to be implemented.
Parameters
argFunction name.

Definition at line 196 of file command.cc.

void Command::startIfBlock ( )

Mark the beginning of an if block.

Definition at line 204 of file command.cc.

void Command::writeAssembly ( )

Free locals

Todo:
Free locals when last used. Maybe change file to a list and search for last usage?

: printf is a toilet.

Toilet has been flushed

Todo:

Load the values into r0, r1, r2, r3 as necessary.

Definition at line 508 of file arm_compiler.cpp.

Member Data Documentation

Command Command::cmd
static

Definition at line 115 of file command.h.

std::string Command::current_string
static

Definition at line 114 of file command.h.

ssize_t Command::line_num = 0
static

Definition at line 116 of file command.h.


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