├── 2021 ├── grammar │ ├── statements │ │ ├── Statement.cpp │ │ ├── Statement.h │ │ ├── VarDecl.cpp │ │ ├── PrintStatement.cpp │ │ ├── ScopeAssignmentList.cpp │ │ ├── StatementList.cpp │ │ ├── Assignment.cpp │ │ ├── ReturnStatement.h │ │ ├── VarDecl.h │ │ ├── ReturnStatement.cpp │ │ ├── PrintStatement.h │ │ ├── StatementList.h │ │ ├── Assignment.h │ │ └── ScopeAssignmentList.h │ ├── expressions │ │ ├── Expression.h │ │ ├── IdentExpression.cpp │ │ ├── NumberExpression.cpp │ │ ├── AddExpression.cpp │ │ ├── DivExpression.cpp │ │ ├── MulExpression.cpp │ │ ├── NumberExpression.h │ │ ├── SubstractExpression.cpp │ │ ├── AddExpression.h │ │ ├── DivExpression.h │ │ ├── IdentExpression.h │ │ ├── MulExpression.h │ │ ├── SubstractExpression.h │ │ ├── FunctionCallExpression.h │ │ └── FunctionCallExpression.cpp │ ├── Program.cpp │ ├── base_elements │ │ └── BaseElement.h │ ├── Program.h │ ├── functions │ │ ├── FunctionList.cpp │ │ ├── Function.cpp │ │ ├── ParamValueList.cpp │ │ ├── FunctionList.h │ │ ├── ParamValueList.h │ │ └── ParamList.h │ └── scanner.h ├── scopes │ ├── BaseScope.cpp │ ├── BaseScope.h │ └── scopes.md ├── symbols │ ├── BaseSymbol.cpp │ ├── StArgument.cpp │ ├── StVariable.cpp │ ├── BaseSymbol.h │ ├── StVariable.h │ ├── StArgument.h │ ├── StFunction.cpp │ └── StFunction.h └── visitors │ └── TemplateVisitor.h ├── 2022 ├── grammar │ ├── statements │ │ ├── Statement.cpp │ │ ├── Statement.h │ │ ├── VarDecl.cpp │ │ ├── PrintStatement.cpp │ │ ├── ScopeAssignmentList.cpp │ │ ├── StatementList.cpp │ │ ├── Assignment.cpp │ │ ├── ReturnStatement.h │ │ ├── VarDecl.h │ │ ├── ReturnStatement.cpp │ │ ├── PrintStatement.h │ │ ├── StatementList.h │ │ ├── Assignment.h │ │ └── ScopeAssignmentList.h │ ├── expressions │ │ ├── Expression.h │ │ ├── IdentExpression.cpp │ │ ├── NumberExpression.cpp │ │ ├── AddExpression.cpp │ │ ├── DivExpression.cpp │ │ ├── MulExpression.cpp │ │ ├── NumberExpression.h │ │ ├── SubstractExpression.cpp │ │ ├── AddExpression.h │ │ ├── DivExpression.h │ │ ├── IdentExpression.h │ │ ├── MulExpression.h │ │ ├── SubstractExpression.h │ │ ├── FunctionCallExpression.h │ │ └── FunctionCallExpression.cpp │ ├── Program.cpp │ ├── base_elements │ │ └── BaseElement.h │ ├── Program.h │ ├── functions │ │ ├── FunctionList.cpp │ │ ├── Function.cpp │ │ ├── ParamValueList.cpp │ │ ├── FunctionList.h │ │ ├── ParamValueList.h │ │ └── ParamList.h │ └── scanner.h ├── symbols │ ├── BaseSymbol.cpp │ ├── Function.cpp │ ├── VariableSymbol.cpp │ ├── VariableSymbol.h │ ├── Function.h │ └── BaseSymbol.h ├── visitors │ └── TemplateVisitor.h └── scopes │ └── scopes.md ├── 01-scanners ├── .gitignore ├── CMakeLists.txt └── lexer.hh ├── bin ├── .gitignore ├── 05-assign-on-not-declared.in ├── 05-undeclared-var-outside-scope.in ├── 02-a.in ├── 05-a-shadowing.in ├── 05-after-value-access.in ├── 06-functions-example.in ├── a_with_print.in ├── 2021-scopes.in ├── 2022-simple-main.in └── 06-multiple-functions.in ├── 05-variable-scopes ├── statements │ ├── Statement.cpp │ ├── Statement.h │ ├── VarDecl.cpp │ ├── PrintStatement.cpp │ ├── ScopeAssignmentList.cpp │ ├── AssignmentList.cpp │ ├── Assignment.cpp │ ├── VarDecl.h │ ├── PrintStatement.h │ ├── AssignmentList.h │ ├── Assignment.h │ └── ScopeAssignmentList.h ├── objects │ ├── Object.cpp │ ├── Object.h │ ├── Integer.cpp │ ├── UninitObject.cpp │ ├── Integer.h │ └── UninitObject.h ├── symbol_table │ ├── ScopeLayerTree.cpp │ ├── ScopeLayerTree.h │ └── Symbol.cpp ├── Program.cpp ├── expressions │ ├── Expression.h │ ├── NumberExpression.h │ ├── IdentExpression.cpp │ ├── NumberExpression.cpp │ ├── AddExpression.h │ ├── DivExpression.h │ ├── IdentExpression.h │ ├── MulExpression.h │ ├── AddExpression.cpp │ ├── DivExpression.cpp │ ├── MulExpression.cpp │ ├── SubstractExpression.h │ └── SubstractExpression.cpp ├── base_elements │ └── BaseElement.h ├── visitors │ ├── TemplateVisitor.h │ ├── TemplateVisitor.cpp │ └── forward_decl.h ├── Program.h └── scanner.h ├── 06-function-calls ├── grammar │ ├── statements │ │ ├── Statement.cpp │ │ ├── Statement.h │ │ ├── VarDecl.cpp │ │ ├── PrintStatement.cpp │ │ ├── ScopeAssignmentList.cpp │ │ ├── AssignmentList.cpp │ │ ├── Assignment.cpp │ │ ├── ReturnStatement.h │ │ ├── VarDecl.h │ │ ├── PrintStatement.h │ │ ├── ReturnStatement.cpp │ │ ├── AssignmentList.h │ │ ├── Assignment.h │ │ └── ScopeAssignmentList.h │ ├── Program.cpp │ ├── expressions │ │ ├── Expression.h │ │ ├── IdentExpression.cpp │ │ ├── NumberExpression.cpp │ │ ├── AddExpression.cpp │ │ ├── DivExpression.cpp │ │ ├── MulExpression.cpp │ │ ├── NumberExpression.h │ │ ├── SubstractExpression.cpp │ │ ├── AddExpression.h │ │ ├── DivExpression.h │ │ ├── IdentExpression.h │ │ ├── MulExpression.h │ │ ├── SubstractExpression.h │ │ ├── FunctionCallExpression.h │ │ └── FunctionCallExpression.cpp │ ├── base_elements │ │ └── BaseElement.h │ ├── Program.h │ ├── functions │ │ ├── FunctionList.cpp │ │ ├── Function.cpp │ │ ├── ParamValueList.cpp │ │ ├── FunctionList.h │ │ ├── ParamValueList.h │ │ └── ParamList.h │ └── scanner.h ├── types │ ├── Type.cpp │ ├── PrimitiveType.cpp │ ├── Type.h │ ├── Integer.cpp │ ├── UninitObject.cpp │ ├── PrimitiveType.h │ ├── Integer.h │ ├── UninitObject.h │ ├── FunctionType.cpp │ └── FunctionType.h ├── visitors │ ├── TemplateVisitor.h │ └── TemplateVisitor.cpp └── symbol_table │ └── Symbol.cpp ├── 07-irtree-build ├── grammar │ ├── statements │ │ ├── Statement.cpp │ │ ├── Statement.h │ │ ├── VarDecl.cpp │ │ ├── PrintStatement.cpp │ │ ├── ScopeAssignmentList.cpp │ │ ├── AssignmentList.cpp │ │ ├── Assignment.cpp │ │ ├── ReturnStatement.h │ │ ├── VarDecl.h │ │ ├── PrintStatement.h │ │ ├── ReturnStatement.cpp │ │ ├── AssignmentList.h │ │ ├── Assignment.h │ │ ├── ScopeAssignmentList.h │ │ ├── IfStatement.cpp │ │ └── IfStatement.h │ ├── Program.cpp │ ├── expressions │ │ ├── Expression.h │ │ ├── IdentExpression.cpp │ │ ├── NumberExpression.cpp │ │ ├── AddExpression.cpp │ │ ├── DivExpression.cpp │ │ ├── MulExpression.cpp │ │ ├── NumberExpression.h │ │ ├── SubstractExpression.cpp │ │ ├── NotExpression.cpp │ │ ├── AddExpression.h │ │ ├── DivExpression.h │ │ ├── IdentExpression.h │ │ ├── MulExpression.h │ │ ├── AndExpression.cpp │ │ ├── OrExpression.cpp │ │ ├── SubstractExpression.h │ │ ├── LtExpression.cpp │ │ ├── GtExpression.cpp │ │ ├── NotExpression.h │ │ ├── AndExpression.h │ │ ├── GtExpression.h │ │ ├── LtExpression.h │ │ ├── OrExpression.h │ │ ├── FunctionCallExpression.h │ │ └── FunctionCallExpression.cpp │ ├── base_elements │ │ └── BaseElement.h │ ├── Program.h │ ├── functions │ │ ├── FunctionList.cpp │ │ ├── Function.cpp │ │ ├── ParamValueList.cpp │ │ ├── FunctionList.h │ │ ├── ParamValueList.h │ │ └── ParamList.h │ └── scanner.h ├── types │ ├── Type.cpp │ ├── PrimitiveType.cpp │ ├── Type.h │ ├── Integer.cpp │ ├── UninitObject.cpp │ ├── PrimitiveType.h │ ├── Integer.h │ ├── UninitObject.h │ ├── FunctionType.cpp │ └── FunctionType.h ├── irtree │ ├── nodes │ │ ├── expressions │ │ │ ├── Expression.h │ │ │ ├── NameExpression.cpp │ │ │ ├── TempExpression.cpp │ │ │ ├── MemExpression.cpp │ │ │ ├── EseqExpression.cpp │ │ │ ├── MemExpression.h │ │ │ ├── ConstExpression.cpp │ │ │ ├── CallExpression.cpp │ │ │ ├── NameExpression.h │ │ │ ├── CallExpression.h │ │ │ ├── BinopExpression.cpp │ │ │ ├── ConstExpression.h │ │ │ ├── TempExpression.h │ │ │ └── EseqExpression.h │ │ ├── statements │ │ │ ├── Statement.h │ │ │ ├── JumpStatement.cpp │ │ │ ├── LabelStatement.cpp │ │ │ ├── SeqStatement.cpp │ │ │ ├── MoveStatement.cpp │ │ │ ├── JumpStatement.h │ │ │ ├── LabelStatement.h │ │ │ ├── SeqStatement.h │ │ │ ├── ExpStatement.cpp │ │ │ └── MoveStatement.h │ │ ├── BaseElement.h │ │ ├── ExpressionList.cpp │ │ └── ExpressionList.h │ ├── types │ │ ├── LogicOperatorType.h │ │ ├── BinaryOperatorType.h │ │ └── LogicOperatorType.cpp │ ├── generators │ │ ├── Label.h │ │ ├── Label.cpp │ │ ├── Temporary.h │ │ └── Temporary.cpp │ └── tree_wrapper │ │ ├── conditional_wrappers │ │ ├── ConditionalWrapper.h │ │ ├── NegateConditionalWrapper.cpp │ │ ├── NegateConditionalWrapper.h │ │ └── OrConditionalWrapper.h │ │ ├── SubtreeWrapper.h │ │ └── StatementWrapper.h ├── visitors │ ├── TemplateVisitor.h │ └── TemplateVisitor.cpp ├── function-mechanisms │ └── address │ │ ├── Address.h │ │ ├── AddressInRegister.cpp │ │ ├── AddressInRegister.h │ │ └── AddressInFrame.h └── symbol_table │ └── Symbol.cpp ├── 08-irtree-optimizations ├── grammar │ ├── statements │ │ ├── Statement.cpp │ │ ├── Statement.h │ │ ├── VarDecl.cpp │ │ ├── PrintStatement.cpp │ │ ├── ScopeAssignmentList.cpp │ │ ├── AssignmentList.cpp │ │ ├── Assignment.cpp │ │ ├── ReturnStatement.h │ │ ├── VarDecl.h │ │ ├── ReturnStatement.cpp │ │ ├── PrintStatement.h │ │ ├── AssignmentList.h │ │ ├── Assignment.h │ │ ├── ScopeAssignmentList.h │ │ ├── IfStatement.cpp │ │ └── IfStatement.h │ ├── Program.cpp │ ├── expressions │ │ ├── Expression.h │ │ ├── IdentExpression.cpp │ │ ├── NumberExpression.cpp │ │ ├── AddExpression.cpp │ │ ├── DivExpression.cpp │ │ ├── MulExpression.cpp │ │ ├── NumberExpression.h │ │ ├── SubstractExpression.cpp │ │ ├── NotExpression.cpp │ │ ├── AddExpression.h │ │ ├── DivExpression.h │ │ ├── MulExpression.h │ │ ├── IdentExpression.h │ │ ├── AndExpression.cpp │ │ ├── LtExpression.cpp │ │ ├── OrExpression.cpp │ │ ├── SubstractExpression.h │ │ ├── GtExpression.cpp │ │ ├── NotExpression.h │ │ ├── AndExpression.h │ │ ├── GtExpression.h │ │ ├── LtExpression.h │ │ ├── OrExpression.h │ │ ├── FunctionCallExpression.h │ │ └── FunctionCallExpression.cpp │ ├── base_elements │ │ └── BaseElement.h │ ├── Program.h │ ├── functions │ │ ├── FunctionList.cpp │ │ ├── Function.cpp │ │ ├── ParamValueList.cpp │ │ ├── FunctionList.h │ │ ├── ParamValueList.h │ │ └── ParamList.h │ └── scanner.h ├── types │ ├── Type.cpp │ ├── PrimitiveType.cpp │ ├── Type.h │ ├── Integer.cpp │ ├── UninitObject.cpp │ ├── PrimitiveType.h │ ├── Integer.h │ ├── UninitObject.h │ ├── FunctionType.cpp │ └── FunctionType.h ├── irtree │ ├── nodes │ │ ├── statements │ │ │ ├── Statement.h │ │ │ ├── JumpStatement.cpp │ │ │ ├── LabelStatement.cpp │ │ │ ├── SeqStatement.cpp │ │ │ ├── MoveStatement.cpp │ │ │ ├── JumpStatement.h │ │ │ ├── LabelStatement.h │ │ │ ├── SeqStatement.h │ │ │ ├── ExpStatement.cpp │ │ │ └── MoveStatement.h │ │ ├── expressions │ │ │ ├── Expression.h │ │ │ ├── NameExpression.cpp │ │ │ ├── TempExpression.cpp │ │ │ ├── MemExpression.cpp │ │ │ ├── MemExpression.h │ │ │ ├── EseqExpression.cpp │ │ │ ├── ConstExpression.cpp │ │ │ ├── CallExpression.cpp │ │ │ ├── NameExpression.h │ │ │ ├── CallExpression.h │ │ │ ├── BinopExpression.cpp │ │ │ ├── ConstExpression.h │ │ │ ├── TempExpression.h │ │ │ └── EseqExpression.h │ │ ├── BaseElement.h │ │ ├── ExpressionList.cpp │ │ └── ExpressionList.h │ ├── types │ │ ├── LogicOperatorType.h │ │ ├── BinaryOperatorType.h │ │ └── LogicOperatorType.cpp │ ├── generators │ │ ├── Label.h │ │ ├── Label.cpp │ │ ├── Temporary.h │ │ └── Temporary.cpp │ ├── visitors │ │ ├── VisitorStruct.h │ │ ├── TemplateVisitor.h │ │ └── TemplateVisitor.cpp │ └── tree_wrapper │ │ ├── conditional_wrappers │ │ ├── ConditionalWrapper.h │ │ ├── NegateConditionalWrapper.cpp │ │ ├── NegateConditionalWrapper.h │ │ └── OrConditionalWrapper.h │ │ ├── SubtreeWrapper.h │ │ └── StatementWrapper.h ├── visitors │ ├── TemplateVisitor.h │ └── TemplateVisitor.cpp ├── function-mechanisms │ └── address │ │ ├── Address.h │ │ ├── AddressInRegister.cpp │ │ ├── AddressInRegister.h │ │ └── AddressInFrame.h └── symbol_table │ └── Symbol.cpp ├── 03-parsers-with-ast ├── expressions │ ├── Expression.h │ ├── NumberExpression.cpp │ ├── AddExpression.cpp │ ├── IdentExpression.cpp │ ├── NumberExpression.h │ ├── DivExpression.cpp │ ├── MulExpression.cpp │ ├── SubstractExpression.cpp │ ├── PowerExpression.h │ ├── AddExpression.h │ ├── DivExpression.h │ ├── MulExpression.h │ ├── SubstractExpression.h │ ├── IdentExpression.h │ └── PowerExpression.cpp ├── assignments │ ├── AssignmentList.cpp │ ├── Assignment.cpp │ ├── AssignmentList.h │ └── Assignment.h ├── Program.cpp ├── Program.h └── scanner.h ├── 04-visitors ├── expressions │ ├── Expression.h │ ├── NumberExpression.h │ ├── IdentExpression.cpp │ ├── NumberExpression.cpp │ ├── AddExpression.h │ ├── DivExpression.h │ ├── AddExpression.cpp │ ├── IdentExpression.h │ ├── MulExpression.h │ ├── DivExpression.cpp │ ├── MulExpression.cpp │ ├── SubstractExpression.h │ └── SubstractExpression.cpp ├── Program.cpp ├── base_elements │ └── BaseElement.h ├── assignments │ ├── AssignmentList.cpp │ ├── Assignment.cpp │ ├── AssignmentList.h │ └── Assignment.h ├── Program.h ├── visitors │ ├── forward_decl.h │ └── elements.h └── scanner.h ├── milestones └── milestones-2020 │ ├── 05.5-error-codes.md │ └── 03-visitors.md ├── Dockerfile ├── 02-parsers └── scanner.h └── .gitignore /01-scanners/.gitignore: -------------------------------------------------------------------------------- 1 | lexer.cpp 2 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*.in 3 | !.* 4 | -------------------------------------------------------------------------------- /bin/05-assign-on-not-declared.in: -------------------------------------------------------------------------------- 1 | three := 3; 2 | two -------------------------------------------------------------------------------- /2021/grammar/statements/Statement.cpp: -------------------------------------------------------------------------------- 1 | #include "Statement.h" 2 | -------------------------------------------------------------------------------- /2022/grammar/statements/Statement.cpp: -------------------------------------------------------------------------------- 1 | #include "Statement.h" 2 | -------------------------------------------------------------------------------- /05-variable-scopes/statements/Statement.cpp: -------------------------------------------------------------------------------- 1 | #include "Statement.h" 2 | -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/Statement.cpp: -------------------------------------------------------------------------------- 1 | #include "Statement.h" 2 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/Statement.cpp: -------------------------------------------------------------------------------- 1 | #include "Statement.h" 2 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/Statement.cpp: -------------------------------------------------------------------------------- 1 | #include "Statement.h" 2 | -------------------------------------------------------------------------------- /06-function-calls/types/Type.cpp: -------------------------------------------------------------------------------- 1 | #include "Type.h" 2 | 3 | int Type::ToInt() { 4 | return 0; 5 | } -------------------------------------------------------------------------------- /07-irtree-build/types/Type.cpp: -------------------------------------------------------------------------------- 1 | #include "Type.h" 2 | 3 | int Type::ToInt() { 4 | return 0; 5 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/types/Type.cpp: -------------------------------------------------------------------------------- 1 | #include "Type.h" 2 | 3 | int Type::ToInt() { 4 | return 0; 5 | } -------------------------------------------------------------------------------- /05-variable-scopes/objects/Object.cpp: -------------------------------------------------------------------------------- 1 | #include "Object.h" 2 | 3 | int Object::ToInt() { 4 | return 0; 5 | } -------------------------------------------------------------------------------- /2021/scopes/BaseScope.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | #include "BaseScope.h" 6 | -------------------------------------------------------------------------------- /bin/05-undeclared-var-outside-scope.in: -------------------------------------------------------------------------------- 1 | { 2 | var three; 3 | three := 3; 4 | } 5 | print(three); 6 | one + two -------------------------------------------------------------------------------- /2021/symbols/BaseSymbol.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | #include "BaseSymbol.h" 6 | -------------------------------------------------------------------------------- /2022/symbols/BaseSymbol.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | #include "BaseSymbol.h" 6 | -------------------------------------------------------------------------------- /07-irtree-build/types/PrimitiveType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "PrimitiveType.h" 6 | -------------------------------------------------------------------------------- /06-function-calls/types/PrimitiveType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "PrimitiveType.h" 6 | -------------------------------------------------------------------------------- /bin/02-a.in: -------------------------------------------------------------------------------- 1 | three := 3 2 | seven := 7 3 | two := 2 4 | one := three - two 5 | seven := three * two + one 6 | five := 5 7 | seven * seven 8 | -------------------------------------------------------------------------------- /06-function-calls/types/Type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Type { 4 | public: 5 | virtual int ToInt(); 6 | virtual ~Type() = default; 7 | }; -------------------------------------------------------------------------------- /07-irtree-build/types/Type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Type { 4 | public: 5 | virtual int ToInt(); 6 | virtual ~Type() = default; 7 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/types/PrimitiveType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "PrimitiveType.h" 6 | -------------------------------------------------------------------------------- /2021/grammar/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "base_elements/BaseElement.h" 3 | 4 | class Expression : public BaseElement { 5 | }; -------------------------------------------------------------------------------- /2022/grammar/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "base_elements/BaseElement.h" 3 | 4 | class Expression : public BaseElement { 5 | }; -------------------------------------------------------------------------------- /2022/symbols/Function.cpp: -------------------------------------------------------------------------------- 1 | #include "Function.h" 2 | 3 | 4 | Function::Function() { 5 | base_type = "function"; 6 | type = "function"; 7 | } -------------------------------------------------------------------------------- /05-variable-scopes/symbol_table/ScopeLayerTree.cpp: -------------------------------------------------------------------------------- 1 | #include "ScopeLayerTree.h" 2 | 3 | ScopeLayerTree::ScopeLayerTree(ScopeLayer* root) : root_(root) {} -------------------------------------------------------------------------------- /2021/grammar/statements/Statement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base_elements/BaseElement.h" 4 | 5 | class Statement: public BaseElement { 6 | }; -------------------------------------------------------------------------------- /2022/grammar/statements/Statement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base_elements/BaseElement.h" 4 | 5 | class Statement: public BaseElement { 6 | }; -------------------------------------------------------------------------------- /05-variable-scopes/objects/Object.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Object { 4 | public: 5 | virtual int ToInt(); 6 | virtual ~Object() = default; 7 | }; -------------------------------------------------------------------------------- /05-variable-scopes/statements/Statement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base_elements/BaseElement.h" 4 | 5 | class Statement: public BaseElement { 6 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Program.h" 2 | 3 | Program::Program( 4 | FunctionList* function_list 5 | ): function_list_(function_list) {} -------------------------------------------------------------------------------- /08-irtree-optimizations/types/Type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Type { 4 | public: 5 | virtual int ToInt(); 6 | virtual ~Type() = default; 7 | }; -------------------------------------------------------------------------------- /bin/05-a-shadowing.in: -------------------------------------------------------------------------------- 1 | var three; 2 | three := 3; 3 | { 4 | var three; 5 | three := 4; 6 | print(three); 7 | } 8 | print(three); 9 | two + two * two -------------------------------------------------------------------------------- /06-function-calls/grammar/Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Program.h" 2 | 3 | Program::Program( 4 | FunctionList* function_list 5 | ): function_list_(function_list) {} -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "base_elements/BaseElement.h" 3 | 4 | class Expression : public BaseElement { 5 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/Statement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base_elements/BaseElement.h" 4 | 5 | class Statement: public BaseElement { 6 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "base_elements/BaseElement.h" 3 | 4 | class Expression : public BaseElement { 5 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/Statement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base_elements/BaseElement.h" 4 | 5 | class Statement: public BaseElement { 6 | }; -------------------------------------------------------------------------------- /2022/symbols/VariableSymbol.cpp: -------------------------------------------------------------------------------- 1 | #include "VariableSymbol.h" 2 | 3 | VariableSymbol::VariableSymbol() { 4 | base_type = "variable"; 5 | type = "int"; 6 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Program.h" 2 | 3 | Program::Program( 4 | FunctionList* function_list 5 | ): function_list_(function_list) {} -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "base_elements/BaseElement.h" 3 | 4 | class Expression : public BaseElement { 5 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/Statement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base_elements/BaseElement.h" 4 | 5 | class Statement: public BaseElement { 6 | }; -------------------------------------------------------------------------------- /2022/symbols/VariableSymbol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseSymbol.h" 4 | 5 | class VariableSymbol: public BaseSymbol { 6 | public: 7 | VariableSymbol(); 8 | }; -------------------------------------------------------------------------------- /06-function-calls/types/Integer.cpp: -------------------------------------------------------------------------------- 1 | #include "Integer.h" 2 | 3 | Integer::Integer(int value): value_(value) {} 4 | 5 | int Integer::ToInt() { 6 | return value_; 7 | } 8 | -------------------------------------------------------------------------------- /07-irtree-build/types/Integer.cpp: -------------------------------------------------------------------------------- 1 | #include "Integer.h" 2 | 3 | Integer::Integer(int value): value_(value) {} 4 | 5 | int Integer::ToInt() { 6 | return value_; 7 | } 8 | -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Driver; 3 | 4 | class Expression { 5 | public: 6 | virtual int eval(const Driver& driver) const = 0; 7 | }; -------------------------------------------------------------------------------- /05-variable-scopes/objects/Integer.cpp: -------------------------------------------------------------------------------- 1 | #include "Integer.h" 2 | 3 | Integer::Integer(int value): value_(value) {} 4 | 5 | int Integer::ToInt() { 6 | return value_; 7 | } 8 | -------------------------------------------------------------------------------- /08-irtree-optimizations/types/Integer.cpp: -------------------------------------------------------------------------------- 1 | #include "Integer.h" 2 | 3 | Integer::Integer(int value): value_(value) {} 4 | 5 | int Integer::ToInt() { 6 | return value_; 7 | } 8 | -------------------------------------------------------------------------------- /04-visitors/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "base_elements/BaseElement.h" 3 | 4 | class Expression : public BaseElement { 5 | public: 6 | virtual int eval() const = 0; 7 | }; -------------------------------------------------------------------------------- /07-irtree-build/types/UninitObject.cpp: -------------------------------------------------------------------------------- 1 | #include "UninitObject.h" 2 | 3 | #include 4 | 5 | int UninitObject::ToInt() { 6 | throw std::runtime_error("Variable not initialized"); 7 | } -------------------------------------------------------------------------------- /03-parsers-with-ast/assignments/AssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "AssignmentList.h" 2 | 3 | 4 | void StatementList::AddAssignment(Assignment* assignment) { 5 | assignments_.push_back(assignment); 6 | } -------------------------------------------------------------------------------- /04-visitors/Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Program.h" 2 | 3 | Program::Program( 4 | AssignmentList* assignments, 5 | Expression* expression 6 | ): assignments_(assignments), expression_(expression) {} -------------------------------------------------------------------------------- /05-variable-scopes/objects/UninitObject.cpp: -------------------------------------------------------------------------------- 1 | #include "UninitObject.h" 2 | 3 | #include 4 | 5 | int UninitObject::ToInt() { 6 | throw std::runtime_error("Variable not initialized"); 7 | } -------------------------------------------------------------------------------- /06-function-calls/types/UninitObject.cpp: -------------------------------------------------------------------------------- 1 | #include "UninitObject.h" 2 | 3 | #include 4 | 5 | int UninitObject::ToInt() { 6 | throw std::runtime_error("Variable not initialized"); 7 | } -------------------------------------------------------------------------------- /2021/symbols/StArgument.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | #include "StArgument.h" 6 | StArgument::StArgument(std::string argument) { 7 | name = argument; 8 | } 9 | -------------------------------------------------------------------------------- /05-variable-scopes/Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Program.h" 2 | 3 | Program::Program( 4 | StatementList* assignments, 5 | Expression* expression 6 | ): assignments_(assignments), expression_(expression) {} -------------------------------------------------------------------------------- /05-variable-scopes/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "base_elements/BaseElement.h" 3 | 4 | class Expression : public BaseElement { 5 | public: 6 | virtual int eval() const = 0; 7 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/types/UninitObject.cpp: -------------------------------------------------------------------------------- 1 | #include "UninitObject.h" 2 | 3 | #include 4 | 5 | int UninitObject::ToInt() { 6 | throw std::runtime_error("Variable not initialized"); 7 | } -------------------------------------------------------------------------------- /bin/05-after-value-access.in: -------------------------------------------------------------------------------- 1 | var three; 2 | three := 3; 3 | var four; 4 | four := 4; 5 | { 6 | var three; 7 | three := four; 8 | print(three); 9 | } 10 | print(three); 11 | two + two * two -------------------------------------------------------------------------------- /2021/symbols/StVariable.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | #include "StVariable.h" 6 | 7 | StVariable::StVariable(std::string name) { 8 | this->name = name; 9 | } 10 | -------------------------------------------------------------------------------- /bin/06-functions-example.in: -------------------------------------------------------------------------------- 1 | func main() { 2 | var three; 3 | three := 3; 4 | { 5 | var three; 6 | three := 4; 7 | print(three); 8 | } 9 | print(three); 10 | } -------------------------------------------------------------------------------- /bin/a_with_print.in: -------------------------------------------------------------------------------- 1 | var three; 2 | { 3 | three := 3; 4 | print(three); 5 | var seven; 6 | seven := one + two * three; 7 | print(seven * seven); 8 | } 9 | print(three); 10 | three * three -------------------------------------------------------------------------------- /2021/grammar/Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Program.h" 2 | 3 | Program::Program( 4 | FunctionList* function_list, 5 | StatementList* statement_list 6 | ): function_list_(function_list), statement_list_(statement_list) {} -------------------------------------------------------------------------------- /2022/grammar/Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Program.h" 2 | 3 | Program::Program( 4 | FunctionList* function_list, 5 | StatementList* statement_list 6 | ): function_list_(function_list), statement_list_(statement_list) {} -------------------------------------------------------------------------------- /03-parsers-with-ast/assignments/Assignment.cpp: -------------------------------------------------------------------------------- 1 | #include "Assignment.h" 2 | 3 | Assignment::Assignment( 4 | const std::string& variable, 5 | Expression* expression 6 | ) : variable_(variable), expression_(expression) {} -------------------------------------------------------------------------------- /06-function-calls/types/PrimitiveType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "Type.h" 8 | 9 | class PrimitiveType : public Type { 10 | }; 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /07-irtree-build/types/PrimitiveType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "Type.h" 8 | 9 | class PrimitiveType : public Type { 10 | }; 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bin/2021-scopes.in: -------------------------------------------------------------------------------- 1 | var six; 2 | six := 6; 3 | 4 | func main() { 5 | var three; 6 | three := 3; 7 | var four; 8 | four := 4; 9 | print(three * three); 10 | } 11 | 12 | func foo(a, b, c) { 13 | 14 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/types/PrimitiveType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "Type.h" 8 | 9 | class PrimitiveType : public Type { 10 | }; 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /06-function-calls/types/Integer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | 5 | class Integer: public Type { 6 | public: 7 | explicit Integer(int value); 8 | int ToInt() override; 9 | private: 10 | int value_; 11 | }; -------------------------------------------------------------------------------- /06-function-calls/types/UninitObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | 5 | class UninitObject: public Type { 6 | public: 7 | // explicit Integer(int value); 8 | int ToInt() override; 9 | // int value_; 10 | }; -------------------------------------------------------------------------------- /07-irtree-build/types/Integer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | 5 | class Integer: public Type { 6 | public: 7 | explicit Integer(int value); 8 | int ToInt() override; 9 | private: 10 | int value_; 11 | }; -------------------------------------------------------------------------------- /07-irtree-build/types/UninitObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | 5 | class UninitObject: public Type { 6 | public: 7 | // explicit Integer(int value); 8 | int ToInt() override; 9 | // int value_; 10 | }; -------------------------------------------------------------------------------- /05-variable-scopes/symbol_table/ScopeLayerTree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ScopeLayer.h" 4 | 5 | class ScopeLayerTree { 6 | public: 7 | explicit ScopeLayerTree(ScopeLayer* root); 8 | public: 9 | ScopeLayer* root_; 10 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/types/Integer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | 5 | class Integer: public Type { 6 | public: 7 | explicit Integer(int value); 8 | int ToInt() override; 9 | private: 10 | int value_; 11 | }; -------------------------------------------------------------------------------- /2021/grammar/base_elements/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "visitors/Visitor.h" 4 | 5 | class BaseElement { 6 | public: 7 | virtual void Accept(Visitor* visitor) = 0; 8 | virtual ~BaseElement() = default; 9 | }; 10 | -------------------------------------------------------------------------------- /2022/grammar/base_elements/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "visitors/Visitor.h" 4 | 5 | class BaseElement { 6 | public: 7 | virtual void Accept(Visitor* visitor) = 0; 8 | virtual ~BaseElement() = default; 9 | }; 10 | -------------------------------------------------------------------------------- /04-visitors/base_elements/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "visitors/Visitor.h" 4 | 5 | 6 | class BaseElement { 7 | public: 8 | virtual void Accept(Visitor* visitor) = 0; 9 | virtual ~BaseElement() = default; 10 | }; 11 | -------------------------------------------------------------------------------- /05-variable-scopes/objects/Integer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Object.h" 4 | 5 | class Integer: public Object { 6 | public: 7 | explicit Integer(int value); 8 | int ToInt() override; 9 | private: 10 | int value_; 11 | }; -------------------------------------------------------------------------------- /05-variable-scopes/objects/UninitObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Object.h" 4 | 5 | class UninitObject: public Object { 6 | public: 7 | // explicit Integer(int value); 8 | int ToInt() override; 9 | // int value_; 10 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/types/UninitObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Type.h" 4 | 5 | class UninitObject: public Type { 6 | public: 7 | // explicit Integer(int value); 8 | int ToInt() override; 9 | // int value_; 10 | }; -------------------------------------------------------------------------------- /2021/grammar/expressions/IdentExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "IdentExpression.h" 2 | 3 | IdentExpression::IdentExpression(const std::string& ident): ident_(ident) {} 4 | 5 | void IdentExpression::Accept(Visitor* visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /2021/grammar/statements/VarDecl.cpp: -------------------------------------------------------------------------------- 1 | #include "VarDecl.h" 2 | 3 | VarDecl::VarDecl( 4 | const std::string& variable 5 | ) : variable_(variable) {} 6 | 7 | 8 | void VarDecl::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /2022/grammar/expressions/IdentExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "IdentExpression.h" 2 | 3 | IdentExpression::IdentExpression(const std::string& ident): ident_(ident) {} 4 | 5 | void IdentExpression::Accept(Visitor* visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /2022/grammar/statements/VarDecl.cpp: -------------------------------------------------------------------------------- 1 | #include "VarDecl.h" 2 | 3 | VarDecl::VarDecl( 4 | const std::string& variable 5 | ) : variable_(variable) {} 6 | 7 | 8 | void VarDecl::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /05-variable-scopes/base_elements/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "visitors/Visitor.h" 4 | 5 | class BaseElement { 6 | public: 7 | virtual void Accept(Visitor* visitor) = 0; 8 | virtual ~BaseElement() = default; 9 | }; 10 | -------------------------------------------------------------------------------- /05-variable-scopes/statements/VarDecl.cpp: -------------------------------------------------------------------------------- 1 | #include "VarDecl.h" 2 | 3 | VarDecl::VarDecl( 4 | const std::string& variable 5 | ) : variable_(variable) {} 6 | 7 | 8 | void VarDecl::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../BaseElement.h" 4 | 5 | namespace IRT { 6 | 7 | class Expression : public BaseElement { 8 | public: 9 | virtual ~Expression() = default; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/Statement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../BaseElement.h" 4 | 5 | namespace IRT { 6 | 7 | class Statement : public BaseElement { 8 | public: 9 | virtual ~Statement() = default; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /2021/grammar/expressions/NumberExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberExpression.h" 2 | 3 | NumberExpression::NumberExpression(int value) { 4 | value_ = value; 5 | } 6 | 7 | void NumberExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /2022/grammar/expressions/NumberExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberExpression.h" 2 | 3 | NumberExpression::NumberExpression(int value) { 4 | value_ = value; 5 | } 6 | 7 | void NumberExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/NumberExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberExpression.h" 2 | 3 | NumberExpression::NumberExpression(int value) { 4 | value_ = value; 5 | } 6 | 7 | int NumberExpression::eval(const Driver& driver) const { 8 | return value_; 9 | } -------------------------------------------------------------------------------- /06-function-calls/grammar/base_elements/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "visitors/Visitor.h" 4 | 5 | class BaseElement { 6 | public: 7 | virtual void Accept(Visitor* visitor) = 0; 8 | virtual ~BaseElement() = default; 9 | }; 10 | -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/VarDecl.cpp: -------------------------------------------------------------------------------- 1 | #include "VarDecl.h" 2 | 3 | VarDecl::VarDecl( 4 | const std::string& variable 5 | ) : variable_(variable) {} 6 | 7 | 8 | void VarDecl::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/base_elements/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "visitors/Visitor.h" 4 | 5 | class BaseElement { 6 | public: 7 | virtual void Accept(Visitor* visitor) = 0; 8 | virtual ~BaseElement() = default; 9 | }; 10 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/IdentExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "IdentExpression.h" 2 | 3 | IdentExpression::IdentExpression(const std::string& ident): ident_(ident) {} 4 | 5 | void IdentExpression::Accept(Visitor* visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/VarDecl.cpp: -------------------------------------------------------------------------------- 1 | #include "VarDecl.h" 2 | 3 | VarDecl::VarDecl( 4 | const std::string& variable 5 | ) : variable_(variable) {} 6 | 7 | 8 | void VarDecl::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/Statement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../BaseElement.h" 4 | 5 | namespace IRT { 6 | 7 | class Statement : public BaseElement { 8 | public: 9 | virtual ~Statement() = default; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /2021/grammar/expressions/AddExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "AddExpression.h" 2 | 3 | AddExpression::AddExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | 6 | void AddExpression::Accept(Visitor* visitor) { 7 | visitor->Visit(this); 8 | } -------------------------------------------------------------------------------- /2022/grammar/expressions/AddExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "AddExpression.h" 2 | 3 | AddExpression::AddExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | 6 | void AddExpression::Accept(Visitor* visitor) { 7 | visitor->Visit(this); 8 | } -------------------------------------------------------------------------------- /bin/2022-simple-main.in: -------------------------------------------------------------------------------- 1 | func main() { 2 | var three; 3 | var four; 4 | three := 3; 5 | four := 4; 6 | { 7 | var three; 8 | three := 4; 9 | four := 5; 10 | } 11 | 12 | print(three); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/IdentExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "IdentExpression.h" 2 | 3 | IdentExpression::IdentExpression(const std::string& ident): ident_(ident) {} 4 | 5 | void IdentExpression::Accept(Visitor* visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/NumberExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberExpression.h" 2 | 3 | NumberExpression::NumberExpression(int value) { 4 | value_ = value; 5 | } 6 | 7 | void NumberExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/base_elements/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "visitors/Visitor.h" 4 | 5 | class BaseElement { 6 | public: 7 | virtual void Accept(Visitor* visitor) = 0; 8 | virtual ~BaseElement() = default; 9 | }; 10 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/Expression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../BaseElement.h" 4 | 5 | namespace IRT { 6 | 7 | class Expression : public BaseElement { 8 | public: 9 | virtual ~Expression() = default; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/NumberExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberExpression.h" 2 | 3 | NumberExpression::NumberExpression(int value) { 4 | value_ = value; 5 | } 6 | 7 | void NumberExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/AddExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "AddExpression.h" 2 | 3 | AddExpression::AddExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | 6 | void AddExpression::Accept(Visitor* visitor) { 7 | visitor->Visit(this); 8 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/IdentExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "IdentExpression.h" 2 | 3 | IdentExpression::IdentExpression(const std::string& ident): ident_(ident) {} 4 | 5 | void IdentExpression::Accept(Visitor* visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/VarDecl.cpp: -------------------------------------------------------------------------------- 1 | #include "VarDecl.h" 2 | 3 | VarDecl::VarDecl( 4 | const std::string& variable 5 | ) : variable_(variable) {} 6 | 7 | 8 | void VarDecl::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /2021/grammar/expressions/DivExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "DivExpression.h" 2 | 3 | DivExpression::DivExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void DivExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /2021/grammar/expressions/MulExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "MulExpression.h" 2 | 3 | MulExpression::MulExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void MulExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /2022/grammar/expressions/DivExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "DivExpression.h" 2 | 3 | DivExpression::DivExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void DivExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /2022/grammar/expressions/MulExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "MulExpression.h" 2 | 3 | MulExpression::MulExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void MulExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /05-variable-scopes/visitors/TemplateVisitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Visitor.h" 4 | 5 | template 6 | class TemplateVisitor : public Visitor { 7 | public: 8 | T Accept(BaseElement* element); 9 | protected: 10 | T tos_value_; 11 | 12 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/AddExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "AddExpression.h" 2 | 3 | AddExpression::AddExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | 6 | void AddExpression::Accept(Visitor* visitor) { 7 | visitor->Visit(this); 8 | } -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../visitors/Visitor.h" 4 | namespace IRT { 5 | 6 | class BaseElement { 7 | public: 8 | virtual ~BaseElement() = default; 9 | virtual void Accept(Visitor* visitor) = 0; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/NumberExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberExpression.h" 2 | 3 | NumberExpression::NumberExpression(int value) { 4 | value_ = value; 5 | } 6 | 7 | void NumberExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /2021/symbols/BaseSymbol.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | class BaseSymbol { 11 | public: 12 | std::string name; 13 | virtual ~BaseSymbol() = default; 14 | }; 15 | 16 | 17 | -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/DivExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "DivExpression.h" 2 | 3 | DivExpression::DivExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void DivExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/MulExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "MulExpression.h" 2 | 3 | MulExpression::MulExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void MulExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/DivExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "DivExpression.h" 2 | 3 | DivExpression::DivExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void DivExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/MulExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "MulExpression.h" 2 | 3 | MulExpression::MulExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void MulExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/AddExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "AddExpression.h" 2 | 3 | AddExpression::AddExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | 6 | void AddExpression::Accept(Visitor* visitor) { 7 | visitor->Visit(this); 8 | } -------------------------------------------------------------------------------- /2021/grammar/expressions/NumberExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class NumberExpression: public Expression { 5 | public: 6 | explicit NumberExpression(int value); 7 | void Accept(Visitor* visit) override; 8 | 9 | int value_; 10 | }; -------------------------------------------------------------------------------- /2022/grammar/expressions/NumberExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class NumberExpression: public Expression { 5 | public: 6 | explicit NumberExpression(int value); 7 | void Accept(Visitor* visit) override; 8 | 9 | int value_; 10 | }; -------------------------------------------------------------------------------- /06-function-calls/visitors/TemplateVisitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/visitors/Visitor.h" 4 | 5 | template 6 | class TemplateVisitor : public Visitor { 7 | public: 8 | T Accept(BaseElement* element); 9 | protected: 10 | T tos_value_; 11 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/BaseElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../visitors/Visitor.h" 4 | namespace IRT { 5 | 6 | class BaseElement { 7 | public: 8 | virtual ~BaseElement() = default; 9 | virtual void Accept(Visitor* visitor) = 0; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /2021/grammar/expressions/SubstractExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "SubstractExpression.h" 2 | 3 | SubstractExpression::SubstractExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | void SubstractExpression::Accept(Visitor *visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /2021/grammar/statements/PrintStatement.cpp: -------------------------------------------------------------------------------- 1 | #include "PrintStatement.h" 2 | 3 | PrintStatement::PrintStatement( 4 | Expression* expression 5 | ) : expression_(expression) {} 6 | 7 | 8 | void PrintStatement::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /2021/grammar/statements/ScopeAssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "ScopeAssignmentList.h" 2 | 3 | 4 | ScopeAssignmentList::ScopeAssignmentList(StatementList *list): 5 | statement_list(list) {} 6 | 7 | void ScopeAssignmentList::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /2022/grammar/expressions/SubstractExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "SubstractExpression.h" 2 | 3 | SubstractExpression::SubstractExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | void SubstractExpression::Accept(Visitor *visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /2022/grammar/statements/PrintStatement.cpp: -------------------------------------------------------------------------------- 1 | #include "PrintStatement.h" 2 | 3 | PrintStatement::PrintStatement( 4 | Expression* expression 5 | ) : expression_(expression) {} 6 | 7 | 8 | void PrintStatement::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /2022/grammar/statements/ScopeAssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "ScopeAssignmentList.h" 2 | 3 | 4 | ScopeAssignmentList::ScopeAssignmentList(StatementList *list): 5 | statement_list(list) {} 6 | 7 | void ScopeAssignmentList::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /05-variable-scopes/statements/PrintStatement.cpp: -------------------------------------------------------------------------------- 1 | #include "PrintStatement.h" 2 | 3 | PrintStatement::PrintStatement( 4 | Expression* expression 5 | ) : expression_(expression) {} 6 | 7 | 8 | void PrintStatement::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /05-variable-scopes/statements/ScopeAssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "ScopeAssignmentList.h" 2 | 3 | 4 | ScopeAssignmentList::ScopeAssignmentList(StatementList *list): 5 | statement_list(list) {} 6 | 7 | void ScopeAssignmentList::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/NumberExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class NumberExpression: public Expression { 5 | public: 6 | explicit NumberExpression(int value); 7 | void Accept(Visitor* visit) override; 8 | 9 | int value_; 10 | }; -------------------------------------------------------------------------------- /07-irtree-build/visitors/TemplateVisitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/visitors/Visitor.h" 4 | 5 | template 6 | class TemplateVisitor : public Visitor { 7 | public: 8 | T Accept(BaseElement* element); 9 | protected: 10 | T tos_value_; 11 | 12 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/DivExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "DivExpression.h" 2 | 3 | DivExpression::DivExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void DivExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/MulExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "MulExpression.h" 2 | 3 | MulExpression::MulExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | void MulExpression::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /2021/grammar/statements/StatementList.cpp: -------------------------------------------------------------------------------- 1 | #include "StatementList.h" 2 | 3 | 4 | void StatementList::AddStatement(Statement* assignment) { 5 | statements_.push_back(assignment); 6 | } 7 | 8 | void StatementList::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /2022/grammar/statements/StatementList.cpp: -------------------------------------------------------------------------------- 1 | #include "StatementList.h" 2 | 3 | 4 | void StatementList::AddStatement(Statement* assignment) { 5 | statements_.push_back(assignment); 6 | } 7 | 8 | void StatementList::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /04-visitors/assignments/AssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "AssignmentList.h" 2 | 3 | 4 | void AssignmentList::AddAssignment(Assignment* assignment) { 5 | assignments_.push_back(assignment); 6 | } 7 | 8 | void AssignmentList::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /05-variable-scopes/statements/AssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "AssignmentList.h" 2 | 3 | 4 | void StatementList::AddStatement(Statement* assignment) { 5 | statements_.push_back(assignment); 6 | } 7 | 8 | void StatementList::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/NumberExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class NumberExpression: public Expression { 5 | public: 6 | explicit NumberExpression(int value); 7 | void Accept(Visitor* visit) override; 8 | 9 | int value_; 10 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/PrintStatement.cpp: -------------------------------------------------------------------------------- 1 | #include "PrintStatement.h" 2 | 3 | PrintStatement::PrintStatement( 4 | Expression* expression 5 | ) : expression_(expression) {} 6 | 7 | 8 | void PrintStatement::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/SubstractExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "SubstractExpression.h" 2 | 3 | SubstractExpression::SubstractExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | void SubstractExpression::Accept(Visitor *visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/PrintStatement.cpp: -------------------------------------------------------------------------------- 1 | #include "PrintStatement.h" 2 | 3 | PrintStatement::PrintStatement( 4 | Expression* expression 5 | ) : expression_(expression) {} 6 | 7 | 8 | void PrintStatement::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/ScopeAssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "ScopeAssignmentList.h" 2 | 3 | 4 | ScopeAssignmentList::ScopeAssignmentList(StatementList *list): 5 | statement_list(list) {} 6 | 7 | void ScopeAssignmentList::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/AddExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "AddExpression.h" 2 | 3 | AddExpression::AddExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | int AddExpression::eval(const Driver& driver) const { 6 | return first->eval(driver) + second->eval(driver); 7 | } -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/SubstractExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "SubstractExpression.h" 2 | 3 | SubstractExpression::SubstractExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | void SubstractExpression::Accept(Visitor *visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/ScopeAssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "ScopeAssignmentList.h" 2 | 3 | 4 | ScopeAssignmentList::ScopeAssignmentList(StatementList *list): 5 | statement_list(list) {} 6 | 7 | void ScopeAssignmentList::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /07-irtree-build/function-mechanisms/address/Address.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | namespace IRT { 5 | 6 | class Address { 7 | public: 8 | virtual ~Address() = default; 9 | virtual Expression* ToExpression() = 0; 10 | }; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/AssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "AssignmentList.h" 2 | 3 | 4 | void StatementList::AddStatement(Statement* assignment) { 5 | statements_.push_back(assignment); 6 | } 7 | 8 | void StatementList::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/NumberExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class NumberExpression: public Expression { 5 | public: 6 | explicit NumberExpression(int value); 7 | void Accept(Visitor* visit) override; 8 | 9 | int value_; 10 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/PrintStatement.cpp: -------------------------------------------------------------------------------- 1 | #include "PrintStatement.h" 2 | 3 | PrintStatement::PrintStatement( 4 | Expression* expression 5 | ) : expression_(expression) {} 6 | 7 | 8 | void PrintStatement::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/visitors/TemplateVisitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/visitors/Visitor.h" 4 | 5 | template 6 | class TemplateVisitor : public Visitor { 7 | public: 8 | T Accept(BaseElement* element); 9 | protected: 10 | T tos_value_; 11 | 12 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/assignments/AssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "assignments/Assignment.h" 4 | 5 | #include 6 | 7 | class StatementList { 8 | public: 9 | void AddAssignment(Assignment* assignment); 10 | private: 11 | std::vector assignments_; 12 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/IdentExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "IdentExpression.h" 2 | #include 3 | 4 | IdentExpression::IdentExpression(const std::string& ident): ident_(ident) {} 5 | 6 | int IdentExpression::eval(const Driver& driver) const { 7 | return driver.variables.at(ident_); 8 | } -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/NumberExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class NumberExpression: public Expression { 5 | public: 6 | explicit NumberExpression(int value); 7 | int eval(const Driver& driver) const override; 8 | private: 9 | int value_; 10 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/AssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "AssignmentList.h" 2 | 3 | 4 | void StatementList::AddStatement(Statement* assignment) { 5 | statements_.push_back(assignment); 6 | } 7 | 8 | void StatementList::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/function-mechanisms/address/Address.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | namespace IRT { 5 | 6 | class Address { 7 | public: 8 | virtual ~Address() = default; 9 | virtual Expression* ToExpression() = 0; 10 | }; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/SubstractExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "SubstractExpression.h" 2 | 3 | SubstractExpression::SubstractExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | void SubstractExpression::Accept(Visitor *visitor) { 6 | visitor->Visit(this); 7 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/ScopeAssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "ScopeAssignmentList.h" 2 | 3 | 4 | ScopeAssignmentList::ScopeAssignmentList(StatementList *list): 5 | statement_list(list) {} 6 | 7 | void ScopeAssignmentList::Accept(Visitor* visitor) { 8 | visitor->Visit(this); 9 | } -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/DivExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "DivExpression.h" 2 | 3 | DivExpression::DivExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | int DivExpression::eval(const Driver& driver) const { 8 | return first->eval(driver) / second->eval(driver); 9 | } -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/MulExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "MulExpression.h" 2 | 3 | MulExpression::MulExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | int MulExpression::eval(const Driver& driver) const { 8 | return first->eval(driver) * second->eval(driver); 9 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/AssignmentList.cpp: -------------------------------------------------------------------------------- 1 | #include "AssignmentList.h" 2 | 3 | 4 | void StatementList::AddStatement(Statement* assignment) { 5 | statements_.push_back(assignment); 6 | } 7 | 8 | void StatementList::Accept(Visitor* visitor) { 9 | visitor->Visit(this); 10 | } -------------------------------------------------------------------------------- /2022/symbols/Function.h: -------------------------------------------------------------------------------- 1 | #include "BaseSymbol.h" 2 | #include 3 | #include 4 | #include "VariableSymbol.h" 5 | 6 | 7 | class Function: public BaseSymbol { 8 | public: 9 | Function(); 10 | std::string return_type; 11 | std::vector arguments; 12 | }; 13 | -------------------------------------------------------------------------------- /04-visitors/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "assignments/AssignmentList.h" 4 | #include "expressions/Expression.h" 5 | 6 | class Program { 7 | public: 8 | Program(AssignmentList* assignments, Expression* expression); 9 | AssignmentList* assignments_; 10 | Expression* expression_; 11 | }; -------------------------------------------------------------------------------- /04-visitors/expressions/NumberExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class NumberExpression: public Expression { 5 | public: 6 | explicit NumberExpression(int value); 7 | int eval() const override; 8 | void Accept(Visitor* visit) override; 9 | 10 | int value_; 11 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "statements/AssignmentList.h" 4 | #include "expressions/Expression.h" 5 | #include 6 | 7 | class Program { 8 | public: 9 | explicit Program(FunctionList* function_list); 10 | FunctionList* function_list_; 11 | }; -------------------------------------------------------------------------------- /2021/grammar/expressions/AddExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class AddExpression: public Expression { 5 | public: 6 | AddExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /2021/grammar/expressions/DivExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class DivExpression: public Expression { 5 | public: 6 | DivExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /2022/grammar/expressions/AddExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class AddExpression: public Expression { 5 | public: 6 | AddExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /2022/grammar/expressions/DivExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class DivExpression: public Expression { 5 | public: 6 | DivExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /04-visitors/assignments/Assignment.cpp: -------------------------------------------------------------------------------- 1 | #include "Assignment.h" 2 | 3 | Assignment::Assignment( 4 | const std::string& variable, 5 | Expression* expression 6 | ) : variable_(variable), expression_(expression) {} 7 | 8 | 9 | void Assignment::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /04-visitors/visitors/forward_decl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Expression; 4 | class NumberExpression; 5 | class AddExpression; 6 | class SubstractExpression; 7 | class MulExpression; 8 | class DivExpression; 9 | class IdentExpression; 10 | class Assignment; 11 | class AssignmentList; 12 | class Program; 13 | -------------------------------------------------------------------------------- /05-variable-scopes/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "statements/AssignmentList.h" 4 | #include "expressions/Expression.h" 5 | 6 | class Program { 7 | public: 8 | Program(StatementList* assignments, Expression* expression); 9 | StatementList* assignments_; 10 | Expression* expression_; 11 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "statements/AssignmentList.h" 4 | #include "expressions/Expression.h" 5 | #include 6 | 7 | class Program { 8 | public: 9 | explicit Program(FunctionList* function_list); 10 | FunctionList* function_list_; 11 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/NotExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "NotExpression.h" 6 | void NotExpression::Accept(Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | NotExpression::NotExpression(Expression *e1): expression_(e1) { 11 | } 12 | -------------------------------------------------------------------------------- /2021/grammar/statements/Assignment.cpp: -------------------------------------------------------------------------------- 1 | #include "Assignment.h" 2 | 3 | Assignment::Assignment( 4 | const std::string& variable, 5 | Expression* expression 6 | ) : variable_(variable), expression_(expression) {} 7 | 8 | 9 | void Assignment::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /2021/symbols/StVariable.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "BaseSymbol.h" 9 | 10 | 11 | class StVariable : public BaseSymbol { 12 | public: 13 | explicit StVariable(std::string name); 14 | std::string type = "int"; 15 | }; 16 | 17 | 18 | -------------------------------------------------------------------------------- /2022/grammar/statements/Assignment.cpp: -------------------------------------------------------------------------------- 1 | #include "Assignment.h" 2 | 3 | Assignment::Assignment( 4 | const std::string& variable, 5 | Expression* expression 6 | ) : variable_(variable), expression_(expression) {} 7 | 8 | 9 | void Assignment::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /03-parsers-with-ast/Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Program.h" 2 | 3 | Program::Program( 4 | StatementList* assignments, 5 | Expression* expression 6 | ): assignments_(assignments), expression_(expression) {} 7 | 8 | 9 | int Program::eval(Driver& driver) { 10 | return expression_->eval(driver); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /05-variable-scopes/expressions/NumberExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class NumberExpression: public Expression { 5 | public: 6 | explicit NumberExpression(int value); 7 | int eval() const override; 8 | void Accept(Visitor* visit) override; 9 | 10 | int value_; 11 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "statements/AssignmentList.h" 4 | #include "expressions/Expression.h" 5 | #include 6 | 7 | class Program { 8 | public: 9 | explicit Program(FunctionList* function_list); 10 | FunctionList* function_list_; 11 | }; -------------------------------------------------------------------------------- /2021/grammar/expressions/IdentExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | #include 5 | 6 | class IdentExpression: public Expression { 7 | public: 8 | IdentExpression(const std::string& ident); 9 | void Accept(Visitor* visitor) override; 10 | 11 | std::string ident_; 12 | }; -------------------------------------------------------------------------------- /2021/grammar/expressions/MulExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class MulExpression: public Expression { 5 | public: 6 | MulExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /2022/grammar/expressions/IdentExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | #include 5 | 6 | class IdentExpression: public Expression { 7 | public: 8 | IdentExpression(const std::string& ident); 9 | void Accept(Visitor* visitor) override; 10 | 11 | std::string ident_; 12 | }; -------------------------------------------------------------------------------- /2022/grammar/expressions/MulExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class MulExpression: public Expression { 5 | public: 6 | MulExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/SubstractExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "SubstractExpression.h" 2 | 3 | SubstractExpression::SubstractExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | int SubstractExpression::eval(const Driver& driver) const { 6 | return first->eval(driver) - second->eval(driver); 7 | } -------------------------------------------------------------------------------- /04-visitors/expressions/IdentExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "IdentExpression.h" 2 | 3 | IdentExpression::IdentExpression(const std::string& ident): ident_(ident) {} 4 | 5 | int IdentExpression::eval() const { 6 | return 0; 7 | } 8 | 9 | void IdentExpression::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /05-variable-scopes/statements/Assignment.cpp: -------------------------------------------------------------------------------- 1 | #include "Assignment.h" 2 | 3 | Assignment::Assignment( 4 | const std::string& variable, 5 | Expression* expression 6 | ) : variable_(variable), expression_(expression) {} 7 | 8 | 9 | void Assignment::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/AddExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class AddExpression: public Expression { 5 | public: 6 | AddExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/DivExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class DivExpression: public Expression { 5 | public: 6 | DivExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/AddExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class AddExpression: public Expression { 5 | public: 6 | AddExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/DivExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class DivExpression: public Expression { 5 | public: 6 | DivExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/NotExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "NotExpression.h" 6 | void NotExpression::Accept(Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | NotExpression::NotExpression(Expression *e1): expression_(e1) { 11 | } 12 | -------------------------------------------------------------------------------- /2022/symbols/BaseSymbol.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | class BaseSymbol { 11 | public: 12 | std::string name; 13 | std::string base_type; 14 | std::string type; 15 | virtual ~BaseSymbol() = default; 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /05-variable-scopes/expressions/IdentExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "IdentExpression.h" 2 | 3 | IdentExpression::IdentExpression(const std::string& ident): ident_(ident) {} 4 | 5 | int IdentExpression::eval() const { 6 | return 0; 7 | } 8 | 9 | void IdentExpression::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/IdentExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | #include 5 | 6 | class IdentExpression: public Expression { 7 | public: 8 | IdentExpression(const std::string& ident); 9 | void Accept(Visitor* visitor) override; 10 | 11 | std::string ident_; 12 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/MulExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class MulExpression: public Expression { 5 | public: 6 | MulExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/Assignment.cpp: -------------------------------------------------------------------------------- 1 | #include "Assignment.h" 2 | 3 | Assignment::Assignment( 4 | const std::string& variable, 5 | Expression* expression 6 | ) : variable_(variable), expression_(expression) {} 7 | 8 | 9 | void Assignment::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/IdentExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | #include 5 | 6 | class IdentExpression: public Expression { 7 | public: 8 | IdentExpression(const std::string& ident); 9 | void Accept(Visitor* visitor) override; 10 | 11 | std::string ident_; 12 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/MulExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class MulExpression: public Expression { 5 | public: 6 | MulExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/Assignment.cpp: -------------------------------------------------------------------------------- 1 | #include "Assignment.h" 2 | 3 | Assignment::Assignment( 4 | const std::string& variable, 5 | Expression* expression 6 | ) : variable_(variable), expression_(expression) {} 7 | 8 | 9 | void Assignment::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/AddExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class AddExpression: public Expression { 5 | public: 6 | AddExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/DivExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class DivExpression: public Expression { 5 | public: 6 | DivExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | Expression* first; 9 | Expression* second; 10 | }; -------------------------------------------------------------------------------- /2021/symbols/StArgument.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "BaseSymbol.h" 9 | 10 | #include 11 | class StArgument : public BaseSymbol { 12 | public: 13 | StArgument(std::string argument); 14 | std::string type = "int"; 15 | }; 16 | 17 | 18 | -------------------------------------------------------------------------------- /2021/symbols/StFunction.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | #include "StFunction.h" 6 | 7 | StFunction::StFunction(Function *function) { 8 | name = function->name_; 9 | for (auto argument: function->param_list_->params_) { 10 | arguments.emplace_back(argument); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /03-parsers-with-ast/assignments/Assignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | 5 | #include 6 | 7 | class Assignment { 8 | public: 9 | Assignment(const std::string& variable, Expression* expression); 10 | private: 11 | std::string variable_; 12 | Expression* expression_; 13 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/PowerExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class PowerExpression: public Expression { 5 | public: 6 | PowerExpression(Expression* expr1, Expression* expr2); 7 | int eval(const Driver& driver) const; 8 | private: 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /04-visitors/expressions/NumberExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberExpression.h" 2 | 3 | NumberExpression::NumberExpression(int value) { 4 | value_ = value; 5 | } 6 | 7 | int NumberExpression::eval() const { 8 | return value_; 9 | } 10 | 11 | void NumberExpression::Accept(Visitor* visitor) { 12 | visitor->Visit(this); 13 | } -------------------------------------------------------------------------------- /05-variable-scopes/visitors/TemplateVisitor.cpp: -------------------------------------------------------------------------------- 1 | #include "TemplateVisitor.h" 2 | 3 | #include "elements.h" 4 | 5 | template 6 | T TemplateVisitor::Accept(BaseElement * element) { 7 | element->Accept(this); 8 | return tos_value_; 9 | } 10 | 11 | template int TemplateVisitor::Accept(BaseElement* element); -------------------------------------------------------------------------------- /06-function-calls/visitors/TemplateVisitor.cpp: -------------------------------------------------------------------------------- 1 | #include "TemplateVisitor.h" 2 | 3 | #include "elements.h" 4 | 5 | template 6 | T TemplateVisitor::Accept(BaseElement * element) { 7 | element->Accept(this); 8 | return tos_value_; 9 | } 10 | 11 | template int TemplateVisitor::Accept(BaseElement* element); -------------------------------------------------------------------------------- /07-irtree-build/irtree/types/LogicOperatorType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | namespace IRT { 9 | enum class LogicOperatorType : char { 10 | LT, 11 | GT, 12 | EQ, 13 | NE 14 | }; 15 | 16 | std::string ToString(LogicOperatorType type); 17 | } 18 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/MulExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class MulExpression: public Expression { 5 | public: 6 | MulExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/Assignment.cpp: -------------------------------------------------------------------------------- 1 | #include "Assignment.h" 2 | 3 | Assignment::Assignment( 4 | const std::string& variable, 5 | Expression* expression 6 | ) : variable_(variable), expression_(expression) {} 7 | 8 | 9 | void Assignment::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /2021/grammar/expressions/SubstractExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class SubstractExpression: public Expression { 5 | public: 6 | SubstractExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /2021/grammar/statements/ReturnStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Statement.h" 5 | 6 | class ReturnStatement : public Statement { 7 | public: 8 | void Accept(Visitor *visitor) override; 9 | explicit ReturnStatement(Expression* expression); 10 | 11 | Expression* return_expression_; 12 | }; 13 | 14 | 15 | -------------------------------------------------------------------------------- /2021/grammar/statements/VarDecl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class VarDecl: public Statement { 9 | public: 10 | VarDecl(const std::string& variable); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | }; -------------------------------------------------------------------------------- /2022/grammar/expressions/SubstractExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class SubstractExpression: public Expression { 5 | public: 6 | SubstractExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /2022/grammar/statements/ReturnStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Statement.h" 5 | 6 | class ReturnStatement : public Statement { 7 | public: 8 | void Accept(Visitor *visitor) override; 9 | explicit ReturnStatement(Expression* expression); 10 | 11 | Expression* return_expression_; 12 | }; 13 | 14 | 15 | -------------------------------------------------------------------------------- /2022/grammar/statements/VarDecl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class VarDecl: public Statement { 9 | public: 10 | VarDecl(const std::string& variable); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/AddExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class AddExpression: public Expression { 5 | public: 6 | AddExpression(Expression* e1, Expression* e2); 7 | int eval(const Driver& driver) const override; 8 | private: 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/DivExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class DivExpression: public Expression { 5 | public: 6 | DivExpression(Expression* e1, Expression* e2); 7 | int eval(const Driver& driver) const override; 8 | private: 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/MulExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class MulExpression: public Expression { 5 | public: 6 | MulExpression(Expression* e1, Expression* e2); 7 | int eval(const Driver& driver) const override; 8 | private: 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /05-variable-scopes/statements/VarDecl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class VarDecl: public Statement { 9 | public: 10 | VarDecl(const std::string& variable); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/IdentExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | #include 5 | 6 | class IdentExpression: public Expression { 7 | public: 8 | IdentExpression(const std::string& ident); 9 | void Accept(Visitor* visitor) override; 10 | 11 | std::string ident_; 12 | }; -------------------------------------------------------------------------------- /04-visitors/expressions/AddExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class AddExpression: public Expression { 5 | public: 6 | AddExpression(Expression* e1, Expression* e2); 7 | int eval() const override; 8 | void Accept(Visitor* visitor) override; 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /04-visitors/expressions/DivExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class DivExpression: public Expression { 5 | public: 6 | DivExpression(Expression* e1, Expression* e2); 7 | int eval() const override; 8 | void Accept(Visitor* visitor) override; 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /05-variable-scopes/expressions/NumberExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberExpression.h" 2 | 3 | NumberExpression::NumberExpression(int value) { 4 | value_ = value; 5 | } 6 | 7 | int NumberExpression::eval() const { 8 | return value_; 9 | } 10 | 11 | void NumberExpression::Accept(Visitor* visitor) { 12 | visitor->Visit(this); 13 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/AndExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "AndExpression.h" 6 | void AndExpression::Accept(Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | AndExpression::AndExpression(Expression *e1, Expression *e2): first(e1), second(e2) { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/OrExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "OrExpression.h" 6 | 7 | void OrExpression::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | 10 | } 11 | OrExpression::OrExpression(Expression *e1, Expression *e2) : first(e1), second(e2) { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/SubstractExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class SubstractExpression: public Expression { 5 | public: 6 | SubstractExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/ReturnStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Statement.h" 5 | 6 | class ReturnStatement : public Statement { 7 | public: 8 | void Accept(Visitor *visitor) override; 9 | explicit ReturnStatement(Expression* expression); 10 | 11 | Expression* return_expression_; 12 | }; 13 | 14 | 15 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/VarDecl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class VarDecl: public Statement { 9 | public: 10 | VarDecl(const std::string& variable); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/types/LogicOperatorType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | namespace IRT { 9 | enum class LogicOperatorType : char { 10 | LT, 11 | GT, 12 | EQ, 13 | NE 14 | }; 15 | 16 | std::string ToString(LogicOperatorType type); 17 | } 18 | -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/SubstractExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class SubstractExpression: public Expression { 5 | public: 6 | SubstractExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/ReturnStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Statement.h" 5 | 6 | class ReturnStatement : public Statement { 7 | public: 8 | void Accept(Visitor *visitor) override; 9 | explicit ReturnStatement(Expression* expression); 10 | 11 | Expression* return_expression_; 12 | }; 13 | 14 | 15 | -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/VarDecl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class VarDecl: public Statement { 9 | public: 10 | VarDecl(const std::string& variable); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/LtExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "LtExpression.h" 6 | void LtExpression::Accept(Visitor *visitor) { 7 | visitor->Visit(this); 8 | } 9 | LtExpression::LtExpression(Expression *first, Expression *second) : first(first), second(second) { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /2021/grammar/statements/ReturnStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ReturnStatement.h" 6 | 7 | void ReturnStatement::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | ReturnStatement::ReturnStatement(Expression *expression): return_expression_(expression) { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /2022/grammar/statements/ReturnStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ReturnStatement.h" 6 | 7 | void ReturnStatement::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | ReturnStatement::ReturnStatement(Expression *expression): return_expression_(expression) { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04-visitors/expressions/AddExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "AddExpression.h" 2 | 3 | AddExpression::AddExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | int AddExpression::eval() const { 6 | return first->eval() + second->eval(); 7 | } 8 | 9 | void AddExpression::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /04-visitors/expressions/IdentExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | #include 5 | 6 | class IdentExpression: public Expression { 7 | public: 8 | IdentExpression(const std::string& ident); 9 | int eval() const override; 10 | void Accept(Visitor* visitor) override; 11 | 12 | std::string ident_; 13 | }; -------------------------------------------------------------------------------- /04-visitors/expressions/MulExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class MulExpression: public Expression { 5 | public: 6 | MulExpression(Expression* e1, Expression* e2); 7 | int eval() const override; 8 | void Accept(Visitor* visitor) override; 9 | 10 | Expression* first; 11 | Expression* second; 12 | }; -------------------------------------------------------------------------------- /05-variable-scopes/expressions/AddExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class AddExpression: public Expression { 5 | public: 6 | AddExpression(Expression* e1, Expression* e2); 7 | int eval() const override; 8 | void Accept(Visitor* visitor) override; 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /05-variable-scopes/expressions/DivExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class DivExpression: public Expression { 5 | public: 6 | DivExpression(Expression* e1, Expression* e2); 7 | int eval() const override; 8 | void Accept(Visitor* visitor) override; 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/GtExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "GtExpression.h" 6 | void GtExpression::Accept(Visitor *visitor) { 7 | visitor->Visit(this); 8 | } 9 | 10 | GtExpression::GtExpression(Expression *first, Expression *second) : first(first), second(second) { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/JumpStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "JumpStatement.h" 6 | 7 | namespace IRT { 8 | 9 | void JumpStatement::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | 12 | } 13 | JumpStatement::JumpStatement(Label label): label_(label) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/AndExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "AndExpression.h" 6 | void AndExpression::Accept(Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | AndExpression::AndExpression(Expression *e1, Expression *e2): first(e1), second(e2) { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/LtExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "LtExpression.h" 6 | void LtExpression::Accept(Visitor *visitor) { 7 | visitor->Visit(this); 8 | } 9 | LtExpression::LtExpression(Expression *first, Expression *second) : first(first), second(second) { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/OrExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "OrExpression.h" 6 | 7 | void OrExpression::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | 10 | } 11 | OrExpression::OrExpression(Expression *e1, Expression *e2) : first(e1), second(e2) { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/SubstractExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class SubstractExpression: public Expression { 5 | public: 6 | SubstractExpression(Expression* e1, Expression* e2); 7 | void Accept(Visitor* visitor) override; 8 | 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/ReturnStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Statement.h" 5 | 6 | class ReturnStatement : public Statement { 7 | public: 8 | void Accept(Visitor *visitor) override; 9 | explicit ReturnStatement(Expression* expression); 10 | 11 | Expression* return_expression_; 12 | }; 13 | 14 | 15 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/VarDecl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class VarDecl: public Statement { 9 | public: 10 | VarDecl(const std::string& variable); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | }; -------------------------------------------------------------------------------- /2021/grammar/statements/PrintStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class PrintStatement: public Statement { 9 | public: 10 | PrintStatement(Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | Expression* expression_; 14 | }; -------------------------------------------------------------------------------- /2022/grammar/statements/PrintStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class PrintStatement: public Statement { 9 | public: 10 | PrintStatement(Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | Expression* expression_; 14 | }; -------------------------------------------------------------------------------- /01-scanners/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(Lexer) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | FLEX_TARGET(MyScanner lexer.l ${Lexer_SOURCE_DIR}/lexer.cpp) 6 | 7 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 8 | 9 | add_executable( 10 | 01-LexerExample 11 | main.cpp 12 | ${FLEX_MyScanner_OUTPUTS} 13 | ) 14 | -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/SubstractExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class SubstractExpression: public Expression { 5 | public: 6 | SubstractExpression(Expression* e1, Expression* e2); 7 | int eval(const Driver& driver) const override; 8 | private: 9 | Expression* first; 10 | Expression* second; 11 | }; -------------------------------------------------------------------------------- /05-variable-scopes/expressions/IdentExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | #include 5 | 6 | class IdentExpression: public Expression { 7 | public: 8 | IdentExpression(const std::string& ident); 9 | int eval() const override; 10 | void Accept(Visitor* visitor) override; 11 | 12 | std::string ident_; 13 | }; -------------------------------------------------------------------------------- /05-variable-scopes/expressions/MulExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class MulExpression: public Expression { 5 | public: 6 | MulExpression(Expression* e1, Expression* e2); 7 | int eval() const override; 8 | void Accept(Visitor* visitor) override; 9 | 10 | Expression* first; 11 | Expression* second; 12 | }; -------------------------------------------------------------------------------- /05-variable-scopes/statements/PrintStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class PrintStatement: public Statement { 9 | public: 10 | PrintStatement(Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | Expression* expression_; 14 | }; -------------------------------------------------------------------------------- /2021/grammar/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "statements/StatementList.h" 4 | #include "expressions/Expression.h" 5 | #include 6 | 7 | class Program { 8 | public: 9 | Program(FunctionList* function_list, StatementList* statement_list); 10 | FunctionList* function_list_; 11 | StatementList* statement_list_; 12 | }; -------------------------------------------------------------------------------- /2022/grammar/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "statements/StatementList.h" 4 | #include "expressions/Expression.h" 5 | #include 6 | 7 | class Program { 8 | public: 9 | Program(FunctionList* function_list, StatementList* statement_list); 10 | FunctionList* function_list_; 11 | StatementList* statement_list_; 12 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/IdentExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | #include 5 | 6 | class Driver; 7 | 8 | class IdentExpression: public Expression { 9 | public: 10 | IdentExpression(const std::string& ident); 11 | int eval(const Driver& driver) const override; 12 | private: 13 | std::string ident_; 14 | }; -------------------------------------------------------------------------------- /05-variable-scopes/expressions/AddExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "AddExpression.h" 2 | 3 | AddExpression::AddExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | int AddExpression::eval() const { 6 | return first->eval() + second->eval(); 7 | } 8 | 9 | void AddExpression::Accept(Visitor* visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/PrintStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class PrintStatement: public Statement { 9 | public: 10 | PrintStatement(Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | Expression* expression_; 14 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/ReturnStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ReturnStatement.h" 6 | 7 | void ReturnStatement::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | ReturnStatement::ReturnStatement(Expression *expression): return_expression_(expression) { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/PrintStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class PrintStatement: public Statement { 9 | public: 10 | PrintStatement(Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | Expression* expression_; 14 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/ReturnStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ReturnStatement.h" 6 | 7 | void ReturnStatement::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | ReturnStatement::ReturnStatement(Expression *expression): return_expression_(expression) { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/LabelStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #include "LabelStatement.h" 6 | 7 | namespace IRT { 8 | 9 | void LabelStatement::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | 12 | } 13 | LabelStatement::LabelStatement(IRT::Label label): label_(label) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /07-irtree-build/irtree/types/BinaryOperatorType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | namespace IRT { 9 | enum class BinaryOperatorType : char { 10 | PLUS, 11 | MINUS, 12 | MUL, 13 | DIV, 14 | AND, 15 | OR 16 | }; 17 | 18 | std::string ToString(BinaryOperatorType type); 19 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/GtExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "GtExpression.h" 6 | void GtExpression::Accept(Visitor *visitor) { 7 | visitor->Visit(this); 8 | } 9 | 10 | GtExpression::GtExpression(Expression *first, Expression *second) : first(first), second(second) { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/JumpStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "JumpStatement.h" 6 | 7 | namespace IRT { 8 | 9 | void JumpStatement::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | 12 | } 13 | JumpStatement::JumpStatement(Label label): label_(label) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /2021/grammar/statements/StatementList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "base_elements/BaseElement.h" 5 | #include 6 | 7 | class StatementList : public Statement { 8 | public: 9 | void AddStatement(Statement* assignment); 10 | void Accept(Visitor* visitor); 11 | 12 | std::vector statements_; 13 | }; -------------------------------------------------------------------------------- /2022/grammar/statements/StatementList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "base_elements/BaseElement.h" 5 | #include 6 | 7 | class StatementList : public Statement { 8 | public: 9 | void AddStatement(Statement* assignment); 10 | void Accept(Visitor* visitor); 11 | 12 | std::vector statements_; 13 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "assignments/AssignmentList.h" 4 | #include "expressions/Expression.h" 5 | 6 | class Program { 7 | public: 8 | Program(StatementList* assignments, Expression* expression); 9 | int eval(Driver& driver); 10 | private: 11 | StatementList* assignments_; 12 | Expression* expression_; 13 | }; -------------------------------------------------------------------------------- /04-visitors/expressions/DivExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "DivExpression.h" 2 | 3 | DivExpression::DivExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | int DivExpression::eval() const { 8 | return first->eval() / second->eval(); 9 | } 10 | 11 | void DivExpression::Accept(Visitor* visitor) { 12 | visitor->Visit(this); 13 | } -------------------------------------------------------------------------------- /04-visitors/expressions/MulExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "MulExpression.h" 2 | 3 | MulExpression::MulExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | int MulExpression::eval() const { 8 | return first->eval() * second->eval(); 9 | } 10 | 11 | void MulExpression::Accept(Visitor* visitor) { 12 | visitor->Visit(this); 13 | } -------------------------------------------------------------------------------- /04-visitors/expressions/SubstractExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class SubstractExpression: public Expression { 5 | public: 6 | SubstractExpression(Expression* e1, Expression* e2); 7 | int eval() const override; 8 | void Accept(Visitor* visitor) override; 9 | 10 | Expression* first; 11 | Expression* second; 12 | }; -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/NameExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "NameExpression.h" 6 | 7 | namespace IRT { 8 | 9 | void NameExpression::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | 12 | } 13 | NameExpression::NameExpression(Label label): label_(label) { 14 | 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/TempExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/10/20. 3 | // 4 | 5 | #include "TempExpression.h" 6 | void IRT::TempExpression::Accept(IRT::Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | IRT::TempExpression::TempExpression(const IRT::Temporary &temporary): temporary_(temporary) { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/ReturnStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ReturnStatement.h" 6 | 7 | void ReturnStatement::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | ReturnStatement::ReturnStatement(Expression *expression): return_expression_(expression) { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/types/BinaryOperatorType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | namespace IRT { 9 | enum class BinaryOperatorType : char { 10 | PLUS, 11 | MINUS, 12 | MUL, 13 | DIV, 14 | AND, 15 | OR 16 | }; 17 | 18 | std::string ToString(BinaryOperatorType type); 19 | } -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/AssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "base_elements/BaseElement.h" 5 | #include 6 | 7 | class StatementList : public Statement { 8 | public: 9 | void AddStatement(Statement* assignment); 10 | void Accept(Visitor* visitor); 11 | 12 | std::vector statements_; 13 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/PrintStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class PrintStatement: public Statement { 9 | public: 10 | PrintStatement(Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | Expression* expression_; 14 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/NameExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "NameExpression.h" 6 | 7 | namespace IRT { 8 | 9 | void NameExpression::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | 12 | } 13 | NameExpression::NameExpression(Label label): label_(label) { 14 | 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/LabelStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #include "LabelStatement.h" 6 | 7 | namespace IRT { 8 | 9 | void LabelStatement::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | 12 | } 13 | LabelStatement::LabelStatement(IRT::Label label): label_(label) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /05-variable-scopes/expressions/DivExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "DivExpression.h" 2 | 3 | DivExpression::DivExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | int DivExpression::eval() const { 8 | return first->eval() / second->eval(); 9 | } 10 | 11 | void DivExpression::Accept(Visitor* visitor) { 12 | visitor->Visit(this); 13 | } -------------------------------------------------------------------------------- /05-variable-scopes/expressions/MulExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "MulExpression.h" 2 | 3 | MulExpression::MulExpression( 4 | Expression *e1, Expression *e2 5 | ): first(e1), second(e2) {} 6 | 7 | int MulExpression::eval() const { 8 | return first->eval() * second->eval(); 9 | } 10 | 11 | void MulExpression::Accept(Visitor* visitor) { 12 | visitor->Visit(this); 13 | } -------------------------------------------------------------------------------- /05-variable-scopes/expressions/SubstractExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Expression.h" 3 | 4 | class SubstractExpression: public Expression { 5 | public: 6 | SubstractExpression(Expression* e1, Expression* e2); 7 | int eval() const override; 8 | void Accept(Visitor* visitor) override; 9 | 10 | Expression* first; 11 | Expression* second; 12 | }; -------------------------------------------------------------------------------- /05-variable-scopes/statements/AssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "statements/Statement.h" 4 | #include "base_elements/BaseElement.h" 5 | #include 6 | 7 | class StatementList : public Statement { 8 | public: 9 | void AddStatement(Statement* assignment); 10 | void Accept(Visitor* visitor); 11 | 12 | std::vector statements_; 13 | }; -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/AssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "base_elements/BaseElement.h" 5 | #include 6 | 7 | class StatementList : public Statement { 8 | public: 9 | void AddStatement(Statement* assignment); 10 | void Accept(Visitor* visitor); 11 | 12 | std::vector statements_; 13 | }; -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/ExpressionList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "ExpressionList.h" 6 | 7 | namespace IRT { 8 | void ExpressionList::Accept(Visitor *visitor) { 9 | visitor->Visit(this); 10 | 11 | } 12 | void ExpressionList::Add(Expression *expression) { 13 | expressions_.push_back(expression); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/MemExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/10/20. 3 | // 4 | 5 | #include "MemExpression.h" 6 | 7 | namespace IRT { 8 | 9 | void MemExpression::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | 12 | } 13 | MemExpression::MemExpression(Expression *expression) : expression_(expression) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/TempExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/10/20. 3 | // 4 | 5 | #include "TempExpression.h" 6 | void IRT::TempExpression::Accept(IRT::Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | IRT::TempExpression::TempExpression(const IRT::Temporary &temporary): temporary_(temporary) { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /04-visitors/assignments/AssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "assignments/Assignment.h" 4 | #include "base_elements/BaseElement.h" 5 | #include 6 | 7 | class AssignmentList : public BaseElement { 8 | public: 9 | void AddAssignment(Assignment* assignment); 10 | void Accept(Visitor* visitor); 11 | 12 | std::vector assignments_; 13 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/NotExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | class NotExpression : public Expression { 10 | public: 11 | explicit NotExpression(Expression* e1); 12 | void Accept(Visitor *visitor) override; 13 | 14 | Expression* expression_; 15 | }; 16 | 17 | 18 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/AssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "base_elements/BaseElement.h" 5 | #include 6 | 7 | class StatementList : public Statement { 8 | public: 9 | void AddStatement(Statement* assignment); 10 | void Accept(Visitor* visitor); 11 | 12 | std::vector statements_; 13 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/ExpressionList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "ExpressionList.h" 6 | 7 | namespace IRT { 8 | void ExpressionList::Accept(Visitor *visitor) { 9 | visitor->Visit(this); 10 | 11 | } 12 | void ExpressionList::Add(Expression *expression) { 13 | expressions_.push_back(expression); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /04-visitors/expressions/SubstractExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "SubstractExpression.h" 2 | 3 | SubstractExpression::SubstractExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | int SubstractExpression::eval() const { 6 | return first->eval() - second->eval(); 7 | } 8 | 9 | void SubstractExpression::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/MemExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/10/20. 3 | // 4 | 5 | #include "MemExpression.h" 6 | 7 | namespace IRT { 8 | 9 | void MemExpression::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | 12 | } 13 | MemExpression::MemExpression(Expression *expression) : expression_(expression) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /07-irtree-build/irtree/generators/Label.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | namespace IRT { 10 | class Label { 11 | public: 12 | Label(); 13 | explicit Label(std::string label); 14 | 15 | std::string ToString() const; 16 | 17 | private: 18 | std::string label_; 19 | static int counter_; 20 | }; 21 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/NotExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | class NotExpression : public Expression { 10 | public: 11 | explicit NotExpression(Expression* e1); 12 | void Accept(Visitor *visitor) override; 13 | 14 | Expression* expression_; 15 | }; 16 | 17 | 18 | -------------------------------------------------------------------------------- /2021/symbols/StFunction.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "BaseSymbol.h" 5 | #include "StArgument.h" 6 | 7 | #include 8 | #include 9 | 10 | class StFunction: public BaseSymbol { 11 | public: 12 | std::vector arguments; 13 | std::string return_type = "void"; 14 | explicit StFunction(Function* function); 15 | }; 16 | 17 | 18 | -------------------------------------------------------------------------------- /05-variable-scopes/expressions/SubstractExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "SubstractExpression.h" 2 | 3 | SubstractExpression::SubstractExpression(Expression *e1, Expression *e2): first(e1), second(e2) {} 4 | 5 | int SubstractExpression::eval() const { 6 | return first->eval() - second->eval(); 7 | } 8 | 9 | void SubstractExpression::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | } -------------------------------------------------------------------------------- /2021/grammar/functions/FunctionList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #include "FunctionList.h" 6 | 7 | void FunctionList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | FunctionList::FunctionList() { 12 | } 13 | 14 | void FunctionList::AddFunction(Function *function) { 15 | functions_.push_back(function); 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /2021/scopes/BaseScope.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 3/11/21. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class BaseScope { 13 | public: 14 | std::unordered_map elements; 15 | std::vector children_; 16 | BaseScope* parent_; 17 | }; 18 | 19 | 20 | -------------------------------------------------------------------------------- /2022/grammar/functions/FunctionList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #include "FunctionList.h" 6 | 7 | void FunctionList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | FunctionList::FunctionList() { 12 | } 13 | 14 | void FunctionList::AddFunction(Function *function) { 15 | functions_.push_back(function); 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/SeqStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #include "SeqStatement.h" 6 | 7 | namespace IRT { 8 | 9 | void SeqStatement::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | } 12 | SeqStatement::SeqStatement(Statement *first, Statement *second): first_statement_(first), second_statement_(second) { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/generators/Label.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | namespace IRT { 10 | class Label { 11 | public: 12 | Label(); 13 | explicit Label(std::string label); 14 | 15 | std::string ToString() const; 16 | 17 | private: 18 | std::string label_; 19 | static int counter_; 20 | }; 21 | } -------------------------------------------------------------------------------- /2021/grammar/statements/Assignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class Assignment: public Statement { 9 | public: 10 | Assignment(const std::string& variable, Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | Expression* expression_; 15 | }; -------------------------------------------------------------------------------- /2021/visitors/TemplateVisitor.h: -------------------------------------------------------------------------------- 1 | #include 2 | template 3 | class TemplateVisitor : public Visitor { 4 | public: 5 | T Accept(BaseElement* element); 6 | void SetValue(T value); 7 | protected: 8 | T tos_value_; 9 | }; 10 | 11 | struct PrimitiveTypeHolder { 12 | bool bool_value; 13 | float float_value; 14 | int int_value; 15 | }; 16 | 17 | 18 | -------------------------------------------------------------------------------- /2022/grammar/statements/Assignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class Assignment: public Statement { 9 | public: 10 | Assignment(const std::string& variable, Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | Expression* expression_; 15 | }; -------------------------------------------------------------------------------- /05-variable-scopes/statements/Assignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class Assignment: public Statement { 9 | public: 10 | Assignment(const std::string& variable, Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | Expression* expression_; 15 | }; -------------------------------------------------------------------------------- /06-function-calls/types/FunctionType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "FunctionType.h" 6 | #include "Integer.h" 7 | 8 | FunctionType::FunctionType(const std::vector &argument_names) : argument_names_(argument_names){ 9 | for (const std::string& name : argument_names) { 10 | arguments_.push_back(new Integer(0)); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/functions/FunctionList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #include "FunctionList.h" 6 | 7 | void FunctionList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | FunctionList::FunctionList() { 12 | } 13 | 14 | void FunctionList::AddFunction(Function *function) { 15 | functions_.push_back(function); 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/generators/Label.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "Label.h" 6 | IRT::Label::Label(): label_("L" + std::to_string(counter_++)) { 7 | } 8 | 9 | IRT::Label::Label(std::string label): label_(label) { 10 | 11 | } 12 | std::string IRT::Label::ToString() const { 13 | return label_; 14 | } 15 | 16 | int IRT::Label::counter_ = 0; 17 | 18 | -------------------------------------------------------------------------------- /07-irtree-build/types/FunctionType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "FunctionType.h" 6 | #include "Integer.h" 7 | 8 | FunctionType::FunctionType(const std::vector &argument_names) : argument_names_(argument_names){ 9 | for (const std::string& name : argument_names) { 10 | arguments_.push_back(new Integer(0)); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06-function-calls/grammar/functions/FunctionList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #include "FunctionList.h" 6 | 7 | void FunctionList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | FunctionList::FunctionList() { 12 | } 13 | 14 | void FunctionList::AddFunction(Function *function) { 15 | functions_.push_back(function); 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/Assignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class Assignment: public Statement { 9 | public: 10 | Assignment(const std::string& variable, Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | Expression* expression_; 15 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/AndExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | 10 | class AndExpression : public Expression { 11 | public: 12 | AndExpression(Expression* e1, Expression* e2); 13 | void Accept(Visitor *visitor) override; 14 | Expression* first; 15 | Expression* second; 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/GtExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | class GtExpression : public Expression { 10 | public: 11 | GtExpression(Expression* first, Expression* second); 12 | void Accept(Visitor *visitor) override; 13 | 14 | Expression* first; 15 | Expression* second; 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/LtExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | class LtExpression : public Expression { 10 | public: 11 | LtExpression(Expression* first, Expression* second); 12 | void Accept(Visitor *visitor) override; 13 | 14 | Expression* first; 15 | Expression* second; 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/Assignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class Assignment: public Statement { 9 | public: 10 | Assignment(const std::string& variable, Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | Expression* expression_; 15 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/generators/Label.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "Label.h" 6 | IRT::Label::Label(): label_("L" + std::to_string(counter_++)) { 7 | } 8 | 9 | IRT::Label::Label(std::string label): label_(label) { 10 | 11 | } 12 | std::string IRT::Label::ToString() const { 13 | return label_; 14 | } 15 | 16 | int IRT::Label::counter_ = 0; 17 | 18 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/SeqStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #include "SeqStatement.h" 6 | 7 | namespace IRT { 8 | 9 | void SeqStatement::Accept(Visitor *visitor) { 10 | visitor->Visit(this); 11 | } 12 | SeqStatement::SeqStatement(Statement *first, Statement *second): first_statement_(first), second_statement_(second) { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/visitors/VisitorStruct.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/15/20. 3 | // 4 | 5 | #include "../nodes/expressions/Expression.h" 6 | #include "../nodes/statements/Statement.h" 7 | namespace IRT { 8 | 9 | struct IrtStorage { 10 | Expression* expression_ = nullptr; 11 | Statement* statement_ = nullptr; 12 | ExpressionList* expression_list_ = nullptr; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /08-irtree-optimizations/types/FunctionType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "FunctionType.h" 6 | #include "Integer.h" 7 | 8 | FunctionType::FunctionType(const std::vector &argument_names) : argument_names_(argument_names){ 9 | for (const std::string& name : argument_names) { 10 | arguments_.push_back(new Integer(0)); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04-visitors/assignments/Assignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "base_elements/BaseElement.h" 5 | 6 | #include 7 | 8 | class Assignment: public BaseElement { 9 | public: 10 | Assignment(const std::string& variable, Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | Expression* expression_; 15 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/AndExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | 10 | class AndExpression : public Expression { 11 | public: 12 | AndExpression(Expression* e1, Expression* e2); 13 | void Accept(Visitor *visitor) override; 14 | Expression* first; 15 | Expression* second; 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/functions/FunctionList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #include "FunctionList.h" 6 | 7 | void FunctionList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | FunctionList::FunctionList() { 12 | } 13 | 14 | void FunctionList::AddFunction(Function *function) { 15 | functions_.push_back(function); 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/Assignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/Expression.h" 4 | #include "Statement.h" 5 | 6 | #include 7 | 8 | class Assignment: public Statement { 9 | public: 10 | Assignment(const std::string& variable, Expression* expression); 11 | void Accept(Visitor* visitor); 12 | 13 | std::string variable_; 14 | Expression* expression_; 15 | }; -------------------------------------------------------------------------------- /2021/grammar/functions/Function.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "Function.h" 6 | 7 | void Function::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | Function::Function( 12 | const std::string &name, 13 | ParamList *param_list, 14 | StatementList *statements): name_(name), param_list_(param_list), statements_(statements){ 15 | } 16 | -------------------------------------------------------------------------------- /2022/grammar/functions/Function.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "Function.h" 6 | 7 | void Function::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | Function::Function( 12 | const std::string &name, 13 | ParamList *param_list, 14 | StatementList *statements): name_(name), param_list_(param_list), statements_(statements){ 15 | } 16 | -------------------------------------------------------------------------------- /bin/06-multiple-functions.in: -------------------------------------------------------------------------------- 1 | func main() { 2 | var three; 3 | three := 555; 4 | { 5 | var three; 6 | three := 1000; 7 | three := foo(three); 8 | print(three); 9 | } 10 | 11 | var five; 12 | five := foo(three); 13 | print(five); 14 | } 15 | 16 | func foo(a) { 17 | print(a); 18 | var three; 19 | three := 3; 20 | return a * three; 21 | } 22 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/generators/Temporary.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | namespace IRT { 10 | class Temporary { 11 | public: 12 | Temporary(); 13 | explicit Temporary(const std::string& name); 14 | std::string ToString() const; 15 | private: 16 | std::string name_; 17 | static int counter_; 18 | }; 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/EseqExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/15/20. 3 | // 4 | 5 | #include "EseqExpression.h" 6 | IRT::EseqExpression::EseqExpression(IRT::Statement *statement, IRT::Expression *expression): 7 | statement_(statement), expression_(expression) { 8 | 9 | } 10 | void IRT::EseqExpression::Accept(IRT::Visitor *visitor) { 11 | visitor->Visit(this); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/MemExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/10/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | namespace IRT { 10 | 11 | class MemExpression : public Expression { 12 | public: 13 | MemExpression(Expression *expression); 14 | void Accept(Visitor *visitor) override; 15 | Expression* expression_; 16 | }; 17 | 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/GtExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | class GtExpression : public Expression { 10 | public: 11 | GtExpression(Expression* first, Expression* second); 12 | void Accept(Visitor *visitor) override; 13 | 14 | Expression* first; 15 | Expression* second; 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/LtExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | class LtExpression : public Expression { 10 | public: 11 | LtExpression(Expression* first, Expression* second); 12 | void Accept(Visitor *visitor) override; 13 | 14 | Expression* first; 15 | Expression* second; 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /2021/grammar/expressions/FunctionCallExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Expression.h" 5 | 6 | #include 7 | 8 | class FunctionCallExpression: public Expression { 9 | public: 10 | FunctionCallExpression(const std::string& name, ParamValueList* param_list); 11 | void Accept(Visitor *visitor) override; 12 | std::string name_; 13 | ParamValueList* param_list_; 14 | }; 15 | 16 | 17 | -------------------------------------------------------------------------------- /2021/grammar/statements/ScopeAssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "StatementList.h" 5 | #include "base_elements/BaseElement.h" 6 | #include 7 | 8 | class ScopeAssignmentList : public Statement { 9 | public: 10 | explicit ScopeAssignmentList(StatementList* assignment_list); 11 | void Accept(Visitor* visitor) override; 12 | StatementList* statement_list; 13 | }; -------------------------------------------------------------------------------- /2022/grammar/expressions/FunctionCallExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Expression.h" 5 | 6 | #include 7 | 8 | class FunctionCallExpression: public Expression { 9 | public: 10 | FunctionCallExpression(const std::string& name, ParamValueList* param_list); 11 | void Accept(Visitor *visitor) override; 12 | std::string name_; 13 | ParamValueList* param_list_; 14 | }; 15 | 16 | 17 | -------------------------------------------------------------------------------- /2022/grammar/statements/ScopeAssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "StatementList.h" 5 | #include "base_elements/BaseElement.h" 6 | #include 7 | 8 | class ScopeAssignmentList : public Statement { 9 | public: 10 | explicit ScopeAssignmentList(StatementList* assignment_list); 11 | void Accept(Visitor* visitor) override; 12 | StatementList* statement_list; 13 | }; -------------------------------------------------------------------------------- /2022/visitors/TemplateVisitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | template 5 | class TemplateVisitor : public Visitor { 6 | public: 7 | T Accept(BaseElement* element); 8 | void SetValue(T value); 9 | protected: 10 | T tos_value_; 11 | }; 12 | 13 | struct PrimitiveTypeHolder { 14 | bool bool_value; 15 | float float_value; 16 | int int_value; 17 | }; 18 | 19 | 20 | -------------------------------------------------------------------------------- /01-scanners/lexer.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL int Lexer::ScanToken() 9 | 10 | // ScanToken is function that calls Scanner; It returns int values, we will use enums! 11 | class Lexer: public yyFlexLexer { 12 | public: 13 | virtual ~Lexer() {} 14 | // virtual int yylex(); 15 | virtual int ScanToken(); 16 | }; 17 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/OrExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | class OrExpression : public Expression { 10 | public: 11 | void Accept(Visitor *visitor) override; 12 | 13 | public: 14 | OrExpression(Expression* e1, Expression* e2); 15 | Expression* first; 16 | Expression* second; 17 | 18 | }; 19 | 20 | 21 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/MoveStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #include "MoveStatement.h" 6 | namespace IRT { 7 | void MoveStatement::Accept(IRT::Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | MoveStatement::MoveStatement( 11 | Expression *source, 12 | Expression *target 13 | ): source_(source), target_(target) { 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/generators/Temporary.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | namespace IRT { 10 | class Temporary { 11 | public: 12 | Temporary(); 13 | explicit Temporary(const std::string& name); 14 | std::string ToString() const; 15 | private: 16 | std::string name_; 17 | static int counter_; 18 | }; 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/MemExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/10/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | namespace IRT { 10 | 11 | class MemExpression : public Expression { 12 | public: 13 | MemExpression(Expression *expression); 14 | void Accept(Visitor *visitor) override; 15 | Expression* expression_; 16 | }; 17 | 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /04-visitors/visitors/elements.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "expressions/AddExpression.h" 4 | #include "expressions/SubstractExpression.h" 5 | #include "expressions/DivExpression.h" 6 | #include "expressions/IdentExpression.h" 7 | #include "expressions/MulExpression.h" 8 | #include "expressions/NumberExpression.h" 9 | 10 | #include "assignments/Assignment.h" 11 | #include "assignments/AssignmentList.h" 12 | #include "Program.h" -------------------------------------------------------------------------------- /06-function-calls/grammar/functions/Function.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "Function.h" 6 | 7 | void Function::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | Function::Function( 12 | const std::string &name, 13 | ParamList *param_list, 14 | StatementList *statements): name_(name), param_list_(param_list), statements_(statements){ 15 | } 16 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/functions/Function.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "Function.h" 6 | 7 | void Function::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | Function::Function( 12 | const std::string &name, 13 | ParamList *param_list, 14 | StatementList *statements): name_(name), param_list_(param_list), statements_(statements){ 15 | } 16 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/ScopeAssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "AssignmentList.h" 5 | #include "base_elements/BaseElement.h" 6 | #include 7 | 8 | class ScopeAssignmentList : public Statement { 9 | public: 10 | explicit ScopeAssignmentList(StatementList* assignment_list); 11 | void Accept(Visitor* visitor) override; 12 | StatementList* statement_list; 13 | }; -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/ConstExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "ConstExpression.h" 6 | 7 | void IRT::ConstExpression::Accept(IRT::Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | IRT::ConstExpression::ConstExpression(int value): value_(value) { 12 | 13 | } 14 | 15 | int IRT::ConstExpression::Value() const { 16 | return value_; 17 | } 18 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/EseqExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/15/20. 3 | // 4 | 5 | #include "EseqExpression.h" 6 | IRT::EseqExpression::EseqExpression(IRT::Statement *statement, IRT::Expression *expression): 7 | statement_(statement), expression_(expression) { 8 | 9 | } 10 | void IRT::EseqExpression::Accept(IRT::Visitor *visitor) { 11 | visitor->Visit(this); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/MoveStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #include "MoveStatement.h" 6 | namespace IRT { 7 | void MoveStatement::Accept(IRT::Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | MoveStatement::MoveStatement( 11 | Expression *source, 12 | Expression *target 13 | ): source_(source), target_(target) { 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /2021/scopes/scopes.md: -------------------------------------------------------------------------------- 1 | ## TODO: Scope 2 | 3 | ### GlobalScope 4 | 5 | * переменные (глобальные) 6 | * функции 7 | 8 | 9 | ### FunctionScope 10 | * аргументы 11 | * переменные 12 | * TODO: глобальный scope 13 | 14 | 15 | ## BraceScope {} 16 | * переменные 17 | * TODO: глобальный scope 18 | * TODO: все scope-ы выше 19 | 20 | 21 | ## Что нужно? 22 | 23 | * Доставать быстро по имени доставать информацию по этому имени 24 | -------------------------------------------------------------------------------- /2022/scopes/scopes.md: -------------------------------------------------------------------------------- 1 | ## TODO: Scope 2 | 3 | ### GlobalScope 4 | 5 | * переменные (глобальные) 6 | * функции 7 | 8 | 9 | ### FunctionScope 10 | * аргументы 11 | * переменные 12 | * TODO: глобальный scope 13 | 14 | 15 | ## BraceScope {} 16 | * переменные 17 | * TODO: глобальный scope 18 | * TODO: все scope-ы выше 19 | 20 | 21 | ## Что нужно? 22 | 23 | * Доставать быстро по имени доставать информацию по этому имени 24 | -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/FunctionCallExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Expression.h" 5 | 6 | #include 7 | 8 | class FunctionCallExpression: public Expression { 9 | public: 10 | FunctionCallExpression(const std::string& name, ParamValueList* param_list); 11 | void Accept(Visitor *visitor) override; 12 | std::string name_; 13 | ParamValueList* param_list_; 14 | }; 15 | 16 | 17 | -------------------------------------------------------------------------------- /06-function-calls/grammar/statements/ScopeAssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "AssignmentList.h" 5 | #include "base_elements/BaseElement.h" 6 | #include 7 | 8 | class ScopeAssignmentList : public Statement { 9 | public: 10 | explicit ScopeAssignmentList(StatementList* assignment_list); 11 | void Accept(Visitor* visitor) override; 12 | StatementList* statement_list; 13 | }; -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/FunctionCallExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Expression.h" 5 | 6 | #include 7 | 8 | class FunctionCallExpression: public Expression { 9 | public: 10 | FunctionCallExpression(const std::string& name, ParamValueList* param_list); 11 | void Accept(Visitor *visitor) override; 12 | std::string name_; 13 | ParamValueList* param_list_; 14 | }; 15 | 16 | 17 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/CallExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "CallExpression.h" 6 | void IRT::CallExpression::Accept(IRT::Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | IRT::CallExpression::CallExpression( 11 | IRT::Expression *expression, 12 | IRT::ExpressionList *args 13 | ): function_name_(expression), args_(args) { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/NameExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | #include "../../generators/Label.h" 10 | namespace IRT { 11 | class NameExpression : public Expression { 12 | public: 13 | NameExpression(Label label); 14 | void Accept(Visitor *visitor) override; 15 | Label label_; 16 | }; 17 | 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/OrExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | class OrExpression : public Expression { 10 | public: 11 | void Accept(Visitor *visitor) override; 12 | 13 | public: 14 | OrExpression(Expression* e1, Expression* e2); 15 | Expression* first; 16 | Expression* second; 17 | 18 | }; 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/functions/Function.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #include "Function.h" 6 | 7 | void Function::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | Function::Function( 12 | const std::string &name, 13 | ParamList *param_list, 14 | StatementList *statements): name_(name), param_list_(param_list), statements_(statements){ 15 | } 16 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/ConstExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "ConstExpression.h" 6 | 7 | void IRT::ConstExpression::Accept(IRT::Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | IRT::ConstExpression::ConstExpression(int value): value_(value) { 12 | 13 | } 14 | 15 | int IRT::ConstExpression::Value() const { 16 | return value_; 17 | } 18 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/visitors/TemplateVisitor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/15/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Visitor.h" 9 | #include "../nodes/BaseElement.h" 10 | namespace IRT { 11 | template 12 | class TemplateVisitor : public Visitor { 13 | public: 14 | T Accept(BaseElement* element); 15 | protected: 16 | T tos_value_; 17 | 18 | }; 19 | 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /06-function-calls/types/FunctionType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "Type.h" 8 | 9 | #include 10 | #include 11 | class FunctionType : public Type { 12 | public: 13 | FunctionType(const std::vector& argument_names); 14 | std::vector arguments_; 15 | std::vector argument_names_; 16 | 17 | }; 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/generators/Temporary.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "Temporary.h" 6 | IRT::Temporary::Temporary(): name_("%" + std::to_string(counter_++)) { 7 | 8 | } 9 | std::string IRT::Temporary::ToString() const { 10 | return name_; 11 | } 12 | 13 | int IRT::Temporary::counter_ = 0; 14 | IRT::Temporary::Temporary(const std::string &name): name_(name) { 15 | 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/JumpStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Statement.h" 9 | #include "../../generators/Label.h" 10 | namespace IRT { 11 | 12 | class JumpStatement : public Statement { 13 | public: 14 | explicit JumpStatement(Label label); 15 | void Accept(Visitor *visitor) override; 16 | Label label_; 17 | 18 | }; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/LabelStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | #include "Statement.h" 8 | #include "../../generators/Label.h" 9 | namespace IRT { 10 | 11 | class LabelStatement : public Statement { 12 | public: 13 | explicit LabelStatement(IRT::Label label); 14 | void Accept(Visitor *visitor) override; 15 | Label label_; 16 | }; 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /07-irtree-build/types/FunctionType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "Type.h" 8 | 9 | #include 10 | #include 11 | class FunctionType : public Type { 12 | public: 13 | FunctionType(const std::vector& argument_names); 14 | std::vector arguments_; 15 | std::vector argument_names_; 16 | 17 | }; 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/FunctionCallExpression.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Expression.h" 5 | 6 | #include 7 | 8 | class FunctionCallExpression: public Expression { 9 | public: 10 | FunctionCallExpression(const std::string& name, ParamValueList* param_list); 11 | void Accept(Visitor *visitor) override; 12 | std::string name_; 13 | ParamValueList* param_list_; 14 | }; 15 | 16 | 17 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/ScopeAssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Statement.h" 4 | #include "AssignmentList.h" 5 | #include "base_elements/BaseElement.h" 6 | #include 7 | 8 | class ScopeAssignmentList : public Statement { 9 | public: 10 | explicit ScopeAssignmentList(StatementList* assignment_list); 11 | void Accept(Visitor* visitor) override; 12 | StatementList* statement_list; 13 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/CallExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "CallExpression.h" 6 | void IRT::CallExpression::Accept(IRT::Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | IRT::CallExpression::CallExpression( 11 | IRT::Expression *expression, 12 | IRT::ExpressionList *args 13 | ): function_name_(expression), args_(args) { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/NameExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | #include "../../generators/Label.h" 10 | namespace IRT { 11 | class NameExpression : public Expression { 12 | public: 13 | NameExpression(Label label); 14 | void Accept(Visitor *visitor) override; 15 | Label label_; 16 | }; 17 | 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/JumpStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Statement.h" 9 | #include "../../generators/Label.h" 10 | namespace IRT { 11 | 12 | class JumpStatement : public Statement { 13 | public: 14 | explicit JumpStatement(Label label); 15 | void Accept(Visitor *visitor) override; 16 | Label label_; 17 | 18 | }; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/LabelStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | #include "Statement.h" 8 | #include "../../generators/Label.h" 9 | namespace IRT { 10 | 11 | class LabelStatement : public Statement { 12 | public: 13 | explicit LabelStatement(IRT::Label label); 14 | void Accept(Visitor *visitor) override; 15 | Label label_; 16 | }; 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /08-irtree-optimizations/types/FunctionType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "Type.h" 8 | 9 | #include 10 | #include 11 | class FunctionType : public Type { 12 | public: 13 | FunctionType(const std::vector& argument_names); 14 | std::vector arguments_; 15 | std::vector argument_names_; 16 | 17 | }; 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /05-variable-scopes/statements/ScopeAssignmentList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "statements/Statement.h" 4 | #include "statements/AssignmentList.h" 5 | #include "base_elements/BaseElement.h" 6 | #include 7 | 8 | class ScopeAssignmentList : public Statement { 9 | public: 10 | explicit ScopeAssignmentList(StatementList* assignment_list); 11 | void Accept(Visitor* visitor) override; 12 | StatementList* statement_list; 13 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/generators/Temporary.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "Temporary.h" 6 | IRT::Temporary::Temporary(): name_("%" + std::to_string(counter_++)) { 7 | 8 | } 9 | std::string IRT::Temporary::ToString() const { 10 | return name_; 11 | } 12 | 13 | int IRT::Temporary::counter_ = 0; 14 | IRT::Temporary::Temporary(const std::string &name): name_(name) { 15 | 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/SeqStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | #include "Statement.h" 8 | namespace IRT { 9 | class SeqStatement : public Statement { 10 | public: 11 | SeqStatement(Statement* first, Statement* second); 12 | void Accept(Visitor *visitor) override; 13 | Statement* first_statement_; 14 | Statement* second_statement_; 15 | }; 16 | 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /2021/grammar/expressions/FunctionCallExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "FunctionCallExpression.h" 6 | 7 | 8 | FunctionCallExpression::FunctionCallExpression(const std::string &name, ParamValueList *param_list): 9 | param_list_(param_list), 10 | name_(name) { 11 | 12 | } 13 | 14 | void FunctionCallExpression::Accept(Visitor *visitor) { 15 | visitor->Visit(this); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /2021/grammar/functions/ParamValueList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ParamValueList.h" 6 | 7 | void ParamValueList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | void ParamValueList::AddParam(Expression *expression) { 12 | params_.push_back(expression); 13 | } 14 | 15 | ParamValueList::ParamValueList(Expression *param) { 16 | params_.push_back(param); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2022/grammar/expressions/FunctionCallExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "FunctionCallExpression.h" 6 | 7 | 8 | FunctionCallExpression::FunctionCallExpression(const std::string &name, ParamValueList *param_list): 9 | param_list_(param_list), 10 | name_(name) { 11 | 12 | } 13 | 14 | void FunctionCallExpression::Accept(Visitor *visitor) { 15 | visitor->Visit(this); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /2022/grammar/functions/ParamValueList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ParamValueList.h" 6 | 7 | void ParamValueList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | void ParamValueList::AddParam(Expression *expression) { 12 | params_.push_back(expression); 13 | } 14 | 15 | ParamValueList::ParamValueList(Expression *param) { 16 | params_.push_back(param); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /milestones/milestones-2020/05.5-error-codes.md: -------------------------------------------------------------------------------- 1 | ## Чекпоинт 5.5 Обработка ошибок компиляции 2 | 3 | ### Мягкий дедлайн (уложиться в срок) - 26 апреля 4 | 5 | Мы создали интепретатор! Теперь надо указывать участок в коде, где находятся ошибки компиляции. 6 | Для этих целей можно использовать объект вида `yy::location`, который передается в токенах. 7 | 8 | 9 | Успехов! 10 | 11 | P.S. После этого чекпоинта можно сказать, что мы создали интепретатор!!! -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/SeqStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | #include "Statement.h" 8 | namespace IRT { 9 | class SeqStatement : public Statement { 10 | public: 11 | SeqStatement(Statement* first, Statement* second); 12 | void Accept(Visitor *visitor) override; 13 | Statement* first_statement_; 14 | Statement* second_statement_; 15 | }; 16 | 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /06-function-calls/grammar/functions/ParamValueList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ParamValueList.h" 6 | 7 | void ParamValueList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | void ParamValueList::AddParam(Expression *expression) { 12 | params_.push_back(expression); 13 | } 14 | 15 | ParamValueList::ParamValueList(Expression *param) { 16 | params_.push_back(param); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /07-irtree-build/function-mechanisms/address/AddressInRegister.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "AddressInRegister.h" 6 | 7 | #include 8 | 9 | namespace IRT { 10 | Expression *AddressInRegister::ToExpression() { 11 | return new TempExpression(temp_); 12 | } 13 | AddressInRegister::AddressInRegister(const Temporary &temp) 14 | : temp_(temp) { 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /07-irtree-build/function-mechanisms/address/AddressInRegister.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | #include 8 | #include "Address.h" 9 | namespace IRT { 10 | 11 | class AddressInRegister : public Address { 12 | public: 13 | AddressInRegister(const Temporary& temp); 14 | Expression *ToExpression() override; 15 | private: 16 | Temporary temp_; 17 | }; 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/expressions/FunctionCallExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "FunctionCallExpression.h" 6 | 7 | 8 | FunctionCallExpression::FunctionCallExpression(const std::string &name, ParamValueList *param_list): 9 | param_list_(param_list), 10 | name_(name) { 11 | 12 | } 13 | 14 | void FunctionCallExpression::Accept(Visitor *visitor) { 15 | visitor->Visit(this); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/functions/ParamValueList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ParamValueList.h" 6 | 7 | void ParamValueList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | void ParamValueList::AddParam(Expression *expression) { 12 | params_.push_back(expression); 13 | } 14 | 15 | ParamValueList::ParamValueList(Expression *param) { 16 | params_.push_back(param); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/ExpStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "ExpStatement.h" 6 | 7 | using namespace IRT; 8 | 9 | Expression *ExpStatement::GetExpression() { 10 | return expression_; 11 | } 12 | 13 | ExpStatement::ExpStatement(Expression *expression): expression_(expression) { 14 | 15 | } 16 | 17 | void ExpStatement::Accept(Visitor *visitor) { 18 | visitor->Visit(this); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /05-variable-scopes/visitors/forward_decl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // template 4 | class BaseElement; 5 | class Expression; 6 | class NumberExpression; 7 | class AddExpression; 8 | class SubstractExpression; 9 | class MulExpression; 10 | class DivExpression; 11 | class IdentExpression; 12 | class Statement; 13 | class PrintStatement; 14 | class VarDecl; 15 | class Assignment; 16 | class StatementList; 17 | class ScopeAssignmentList; 18 | class Program; 19 | -------------------------------------------------------------------------------- /06-function-calls/grammar/expressions/FunctionCallExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "FunctionCallExpression.h" 6 | 7 | 8 | FunctionCallExpression::FunctionCallExpression(const std::string &name, ParamValueList *param_list): 9 | param_list_(param_list), 10 | name_(name) { 11 | 12 | } 13 | 14 | void FunctionCallExpression::Accept(Visitor *visitor) { 15 | visitor->Visit(this); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/CallExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | namespace IRT { 10 | class CallExpression: public Expression { 11 | public: 12 | CallExpression(Expression *expression, ExpressionList *args); 13 | void Accept(Visitor *visitor) override; 14 | Expression* function_name_; 15 | ExpressionList* args_; 16 | 17 | }; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/tree_wrapper/conditional_wrappers/ConditionalWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "../SubtreeWrapper.h" 9 | namespace IRT { 10 | 11 | class ConditionalWrapper : public SubtreeWrapper { 12 | public: 13 | virtual ~ConditionalWrapper() = default; 14 | Expression *ToExpression() override; 15 | Statement *ToStatement() override; 16 | 17 | }; 18 | 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /08-irtree-optimizations/function-mechanisms/address/AddressInRegister.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "AddressInRegister.h" 6 | 7 | #include 8 | 9 | namespace IRT { 10 | Expression *AddressInRegister::ToExpression() { 11 | return new TempExpression(temp_); 12 | } 13 | AddressInRegister::AddressInRegister(const Temporary &temp) 14 | : temp_(temp) { 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/functions/ParamValueList.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "ParamValueList.h" 6 | 7 | void ParamValueList::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | 11 | void ParamValueList::AddParam(Expression *expression) { 12 | params_.push_back(expression); 13 | } 14 | 15 | ParamValueList::ParamValueList(Expression *param) { 16 | params_.push_back(param); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /08-irtree-optimizations/function-mechanisms/address/AddressInRegister.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | #include 8 | #include "Address.h" 9 | namespace IRT { 10 | 11 | class AddressInRegister : public Address { 12 | public: 13 | AddressInRegister(const Temporary& temp); 14 | Expression *ToExpression() override; 15 | private: 16 | Temporary temp_; 17 | }; 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/expressions/FunctionCallExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | #include "FunctionCallExpression.h" 6 | 7 | 8 | FunctionCallExpression::FunctionCallExpression(const std::string &name, ParamValueList *param_list): 9 | param_list_(param_list), 10 | name_(name) { 11 | 12 | } 13 | 14 | void FunctionCallExpression::Accept(Visitor *visitor) { 15 | visitor->Visit(this); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/ExpStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "ExpStatement.h" 6 | 7 | using namespace IRT; 8 | 9 | Expression *ExpStatement::GetExpression() { 10 | return expression_; 11 | } 12 | 13 | ExpStatement::ExpStatement(Expression *expression): expression_(expression) { 14 | 15 | } 16 | 17 | void ExpStatement::Accept(Visitor *visitor) { 18 | visitor->Visit(this); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /04-visitors/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/CallExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | namespace IRT { 10 | class CallExpression: public Expression { 11 | public: 12 | CallExpression(Expression *expression, ExpressionList *args); 13 | void Accept(Visitor *visitor) override; 14 | Expression* function_name_; 15 | ExpressionList* args_; 16 | 17 | }; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/tree_wrapper/conditional_wrappers/ConditionalWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "../SubtreeWrapper.h" 9 | namespace IRT { 10 | 11 | class ConditionalWrapper : public SubtreeWrapper { 12 | public: 13 | virtual ~ConditionalWrapper() = default; 14 | Expression *ToExpression() override; 15 | Statement *ToStatement() override; 16 | 17 | }; 18 | 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /2021/grammar/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | }; -------------------------------------------------------------------------------- /2022/grammar/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | }; -------------------------------------------------------------------------------- /03-parsers-with-ast/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | }; -------------------------------------------------------------------------------- /05-variable-scopes/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | }; -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/BinopExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/9/20. 3 | // 4 | 5 | #include "BinopExpression.h" 6 | void IRT::BinopExpression::Accept(IRT::Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | IRT::BinopExpression::BinopExpression( 11 | IRT::BinaryOperatorType type, 12 | IRT::Expression *first, 13 | IRT::Expression *second 14 | ) : operator_type_(type), first_(first), second_(second) { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | }; -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/ConstExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | namespace IRT { 10 | 11 | class ConstExpression : public Expression { 12 | public: 13 | explicit ConstExpression(int value); 14 | ~ConstExpression() final = default; 15 | int Value() const; 16 | 17 | void Accept(Visitor *visitor) override; 18 | private: 19 | int value_; 20 | }; 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/TempExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/10/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "../expressions/Expression.h" 9 | #include "../../generators/Temporary.h" 10 | namespace IRT { 11 | class TempExpression : public Expression { 12 | public: 13 | explicit TempExpression(const IRT::Temporary &temporary); 14 | void Accept(Visitor *visitor) override; 15 | Temporary temporary_; 16 | }; 17 | 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/types/LogicOperatorType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "LogicOperatorType.h" 6 | std::string IRT::ToString(IRT::LogicOperatorType type) { 7 | switch (type) { 8 | case LogicOperatorType::EQ: 9 | return "EQ"; 10 | case LogicOperatorType::NE: 11 | return "NE"; 12 | case LogicOperatorType::LT: 13 | return "LT"; 14 | case LogicOperatorType::GT: 15 | return "GT"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2021/grammar/functions/FunctionList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "Function.h" 9 | 10 | #include 11 | class FunctionList : public BaseElement { 12 | public: 13 | void Accept(Visitor *visitor) override; 14 | 15 | FunctionList(); 16 | 17 | void AddFunction(Function* function); 18 | std::vector functions_; 19 | 20 | 21 | }; 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /2022/grammar/functions/FunctionList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "Function.h" 9 | 10 | #include 11 | class FunctionList : public BaseElement { 12 | public: 13 | void Accept(Visitor *visitor) override; 14 | 15 | FunctionList(); 16 | 17 | void AddFunction(Function* function); 18 | std::vector functions_; 19 | 20 | 21 | }; 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /06-function-calls/grammar/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/BinopExpression.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/9/20. 3 | // 4 | 5 | #include "BinopExpression.h" 6 | void IRT::BinopExpression::Accept(IRT::Visitor *visitor) { 7 | visitor->Visit(this); 8 | 9 | } 10 | IRT::BinopExpression::BinopExpression( 11 | IRT::BinaryOperatorType type, 12 | IRT::Expression *first, 13 | IRT::Expression *second 14 | ) : operator_type_(type), first_(first), second_(second) { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/types/LogicOperatorType.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | #include "LogicOperatorType.h" 6 | std::string IRT::ToString(IRT::LogicOperatorType type) { 7 | switch (type) { 8 | case LogicOperatorType::EQ: 9 | return "EQ"; 10 | case LogicOperatorType::NE: 11 | return "NE"; 12 | case LogicOperatorType::LT: 13 | return "LT"; 14 | case LogicOperatorType::GT: 15 | return "GT"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /08-irtree-optimizations/visitors/TemplateVisitor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "TemplateVisitor.h" 3 | 4 | #include "elements.h" 5 | 6 | template 7 | T TemplateVisitor::Accept(BaseElement * element) { 8 | element->Accept(this); 9 | return tos_value_; 10 | } 11 | 12 | template int TemplateVisitor::Accept(BaseElement* element); 13 | template IRT::SubtreeWrapper* TemplateVisitor::Accept(BaseElement *element); -------------------------------------------------------------------------------- /07-irtree-build/grammar/functions/FunctionList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "Function.h" 9 | 10 | #include 11 | class FunctionList : public BaseElement { 12 | public: 13 | void Accept(Visitor *visitor) override; 14 | 15 | FunctionList(); 16 | 17 | void AddFunction(Function* function); 18 | std::vector functions_; 19 | 20 | 21 | }; 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/statements/MoveStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Statement.h" 9 | #include "../expressions/Expression.h" 10 | namespace IRT { 11 | 12 | class MoveStatement : public Statement { 13 | public: 14 | MoveStatement(Expression *source, Expression *target); 15 | void Accept(Visitor *visitor) override; 16 | Expression* source_; 17 | Expression* target_; 18 | }; 19 | 20 | }; 21 | 22 | 23 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/ConstExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Expression.h" 9 | namespace IRT { 10 | 11 | class ConstExpression : public Expression { 12 | public: 13 | explicit ConstExpression(int value); 14 | ~ConstExpression() final = default; 15 | int Value() const; 16 | 17 | void Accept(Visitor *visitor) override; 18 | private: 19 | int value_; 20 | }; 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/TempExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/10/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "../expressions/Expression.h" 9 | #include "../../generators/Temporary.h" 10 | namespace IRT { 11 | class TempExpression : public Expression { 12 | public: 13 | explicit TempExpression(const IRT::Temporary &temporary); 14 | void Accept(Visitor *visitor) override; 15 | Temporary temporary_; 16 | }; 17 | 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /06-function-calls/grammar/functions/FunctionList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "Function.h" 9 | 10 | #include 11 | class FunctionList : public BaseElement { 12 | public: 13 | void Accept(Visitor *visitor) override; 14 | 15 | FunctionList(); 16 | 17 | void AddFunction(Function* function); 18 | std::vector functions_; 19 | 20 | 21 | }; 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/ExpressionList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | #include "BaseElement.h" 10 | namespace IRT { 11 | class Expression; 12 | class ExpressionList : public BaseElement { 13 | public: 14 | ExpressionList() = default; 15 | 16 | void Add(Expression* expression); 17 | void Accept(Visitor *visitor) override; 18 | 19 | std::vector expressions_; 20 | 21 | }; 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/tree_wrapper/SubtreeWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../generators/Label.h" 4 | #include "../nodes/expressions/Expression.h" 5 | #include "../nodes/statements/Statement.h" 6 | 7 | namespace IRT { 8 | class SubtreeWrapper { 9 | public: 10 | virtual ~SubtreeWrapper() = default; 11 | virtual Expression* ToExpression() = 0; 12 | virtual Statement* ToStatement() = 0; 13 | virtual Statement* ToConditional(Label true_label, Label false_label) = 0; 14 | }; 15 | 16 | } -------------------------------------------------------------------------------- /07-irtree-build/irtree/tree_wrapper/conditional_wrappers/NegateConditionalWrapper.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #include "NegateConditionalWrapper.h" 6 | 7 | namespace IRT { 8 | 9 | Statement *NegateConditionalWrapper::ToConditional(Label true_label, Label false_label) { 10 | return wrapper_->ToConditional(false_label, true_label); 11 | } 12 | 13 | NegateConditionalWrapper::NegateConditionalWrapper(SubtreeWrapper *wrapper): wrapper_(wrapper) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | LABEL maintainer="akhtyamovpavel@gmail.com" 3 | 4 | RUN apt-get update && apt-get install -y cmake build-essential vim tmux git wget automake libtool autopoint graphviz 5 | 6 | RUN wget https://ftp.gnu.org/gnu/bison/bison-3.5.2.tar.gz && tar -zxvf bison-3.5.2.tar.gz 7 | RUN cd bison-3.5.2 && ./configure && make -j9 && make install && cd .. 8 | 9 | RUN apt-get install -y flex 10 | 11 | RUN useradd -ms /bin/bash ubuntu 12 | USER ubuntu 13 | WORKDIR /home/ubuntu 14 | -------------------------------------------------------------------------------- /02-parsers/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if ! defined(yyFlexLexerOnce) 4 | #include 5 | #endif 6 | 7 | #undef YY_DECL 8 | #define YY_DECL yy::parser::symbol_type Scanner::ScanToken() 9 | 10 | #include "parser.hh" 11 | 12 | class Driver; 13 | 14 | class Scanner: public yyFlexLexer { 15 | public: 16 | Scanner(Driver& driver): driver(driver) {} 17 | virtual ~Scanner() {} 18 | virtual yy::parser::symbol_type ScanToken(); 19 | Driver &driver; 20 | void UpdateLocation(); 21 | }; -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/functions/FunctionList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 25.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "Function.h" 9 | 10 | #include 11 | class FunctionList : public BaseElement { 12 | public: 13 | void Accept(Visitor *visitor) override; 14 | 15 | FunctionList(); 16 | 17 | void AddFunction(Function* function); 18 | std::vector functions_; 19 | 20 | 21 | }; 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/statements/MoveStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Statement.h" 9 | #include "../expressions/Expression.h" 10 | namespace IRT { 11 | 12 | class MoveStatement : public Statement { 13 | public: 14 | MoveStatement(Expression *source, Expression *target); 15 | void Accept(Visitor *visitor) override; 16 | Expression* source_; 17 | Expression* target_; 18 | }; 19 | 20 | }; 21 | 22 | 23 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/tree_wrapper/SubtreeWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../generators/Label.h" 4 | #include "../nodes/expressions/Expression.h" 5 | #include "../nodes/statements/Statement.h" 6 | 7 | namespace IRT { 8 | class SubtreeWrapper { 9 | public: 10 | virtual ~SubtreeWrapper() = default; 11 | virtual Expression* ToExpression() = 0; 12 | virtual Statement* ToStatement() = 0; 13 | virtual Statement* ToConditional(Label true_label, Label false_label) = 0; 14 | }; 15 | 16 | } -------------------------------------------------------------------------------- /2021/grammar/functions/ParamValueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | 9 | #include 10 | #include "base_elements/BaseElement.h" 11 | 12 | class ParamValueList : public BaseElement { 13 | public: 14 | ParamValueList() = default; 15 | explicit ParamValueList(Expression* param); 16 | void Accept(Visitor *visitor) override; 17 | void AddParam(Expression* expression); 18 | 19 | std::vector params_; 20 | }; 21 | -------------------------------------------------------------------------------- /2022/grammar/functions/ParamValueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | 9 | #include 10 | #include "base_elements/BaseElement.h" 11 | 12 | class ParamValueList : public BaseElement { 13 | public: 14 | ParamValueList() = default; 15 | explicit ParamValueList(Expression* param); 16 | void Accept(Visitor *visitor) override; 17 | void AddParam(Expression* expression); 18 | 19 | std::vector params_; 20 | }; 21 | -------------------------------------------------------------------------------- /03-parsers-with-ast/expressions/PowerExpression.cpp: -------------------------------------------------------------------------------- 1 | #include "PowerExpression.h" 2 | 3 | PowerExpression::PowerExpression( 4 | Expression* expr1, Expression* expr2 5 | ): first(expr1), second(expr2) {} 6 | 7 | int PowerExpression::eval(const Driver& driver) const { 8 | int power = second->eval(driver); 9 | int base = first->eval(driver); 10 | 11 | int result = 1; 12 | for (int count = 0; count < power; ++count) { 13 | result *= base; 14 | } 15 | 16 | return result; 17 | } -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/ExpressionList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include 9 | #include "BaseElement.h" 10 | namespace IRT { 11 | class Expression; 12 | class ExpressionList : public BaseElement { 13 | public: 14 | ExpressionList() = default; 15 | 16 | void Add(Expression* expression); 17 | void Accept(Visitor *visitor) override; 18 | 19 | std::vector expressions_; 20 | 21 | }; 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/tree_wrapper/conditional_wrappers/NegateConditionalWrapper.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | #include "NegateConditionalWrapper.h" 6 | 7 | namespace IRT { 8 | 9 | Statement *NegateConditionalWrapper::ToConditional(Label true_label, Label false_label) { 10 | return wrapper_->ToConditional(false_label, true_label); 11 | } 12 | 13 | NegateConditionalWrapper::NegateConditionalWrapper(SubtreeWrapper *wrapper): wrapper_(wrapper) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /07-irtree-build/function-mechanisms/address/AddressInFrame.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Address.h" 9 | namespace IRT { 10 | 11 | class AddressInFrame: public Address { 12 | public: 13 | AddressInFrame( 14 | Address* frame_address, 15 | int offset 16 | ); 17 | ~AddressInFrame() = default; 18 | Expression *ToExpression() override; 19 | private: 20 | Address* frame_address_; 21 | int offset_; 22 | 23 | }; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/functions/ParamValueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | 9 | #include 10 | #include "base_elements/BaseElement.h" 11 | 12 | class ParamValueList : public BaseElement { 13 | public: 14 | ParamValueList() = default; 15 | explicit ParamValueList(Expression* param); 16 | void Accept(Visitor *visitor) override; 17 | void AddParam(Expression* expression); 18 | 19 | std::vector params_; 20 | }; 21 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/nodes/expressions/EseqExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/15/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "../statements/Statement.h" 9 | #include "Expression.h" 10 | namespace IRT { 11 | 12 | class EseqExpression: public Expression { 13 | public: 14 | EseqExpression(Statement* statement, Expression* expression); 15 | void Accept(Visitor *visitor) override; 16 | 17 | Statement* statement_; 18 | Expression* expression_; 19 | }; 20 | 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /06-function-calls/grammar/functions/ParamValueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | 9 | #include 10 | #include "base_elements/BaseElement.h" 11 | 12 | class ParamValueList : public BaseElement { 13 | public: 14 | ParamValueList() = default; 15 | explicit ParamValueList(Expression* param); 16 | void Accept(Visitor *visitor) override; 17 | void AddParam(Expression* expression); 18 | 19 | std::vector params_; 20 | }; 21 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/IfStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "IfStatement.h" 6 | 7 | void IfStatement::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | IfStatement::IfStatement( 11 | Expression *bool_expression, 12 | StatementList *true_statement, 13 | StatementList *false_statement 14 | ): bool_expression_(bool_expression), 15 | true_statement_(true_statement), 16 | false_statement_(false_statement) { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /08-irtree-optimizations/function-mechanisms/address/AddressInFrame.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/14/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Address.h" 9 | namespace IRT { 10 | 11 | class AddressInFrame: public Address { 12 | public: 13 | AddressInFrame( 14 | Address* frame_address, 15 | int offset 16 | ); 17 | ~AddressInFrame() = default; 18 | Expression *ToExpression() override; 19 | private: 20 | Address* frame_address_; 21 | int offset_; 22 | 23 | }; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /2021/grammar/functions/ParamList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class ParamList : public BaseElement { 12 | public: 13 | ParamList(); 14 | explicit ParamList(const std::string& param); 15 | void Accept(Visitor *visitor) override; 16 | void AddParam(const std::string& param); 17 | public: 18 | std::vector params_; 19 | }; 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /2022/grammar/functions/ParamList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class ParamList : public BaseElement { 12 | public: 13 | ParamList(); 14 | explicit ParamList(const std::string& param); 15 | void Accept(Visitor *visitor) override; 16 | void AddParam(const std::string& param); 17 | public: 18 | std::vector params_; 19 | }; 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/statements/IfStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Statement.h" 9 | class IfStatement : public Statement { 10 | public: 11 | IfStatement(Expression* bool_expression, StatementList* true_statement, StatementList* false_statement); 12 | void Accept(Visitor *visitor) override; 13 | 14 | Expression* bool_expression_; 15 | StatementList* true_statement_; 16 | StatementList* false_statement_; 17 | 18 | }; 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/functions/ParamValueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/5/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | 9 | #include 10 | #include "base_elements/BaseElement.h" 11 | 12 | class ParamValueList : public BaseElement { 13 | public: 14 | ParamValueList() = default; 15 | explicit ParamValueList(Expression* param); 16 | void Accept(Visitor *visitor) override; 17 | void AddParam(Expression* expression); 18 | 19 | std::vector params_; 20 | }; 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/nodes/expressions/EseqExpression.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/15/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "../statements/Statement.h" 9 | #include "Expression.h" 10 | namespace IRT { 11 | 12 | class EseqExpression: public Expression { 13 | public: 14 | EseqExpression(Statement* statement, Expression* expression); 15 | void Accept(Visitor *visitor) override; 16 | 17 | Statement* statement_; 18 | Expression* expression_; 19 | }; 20 | 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/visitors/TemplateVisitor.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/15/20. 3 | // 4 | 5 | #include "TemplateVisitor.h" 6 | #include "VisitorStruct.h" 7 | 8 | namespace IRT { 9 | template 10 | T TemplateVisitor::Accept(BaseElement * element) { 11 | element->Accept(this); 12 | return tos_value_; 13 | } 14 | 15 | template int TemplateVisitor::Accept(BaseElement* element); 16 | template IrtStorage TemplateVisitor::Accept(IRT::BaseElement *element); 17 | } 18 | -------------------------------------------------------------------------------- /milestones/milestones-2020/03-visitors.md: -------------------------------------------------------------------------------- 1 | ## Чекпоинт 3. Визиторы 2 | 3 | ### Мягкий дедлайн (уложиться в срок) - 5 апреля 4 | 5 | Во втором чекпоинте мы научились строить абстрактное дерево. Цель этого чекпоинта - научиться обходить деревья. 6 | 7 | В этом чекпоинте предлагается реализовать два визитора: 8 | * `PrintVisitor` - визитор, который печатает дерево разбора в файл 9 | * `Interpreter` - визитор, который интерпретирует функцию `main`. 10 | 11 | Пример можно найти в [примере визиторов](/04-visitors). 12 | Успехов! -------------------------------------------------------------------------------- /06-function-calls/grammar/functions/ParamList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class ParamList : public BaseElement { 12 | public: 13 | ParamList(); 14 | explicit ParamList(const std::string& param); 15 | void Accept(Visitor *visitor) override; 16 | void AddParam(const std::string& param); 17 | public: 18 | std::vector params_; 19 | }; 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /07-irtree-build/grammar/functions/ParamList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class ParamList : public BaseElement { 12 | public: 13 | ParamList(); 14 | explicit ParamList(const std::string& param); 15 | void Accept(Visitor *visitor) override; 16 | void AddParam(const std::string& param); 17 | public: 18 | std::vector params_; 19 | }; 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/tree_wrapper/conditional_wrappers/NegateConditionalWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "ConditionalWrapper.h" 9 | namespace IRT { 10 | class NegateConditionalWrapper : public ConditionalWrapper { 11 | public: 12 | explicit NegateConditionalWrapper(SubtreeWrapper* wrapper); 13 | Statement *ToConditional(Label true_label, Label false_label) override; 14 | private: 15 | SubtreeWrapper* wrapper_; 16 | }; 17 | 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/IfStatement.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | #include "IfStatement.h" 6 | 7 | void IfStatement::Accept(Visitor *visitor) { 8 | visitor->Visit(this); 9 | } 10 | IfStatement::IfStatement( 11 | Expression *bool_expression, 12 | StatementList *true_statement, 13 | StatementList *false_statement 14 | ): bool_expression_(bool_expression), 15 | true_statement_(true_statement), 16 | false_statement_(false_statement) { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/statements/IfStatement.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/7/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "Statement.h" 9 | class IfStatement : public Statement { 10 | public: 11 | IfStatement(Expression* bool_expression, StatementList* true_statement, StatementList* false_statement); 12 | void Accept(Visitor *visitor) override; 13 | 14 | Expression* bool_expression_; 15 | StatementList* true_statement_; 16 | StatementList* false_statement_; 17 | 18 | }; 19 | 20 | 21 | -------------------------------------------------------------------------------- /08-irtree-optimizations/grammar/functions/ParamList.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Pavel Akhtyamov on 24.03.2020. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class ParamList : public BaseElement { 12 | public: 13 | ParamList(); 14 | explicit ParamList(const std::string& param); 15 | void Accept(Visitor *visitor) override; 16 | void AddParam(const std::string& param); 17 | public: 18 | std::vector params_; 19 | }; 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/location.hh 2 | **/parser.hh 3 | **/parser.cpp 4 | **/scanner.cpp 5 | *.gv 6 | *.png 7 | 8 | build/ 9 | # Prerequisites 10 | *.d 11 | 12 | # Compiled Object files 13 | *.slo 14 | *.lo 15 | *.o 16 | *.obj 17 | 18 | # Precompiled Headers 19 | *.gch 20 | *.pch 21 | 22 | # Compiled Dynamic libraries 23 | *.so 24 | *.dylib 25 | *.dll 26 | 27 | # Fortran module files 28 | *.mod 29 | *.smod 30 | 31 | # Compiled Static libraries 32 | *.lai 33 | *.la 34 | *.a 35 | *.lib 36 | 37 | # Executables 38 | *.exe 39 | *.out 40 | *.app 41 | -------------------------------------------------------------------------------- /07-irtree-build/visitors/TemplateVisitor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "TemplateVisitor.h" 3 | 4 | #include "elements.h" 5 | #include "../../2021/visitors/TemplateVisitor.h" 6 | 7 | template 8 | T TemplateVisitor::Accept(BaseElement * element) { 9 | element->Accept(this); 10 | return tos_value_; 11 | } 12 | 13 | 14 | template int TemplateVisitor::Accept(BaseElement* element); 15 | template IRT::SubtreeWrapper* TemplateVisitor::Accept(BaseElement *element); -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/tree_wrapper/conditional_wrappers/NegateConditionalWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "ConditionalWrapper.h" 9 | namespace IRT { 10 | class NegateConditionalWrapper : public ConditionalWrapper { 11 | public: 12 | explicit NegateConditionalWrapper(SubtreeWrapper* wrapper); 13 | Statement *ToConditional(Label true_label, Label false_label) override; 14 | private: 15 | SubtreeWrapper* wrapper_; 16 | }; 17 | 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/tree_wrapper/StatementWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "SubtreeWrapper.h" 9 | namespace IRT { 10 | class StatementWrapper : public SubtreeWrapper { 11 | public: 12 | explicit StatementWrapper(Statement* statement); 13 | Expression *ToExpression() override; 14 | Statement *ToStatement() override; 15 | Statement *ToConditional(Label true_label, Label false_label) override; 16 | private: 17 | Statement* statement_; 18 | }; 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /07-irtree-build/irtree/tree_wrapper/conditional_wrappers/OrConditionalWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "ConditionalWrapper.h" 9 | namespace IRT { 10 | class OrConditionalWrapper: public ConditionalWrapper { 11 | public: 12 | OrConditionalWrapper(SubtreeWrapper *first, SubtreeWrapper *second); 13 | Statement *ToConditional(Label true_label, Label false_label) override; 14 | 15 | SubtreeWrapper* first_; 16 | SubtreeWrapper* second_; 17 | }; 18 | 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /07-irtree-build/symbol_table/Symbol.cpp: -------------------------------------------------------------------------------- 1 | #include "Symbol.h" 2 | 3 | #include 4 | 5 | Symbol::Symbol(const std::string& name): name_(name) {} 6 | 7 | Symbol::Symbol(const Symbol& symbol): name_(symbol.name_) {} 8 | 9 | bool Symbol::operator==(const Symbol& other) const { 10 | return name_ == other.name_; 11 | } 12 | 13 | bool Symbol::operator!=(const Symbol& other) const { 14 | return name_ != other.name_; 15 | } 16 | 17 | 18 | 19 | std::string Symbol::GetName() const { 20 | return name_; 21 | } 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /05-variable-scopes/symbol_table/Symbol.cpp: -------------------------------------------------------------------------------- 1 | #include "Symbol.h" 2 | 3 | #include 4 | 5 | Symbol::Symbol(const std::string& name): name_(name) {} 6 | 7 | Symbol::Symbol(const Symbol& symbol): name_(symbol.name_) {} 8 | 9 | bool Symbol::operator==(const Symbol& other) const { 10 | return name_ == other.name_; 11 | } 12 | 13 | bool Symbol::operator!=(const Symbol& other) const { 14 | return name_ != other.name_; 15 | } 16 | 17 | 18 | 19 | std::string Symbol::GetName() const { 20 | return name_; 21 | } 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /06-function-calls/symbol_table/Symbol.cpp: -------------------------------------------------------------------------------- 1 | #include "Symbol.h" 2 | 3 | #include 4 | 5 | Symbol::Symbol(const std::string& name): name_(name) {} 6 | 7 | Symbol::Symbol(const Symbol& symbol): name_(symbol.name_) {} 8 | 9 | bool Symbol::operator==(const Symbol& other) const { 10 | return name_ == other.name_; 11 | } 12 | 13 | bool Symbol::operator!=(const Symbol& other) const { 14 | return name_ != other.name_; 15 | } 16 | 17 | 18 | 19 | std::string Symbol::GetName() const { 20 | return name_; 21 | } 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/tree_wrapper/StatementWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "SubtreeWrapper.h" 9 | namespace IRT { 10 | class StatementWrapper : public SubtreeWrapper { 11 | public: 12 | explicit StatementWrapper(Statement* statement); 13 | Expression *ToExpression() override; 14 | Statement *ToStatement() override; 15 | Statement *ToConditional(Label true_label, Label false_label) override; 16 | private: 17 | Statement* statement_; 18 | }; 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /08-irtree-optimizations/irtree/tree_wrapper/conditional_wrappers/OrConditionalWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by akhtyamovpavel on 4/8/20. 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | #include "ConditionalWrapper.h" 9 | namespace IRT { 10 | class OrConditionalWrapper: public ConditionalWrapper { 11 | public: 12 | OrConditionalWrapper(SubtreeWrapper *first, SubtreeWrapper *second); 13 | Statement *ToConditional(Label true_label, Label false_label) override; 14 | 15 | SubtreeWrapper* first_; 16 | SubtreeWrapper* second_; 17 | }; 18 | 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /08-irtree-optimizations/symbol_table/Symbol.cpp: -------------------------------------------------------------------------------- 1 | #include "Symbol.h" 2 | 3 | #include 4 | 5 | Symbol::Symbol(const std::string& name): name_(name) {} 6 | 7 | Symbol::Symbol(const Symbol& symbol): name_(symbol.name_) {} 8 | 9 | bool Symbol::operator==(const Symbol& other) const { 10 | return name_ == other.name_; 11 | } 12 | 13 | bool Symbol::operator!=(const Symbol& other) const { 14 | return name_ != other.name_; 15 | } 16 | 17 | 18 | 19 | std::string Symbol::GetName() const { 20 | return name_; 21 | } 22 | 23 | 24 | 25 | 26 | --------------------------------------------------------------------------------