MIXAL
Public Member Functions | Public Attributes | Friends | List of all members
mixal::ParsedResult Class Reference

#include <parser.h>

Public Member Functions

 ParsedResult ()
 
bool evaluate (const std::unordered_map< std::string, AtomicValue > &constants)
 
bool evaluated () const
 

Public Attributes

ParsedType parsedType
 
std::string rawLocation
 
Expression location
 
std::string operation
 
std::string rawAddress
 
Expression address
 
std::string rawIndex
 
Expression index
 
std::string rawField
 
Expression field
 
ComputerWord word
 
std::string comment
 
friend Parser
 

Friends

std::ostream & operator<< (std::ostream &out, const ParsedResult &result)
 

Detailed Description

The parsed result.

Definition at line 32 of file parser.h.

Constructor & Destructor Documentation

◆ ParsedResult()

mixal::ParsedResult::ParsedResult ( )
inline

Initialize the parsed result with empties.

Definition at line 48 of file parser.h.

48  : parsedType(ParsedType::EMPTY),
49  rawLocation(), location(),
50  operation(),
51  rawAddress(), address(),
52  rawIndex(), index(),
53  rawField(), field(),
54  word(), comment() {}

Member Function Documentation

◆ evaluate()

bool mixal::ParsedResult::evaluate ( const std::unordered_map< std::string, AtomicValue > &  constants)

Evaluate base address, index, and field expressions.

Definition at line 45 of file parser.cpp.

45  {
46  if (rawAddress.length() > 0 && !evaluateAddress(constants)) {
47  return false;
48  }
49  if (rawIndex.length() > 0 && !evaluateIndex(constants)) {
50  return false;
51  }
52  if (rawField.length() > 0 && !evaluateField(constants)) {
53  return false;
54  }
55  return true;
56 }

References rawAddress, rawField, and rawIndex.

Referenced by mixal::Computer::executeSingle().

◆ evaluated()

bool mixal::ParsedResult::evaluated ( ) const

Whether the instruction has been evaluated.

Definition at line 99 of file parser.cpp.

99  {
100  if (rawAddress.length() > 0 && !address.evaluated()) {
101  return false;
102  }
103  if (rawIndex.length() > 0 && !index.evaluated()) {
104  return false;
105  }
106  if (rawField.length() > 0 && !field.evaluated()) {
107  return false;
108  }
109  return true;
110 }

References address, mixal::Expression::evaluated(), field, index, rawAddress, rawField, and rawIndex.

Referenced by mixal::Computer::executeSingle().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const ParsedResult result 
)
friend

Output the instruction.

Definition at line 112 of file parser.cpp.

112  {
113  if (result.location.evaluated()) {
114  out << result.location.result().value << '\t';
115  } else {
116  out << result.rawLocation << '\t';
117  }
118  out << result.operation << '\t';
119  if (!result.rawAddress.empty()) {
120  if (result.address.evaluated()) {
121  out << result.address.result().value;
122  } else {
123  out << result.address;
124  }
125  }
126  if (!result.rawIndex.empty()) {
127  if (result.index.evaluated()) {
128  out << ',' << result.index.result().value;
129  } else {
130  out << ',' << result.index;
131  }
132  }
133  if (!result.rawField.empty()) {
134  if (result.field.evaluated()) {
135  out << '(' << result.field.result().value << ')';
136  } else {
137  out << '(' << result.field << ')';
138  }
139  }
140  return out;
141 }

Member Data Documentation

◆ address

Expression mixal::ParsedResult::address

The parsed base address expression.

Definition at line 39 of file parser.h.

Referenced by evaluated(), mixal::Computer::executeSingle(), mixal::operator<<(), and mixal::Parser::parseLine().

◆ comment

std::string mixal::ParsedResult::comment

The comments.

Definition at line 45 of file parser.h.

Referenced by mixal::Parser::parseLine().

◆ field

Expression mixal::ParsedResult::field

The parsed field expression.

Definition at line 43 of file parser.h.

Referenced by evaluated(), mixal::Computer::executeSingle(), mixal::operator<<(), and mixal::Parser::parseLine().

◆ index

Expression mixal::ParsedResult::index

The parsed index expression.

Definition at line 41 of file parser.h.

Referenced by evaluated(), mixal::Computer::executeSingle(), mixal::operator<<(), and mixal::Parser::parseLine().

◆ location

Expression mixal::ParsedResult::location

The location expression.

Definition at line 36 of file parser.h.

Referenced by mixal::operator<<().

◆ operation

std::string mixal::ParsedResult::operation

Raw string of the operation name.

Definition at line 37 of file parser.h.

Referenced by mixal::operator<<(), and mixal::Parser::parseLine().

◆ parsedType

ParsedType mixal::ParsedResult::parsedType

Type of the parsed result.

Definition at line 34 of file parser.h.

Referenced by mixal::Computer::executeSingle(), and mixal::Parser::parseLine().

◆ rawAddress

std::string mixal::ParsedResult::rawAddress

Raw string of the base address.

Definition at line 38 of file parser.h.

Referenced by evaluate(), evaluated(), mixal::operator<<(), and mixal::Parser::parseLine().

◆ rawField

std::string mixal::ParsedResult::rawField

Raw string of the field.

Definition at line 42 of file parser.h.

Referenced by evaluate(), evaluated(), mixal::operator<<(), and mixal::Parser::parseLine().

◆ rawIndex

std::string mixal::ParsedResult::rawIndex

Raw string of the index.

Definition at line 40 of file parser.h.

Referenced by evaluate(), evaluated(), mixal::operator<<(), and mixal::Parser::parseLine().

◆ rawLocation

std::string mixal::ParsedResult::rawLocation

Raw string of the location name.

Definition at line 35 of file parser.h.

Referenced by mixal::operator<<(), and mixal::Parser::parseLine().

◆ word

ComputerWord mixal::ParsedResult::word

The converted computer word that represents the instruction.

Definition at line 44 of file parser.h.

Referenced by mixal::Computer::executeSingle(), mixal::Computer::executeSinglePesudo(), and mixal::Parser::parseLine().


The documentation for this class was generated from the following files:
mixal::ParsedResult::field
Expression field
Definition: parser.h:43
mixal::ParsedResult::rawLocation
std::string rawLocation
Definition: parser.h:35
mixal::ParsedResult::rawAddress
std::string rawAddress
Definition: parser.h:38
mixal::ParsedResult::word
ComputerWord word
Definition: parser.h:44
mixal::ParsedResult::rawField
std::string rawField
Definition: parser.h:42
mixal::ParsedResult::comment
std::string comment
Definition: parser.h:45
mixal::Expression::evaluated
bool evaluated() const
Definition: expression.h:144
mixal::ParsedResult::index
Expression index
Definition: parser.h:41
mixal::ParsedResult::location
Expression location
Definition: parser.h:36
mixal::ParsedResult::rawIndex
std::string rawIndex
Definition: parser.h:40
mixal::ParsedResult::parsedType
ParsedType parsedType
Definition: parser.h:34
mixal::ParsedResult::operation
std::string operation
Definition: parser.h:37
mixal::ParsedResult::address
Expression address
Definition: parser.h:39