├── .gitignore ├── CMakeLists.txt ├── Compiler.cpp ├── Compiler.hpp ├── File.cpp ├── File.hpp ├── LICENSE ├── README.md ├── Test ├── Addition.qx ├── Calc.qx ├── Deg.qx ├── Division.qx ├── Multiplication.qx └── Subtraction.qx ├── Token.cpp ├── Token.hpp ├── TokenType.hpp ├── main.cpp └── stinc.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | ### C template 2 | # Object files 3 | *.o 4 | *.ko 5 | *.obj 6 | *.elf 7 | 8 | # Precompiled Headers 9 | *.gch 10 | *.pch 11 | 12 | # Libraries 13 | *.lib 14 | *.a 15 | *.la 16 | *.lo 17 | 18 | # Shared objects (inc. Windows DLLs) 19 | *.dll 20 | *.so 21 | *.so.* 22 | *.dylib 23 | 24 | # Executables 25 | *.exe 26 | *.out 27 | *.app 28 | *.i*86 29 | *.x86_64 30 | *.hex 31 | 32 | # Debug files 33 | *.dSYM/ 34 | ### C++ template 35 | # Compiled Object files 36 | *.slo 37 | *.lo 38 | *.o 39 | *.obj 40 | 41 | # Precompiled Headers 42 | *.gch 43 | *.pch 44 | 45 | # Compiled Dynamic libraries 46 | *.so 47 | *.dylib 48 | *.dll 49 | 50 | # Fortran module files 51 | *.mod 52 | 53 | # Compiled Static libraries 54 | *.lai 55 | *.la 56 | *.a 57 | *.lib 58 | 59 | # Executables 60 | *.exe 61 | *.out 62 | *.app 63 | 64 | # Created by .ignore support plugin (hsz.mobi) 65 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The Quantum Project 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | cmake_minimum_required(VERSION 3.0) 17 | project(QCL_Compiler) 18 | 19 | add_compile_options(-std=c++11) 20 | set(SOURCE_FILES 21 | main.cpp 22 | Token.cpp 23 | Token.hpp 24 | TokenType.hpp 25 | stinc.hpp 26 | File.cpp 27 | File.hpp 28 | Compiler.cpp 29 | Compiler.hpp) 30 | 31 | add_executable(QCL_Compiler ${SOURCE_FILES}) 32 | -------------------------------------------------------------------------------- /Compiler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Compiler.hpp" 19 | 20 | Compiler::Compiler(Compiler::Arguments args) : x_Arguments(args) { 21 | 22 | } 23 | 24 | void Compiler::Compile() { 25 | // arr for each input value 26 | // for each input file compile 27 | // save each input to its corresponding output 28 | } 29 | 30 | void Compiler::Link() { 31 | // link together all the code into one file from the designated out var 32 | // link libraries 33 | } 34 | -------------------------------------------------------------------------------- /Compiler.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCL_COMPILER_COMPILER_H 19 | #define QCL_COMPILER_COMPILER_H 20 | 21 | #include 22 | #include 23 | 24 | /* 25 | * This is the Compiler class, here is where all the magic happens. To modify how this class functions and executes, 26 | * modify the compile arguments before passing them into the constructor. Once the arguments are set, the compiler will 27 | * take over. The first step in compiling is converting the quicel(QCL) code to (Q)byte code (QX). This is a certain 28 | * type of byte code generated and optimized for the Quantum Virtual Machine(QVM). Once the (Q)byte code has been 29 | * generated per input file into its corresponding output file, it needs to be linked. First the compiler will link it's 30 | * own code to the specified output file. The libraries are the last thing to be linked. Once everything is linked into 31 | * the designated output file specified by the arguments given, the code will be ready for execution. Code is executed 32 | * via the Quantum Virtual Machine(QVM). You will execute the QVM with your compiled program as an argument and it will 33 | * execute the file appropriately. 34 | */ 35 | class Compiler { 36 | public: 37 | /* 38 | * This struct stores all of the required arguments of the compiler. These values should all ready be initialized 39 | * before being passed into the Compiler constructor. This is used to make the arguments easy to utilize during 40 | * compilation. These are the following Compile flags in the order that you see them in the struct. 41 | * 42 | * -I ... = Source/Input Files 43 | * -O . = Output File Name 44 | * -L ... = Library Files 45 | * -MXR x = Max RAM for compilation 46 | * -MIR x = Min RAM for compilation 47 | */ 48 | typedef struct { 49 | char* input; //-I : Source Files (input) 50 | char* output; //-O : Output File 51 | char* libraries; //-L : Libraries 52 | unsigned long mxr; //-MXR : Max RAM (For compiling) 53 | unsigned long mir; //-MIR : MIN RAM (For compiling) 54 | } Arguments; 55 | 56 | Compiler(Arguments args); 57 | 58 | /* 59 | * Compile the QCL code down to our own version of byte code witch is designed and optimized to run on the Quantum 60 | * Virtual Machine. Our custom byte code extension is ".qx" and is similar to assembly. This function will take the 61 | * compiler's arguments and look specifiably at the input ("-I"). For each input file listed in the program 62 | * arguments, the compiler will make a corresponding compiled .qx file that contains the byte code we were talking 63 | * about previously. 64 | */ 65 | void Compile(); 66 | 67 | /* 68 | * 69 | */ 70 | void Link(); 71 | 72 | protected: 73 | Arguments x_Arguments; 74 | }; 75 | 76 | #endif //QCL_COMPILER_COMPILER_H 77 | -------------------------------------------------------------------------------- /File.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "File.hpp" 19 | 20 | File::File(const char *filelocation) { 21 | ifstream file(filelocation, ios_base::in); 22 | if (file.is_open()) { 23 | string x; 24 | while (getline(file, x)) { 25 | this->file.append(x); 26 | } 27 | file.close(); 28 | } else { 29 | cerr << filelocation << " was unable to load." << endl; 30 | } 31 | } 32 | 33 | const char *File::GetContents() { 34 | return file.c_str(); 35 | } 36 | -------------------------------------------------------------------------------- /File.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCL_COMPILER_FILE_H 19 | #define QCL_COMPILER_FILE_H 20 | 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | 26 | class File { 27 | public: 28 | 29 | File(const char* filelocation); 30 | 31 | const char* GetContents(); 32 | 33 | protected: 34 | 35 | string file; 36 | 37 | }; 38 | 39 | #endif //QCL_COMPILER_FILE_H 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | QCL Compiler 2 | 3 | Copyright (C) 2015 The Quantum Project 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QCL-Compiler [![Build Status](https://javabilities.com/jenkins/job/QCL-Compiler/badge/icon)](https://javabilities.com/jenkins/job/QCL-Compiler/) [![Coverage Status](https://coveralls.io/repos/The-Quantum-Project/QCL-Compiler/badge.svg?branch=master&service=github)](https://coveralls.io/github/The-Quantum-Project/QCL-Compiler?branch=master) 2 | 3 | This program compiles Quicel(QCL) source code down to (Q)byte code for the Quantum Virtual Machine(QVM) to execute. 4 | -------------------------------------------------------------------------------- /Test/Addition.qx: -------------------------------------------------------------------------------- 1 | var num1; 2 | var num2; 3 | var ans; 4 | 5 | input num1; 6 | input num2; 7 | 8 | add ans num1 num2; 9 | 10 | printvar ans; -------------------------------------------------------------------------------- /Test/Calc.qx: -------------------------------------------------------------------------------- 1 | var p1; 2 | var vdiv; 3 | set vdiv /; 4 | var vmult; 5 | set vmult *; 6 | var vadd; 7 | set vadd +; 8 | var vmin; 9 | set vmin -; 10 | var num1; 11 | var num2; 12 | var opt; 13 | var ans; 14 | 15 | set p1 Enter your first number!; 16 | printvar p1; 17 | input num1; 18 | set p1 Enter the operation!; 19 | printvar p1; 20 | input opt; 21 | set p1 Enter your second number!; 22 | printvar p1; 23 | input num2; 24 | 25 | ifeq opt vadd; 26 | add ans num1 num2; 27 | endif; 28 | ifeq opt vmin; 29 | sub ans num1 num2; 30 | endif; 31 | ifeq opt vmult; 32 | mult ans num1 num2; 33 | endif; 34 | ifeq opt vdiv; 35 | div ans num1 num2; 36 | endif; 37 | 38 | 39 | set p1 The answer is:; 40 | printvar p1; 41 | printvar ans; -------------------------------------------------------------------------------- /Test/Deg.qx: -------------------------------------------------------------------------------- 1 | var deg; 2 | var rad; 3 | var onee; 4 | var pi; 5 | var data; 6 | var ans; 7 | var uIn; 8 | 9 | set pi 3.1415; 10 | set onee 180; 11 | set rad torad; 12 | set deg todeg; 13 | 14 | input data; 15 | input uIn; 16 | 17 | ifeq uIn rad; 18 | div ans pi onee; 19 | endif; 20 | ifeq uIn deg; 21 | div ans onee pi; 22 | endif; 23 | mult ans data ans; 24 | 25 | printvar ans; -------------------------------------------------------------------------------- /Test/Division.qx: -------------------------------------------------------------------------------- 1 | var num1; 2 | var num2; 3 | var ans; 4 | 5 | input num1; 6 | input num2; 7 | 8 | div ans num1 num2; 9 | printvar ans; -------------------------------------------------------------------------------- /Test/Multiplication.qx: -------------------------------------------------------------------------------- 1 | var num1; 2 | var num2; 3 | var ans; 4 | 5 | input num1; 6 | input num2; 7 | 8 | mult ans num1 num2; 9 | 10 | printvar ans; -------------------------------------------------------------------------------- /Test/Subtraction.qx: -------------------------------------------------------------------------------- 1 | var num1; 2 | var num2; 3 | var ans; 4 | 5 | input num1; 6 | input num2; 7 | 8 | sub ans num1 num2; 9 | 10 | printvar ans; -------------------------------------------------------------------------------- /Token.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Token.hpp" 19 | 20 | Token::Token(TokenType tktype, string val) { 21 | type = tktype; 22 | value = val; 23 | } 24 | 25 | Token::~Token() { 26 | } 27 | -------------------------------------------------------------------------------- /Token.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCL_COMPILER_TOKEN_H 19 | #define QCL_COMPILER_TOKEN_H 20 | 21 | #include "TokenType.hpp" 22 | #include 23 | 24 | using namespace std; 25 | 26 | class Token { 27 | public: 28 | string value; 29 | TokenType type; 30 | 31 | Token(TokenType tktype, string val); 32 | 33 | ~Token(); 34 | }; 35 | 36 | #endif //QCL_COMPILER_TOKEN_H 37 | -------------------------------------------------------------------------------- /TokenType.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCL_COMPILER_TOKENTYPE_H 19 | #define QCL_COMPILER_TOKENTYPE_H 20 | 21 | #include 22 | 23 | enum class TokenType { 24 | Identifier = 1, 25 | Double = 2, 26 | String = 2, 27 | LineTerminator = 4, 28 | OpeningBracket = 4, 29 | ClosingBracket = 4, 30 | OpeningSquareBracket = 4, 31 | ClosingSquareBracket = 4, 32 | OpeningParen = 8, 33 | ClosingParen = 8, 34 | BinOp = 16, 35 | UnOp = 16, 36 | CompOp = 16, 37 | AssignOp = 16, 38 | Comma = 16 39 | 40 | }; 41 | 42 | 43 | #endif //QCL_COMPILER_TOKENTYPE_H 44 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Compiler.hpp" 19 | #include "File.hpp" 20 | #include "Token.hpp" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void run(std::list list); 30 | 31 | using namespace std; 32 | 33 | std::ostream &operator<<(std::ostream &os, TokenType tt) { 34 | return os << static_cast(tt); 35 | } 36 | 37 | 38 | std::string join(std::list &elements, const char *const seperator) { 39 | switch (elements.size()) { 40 | case 0: 41 | return ""; 42 | case 1: 43 | return *elements.begin(); 44 | default: 45 | ostringstream os; 46 | copy(elements.begin(), elements.end(), std::ostream_iterator(os, seperator)); 47 | return os.str(); 48 | } 49 | } 50 | 51 | std::list &split(const std::string &s, char delim, std::list &elems) { 52 | std::stringstream ss(s); 53 | std::string item; 54 | while (std::getline(ss, item, delim)) { 55 | if (!item.empty()) { 56 | elems.push_back(item); 57 | } 58 | } 59 | return elems; 60 | } 61 | 62 | std::list split(const std::string &s, char delim) { 63 | std::list elems; 64 | split(s, delim, elems); 65 | return elems; 66 | } 67 | 68 | template 69 | std::string to_string(T const &value) { 70 | stringstream sstr; 71 | sstr << value; 72 | return sstr.str(); 73 | } 74 | 75 | int main(int argc, char *argv[]) { 76 | 77 | for (int i = 1; i < argc; i++) { 78 | 79 | } 80 | 81 | Compiler::Arguments args; 82 | args.input = (char *) ""; 83 | args.libraries = (char *) ""; 84 | args.output = (char *) ""; 85 | args.mxr = 0; 86 | args.mir = 0; 87 | 88 | Compiler compiler(args); 89 | compiler.Compile(); 90 | 91 | 92 | // char *code = (char *) "var hi\n" 93 | // "var hello\n" 94 | // "var ans\n" 95 | // "set hi 5\n" 96 | // "set hello 10\n" 97 | // "mult ans hi hello\n" 98 | // "sub ans ans hi\n" 99 | // "printvar ans\n" 100 | // "input hi\n" 101 | // "printvar hi"; 102 | 103 | //TODO Functions/Methods 104 | 105 | // This code waits for use to enter two numbers, then multiplies together and outputs to screen 106 | char *multiplication_code = (char *) "var num1;var num2;var ans;input num1;input num2;mult ans num1 num2;printvar ans;"; 107 | char *addition_code = (char *) "var num1;var num2;var ans;input num1;input num2;add ans num1 num2;printvar ans;"; 108 | char *subtraction_code = (char *) "var num1;var num2;var ans;input num1;input num2;sub ans num1 num2;printvar ans;"; 109 | char *division_code = (char *) "var num1;var num2;var ans;input num1;input num2;div ans num1 num2;printvar ans;"; 110 | char *deg_code = (char *) "var deg;var rad;var onee;var pi;var data;var ans;var uIn;set pi 3.1415;set onee 180;set rad torad;set deg todeg;input data;input uIn;ifeq uIn rad;div ans pi onee;endif;ifeq uIn deg;div ans onee pi;endif;mult ans data ans;printvar ans;"; 111 | 112 | 113 | //first input is num1, second is operator (+-*/), third is num2 114 | char *calc_code = (char *) "var vdiv;set vdiv /;var vmult;set vmult *;var vadd;set vadd +;var vmin;set vmin -;var num1;var num2;var opt;var ans;input num1;input opt;input num2;ifeq opt vadd;add ans num1 num2;endif;ifeq opt vmin;sub ans num1 num2;endif;ifeq opt vmult;mult ans num1 num2;endif;ifeq opt vdiv;div ans num1 num2;endif;printvar ans;"; 115 | 116 | // char *if_code = (char *) "var div;set div /;"; 117 | 118 | File file("Calc.qx"); 119 | const char *code = file.GetContents(); 120 | 121 | run(split(code, ';')); 122 | 123 | exit(0); 124 | } 125 | 126 | int ifLevel = 0; 127 | 128 | void run(std::list list1) { 129 | unordered_map varMap; 130 | for (std::list::iterator list_iterator = list1.begin(); list_iterator != list1.end(); list_iterator++) { 131 | // std::cout << "\t" << *list_iterator << " : " << ifLevel << endl; 132 | list parts = split(*list_iterator, ' '); 133 | if (ifLevel < 1) { 134 | if (*parts.begin() == "var") { 135 | parts.pop_front(); 136 | varMap.insert(make_pair(*parts.begin(), "")); 137 | } 138 | if (*parts.begin() == "set") { 139 | parts.pop_front(); 140 | string var = *parts.begin(); 141 | parts.pop_front(); 142 | string data = join(parts, " "); 143 | auto it = varMap.find(var); 144 | if (it != varMap.end()) 145 | it->second = data; 146 | } 147 | if (*parts.begin() == "printvar") { 148 | parts.pop_front(); 149 | cout << varMap[*parts.begin()] << endl; 150 | } 151 | if (*parts.begin() == "add") { 152 | parts.pop_front(); 153 | string var = *parts.begin(); 154 | parts.pop_front(); 155 | string v2 = *parts.begin(); 156 | parts.pop_front(); 157 | string v3 = *parts.begin(); 158 | double nVal = strtod(varMap[v2].c_str(), NULL) + strtod(varMap[v3].c_str(), NULL); 159 | auto it = varMap.find(var); 160 | if (it != varMap.end()) 161 | it->second = to_string(nVal); 162 | } 163 | if (*parts.begin() == "mult") { 164 | parts.pop_front(); 165 | string var = *parts.begin(); 166 | parts.pop_front(); 167 | string v2 = *parts.begin(); 168 | parts.pop_front(); 169 | string v3 = *parts.begin(); 170 | double nVal = strtod(varMap[v2].c_str(), NULL) * strtod(varMap[v3].c_str(), NULL); 171 | auto it = varMap.find(var); 172 | if (it != varMap.end()) 173 | it->second = to_string(nVal); 174 | } 175 | if (*parts.begin() == "div") { 176 | parts.pop_front(); 177 | string var = *parts.begin(); 178 | parts.pop_front(); 179 | string v2 = *parts.begin(); 180 | parts.pop_front(); 181 | string v3 = *parts.begin(); 182 | double nVal = strtod(varMap[v2].c_str(), NULL) / strtod(varMap[v3].c_str(), NULL); 183 | auto it = varMap.find(var); 184 | if (it != varMap.end()) 185 | it->second = to_string(nVal); 186 | } 187 | if (*parts.begin() == "sub") { 188 | parts.pop_front(); 189 | string var = *parts.begin(); 190 | parts.pop_front(); 191 | string v2 = *parts.begin(); 192 | parts.pop_front(); 193 | string v3 = *parts.begin(); 194 | double nVal = strtod(varMap[v2].c_str(), NULL) - strtod(varMap[v3].c_str(), NULL); 195 | auto it = varMap.find(var); 196 | if (it != varMap.end()) 197 | it->second = to_string(nVal); 198 | } 199 | if (*parts.begin() == "input") { 200 | parts.pop_front(); 201 | string var = *parts.begin(); 202 | 203 | string uInput; 204 | cin >> uInput; 205 | 206 | auto it = varMap.find(var); 207 | if (it != varMap.end()) 208 | it->second = uInput; 209 | } 210 | } else { 211 | if (*parts.begin() == "endif") { 212 | ifLevel--; 213 | } 214 | } 215 | if (*parts.begin() == "ifeq") { 216 | parts.pop_front(); 217 | string var = *parts.begin(); 218 | parts.pop_front(); 219 | string var2 = *parts.begin(); 220 | cout << "\t\t" << varMap[var] << " : " << varMap[var2] << " : " << (varMap[var] == varMap[var2]) << endl; 221 | if (varMap[var] != varMap[var2]) ifLevel++; 222 | } 223 | 224 | } 225 | 226 | for (int i = 0; i < 10; i++) 227 | cout << endl; 228 | 229 | } -------------------------------------------------------------------------------- /stinc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Quantum Project 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCL_COMPILER_STDAFX_H 19 | #define QCL_COMPILER_STDAFX_H 20 | 21 | #include 22 | #include // TODO : Cannot find on Linux but doesnt cause error (yet) 23 | 24 | #endif //QCL_COMPILER_STDAFX_H 25 | --------------------------------------------------------------------------------