├── .github └── workflows │ └── c-cpp.yml ├── LICENSE ├── Lexer.cpp ├── Lexer.h ├── README.md ├── error.cpp ├── error.h ├── examples ├── guessing_game.pie └── math.pie ├── grammar.pie ├── helpers.h ├── main ├── main.cpp ├── parser ├── ast.cpp ├── parser.cpp └── parser.h └── tests.pie /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: configure 17 | run: ./configure 18 | - name: make 19 | run: make 20 | - name: make check 21 | run: make check 22 | - name: make distcheck 23 | run: make distcheck 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Eli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lexer.cpp: -------------------------------------------------------------------------------- 1 | // Lexer.cpp 2 | #include 3 | #include "error.h" 4 | #include "setup.h" 5 | #include "Lexer.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | //std::vector tokenstream; 12 | typedef std::map, std::variant> Dict; 13 | 14 | int nums[10] = {0,1,2,3,4,5,6,7,8,9}; 15 | int Lexer::mainLexer(){ 16 | Dict tokenstream; 17 | int line = 0; 18 | int pmakeSurePlease = 0; 19 | std::string reserved[14] = {"out","get","if", "elsif", "els", "do", "while", "true", "false", "func", "i32", "str", "char","null"}; // and will be && and or will be || 20 | int placeholder = 0; 21 | std::ifstream pie_file("tests.pie"); 22 | std::string tp; 23 | // std::string code; 24 | while(getline(pie_file, tp)){ 25 | 26 | code += tp; 27 | code += '\n'; 28 | /* 29 | 30 | */ 31 | } 32 | 33 | 34 | for (; i < code.size(); i++) { 35 | 36 | char c = code[i]; 37 | std::cout << c << std::endl; 38 | if(c == '/' && peek() == '/') { 39 | while (curr() != '\n') i++; 40 | } else { 41 | switch (c) { 42 | case '+': 43 | tokenstream["PLUS: "] = c; // find out how to append the plus 44 | case '-': 45 | //case isdigit(c): 46 | // tokenstream.push_back("NUMBER"); 47 | //case isalpha(c): 48 | // tokenstream.push_back("INITI"); 49 | case '*': 50 | tokenstream["STAR"] = c; 51 | 52 | case '/': 53 | tokenstream["DIV"] =c; 54 | case ' ': 55 | continue; 56 | case '\n': 57 | continue; 58 | case '\r': 59 | continue; 60 | 61 | case 'a': 62 | case 'b': 63 | case 'c': 64 | case 'd': 65 | case 'e': 66 | case 'f': 67 | case 'g': 68 | case 'h': 69 | case 'j': 70 | case 'i': 71 | case 'k': 72 | case 'l': 73 | case 'm': 74 | case 'n': 75 | 76 | case 'p': 77 | case 'q': 78 | case 'r': 79 | case 's': 80 | case 'u': 81 | case 't': 82 | case 'v': 83 | case 'w': 84 | case 'y': 85 | case 'x': 86 | case 'z': 87 | case 'A': 88 | case 'B': 89 | case 'C': 90 | case 'D': 91 | case 'E': 92 | case 'F': 93 | case 'G': 94 | case 'H': 95 | case 'I': 96 | case 'J': 97 | case 'K': 98 | case 'L': 99 | case 'M': 100 | case 'N': 101 | case 'O': 102 | case 'P': 103 | case 'Q': 104 | case 'R': 105 | case 'S': 106 | case 'W': 107 | case 'X': 108 | case 'Y': 109 | case 'Z': 110 | while( c != ' '){ 111 | pmakeSurePlease++; 112 | // explaination: notice: it starts when it sees a character then adds it to the array. 113 | 114 | 115 | 116 | std::string holder[100000] = {}; 117 | holder[pmakeSurePlease] = c; 118 | // get whole string: 119 | for(int i = 0; i++;){ 120 | // holder[i] 121 | } 122 | } 123 | 124 | //std::string full_string = 125 | tokenstream["INITI"] = c; 126 | 127 | //case 1: 128 | //case 0: 129 | //case 2: 130 | //case 3: 131 | //case 4: 132 | //case 5: 133 | //case 6: 134 | //case 7: 135 | //case 8: 136 | //case 9: 137 | //tokenstream.push_back("ONE_NUMBER"); 138 | 139 | case '\t': 140 | continue; 141 | 142 | case '(': 143 | tokenstream["LPAREN"] = c; 144 | case ')': 145 | tokenstream["RPAREN"] =c; 146 | case '[': 147 | tokenstream["LBRACKET"] =c; 148 | case ']': 149 | tokenstream["RBRACKET"] =c; 150 | case '{': 151 | tokenstream["LCURLY"] = c; 152 | case '}': 153 | tokenstream["RCURLY"] = c; 154 | case '<': 155 | tokenstream["LESS_THAN"] = c; 156 | case '>': 157 | tokenstream["LARGER_THAN"] = c; 158 | 159 | case '&': 160 | if(c == '&' && peek() == '&'){ 161 | while(curr() != '\n')i++; 162 | tokenstream["AND"] = "||"; 163 | }else{ 164 | tokenstream["ANDSYMBOL: "]=c; 165 | } 166 | case '|': 167 | if(c == '|' && peek() == '|'){ 168 | while(curr() != '\n') 169 | tokenstream["OR"] = "||"; 170 | }else{ 171 | tokenstream["PIPE"]=c; 172 | } 173 | case ';': 174 | tokenstream["EOL"] = c; 175 | case 'o': 176 | if(c == 'o'&& peek() == 'u'){ 177 | if (c == 'u' && peek() == 't'){ 178 | while(curr()!= '\n') 179 | tokenstream["PRINT_STATEMENT"] = "out"; 180 | } 181 | } 182 | 183 | 184 | default: 185 | Errors::UnknownToken(c, line); 186 | 187 | 188 | } 189 | } 190 | for(auto& k_v: tokenstream){ 191 | std::visit( 192 | [](auto& value){std::cout << "\n" << value << '\n';}, 193 | k_v.second // k_v.first to print all keys in d 194 | ); 195 | } 196 | // if() 197 | // std::cout.flush(); 198 | } 199 | 200 | return 0; 201 | } 202 | //char Lexer::prev(){ 203 | // return code[i-1]; 204 | //} 205 | 206 | char Lexer::peek() { 207 | return code[i+1]; 208 | } 209 | 210 | char Lexer::curr() { 211 | return code[i]; 212 | } 213 | 214 | int stringify(int intorsomething) { 215 | std::to_string(intorsomething); 216 | return 0; 217 | } 218 | -------------------------------------------------------------------------------- /Lexer.h: -------------------------------------------------------------------------------- 1 | #ifndef LEXER_h 2 | #define LEXER_h 3 | 4 | struct Token{ 5 | std::string type; 6 | std::string value; // This means i will turn it into a string example: 2 would turn into "2" 7 | // other 8 | int line; 9 | }; 10 | 11 | enum class Types{ 12 | Number, 13 | DoubleQuote, 14 | Quote, 15 | Initializer, 16 | LessThan, 17 | LargerThan, 18 | Equal, 19 | SlashOrComment, 20 | AtOrReturn, 21 | Pipe, 22 | LParen, 23 | RParen, 24 | LCurly, 25 | RCurly, 26 | RBracket, 27 | LBracket, 28 | Colon, 29 | SemiColon, 30 | Star, 31 | Plus, 32 | Caret, 33 | //more later. 34 | }; 35 | 36 | struct Lexer{ 37 | int i = 0; 38 | std::string code; 39 | int mainLexer(); 40 | char peek(); 41 | char curr(); 42 | }; 43 | 44 | int stringify(int intorsomething); 45 | 46 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PieLang 2 | Pie language, interpreted, easy to learn, and has a similar C++ & Ruby syntax. 3 | 4 | 5 | # Warning 6 | Pie is still under development so you *will* encounter bugs. 7 | This is also my first *official* language that I have ever made! 8 | 9 | # About 10 | My last name *piechocki* starts with **Pie**. So, I decided to turn everything around in my life to *pie*. Pie is yummy, and has a ring to it(i think lol). So then came along the age of language development. I decided to learn C++ and create a language called *Pie*. This is a fun excersise that helps me grow my knowledge of C++! I hope people can use Pie all around the world! 11 | 12 | 13 | 14 | # An example syntax 15 | ```cpp 16 | 17 | out "Hello, world"; 18 | name = "Elipie"; 19 | 20 | for(i = 0; i < 10; i++){ 21 | out i; 22 | } 23 | do{ 24 | i = 10; 25 | i --; 26 | }while(i > 0); 27 | array<2> = ["pie", "good"]; 28 | // control flow 29 | pie = "gud"; 30 | if(pie == "gud"){ 31 | out "yes."; 32 | }elsif(pie != "gud"){ 33 | out "no"; 34 | }else { 35 | out "Pie good"; 36 | } 37 | func add(a,b) -> i32{ 38 | @ a + b; 39 | } 40 | add(1,2); 41 | 42 | ``` 43 | 44 | Hello everyone, I am back from my long break of coding. I will mostly be working on PieLang in IDE's this weekend, so you won't see a lot of github pushes. 45 | -------------------------------------------------------------------------------- /error.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace Errors{ 3 | 4 | int SyntaxError(std::string msg, int line){ 5 | std::cout << "Syntax Error near line " << line << "\n "<< msg; 6 | return 1; 7 | 8 | } 9 | 10 | int UnexpectedEOL(std::string msg, int line){ 11 | std::cout << " Unexpected EOL(end of line) near line "< number){ 7 | out "Too large!"; 8 | numGuesses++; 9 | get "> " 10 | } 11 | elsif(guess < number){ 12 | out "Too small"; 13 | 14 | numGuesses++; 15 | get "> " 16 | els{ 17 | out "You got it! With "+numGuesses+" number of guesses!"; 18 | -------------------------------------------------------------------------------- /examples/math.pie: -------------------------------------------------------------------------------- 1 | func sqrt(num) -> i32{ 2 | 3 | @ num ** 0.5; 4 | } 5 | 6 | func trig(num) { 7 | // nothing 8 | } 9 | -------------------------------------------------------------------------------- /grammar.pie: -------------------------------------------------------------------------------- 1 | // Guessing game 2 | use random 3 | 4 | number = random.int(1,100); 5 | tries = 10 6 | out "Guess a number between 1 and 100, you have 10 tries"; 7 | guess = get "> "; 8 | 9 | do { 10 | if (guess > number){ 11 | out "To big! You have "+tries+" more tries"; 12 | }elsif (guess < number){ 13 | out "To tiny! You have "+tries+" more tries"; 14 | } elsif (guess == number){ 15 | out "You got it! With "+tries+" more tries!"; 16 | } 17 | tries--; 18 | } while(tries > 0); 19 | 20 | // array 21 | array<3> = ["1", "e", "$"]; 22 | //much more coming. 23 | -------------------------------------------------------------------------------- /helpers.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // for functions 4 | typedef std::string Name; 5 | typedef std::string Paramaters; 6 | 7 | // turns out you cant use auto for typedef, so I will have to figure it out later. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elipie/PieLang/2285d74f9755772aa9983325232107e5737665dd/main -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | //main.cpp 2 | #include 3 | #include "error.h" 4 | #include "helpers.h" 5 | #include "Lexer.h" 6 | 7 | int main(){ 8 | Lexer obj; 9 | obj.mainLexer(); 10 | 11 | //nothing yet 12 | } -------------------------------------------------------------------------------- /parser/ast.cpp: -------------------------------------------------------------------------------- 1 | #include "parser.h" 2 | -------------------------------------------------------------------------------- /parser/parser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Lexer.h" 3 | 4 | 5 | namespace Pie{ 6 | int parser(){ 7 | 8 | return 0; 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /parser/parser.h: -------------------------------------------------------------------------------- 1 | namespace Pie{ 2 | int parser(); 3 | } -------------------------------------------------------------------------------- /tests.pie: -------------------------------------------------------------------------------- 1 | out 2 | --------------------------------------------------------------------------------