-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
193 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Generated from CLion C/C++ Code Style settings | ||
BasedOnStyle: LLVM | ||
AccessModifierOffset: -4 | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: None | ||
AlignOperands: Align | ||
AllowAllArgumentsOnNextLine: false | ||
AllowAllConstructorInitializersOnNextLine: false | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowShortBlocksOnASingleLine: Always | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: All | ||
AllowShortIfStatementsOnASingleLine: Always | ||
AllowShortLambdasOnASingleLine: All | ||
AllowShortLoopsOnASingleLine: true | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakTemplateDeclarations: Yes | ||
BreakBeforeBraces: Custom | ||
BraceWrapping: | ||
AfterCaseLabel: false | ||
AfterClass: false | ||
AfterControlStatement: Never | ||
AfterEnum: false | ||
AfterFunction: false | ||
AfterNamespace: false | ||
AfterUnion: false | ||
BeforeCatch: false | ||
BeforeElse: false | ||
IndentBraces: false | ||
SplitEmptyFunction: false | ||
SplitEmptyRecord: true | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializers: BeforeColon | ||
BreakInheritanceList: BeforeColon | ||
ColumnLimit: 0 | ||
CompactNamespaces: false | ||
ContinuationIndentWidth: 8 | ||
IndentCaseLabels: true | ||
IndentPPDirectives: None | ||
IndentWidth: 4 | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
MaxEmptyLinesToKeep: 2 | ||
NamespaceIndentation: All | ||
ObjCSpaceAfterProperty: false | ||
ObjCSpaceBeforeProtocolList: true | ||
PointerAlignment: Right | ||
ReflowComments: false | ||
SpaceAfterCStyleCast: true | ||
SpaceAfterLogicalNot: false | ||
SpaceAfterTemplateKeyword: false | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeCpp11BracedList: false | ||
SpaceBeforeCtorInitializerColon: true | ||
SpaceBeforeInheritanceColon: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceBeforeRangeBasedForLoopColon: false | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 0 | ||
SpacesInAngles: false | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInContainerLiterals: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
TabWidth: 4 | ||
UseTab: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
#ifndef YASI_FUNCTION_H | ||
#define YASI_FUNCTION_H | ||
|
||
#include "../parser/SyntaxTreeNode.h" | ||
|
||
class Function { | ||
public: | ||
virtual ~Function()= default; | ||
virtual SyntaxTreeNode evaluate(const std::vector<SyntaxTreeNode>& args) = 0; | ||
virtual ~Function() = default; | ||
virtual SyntaxTreeNode evaluate( | ||
const std::vector<SyntaxTreeNode> &args) = 0; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
#include <unordered_map> | ||
#include "eval.h" | ||
#include "../builtin_functions/add/add.h" | ||
#include "../builtin_functions/multiply/multiply.h" | ||
#include "../builtin_functions/subtract/subtract.h" | ||
#include "exceptions/SyntaxError.h" | ||
#include "builtin_functions/divide/Divide.h" | ||
#include "exceptions/SyntaxError.h" | ||
#include <unordered_map> | ||
|
||
SyntaxTreeNode Evaluate::evaluate(const SyntaxTreeNode &tree) { | ||
static std::unordered_map<std::string, Function *> builtin = { | ||
{"+", dynamic_cast<Function *>(new Add())}, | ||
{"-", dynamic_cast<Function *>(new Subtract())}, | ||
{"*", dynamic_cast<Function *>(new Multiply())}, | ||
{"/", dynamic_cast<Function *>(new Divide())} | ||
}; | ||
{"/", dynamic_cast<Function *>(new Divide())}}; | ||
if (tree.children.empty()) { | ||
return SyntaxTreeNode(tree.token); | ||
} | ||
if (builtin.find(tree.token.token) != builtin.end()) { | ||
return builtin.at(tree.token.token)->evaluate(tree.children); | ||
} else { | ||
auto errorMessage = "Syntax error: name `" | ||
+ tree.token.token + | ||
"` is not defined"; | ||
auto errorMessage = | ||
"Syntax error: name `" + tree.token.token + "` is not defined"; | ||
throw SyntaxError(errorMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.