MIXAL
parser.h
Go to the documentation of this file.
1 #ifndef INCLUDE_PARSER_H_
2 #define INCLUDE_PARSER_H_
3 
4 #include <string>
5 #include <stdexcept>
6 #include <unordered_map>
7 #include "instructions.h"
8 #include "expression.h"
9 #include "memory.h"
10 #include "errors.h"
11 
17 namespace mixal {
18 
20 enum class ParsedType {
21  EMPTY,
22  INSTRUCTION,
23  PSEUDO,
24 };
25 
27 std::ostream& operator<<(std::ostream& os, ParsedType c);
28 
29 class Parser;
30 
32 class ParsedResult {
33  public:
35  std::string rawLocation;
37  std::string operation;
38  std::string rawAddress;
40  std::string rawIndex;
42  std::string rawField;
45  std::string comment;
49  rawLocation(), location(),
50  operation(),
51  rawAddress(), address(),
52  rawIndex(), index(),
53  rawField(), field(),
54  word(), comment() {}
55 
57  bool evaluate(const std::unordered_map<std::string, AtomicValue>& constants);
59  bool evaluated() const;
60 
61  friend Parser;
63  friend std::ostream& operator<<(std::ostream& out, const ParsedResult& result);
64 
65  private:
67  bool evaluateAddress(const std::unordered_map<std::string, AtomicValue>& constants, int32_t index = 0);
69  bool evaluateIndex(const std::unordered_map<std::string, AtomicValue>& constants, int32_t index = 0);
71  bool evaluateField(const std::unordered_map<std::string, AtomicValue>& constants, int32_t index = 0);
72 };
73 
74 class Parser {
75  public:
82  static ParsedResult parseLine(const std::string& line, const std::string& lineSymbol, bool hasLocation = true);
83 };
84 
85 }; // namespace mixal
86 
87 #endif // INCLUDE_PARSER_H_
expression.h
To parse the expressions.
mixal::ParsedType
ParsedType
Definition: parser.h:20
mixal::ComputerWord
Definition: memory.h:25
mixal::Parser
Definition: parser.h:74
mixal::ParsedResult::field
Expression field
Definition: parser.h:43
mixal::ParsedResult::rawLocation
std::string rawLocation
Definition: parser.h:35
errors.h
The definition of some errors.
mixal::Parser::parseLine
static ParsedResult parseLine(const std::string &line, const std::string &lineSymbol, bool hasLocation=true)
Definition: parser.cpp:143
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::ParsedResult::index
Expression index
Definition: parser.h:41
mixal::ParsedResult::operator<<
friend std::ostream & operator<<(std::ostream &out, const ParsedResult &result)
Definition: parser.cpp:112
mixal::ParsedResult
Definition: parser.h:32
mixal::ParsedResult::evaluated
bool evaluated() const
Definition: parser.cpp:99
mixal::ParsedResult::location
Expression location
Definition: parser.h:36
instructions.h
Definitions of instructions.
mixal::ParsedResult::evaluate
bool evaluate(const std::unordered_map< std::string, AtomicValue > &constants)
Definition: parser.cpp:45
mixal::ParsedResult::ParsedResult
ParsedResult()
Definition: parser.h:48
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::Expression
Definition: expression.h:103
memory.h
The definition of a computer word.
mixal::ParsedResult::address
Expression address
Definition: parser.h:39