From 97c7ecad35d10e4fe430371fe2f7dd7404d64b56 Mon Sep 17 00:00:00 2001 From: Antonia Heinen Date: Tue, 19 Jan 2021 11:20:56 +0100 Subject: [PATCH] Deleted Node.Clone and renamed ScriptNode -> ProgramNode --- CompilerSpecification/Nodes.md | 31 ++ LanguageSpecification/1_LexicalStructure.md | 271 ++++++++++++++++++ LanguageSpecification/2_Expressions.md | 187 ++++++++++++ LanguageSpecification/3_Variables.md | 63 ++++ LanguageSpecification/4_Datatypes.md | 52 ++++ LanguageSpecification/5_Statements.md | 221 ++++++++++++++ LanguageSpecification/6_Functions.md | 60 ++++ LanguageSpecification/7_Constants.md | 14 + LanguageSpecification/8_TopLevelCode.md | 11 + LanguageSpecification/9_IdentifierBinding.md | 61 ++++ LanguageSpecification/TableOfContents.md | 71 +++++ .../BinaryOperationChainExpressionNode.cs | 17 -- .../BinaryOperationExpressionNode.cs | 4 +- .../AdditionBinaryOperationExpressionNode.cs | 5 - ...BitwiseAndBinaryOperationExpressionNode.cs | 5 - ...eLeftShiftBinaryOperationExpressionNode.cs | 5 - .../BitwiseOrBinaryOperationExpressionNode.cs | 5 - ...RightShiftBinaryOperationExpressionNode.cs | 5 - ...BitwiseXOrBinaryOperationExpressionNode.cs | 5 - .../EqualityBinaryOperationExpressionNode.cs | 5 - ...nentiationBinaryOperationExpressionNode.cs | 5 - ...reaterThanBinaryOperationExpressionNode.cs | 5 - ...anOrEqualsBinaryOperationExpressionNode.cs | 5 - ...erDivisionBinaryOperationExpressionNode.cs | 5 - .../LessThanBinaryOperationExpressionNode.cs | 5 - ...anOrEqualsBinaryOperationExpressionNode.cs | 5 - ...LogicalAndBinaryOperationExpressionNode.cs | 5 - .../LogicalOrBinaryOperationExpressionNode.cs | 5 - ...LogicalXOrBinaryOperationExpressionNode.cs | 5 - .../ModuloBinaryOperationExpressionNode.cs | 5 - ...iplicationBinaryOperationExpressionNode.cs | 5 - ...alDivisionBinaryOperationExpressionNode.cs | 5 - ...ubtractionBinaryOperationExpressionNode.cs | 5 - ...UnequalityBinaryOperationExpressionNode.cs | 5 - .../Nodes/Expressions/ExpressionNode.cs | 4 +- .../Expressions/FunctionCallExpressionNode.cs | 5 - .../Expressions/IdentifierExpressionNode.cs | 5 - .../Expressions/LiteralExpressionNode.cs | 4 +- .../Literals/BooleanLiteralExpressionNode.cs | 5 - .../Literals/CharLiteralExpressionNode.cs | 5 - .../ImaginaryLiteralExpressionNode.cs | 5 - .../Literals/IntegerLiteralExpressionNode.cs | 5 - .../Literals/RationalLiteralExpressionNode.cs | 5 - .../Literals/StringLiteralExpressionNode.cs | 5 - .../UnaryOperationExpressionNode.cs | 4 +- .../BitwiseNotUnaryOperationExpressionNode.cs | 5 - .../LogicalNotUnaryOperationExpressionNode.cs | 5 - .../NegationUnaryOperationExpressionNode.cs | 5 - .../AbstractSyntaxTree/Nodes/INode.cs | 2 - .../Nodes/Identifiers/BoundIdentifierNode.cs | 2 - .../Nodes/Identifiers/IdentifierNode.cs | 4 +- .../Identifiers/UnboundIdentifierNode.cs | 2 - .../Analysis/AbstractSyntaxTree/Nodes/Node.cs | 15 +- .../AbstractSyntaxTree/Nodes/ParameterNode.cs | 2 - .../Nodes/{ScriptNode.cs => ProgramNode.cs} | 9 +- .../Nodes/StatementCollectionNode.cs | 5 - .../Nodes/Statements/BlockStatementNode.cs | 5 - .../Statements/FunctionCallStatementNode.cs | 5 - .../Nodes/Statements/StatementNode.cs | 4 +- .../VariableAssignmentStatementNode.cs | 5 - .../VariableDeclarationStatementNode.cs | 5 - .../Nodes/Statements/WhileStatementNode.cs | 5 - .../Symbols/BuiltinFunctionSymbolNode.cs | 2 - .../Nodes/Symbols/BuiltinTypeSymbolNode.cs | 2 - .../Nodes/Symbols/FunctionSymbolNode.cs | 2 - .../Nodes/Symbols/LocalVariableSymbolNode.cs | 2 - .../Symbols/ParameterVariableSymbolNode.cs | 2 - .../Nodes/Symbols/SymbolNode.cs | 4 +- .../Nodes/Symbols/TypeSymbolNode.cs | 2 - .../Nodes/Symbols/VariableSymbolNode.cs | 2 - .../Nodes/Types/IdentifierTypeNode.cs | 5 - .../Nodes/Types/TypeNode.cs | 4 +- .../Analysis/AbstractSyntaxTree/SyntaxTree.cs | 4 +- Source/Analysis/Grammatical/ScriptParser.cs | 2 +- UnitTests/ScriptTests.cs | 4 +- UnitTests/SyntaxTreeTests.cs | 18 +- 76 files changed, 1062 insertions(+), 298 deletions(-) create mode 100644 CompilerSpecification/Nodes.md create mode 100644 LanguageSpecification/1_LexicalStructure.md create mode 100644 LanguageSpecification/2_Expressions.md create mode 100644 LanguageSpecification/3_Variables.md create mode 100644 LanguageSpecification/4_Datatypes.md create mode 100644 LanguageSpecification/5_Statements.md create mode 100644 LanguageSpecification/6_Functions.md create mode 100644 LanguageSpecification/7_Constants.md create mode 100644 LanguageSpecification/8_TopLevelCode.md create mode 100644 LanguageSpecification/9_IdentifierBinding.md create mode 100644 LanguageSpecification/TableOfContents.md rename Source/Analysis/AbstractSyntaxTree/Nodes/{ScriptNode.cs => ProgramNode.cs} (73%) diff --git a/CompilerSpecification/Nodes.md b/CompilerSpecification/Nodes.md new file mode 100644 index 0000000..b4910d4 --- /dev/null +++ b/CompilerSpecification/Nodes.md @@ -0,0 +1,31 @@ +# Nodes + +A node is a part of the abstract syntax tree. Each node has exactly one **parent** and a variable number of **children**. Children, children's children, etc. are called **ancestors**. + +An example: + +``` + X + / \ +Y Z + / \ + A B +``` + +This is a very simple tree where X is the parent of both Y and Z, and Y and Z are X's children. Y, Z, A and B are all ancestors of X. + +## The class `Node` + +The class `Node` is the base class of every node, so it provides the functionality that each node is capable of. + +- The public property `LineNumber`, which represents the line number of the first lexeme that makes up this node (for error reporting purposes) +- The public property `Parent`, which represents the parent of this node as specified above, or `null`, if this node is the root +- The public method `GetChildren`, which returns a list of children of this node +- The public method `GetAncestors`, which returns a list of ancestors +- The internal methods `PopulateChildren` and `PopulateAncestors`, which add children or ancestors respectively to a list of nodes. + +A class can only be derived from `Node` if it is in the `Krypton.Analysis` assembly. + +## The class `ProgramNode` + +The class `ProgramNode` represents a whole Krypton program and the root of a syntax tree. \ No newline at end of file diff --git a/LanguageSpecification/1_LexicalStructure.md b/LanguageSpecification/1_LexicalStructure.md new file mode 100644 index 0000000..b6e1e20 --- /dev/null +++ b/LanguageSpecification/1_LexicalStructure.md @@ -0,0 +1,271 @@ +# 1 Lexical structure + +## 1.1 Case + +Krypton programs are entirely case sensitive. That means, that an identifier `Something` and an identifier `something` (note the different casing of the "S") do not mean the same thing and can coexist. Casing also affects keywords. For example, the keyword `Var` is used for declaring a variable and due to being a reserved keyword, it cannot be used as and identifier, while `var` is a valid identifier. + +## 1.2 Whitespace + +For the most part, programs are whitespace insensitive. That means, that no whitespace affects the meaning of a script. For example, code can have any number of blank lines, and can be indented with any number of tabs or spaces. + +As an example, all three of these scripts are legal and mean the same thing: + +``` +Output("What's your name?"); +Var name = Input(); +If name.Length > 10 +{ + Output("Oh, you have a long name!"); +} +Out "Hello " + name; +``` + +``` +Output("What's your name?")Var name=Input();If name.Length>10{Out"Oh, you have a long name!";}Out"Hello "+name; +``` + +``` +Output("What's your name?"); + Var name = Input(); + If name.Length > 10 + { + Output("Oh, you have a long name!"); + } + + + +Output("Hello " + name); +``` + +The only situation in which a whitespace character changes the meaning of a program is between two identifiers, two reserved keywords or one identifier and one keyword. Consider the following situation: + +``` +Var x As String; +VarxAsString; +``` + +The first one declares a variable of datatype `String` whereas the second one is a compile time error because a single identifier can never be used as a whole statement. + +## 1.3 Comments + +A comment is a portion of code that is ignored after lexical analysis. + +There are three kinds of comments: + +### 1.3.1 Single line comments + +A single line comment is opened using three dot characters `.` and does not have to be closed as it is considered closed at the end of the line. + +``` +Output("Hello world!"); ... this is a comment +``` + +### 1.3.2 Normal multiline comment + +A normal multiline comment is opened using two consecutive greater than characters `>` and closed using two consecutive less than characters `<`. Because of this syntax, it is possible for a not nested multiline comment to span multiple lines. However, there is no requirement for that. + +A normal multiline comment works like a nested multiline comment with the exception of the balancing rule, which does not apply to weak multiline comments. Thus, this comment is properly closed: + +``` +>> This is a comment >> It is closed there: << +``` + +As you can see, normal multiline comments only use two greater/less than signs. + +It is legal for a weak multiline comment to not be closed at all. In that case the whole rest of the code will be ignored. + +### 1.3.3 Nested multiline comment + +A nested multiline comment works like a normal multiline comment, except that it uses three consecutive greater than characters for the starting and the ending lexeme. + +``` +Output("Hello world!"); >>> This is a comment <<< +>>> This is also a comment +It is not closed on the same line <<< +``` + +An additional rule applies. The number of starting lexemes `>>>` has to equal the number of ending lexemes `<<<`. That means, that the following comment is not closed, for example: + +``` +>>> This is comment >>> It is not closed there: <<< +``` + +That is because there are two starting lexemes but only one ending lexeme. To properly close this comment, the code has to look like this: + +``` +>>> This is a comment >>> It is not closed there: <<< But there: <<< +``` + +Both kinds of comments ignore the starting and ending lexemes of the other kind. That means, that this strict multiline comment is closed: + +``` +>>> Strict >> something <<< +``` + +And these comments aren't: + +``` +>>> Comment << +>> Comment <<< +``` + +It is legal for a nested multiline comment to not be closed at all. In that case, the whole rest of the code will be ignored. + +## 1.4 Identifiers + +Identifiers are strings of characters that obey the following rules: + +- The first character is a letter or an underscore +- The second to last character are all letters, underscores and/or numbers +- The identifier as a whole does not equal a reserved keyword (case sensitive) + +This is the syntax for an identifier: + +``` +id = id_first_char {id_other_char}; +id_other_char = id_first_char | number; +id_first_char = letter | "_"; +``` + +(Here, `letter` corresponds to the characters in the range `0x41` ("A") to `0x5A` ("Z") and `0x61` ("a") to `0x7A` ("z"), and `number` corresponds to the characters in the range `0x30` ("0") to `0x39` ("9"). ) + +These are examples of valid identifiers: `PascalCase`, `camelCase`, `snake_case`, `SCREAMING_SNAKE_CASE`, `___` (these are three consecutive underscores) +These are examples of invalid identifiers: `3D`, `$abc`, `If` + +## 1.5 Reserved keywords + +Reserved keywords are strings of letters with a special meaning in the language. An identifier cannot equal a reserved keyword. + +This is a full list of reserved keywords: + +- `And` +- `Continue` +- `Div` +- `Func` +- `Leave` +- `Left` +- `Let` +- `Mod` +- `Or` +- `Return` +- `Right` +- `Var` +- `With` +- `Xor` + +## 1.6 String literals + +A **string** is a string of characters. + +A string literal is a hardcoded string in the script itself. It starts and ends with a double quotation mark character `"`. It is the compile time error 002 to start a string literal but not end it on the same line. + +The backslash character `\` can stop the string literal from ending. If a quotation mark is prepended by backslash character, it will not close the string literal but instead exist in the string literal itself as a character. A backslash does not escape another character if itself is prepended by an unescaped backslash character. + +Unescaped quotation marks and backslashes do not appear in the final string. + +An example for a valid string literal: `"This is a string!"` + +An example for an invalid string literal: `"This is not a string` + +## 1.7 Character literals + +While a string represents several characters one after each other, a **char** is only a single character. A char literal is started and ended by a single quotation mark character `'`. As with a string literal, a char literal must be terminated on the line it was started. Additionally, it is a compile time error for a script to contain a character literal with more than one character. The literal has to be a single character or an escape sequence. + +## 1.8 Escape sequences + +Some characters cannot be represented in a string or char literal. One common example would be a new line. To be able to include one in the string literal, an escape sequence can be used. It is a backslash followed by a special character potentially followed by the Unicode representation of a character. + +| Escape sequence | Corresponding character | +| ---------------------- | ------------------------------ | +| `\a` | Bell (alert) | +| `\b` | Backspace | +| `\f` | Form feed | +| `\n` | New line | +| `\r` | Carriage return | +| `\t` | Tab | +| `\0` | Null character | +| `\\` | Backspace | +| `\"` | Double quotation mark | +| `\'` | Single quotation mark | +| `\u[n]`, e.g. `\u004F` | A Unicode character in base 16 | + +The base 16 literal has exactly 4 digits, so it has to be "padded" by leading zeroes if the number would not have 4 digits. + +It is the compile time error 004 for a string to contain an unescaped backslash without an escape sequence following. + +## 1.9 Number literals + +There are three types of number literals. + +### 1.9.1 Integer literals + +An integer literal represents a whole number. It obeys the following rules: + +- It consists only of digits 0 to 9, except: +- If the first character is a `0`, then the second character can be a `b` or `x`. This means, that the integer literal is in base 2 (`b` for binary) or 16 (`x` for hexadecimal). +- If the integer literal is in base 16, it also allows the letters a through f. Both lower- and uppercase are allowed, however it is the compile time error 005 if the casing is not consistent (that means that both lowercase and uppercase letters are used). +- No matter the base, an integer literal can contain underscore characters `_`. If it is a binary or hexadecimal integer literal, these underscores are only permitted after the `b` or `x`. More than one underscore is allowed after each other, and trailing underscores are permitted. Integer literals with underscores are exactly equal to the corresponding integer literal without. + +These are examples of valid integer literals: + +```` +1234 +1_000_000 +0xFF00FF +0b0101011101011010 +0xFF_FF_FF +0b010_111_011 +```` + +These are examples of invalid integer literals: + +``` +0a144552 +0x011T91 +0_b11010101 +``` + +Invalid in this case does not necessarily mean that a compile time error is reported. The last example for example is split into two lexemes: the integer literal `0` and the identifier `_b11010101`. + +### 1.9.2 Rational literals + +A rational literal represents a real number. It obeys the following rules: + +- It consists only of digits 0 to 9, except: +- It has to contain exactly one dot character `.` to represent the decimal point. If it lacks it, it is not a rational but an integer literal. The dot may not be the first or last character. +- It may also have the underscores as described under 1.9.1 Integer literals. However, these underscores are not allowed directly before or directly after the decimal point. + +These are examples of valid real literals: + +``` +3.14159265 +3.141_592_65 +``` + +These are examples of invalid real literals, that are also analyzed as something other than a real literal: + +``` +3_.14159 +3.141.59 +3. +.5 +``` + +### 1.9.3 Imaginary literals + +Imaginary literals are integer or rational literals, if they are immediately followed by an `i`. + +For example, `4i` is an imaginary literal. + +Only `i` without an integer or rational literal in front of it is an identifier. + +## 1.10 Syntax characters + +Syntax characters are the punctuation of the language and operators like `+`. They are always analyzed greedily. For example: + +``` +x += 5; +``` + +The `+=` is not analyzed as `+` and `=` but as the whole lexeme `+=`. Krypton is lexed greedily. + diff --git a/LanguageSpecification/2_Expressions.md b/LanguageSpecification/2_Expressions.md new file mode 100644 index 0000000..4dd444a --- /dev/null +++ b/LanguageSpecification/2_Expressions.md @@ -0,0 +1,187 @@ +# 2 Expressions + +Expressions compute values at runtime. They can be used in the following contexts: + +- As initializers of variables +- As arguments of function call +- As a return value +- As subexpressions, so as operands to other kinds of expressions + +Expression have the following syntax: + +``` +expression = identifier + | literal + | binary_operation + | function_call_expressions + | member_access; +``` + +## 2.1 Literals + +Literals yield the value of the literal and have the datatype that the kind of literal is associated with. More information in 5 Datatypes. + +``` +literal = string_literal + | char_literal + | int_literal + | imag_literal + | rational_literal + | "True" + | "False"; +``` + +## 2.2 Identifiers + +Identifiers represent local variables, constants, or functions. + +### 2.2.1 Variables + +If the identifier is bound to a local variable (10 Identifier binding), the expression has the type of that variable. More information in 4 Variables. + +### 2.2.2 Constants + +If the identifier is bound to a constant (10 Identifier binding), the expression has the type and value of that constant. More information in X Constants. + +### 2.2.3 Functions + +If the identifier is bound to a function (10 Identifier binding), the expression can be invoked. See X Functions and 2.4 Function call expressions. + +## 2.3 Operations + +Operations use a unary or binary operator. An example would be `x + 4`. + +These operators are only valid on types that allow them. More information in the framework documentation. + +### 2.3.1 Unary operations + +Unary operators modify the subexpression they are used with. + +A unary operation uses the following syntax: + +``` +unary_op_exp = unary_operator exp; +unary_operator = "~" + | "-" + | "Not"; +``` + +The following unary operators exist: + +`-x`, `~x` and `Not x` + +### 2.3.2 Binary operations + +Binary operators take two subexpressions as their left and right operands and return a value based on those two expressions. + +A binary operation uses the following syntax: + +``` +binary_op_exp = exp binary_operator exp; +binary_operator = "**" + | "*" + | "/" + | "Div" + | "Mod" + | "+" + | "-" + | "&" + | "^" + | "|" + | "->" + | "<-" + | "<" + | "<=" + | ">=" + | ">" + | "==" + | "!=" + | "And" + | "Xor" + | "Or"; +``` + +A binary operations returns a value based on their two operands. The functionality and type of the expression is specified by the framework documentation. + +The following binary operators exist: + +`x + y`, `x - y`, `x * y`, `x / y`, `x Div y`, `x Mod y`, `x ** y`, `x & y`, `x ^ y`, `x -> y`, `x <- y`, `x | y`, `x == y`, `x != y`, `x > y`, `x < y`, `x >= y`, `x <= y`, `x And y`, `x Or y`, `x Xor y` + +### 2.3.3 Operator precedence + +Operator precedence decides the ambiguity of a case like this: `x + y * z`. Evaluating this as `(x + y) * z` yields a different result than `x + (y * z)`. Operators with a higher precedence bind more closely. In this case, `*` has a higher precedence, so the second variant is chosen. + +This is a full table of precedence: + +| Precedence | Name of group | Concrete operators | +| ---------- | ---------------------- | -------------------------------------- | +| 11 | Unary number operators | `-x`, `~x` | +| 10 | Exponentiation | `x ** y` | +| 9 | Multiplicative | `x * y`, `x / y`, `x Div y`, `x Mod y` | +| 8 | Additive | `x + y`, `x - y` | +| 7 | Bitwise | `x & y`, `x ^ y`, `x | y` | +| 6 | Shift | `x -> y`, `x <- y` | +| 5 | Comparison | `x < y`, `x <= y`, `x >= y`, `x > y` | +| 4 | Equality | `x == y`, `x != y` | +| 3 | Logical Not | `Not x` | +| 2 | Logical And | `x And y` | +| 1 | Logical exclusive Or | `x Xor y` | +| 0 | Logical Or | `x Or y` | + +Unlike the `**` operator, chains of the same operator are always analyzed the following way: `a op b op c` = `(a op b) op c`. For the `**` operator, it is done the other way round: `a ** b ** c` = `a ** (b ** c)`. + +### 2.3.4 Short circuiting + +The Logical `And` and `Or` operators are short circuiting. That means that the right operand is not evaluated if it cannot change the result of the operation. + +In case of the `And` operator, the right operand is only evaluated if the left operand returned `True`. If it returned `False`, the whole operation returns `False` without evaluating the right operand. If it is `True`, the whole operation returns the result of the right operand. + +In case of the `Or` operator, the right operand is only evaluated if the left operand returned `False`. If it returned `True`, the whole operation returns `True` without evaluating the right operand. If it is `False`, the whole operation returns the result of the right operand. + +## 2.4 Function call expressions + +An identifier may be followed by a comma separated list of expression enclosed in `()`. This list may be empty. + +``` +func_call_exp = id "(" [arglist] ")"; +arglist = exp {notfirst_arg}; +notfirst_arg = "," exp; +``` + +The function (see 7 Function) associated with the identifier (see 10 Identifier binding) is executed when this expression is evaluated. It yields the return value of this function. + +## 2.5 Property get expressions + +A property get expression reads the content of a property of an expression. It uses the following syntax: + +``` +prop_get_exp = exp "." id; +``` + +The property has to exist on the type of the expression (see 5.x Properties), else a compile-time error is reported. The property get expression has the type of this property. + +This is an example for a property get expression: + +``` +Var z As Complex = 3 + 4i; +Var r = z.Real; ... z.Real is the property get +``` + +## 2.6 Expressions with and without type + +If an expression has a type, it can be assigned to a variable declared without type specifier (`As` clause). If the variable has a type specifier, the expression has to implicitly convertible to that type. + +If an expression does not have a type, it cannot be assigned to a variable declared without type specifier. The expression has to be implicitly convertible to the type specified by that type specifier. + +The following table specifies which expression have a type and which do not: + +| Expression kind | Has a type | Type or conversion rule | +| --------------------------- | ---------- | ------------------------------------------------------------ | +| Literal | Yes | Type specified by 5.x Literal types | +| Variable | Yes | Type the variable is declared with | +| Constant | Yes | Type the constant is declared with | +| Operation | Yes | Type specified by the framework documentation | +| Function call | Yes | Type specified by the function declaration's type specifier | +| `Default(T)` for any type T | Yes | T | +| `Default` | No | Convertible to any type, equivalent to `Default(T)` where T is the target type | + diff --git a/LanguageSpecification/3_Variables.md b/LanguageSpecification/3_Variables.md new file mode 100644 index 0000000..bc50138 --- /dev/null +++ b/LanguageSpecification/3_Variables.md @@ -0,0 +1,63 @@ +# 3 Variables + +A variable is a named storage location. It is declared with the following syntax: + +``` +local_declaration = var_decl_with_type + | var_decl_without_type; + | let_decl; +var_decl_with_type = "Var" identifier "As" type_spec [initializer]; +var_decl_without_type = "Var" identifier initializer; +let_decl = "Let" identifier [type_spec_with_as] initializer; +initializer = "=" expression; +type_spec_with_as = "As" type_spec; +``` + +## 3.1 Identifier + +Any legal identifier may be used as the name of the variable. It is a compile time error to declare a variable with an identifier that a different variable that is in scope (more in 4.5 Scope) already uses. + +## 3.2 As clause + +The `As` keyword starts the As clause. It is used to specify the type of the new variable. This datatype may be any legal type expression as described in 5 Datatypes. + +The `As` clause may be left out if an expression is given and it has a type (see 3.5 Expressions with and without type) but has to be provided if the expression does not have a type (see 3.x Expression with and without type) or there is no expression in the first place. In case that it is left out, it is inferred from the expression (see x Type inference) + +## 3.3 Assigned value + +For `Var` variables optionally and for `Let` variables necessarily, after an equals character `=` an expression provides an initial value for the new variable. + +This value has to match the type specified by the As clause if it has a type or has to be convertible to this type if it doesn't have a type. Else, the compile-time error 501 is reported. + +If there is no assigned value and the variable is declared using `Var` it is assigned with the default value of the type specified by the As clause (see 5.x Default value of a datatype). + +## 3.4 `Var` vs `Let` + +The value of a variable that has been declared using `Var` may be replaced after declaration with a new (not necessarily different) value. It is a compile time error for this new value to have a different type than the initial variable. + +On the other hand, a variable declared with `Let` is immutable. That means that it is a compile time error to reassign this variable. A value has to be assigned at declaration because this value will not change for the lifetime of the variable. + +## 3.5 Scope + +The scope of a variable means the area of code where the variable may be used and assigned to. A function body or the top level code both create a scope, however the following statements create nested scopes: + +- `Block` +- `If` +- `While` +- `For` + +If in a scope a nested scope is created, the original scope is considered a parent scope of the nested scope. See this example: + +``` +Block +{ ... Parent scope + Block + { ... Nested scope + + } +} +``` + +A variable is in scope in the scope that it is declared in and all of that scope's nested scopes. + +If a variable is declared even though a different variable with the same name is in scope, a compile-time error is reported. \ No newline at end of file diff --git a/LanguageSpecification/4_Datatypes.md b/LanguageSpecification/4_Datatypes.md new file mode 100644 index 0000000..968c594 --- /dev/null +++ b/LanguageSpecification/4_Datatypes.md @@ -0,0 +1,52 @@ +# 4 Datatypes + +Datatypes are used to guarantee the correctness of the program. Every function and every operation is defined with its types. Violations of type safety cause one of the compile time errors 500 <= x < 600. + +## 4.1 Datatypes of literals + +Every kind of literal has a built-in datatype associated with it. + +| Kind of literal | Datatype | Example | +| ----------------- | ---------- | --------------- | +| Integer literal | `Int` | `42` | +| Rational literal | `Rational` | `3.14159265` | +| Imaginary literal | `Complex` | `4i` | +| Character literal | `Char` | `'a'` | +| String literal | `String` | `"Hello world"` | +| Boolean literal | `Bool` | `True`, `False` | + +## 4.2 Default values + +The default value is the value of a variable of a type that has not been assigned a value. + +The default value of a type can be used in a typed context using the `Default` keyword and in any context using the `Default(T)` syntax, where `T` is the type. For example, the default value of the type `Int` can be used the following way: `Default(Int)`. + +The following list lists the default values for built-in datatypes: + +| Datatype | Default value | +| ---------- | ------------- | +| `Int` | `0` | +| `Rational` | `0.0` | +| `Complex` | `0 + 0i` | +| `Char` | `'\0'` | +| `String` | `""` | +| `Bool` | `False` | + +## 4.3 Properties + +A property of a type is accessible from expressions of this type. It has a type and is read only. + +## 4.4 Type inference + +If an expression has a type, it may be assigned to a variable declaration which lacks the `As` clause. The type of the variable is said to be inferred. + +Inference works the following way: + +- If the whole expression is a function call, the type is inferred to be the return type of this function. +- If the whole expression is an operation, the type is inferred to be the return type of the rightmost appearance of the operator with the lowest precedence (leftmost, if this operator is `**`). +- If the whole expression is a literal with a type (see 5.1 Datatypes of literals), the type is inferred to be this literal kind's type. +- If the whole expression is a read access to a variable, the type is inferred to be the type that this variable was declared with (or that was inferred for this variable). + +## 4.5 Conversions + +If a type `X` is implicitly convertible to the type `Y`, an expression of type `X` can be used where an expression of type `Y` is expected. Implicit conversions are specified by the framework documentation. \ No newline at end of file diff --git a/LanguageSpecification/5_Statements.md b/LanguageSpecification/5_Statements.md new file mode 100644 index 0000000..e842362 --- /dev/null +++ b/LanguageSpecification/5_Statements.md @@ -0,0 +1,221 @@ +# 5 Statements + +A statement is an executable portion of code. + +``` +stmt = single_stmt + | parent_stmt; + +single_stmt = local_decl_stmt + | assignment_stmt + | func_call_stmt + | leave_stmt + | continue_stmt + | return_stmt; + +parent_stmt = if_stmt + | while_stmt + | for_stmt + | block_stmt; +``` + +## 5.1 Function call statements + +A function call can be used as a statement. It uses the same syntax as a function call expression (see 3.4 Function call expressions): + +``` +func_call_stmt = func_call_exp ";"; + +func_call_exp = id arglist; +arglist = "(" [arglist_not_empty] ")"; +arglist_not_empty = exp {notfirst_arg}; +notfirst_arg = "," exp; +``` + +This is an example of a function call statement: + +``` +Output("Hello world"); +``` + +A function call statement has to be terminated by a semicolon character `;`. If this it not the case, a compile-time error is reported. + +## 5.2 Variable declaration statements + +A variable declaration uses the following syntax: + +``` +local_decl_stmt = var_decl_with_type + | var_decl_without_type; + | let_decl; +var_decl_with_type = "Var" id "As" typespec [initializer] ";"; +var_decl_without_type = "Var" id initializer ";"; +let_decl = "Let" id [typespec_with_as] initializer ";"; + +initializer = "=" exp; +typespec_with_as = "As" typespec; +``` + +A variable declaration statement has to be terminated by a semicolon character `;`. If this is not the case, a compile-time error is reported. + +This is an example of a variable declaration statement: + +``` +Var x As String = ""; +``` + +For more information, see 4 Variables. + +## 5.3 Variable assignment statements + +A variable assignment uses the following syntax: + +``` +assignment_stmt = id initializer ";"; +initializer = "=" exp; +``` + +A variable assignment statement has to be terminated by a semicolon character `;`. If this is not the case, a compile-time error is reported. + +## 5.4 `Return` statements + +A `Return` statement immediately terminates execution of a function. If the function has a return type, it provides the return value of this function call. If a `Return` statement is used in top level code, execution of the whole script terminates. + +A `Return` statement uses the following syntax: + +``` +continue_stmt = "Continue" [int_literal] ";"; +``` + +The expression has to be of the return type or implicitly convertible to it. If there is no return type, there must not be an expression. If the expression is not of the correct type or the presence / absence of the expression does not match the presence / absence of a return type, a compile-time error is reported. + +A `Return` statement has to be terminated by a semicolon character `;`. If this it not the case, the compile-time error 101 is reported. + +## 5.5 `Block` statements + +A `Block` statement creates a new scope for local variables. It uses the following syntax: + +``` +block_statement = "Block" statement_block; +statement_block = "{" {statement} "}"; +``` + +## 5.6 `If` statements + +An `If` statement selects a block of code to execute based on at least one condition. It use the following syntax: + +``` +if_stmt = if_part {elseif_part} [else_part]; +if_part = "If" exp block; +elseif_part = "Else" "If" exp block; +else_part = "Else" block; + +block = "{" {stmt} "}"; +``` + +### 5.6.1 `If` part + +The `If` part starts an `If` statement. The condition is any expression that returns `Bool`. The statements in the block is only executed if the condition evaluates as `True`. If it doesn't and there exists at least one `Else If` or `Else` part, the next part is started. + +### 5.6.2 `Else If` part + +The `If` part may be followed by an unlimited number of `Else If` statements. If and only if the original condition evaluates as `False`, the condition for the next `Else If` is evaluated. If it evaluates as `True`, its statements are executed. Else the next `Else If` - if it exists - is considered. Here, the same constraints that are in place for `condition` are also in place for the other conditions. + +It is a compile-time error for an `Else If` part to appear in code unless it directly follows an `If` or `Else If` part. + +### 5.6.3 `Else` part + +An `If` or `Else If` part may be followed by exactly one `Else` part. If the conditions of each of the `If` and `Else If` parts evaluated as `False`, the `Else` block is executed. If it doesn't exist, execution resumes after the last `Else If` statement. + +It is a compile-time error for an `Else` statement to appear in code unless it directly follows an `If` or `Else If` statement. + +## 5.7 `While` statements + +A `While` statement executes multiple times, as long as the condition always evaluates as `True`. It uses the following syntax: + +``` +while_stmt = "While" exp block; +``` + +A `While` statement is a loop, so `Leave` and `Continue` statements can interact with it. + +## 5.8 `For` statements + +A `For` statement executes multiple times for a specific range of numbers. The current number can be used by reading from the iteration variable. + +A `For` statement uses the following syntax: + +``` +for_stmt = "For" for_var_part for_parts block; +for_parts = for_while_part for_with_part + | for_while_part + | for_with_part; + +for_var_part = id [initializer] + | "Var" id [typespec_with_as] initializer; + +for_while_part = "While" for_condition; +for_condition = for_condition_leading_var + | for_condition_trailing_var + | "True"; +for_condition_leading_var = id comparison_operator exp; +for_condition_trailing_var = exp comparison_operator id; +comparison_operator = ">" + | "<" + | ">=" + | "<="; + +for_with_part = "With" exp; +``` + +If the `For` keyword is followed by an identifier, that identifier has to correspond to a local variable. This local variable is then used as the iteration variable. It can optionally be assigned a new value. If this is not the case, the initial value is the value that the variable holds at that time. + +If the `For` keyword is followed by a variable declaration (so the `Var` keyword, an identifier, optionally a type specifier, and an assignment), a new iteration variable is declared. It is scoped to the body of the block of the `For` statement. + +The variable is only accepted if is of one of the following types: `Int`, `Rational` or `Complex`. + +After the `While` keyword a condition specifies when the loop will run (this is equivalent to the condition for a `While` loop). This condition is a comparison of the iteration variable with any other expression of that type. Therefore, it has to use one of the following operators: `<`, `<=`, `>` or `>=`. It does not matter whether the iteration variable appears on the left or right of that operation. Alternatively, it may be the Boolean literal `True`. The `While` part may be omitted. In that case, `True` is assumed. If the condition is neither a comparison nor the Boolean literal `True`, a compile-time error is reported. + +After the `With` keyword there is an assignment to the iteration variable. This assignment has to be valid in terms of its types. After each iteration, the expression that is assigned to the variable is evaluated and assigned to the variable. The `With` part may be omitted. In that case, `iterationVariable = iterationVariable + 1` is assumed. + +It is a compile-time error to omit both the `While` as well as the `With` part. + +A `For` statement is a loop, so `Leave` and `Continue` statements can interact with it. + +## 5.9 `Leave` statements + +A `Leave` statement leaves the body of a loop. It uses the following syntax: + +``` +leave_stmt = "Leave" [int_literal] ";"; +``` + +The integer literal represents the number of nested loops to leave. If it is not provided, 1 is assumed. For example: + +``` +While True +{ + While True + { + Leave 2; + } +} +``` + +This would leave the outer `While` loop. + +It is a compile-time error for a `Leave` statement to appear without being in a loop or the integer literal to be greater than the number of nested loops. + +A `Leave` statement has to be terminated by a semicolon character `;`. If this it not the case, a compile-time error is reported. + +## 5.10 `Continue` statements + +A `Continue` statement terminates the current execution of the loop body. It reevaluates the condition and depending on whether it evaluates as `True` executes the loop body or leaves the loop. It uses the following syntax: + +``` +continue_stmt = "Continue" [int_literal] ";"; +``` + +The integer literal represents the number of nested loops to continue. If it is not provided, 1 is assumed. It behaves exactly like the `Leave` statement in choosing the loop to continue. + +A `Continue` statement has to be terminated by a semicolon character `;`. If this it not the case, a compile-time error is reported. \ No newline at end of file diff --git a/LanguageSpecification/6_Functions.md b/LanguageSpecification/6_Functions.md new file mode 100644 index 0000000..cfc39b4 --- /dev/null +++ b/LanguageSpecification/6_Functions.md @@ -0,0 +1,60 @@ +# 6 Functions + +A function is encapsulated functionality that can be called several times. It can be passed values as arguments and return a value. + +## 6.1 Declaration syntax + +A function declaration uses the following syntax: + +``` +func_decl = "Func" identifier param_list [type_spec_with_as] block; +param_list = "(" param {not_first_param} ")"; +not_first_param = "," param; +param = identifier "As" type_spec; +type_spec_with_as = "As" type_spec; +``` + +The name of the function has to be a legal identifier as specified in 1.x Identifiers. Additionally, it may not be used by another function or a constant, be it built-in or declared in the code. + +The parameter list is described in 8.1 Parameters. + +The return type has to be a legal datatype as specified in 5 Datatypes. + +The body may be any collection of statements as specified in 6 Statements. + +## 6.2 Parameters + +The parameter list is a comma separated list of the following syntax: + +``` +identifier As type +``` + +The identifier has to be a legal identifier and type has to be a legal datatype. + +Parameters are available in the body of the function as variables of the specified type. + +## 6.3 The return type + +The `As` clause specifies the value that is going to be returned by the function and is going to be the value in an expression if the function call is used as an argument. + +It can be omitted. In that case, the function doesn't return anything. A call to such a function may only be used as a statement but not as an expression. + +## 6.4 The `Return` statement + +The `Return` statement directly terminates execution of the function and returns the variable that the function call expression has. + +Its syntax is: + +``` +Return value; ... Returns a value +Return; ... Returns no value +``` + +If a return type is specified, `Return` with value has to be used. In that case, the type of the value has to match the return type. + +If no return is type is specified, only `Return` without value is permitted. + +## 6.5 Scope + +The function body is a new scope. See 4.5 Scope. \ No newline at end of file diff --git a/LanguageSpecification/7_Constants.md b/LanguageSpecification/7_Constants.md new file mode 100644 index 0000000..cc54b48 --- /dev/null +++ b/LanguageSpecification/7_Constants.md @@ -0,0 +1,14 @@ +# 7 Constants + +A constant is a named literal. It always points to the same value and can never change. It is declared globally. + +It uses the following syntax: + +``` +const_decl = "Const" id [typespec_with_as] "=" literal ";"; +typespec_with_as = "As" typespec; +``` + +It is a compile-time error for a constant to have the same identifier as another constant or a function, be it built-in or declared in the program. + +Reading from a constant is an expression. This expression has the type of the constant (be it explicitly specified or inferred). \ No newline at end of file diff --git a/LanguageSpecification/8_TopLevelCode.md b/LanguageSpecification/8_TopLevelCode.md new file mode 100644 index 0000000..90ad3f2 --- /dev/null +++ b/LanguageSpecification/8_TopLevelCode.md @@ -0,0 +1,11 @@ +# 8 Top level code + +The top level code is the code that runs when the script starts. It consists of statements. Statements are allowed to be cut off by function declarations. They still belong together and their order of execution exactly resembles the order they appear in code. + +## 8.1 Scope + +The whole top level code is a scope that coexists with the scope of declared functions. Those functions are not able to access any variables declared in top level code. + +## 8.2 `Return` + +A `Return` statement in top level code must not have an expression. When it is executed, the execution of the whole script stops. \ No newline at end of file diff --git a/LanguageSpecification/9_IdentifierBinding.md b/LanguageSpecification/9_IdentifierBinding.md new file mode 100644 index 0000000..ffd14c6 --- /dev/null +++ b/LanguageSpecification/9_IdentifierBinding.md @@ -0,0 +1,61 @@ +# 9 Identifier binding + +Identifiers are bound at the beginning of semantical analysis. Binding refers to the act of associating an identifier with the symbol that is declared with this name. + +Different binding semantics are applied to these different contexts: + +## 9.1 In an expression + +If a local variable declared with the identifier that is about to be bound is in scope (see 4.x Scope, binding always chooses it, even if a function with the same name exists. This is the case even when the variable is called even though it does not allow it, while the call to the function would have been legal. An example: + +``` +Func Test() +{ + Var Identifier = 4; + Identifier(); ... error +} + +Func Identifier() +{ + Output("Called the function"); +} +``` + +In this code snippet, a compile time error is reported. A variable of type `Int` is not callable. The function is not considered, even though the call would have been legal if the identifier would have been bound to the function. + +If no local variable with this identifier is found, then built-in and declared functions are considered. If a function with this name is found, the identifier is bound to that function. + +If neither a variable nor a function is found, a compile-time error is reported. + +## 9.2 In a type specifier + +In a type expression, only datatypes are considered when binding identifiers. The only identifiers that are allowed here are the built-in types: + +- `Int` +- `Real` +- `Rational` +- `Complex` +- `Char` +- `String` +- `Bool` + +Because of this, it is perfectly valid to have a variable or function in scope which is declared with one of these identifiers: + +``` +If Real() +{ + Output("Everything is real"); +} +Else +{ + Output("This is just a dream"); +} + +Var r As Real; ... can still use the type Real. + +Func Real() As Bool +{ + Return RandomRational() > 0.9; +} +``` + diff --git a/LanguageSpecification/TableOfContents.md b/LanguageSpecification/TableOfContents.md new file mode 100644 index 0000000..2132f54 --- /dev/null +++ b/LanguageSpecification/TableOfContents.md @@ -0,0 +1,71 @@ +# Table of contents + +1. Lexical structure + 1. Case + 2. Whitespace + 3. Comments + 1. Single line comments + 2. Normal multiline comments + 3. Nested multiline comments + 4. Identifiers + 5. Reserved keywords + 6. String literals + 7. Character literals + 8. Escape sequences + 9. Number literals + 1. Integer literals + 2. Rational literals + 3. Imaginary literals + 10. Syntax characters +3. Expressions + 1. Literals + 2. Identifiers + 1. Variables + 2. Constants + 3. Functions + 3. Operations + 1. Unary operations + 2. Binary operations + 3. Operator precedence + 4. Function call expressions + 5. Property get expressions + 6. Expressions with and without type +3. Variables + 1. Identifier + 2. As clause + 3. Assigned value + 4. `Var` vs `Let` + 5. Scope +4. Datatypes + 2. Datatypes of literals + 2. Default values + 3. Properties + 6. Type inference + 6. Implicit conversions +5. Statements + 1. Function call statements + 2. Variable declaration statements + 3. Variable assignment statements + 4. `Return` statements + 5. `Block` statements + 6. `If` statements + 1. `If` part + 2. `Else If` part + 3. `Else` part + 7. `While` statements + 8. `For` statements + 9. `Leave` statements + 10. `Continue` statements +6. Functions + 1. Declaration syntax + 2. Parameters + 3. The return type + 4. The `Return` statement + 5. Scope +7. Constants +8. Top level code + 1. Scope + 2. `Return` +9. Identifier binding + 1. In an expression + 2. In a type specifier diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperationChainExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperationChainExpressionNode.cs index 6e05767..971ad54 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperationChainExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperationChainExpressionNode.cs @@ -40,23 +40,6 @@ public void AddOperand(ExpressionNode operand) operands.Add(operand); } - public override BinaryOperationChainExpressionNode Clone() - { - Debug.Assert(operands.Count == operators.Count + 1); - - BinaryOperationChainExpressionNode newChain = new(LineNumber); - - for (int i = 0; i < operators.Count; i++) - { - newChain.AddOperand(operands[i]); - newChain.AddOperator(operators[2]); - } - - newChain.AddOperand(operands[^1]); - - return newChain; - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperationExpressionNode.cs index 67063fb..28f1177 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperationExpressionNode.cs @@ -9,7 +9,7 @@ namespace Krypton.Analysis.AbstractSyntaxTree.Nodes.Expressions */ public abstract class BinaryOperationExpressionNode : ExpressionNode { - protected BinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(lineNumber) + protected private BinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(lineNumber) { Left = left; Left.Parent = this; @@ -21,8 +21,6 @@ protected BinaryOperationExpressionNode(ExpressionNode left, ExpressionNode righ public ExpressionNode Right { get; } - public abstract override BinaryOperationExpressionNode Clone(); - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/AdditionBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/AdditionBinaryOperationExpressionNode.cs index f5cb25e..722ee62 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/AdditionBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/AdditionBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class AdditionBinaryOperationExpressionNode : BinaryOperationExpressionNode { public AdditionBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override AdditionBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseAndBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseAndBinaryOperationExpressionNode.cs index b603917..6e97f6e 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseAndBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseAndBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class BitwiseAndBinaryOperationExpressionNode : BinaryOperationExpressionNode { public BitwiseAndBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override BitwiseAndBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseLeftShiftBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseLeftShiftBinaryOperationExpressionNode.cs index c6b06d4..6317118 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseLeftShiftBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseLeftShiftBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class BitwiseLeftShiftBinaryOperationExpressionNode : BinaryOperationExpressionNode { public BitwiseLeftShiftBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override BitwiseLeftShiftBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseOrBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseOrBinaryOperationExpressionNode.cs index 33a84ea..948efbc 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseOrBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseOrBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class BitwiseOrBinaryOperationExpressionNode : BinaryOperationExpressionNode { public BitwiseOrBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override BitwiseOrBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseRightShiftBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseRightShiftBinaryOperationExpressionNode.cs index 42dc6f2..46165e0 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseRightShiftBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseRightShiftBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class BitwiseRightShiftBinaryOperationExpressionNode : BinaryOperationExpressionNode { public BitwiseRightShiftBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override BitwiseRightShiftBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseXOrBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseXOrBinaryOperationExpressionNode.cs index 13b745f..c8203aa 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseXOrBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/BitwiseXOrBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class BitwiseXorBinaryOperationExpressionNode : BinaryOperationExpressionNode { public BitwiseXorBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override BitwiseXorBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/EqualityBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/EqualityBinaryOperationExpressionNode.cs index 1035366..d01ea1e 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/EqualityBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/EqualityBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class EqualityBinaryOperationExpressionNode : BinaryOperationExpressionNode { public EqualityBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override EqualityBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/ExponentiationBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/ExponentiationBinaryOperationExpressionNode.cs index b845376..5f1a8af 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/ExponentiationBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/ExponentiationBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class ExponentiationBinaryOperationExpressionNode : BinaryOperationExpressionNode { public ExponentiationBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override ExponentiationBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/GreaterThanBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/GreaterThanBinaryOperationExpressionNode.cs index a23b33e..fb9f87a 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/GreaterThanBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/GreaterThanBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class GreaterThanBinaryOperationExpressionNode : BinaryOperationExpressionNode { public GreaterThanBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override GreaterThanBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/GreaterThanOrEqualsBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/GreaterThanOrEqualsBinaryOperationExpressionNode.cs index 271b181..0c3e86d 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/GreaterThanOrEqualsBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/GreaterThanOrEqualsBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class GreaterThanOrEqualsBinaryOperationExpressionNode : BinaryOperationExpressionNode { public GreaterThanOrEqualsBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override GreaterThanOrEqualsBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/IntegerDivisionBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/IntegerDivisionBinaryOperationExpressionNode.cs index 1dc6693..2cf5ce6 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/IntegerDivisionBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/IntegerDivisionBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class IntegerDivisionBinaryOperationExpressionNode : BinaryOperationExpressionNode { public IntegerDivisionBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override IntegerDivisionBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LessThanBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LessThanBinaryOperationExpressionNode.cs index f1f79d9..6ee01ad 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LessThanBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LessThanBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class LessThanBinaryOperationExpressionNode : BinaryOperationExpressionNode { public LessThanBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override LessThanBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LessThanOrEqualsBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LessThanOrEqualsBinaryOperationExpressionNode.cs index 99b1efe..12b2ce9 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LessThanOrEqualsBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LessThanOrEqualsBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class LessThanOrEqualsBinaryOperationExpressionNode : BinaryOperationExpressionNode { public LessThanOrEqualsBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override LessThanOrEqualsBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalAndBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalAndBinaryOperationExpressionNode.cs index d6b0390..6e78e09 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalAndBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalAndBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class LogicalAndBinaryOperationExpressionNode : BinaryOperationExpressionNode { public LogicalAndBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override LogicalAndBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalOrBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalOrBinaryOperationExpressionNode.cs index e815fbe..edcd2cc 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalOrBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalOrBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class LogicalOrBinaryOperationExpressionNode : BinaryOperationExpressionNode { public LogicalOrBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override LogicalOrBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalXOrBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalXOrBinaryOperationExpressionNode.cs index fc23d80..592d46b 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalXOrBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/LogicalXOrBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class LogicalXorBinaryOperationExpressionNode : BinaryOperationExpressionNode { public LogicalXorBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override LogicalXorBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/ModuloBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/ModuloBinaryOperationExpressionNode.cs index defb49a..065e48f 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/ModuloBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/ModuloBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class ModuloBinaryOperationExpressionNode : BinaryOperationExpressionNode { public ModuloBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override ModuloBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/MultiplicationBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/MultiplicationBinaryOperationExpressionNode.cs index 12a7d17..3ec6888 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/MultiplicationBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/MultiplicationBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class MultiplicationBinaryOperationExpressionNode : BinaryOperationExpressionNode { public MultiplicationBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override MultiplicationBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/RationalDivisionBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/RationalDivisionBinaryOperationExpressionNode.cs index 0e0d7b8..e7e32e8 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/RationalDivisionBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/RationalDivisionBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class RationalDivisionBinaryOperationExpressionNode : BinaryOperationExpressionNode { public RationalDivisionBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override RationalDivisionBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/SubtractionBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/SubtractionBinaryOperationExpressionNode.cs index 5d39de6..5366fbc 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/SubtractionBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/SubtractionBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class SubtractionBinaryOperationExpressionNode : BinaryOperationExpressionNode { public SubtractionBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override SubtractionBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/UnequalityBinaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/UnequalityBinaryOperationExpressionNode.cs index 2abab8e..aa07505 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/UnequalityBinaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/BinaryOperations/UnequalityBinaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class UnequalityBinaryOperationExpressionNode : BinaryOperationExpressionNode { public UnequalityBinaryOperationExpressionNode(ExpressionNode left, ExpressionNode right, int lineNumber) : base(left, right, lineNumber) { } - - public override UnequalityBinaryOperationExpressionNode Clone() - { - return new(Left.Clone(), Right.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/ExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/ExpressionNode.cs index 25b1659..1cad15c 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/ExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/ExpressionNode.cs @@ -12,8 +12,6 @@ */ public abstract class ExpressionNode : Node { - protected ExpressionNode(int lineNumber) : base(lineNumber) { } - - public abstract override ExpressionNode Clone(); + protected private ExpressionNode(int lineNumber) : base(lineNumber) { } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/FunctionCallExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/FunctionCallExpressionNode.cs index a227f32..6a86787 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/FunctionCallExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/FunctionCallExpressionNode.cs @@ -30,11 +30,6 @@ public FunctionCallExpressionNode(ExpressionNode functionExpression, IEnumerable public ExpressionNode FunctionExpression { get; } - public override FunctionCallExpressionNode Clone() - { - return new(FunctionExpression.Clone(), Arguments?.Select(a => a.Clone()), LineNumber); - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/IdentifierExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/IdentifierExpressionNode.cs index 20050ab..9b4661c 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/IdentifierExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/IdentifierExpressionNode.cs @@ -28,11 +28,6 @@ public void Bind(SymbolNode symbol) IdentifierNode = new BoundIdentifierNode(Identifier, symbol, IdentifierNode.LineNumber) { Parent = this }; } - public override IdentifierExpressionNode Clone() - { - return new(IdentifierNode.Clone(), LineNumber); - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/LiteralExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/LiteralExpressionNode.cs index ca721a0..b304510 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/LiteralExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/LiteralExpressionNode.cs @@ -4,9 +4,7 @@ namespace Krypton.Analysis.AbstractSyntaxTree.Nodes.Expressions { public abstract class LiteralExpressionNode : ExpressionNode { - protected LiteralExpressionNode(int lineNumber) : base(lineNumber) { } - - public abstract override LiteralExpressionNode Clone(); + protected private LiteralExpressionNode(int lineNumber) : base(lineNumber) { } public override void PopulateBranches(List list) { diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/BooleanLiteralExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/BooleanLiteralExpressionNode.cs index c400be6..1e7b448 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/BooleanLiteralExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/BooleanLiteralExpressionNode.cs @@ -8,10 +8,5 @@ public BooleanLiteralExpressionNode(bool value, int lineNumber) : base(lineNumbe } public bool Value { get; } - - public override BooleanLiteralExpressionNode Clone() - { - return new(Value, LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/CharLiteralExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/CharLiteralExpressionNode.cs index 26af745..e95601f 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/CharLiteralExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/CharLiteralExpressionNode.cs @@ -8,10 +8,5 @@ public CharLiteralExpressionNode(char value, int lineNumber) : base(lineNumber) } public char Value { get; } - - public override CharLiteralExpressionNode Clone() - { - return new(Value, LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/ImaginaryLiteralExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/ImaginaryLiteralExpressionNode.cs index 8effb68..77b108c 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/ImaginaryLiteralExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/ImaginaryLiteralExpressionNode.cs @@ -10,10 +10,5 @@ public ImaginaryLiteralExpressionNode(RationalLiteralValue value, int lineNumber } public RationalLiteralValue Value { get; } - - public override ImaginaryLiteralExpressionNode Clone() - { - return new(Value, LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/IntegerLiteralExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/IntegerLiteralExpressionNode.cs index 00001e5..05b25c1 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/IntegerLiteralExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/IntegerLiteralExpressionNode.cs @@ -8,10 +8,5 @@ public IntegerLiteralExpressionNode(long value, int lineNumber) : base(lineNumbe } public long Value { get; } - - public override IntegerLiteralExpressionNode Clone() - { - return new(Value, LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/RationalLiteralExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/RationalLiteralExpressionNode.cs index 1eef72c..f9636e6 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/RationalLiteralExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/RationalLiteralExpressionNode.cs @@ -10,10 +10,5 @@ public RationalLiteralExpressionNode(RationalLiteralValue value, int lineNumber) } public RationalLiteralValue Value { get; } - - public override RationalLiteralExpressionNode Clone() - { - return new(Value, LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/StringLiteralExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/StringLiteralExpressionNode.cs index 86a7fd8..bbe7276 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/StringLiteralExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/Literals/StringLiteralExpressionNode.cs @@ -8,10 +8,5 @@ public StringLiteralExpressionNode(string content, int lineNumber) : base(lineNu } public string Content { get; } - - public override StringLiteralExpressionNode Clone() - { - return new(Content, LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperationExpressionNode.cs index 1e0c9d7..4f97366 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperationExpressionNode.cs @@ -4,15 +4,13 @@ namespace Krypton.Analysis.AbstractSyntaxTree.Nodes.Expressions { public abstract class UnaryOperationExpressionNode : ExpressionNode { - protected UnaryOperationExpressionNode(ExpressionNode operand, int lineNumber) : base(lineNumber) + protected private UnaryOperationExpressionNode(ExpressionNode operand, int lineNumber) : base(lineNumber) { Operand = operand; } public ExpressionNode Operand { get; } - public abstract override UnaryOperationExpressionNode Clone(); - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/BitwiseNotUnaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/BitwiseNotUnaryOperationExpressionNode.cs index 3664010..b420c50 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/BitwiseNotUnaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/BitwiseNotUnaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class BitwiseNotUnaryOperationExpressionNode : UnaryOperationExpressionNode { public BitwiseNotUnaryOperationExpressionNode(ExpressionNode operand, int lineNumber) : base(operand, lineNumber) { } - - public override BitwiseNotUnaryOperationExpressionNode Clone() - { - return new(Operand.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/LogicalNotUnaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/LogicalNotUnaryOperationExpressionNode.cs index 23e2132..1d7cce1 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/LogicalNotUnaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/LogicalNotUnaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class LogicalNotUnaryOperationExpressionNode : UnaryOperationExpressionNode { public LogicalNotUnaryOperationExpressionNode(ExpressionNode operand, int lineNumber) : base(operand, lineNumber) { } - - public override LogicalNotUnaryOperationExpressionNode Clone() - { - return new(Operand.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/NegationUnaryOperationExpressionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/NegationUnaryOperationExpressionNode.cs index 1875f23..a6eee71 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/NegationUnaryOperationExpressionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Expressions/UnaryOperations/NegationUnaryOperationExpressionNode.cs @@ -3,10 +3,5 @@ public sealed class NegationUnaryOperationExpressionNode : UnaryOperationExpressionNode { public NegationUnaryOperationExpressionNode(ExpressionNode operand, int lineNumber) : base(operand, lineNumber) { } - - public override NegationUnaryOperationExpressionNode Clone() - { - return new(Operand.Clone(), LineNumber); - } } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/INode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/INode.cs index 2420c8b..574cfeb 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/INode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/INode.cs @@ -8,8 +8,6 @@ public interface INode Node? Parent { get; } - Node Clone(); - List GetBranches(); void PopulateBranches(List list); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/BoundIdentifierNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/BoundIdentifierNode.cs index c344056..e749290 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/BoundIdentifierNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/BoundIdentifierNode.cs @@ -12,8 +12,6 @@ public BoundIdentifierNode(string identifier, SymbolNode symbol, int lineNumber) public SymbolNode Symbol { get; } - public override BoundIdentifierNode Clone() => new(Identifier, Symbol.Clone(), LineNumber) { Parent = this }; - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/IdentifierNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/IdentifierNode.cs index 9acfc09..a42eba3 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/IdentifierNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/IdentifierNode.cs @@ -2,13 +2,11 @@ { public abstract class IdentifierNode : Node { - protected IdentifierNode(string identifier, int lineNumber) : base(lineNumber) + protected private IdentifierNode(string identifier, int lineNumber) : base(lineNumber) { Identifier = identifier; } public string Identifier { get; } - - public abstract override IdentifierNode Clone(); } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/UnboundIdentifierNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/UnboundIdentifierNode.cs index f4bb90f..ea86cbd 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/UnboundIdentifierNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Identifiers/UnboundIdentifierNode.cs @@ -6,8 +6,6 @@ public sealed class UnboundIdentifierNode : IdentifierNode { public UnboundIdentifierNode(string identifier, int lineNumber) : base(identifier, lineNumber) { } - public override UnboundIdentifierNode Clone() => new(Identifier, LineNumber); - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Node.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Node.cs index 16d3961..0bb92dc 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Node.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Node.cs @@ -36,25 +36,16 @@ namespace Krypton.Analysis.AbstractSyntaxTree.Nodes [DebuggerDisplay("{GetType().Name} -- {GetHashCode()}")] public abstract class Node : INode { - protected Node(int lineNumber) + protected private Node(int lineNumber) { LineNumber = lineNumber; } - private Node? parent; - public int LineNumber { get; } - public Node? Parent - { - get => parent; - internal set - { - parent = value; - } - } + public Node? Parent { get; internal set; } - public abstract Node Clone(); + //public abstract Node Clone(); public List GetBranches() { diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/ParameterNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/ParameterNode.cs index 1c05d33..c870eb1 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/ParameterNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/ParameterNode.cs @@ -27,8 +27,6 @@ private ParameterNode(IdentifierNode identifierNode, TypeSymbolNode type, int li public TypeSymbolNode Type { get; } - public override ParameterNode Clone() => new(IdentifierNode.Clone(), Type.Clone(), LineNumber); - public ParameterVariableSymbolNode CreateParameter() { ParameterVariableSymbolNode symbol = new(Identifier, Type, LineNumber); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/ScriptNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/ProgramNode.cs similarity index 73% rename from Source/Analysis/AbstractSyntaxTree/Nodes/ScriptNode.cs rename to Source/Analysis/AbstractSyntaxTree/Nodes/ProgramNode.cs index b401e74..28fe014 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/ScriptNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/ProgramNode.cs @@ -11,20 +11,15 @@ namespace Krypton.Analysis.AbstractSyntaxTree.Nodes * - A StatementCollection that represents the * top level statements */ - public sealed class ScriptNode : Node + public sealed class ProgramNode : Node { - public ScriptNode(StatementCollectionNode statements, int lineNumber) : base(lineNumber) + public ProgramNode(StatementCollectionNode statements, int lineNumber) : base(lineNumber) { TopLevelStatements = statements; } public StatementCollectionNode TopLevelStatements { get; } - public override ScriptNode Clone() - { - return new(TopLevelStatements.Clone(), LineNumber); - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/StatementCollectionNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/StatementCollectionNode.cs index 79ff935..bb7004e 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/StatementCollectionNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/StatementCollectionNode.cs @@ -38,11 +38,6 @@ public StatementNode this[int index] public int Count => statements.Count; - public override StatementCollectionNode Clone() - { - return new(statements.Select(s => s.Clone())); - } - public IEnumerator GetEnumerator() => statements.GetEnumerator(); public override void PopulateBranches(List list) diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/BlockStatementNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/BlockStatementNode.cs index 40d3351..26e3986 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/BlockStatementNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/BlockStatementNode.cs @@ -11,11 +11,6 @@ public BlockStatementNode(StatementCollectionNode statements, int lineNumber) : public StatementCollectionNode Statements { get; } - public override BlockStatementNode Clone() - { - return new(Statements.Clone(), LineNumber); - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/FunctionCallStatementNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/FunctionCallStatementNode.cs index e7052cc..45c99a3 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/FunctionCallStatementNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/FunctionCallStatementNode.cs @@ -17,11 +17,6 @@ public FunctionCallStatementNode(FunctionCallExpressionNode expression, int line public ExpressionNode FunctionExpression => expression.FunctionExpression; - public override FunctionCallStatementNode Clone() - { - return new(expression.Clone(), LineNumber); - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/StatementNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/StatementNode.cs index 0a6a86b..45f822d 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/StatementNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/StatementNode.cs @@ -2,12 +2,10 @@ { public abstract class StatementNode : Node { - protected StatementNode(int lineNumber) : base(lineNumber) { } + protected private StatementNode(int lineNumber) : base(lineNumber) { } public StatementNode? Next { get; internal set; } public StatementNode? Previous { get; internal set; } - - public abstract override StatementNode Clone(); } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/VariableAssignmentStatementNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/VariableAssignmentStatementNode.cs index 915bc6c..c0d149f 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/VariableAssignmentStatementNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/VariableAssignmentStatementNode.cs @@ -27,11 +27,6 @@ public void Bind(LocalVariableSymbolNode symbol) VariableIdentifierNode = new BoundIdentifierNode(VariableIdentifier, symbol, VariableIdentifierNode.LineNumber) { Parent = this }; } - public override VariableAssignmentStatementNode Clone() - { - return new(VariableIdentifierNode.Clone(), AssignedValue.Clone(), LineNumber); - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/VariableDeclarationStatementNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/VariableDeclarationStatementNode.cs index 0694b7d..bcf7d19 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/VariableDeclarationStatementNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/VariableDeclarationStatementNode.cs @@ -34,11 +34,6 @@ public VariableDeclarationStatementNode(IdentifierNode identifier, TypeNode? typ public ExpressionNode? Value { get; } - public override VariableDeclarationStatementNode Clone() - { - return new(VariableIdentifierNode.Clone(), Type?.Clone(), Value?.Clone(), LineNumber); - } - public LocalVariableSymbolNode CreateVariable(TypeSymbolNode? typeSymbol) { LocalVariableSymbolNode var = new LocalVariableSymbolNode(Identifier, typeSymbol, VariableIdentifierNode.LineNumber); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/WhileStatementNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/WhileStatementNode.cs index 6f6a381..5bb4a2a 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/WhileStatementNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Statements/WhileStatementNode.cs @@ -17,11 +17,6 @@ public WhileStatementNode(ExpressionNode condition, StatementCollectionNode stat public StatementCollectionNode Statements { get; } - public override WhileStatementNode Clone() - { - return new(Condition.Clone(), Statements.Clone(), LineNumber); - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/BuiltinFunctionSymbolNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/BuiltinFunctionSymbolNode.cs index 3a9ee29..e3c5b82 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/BuiltinFunctionSymbolNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/BuiltinFunctionSymbolNode.cs @@ -14,8 +14,6 @@ public BuiltinFunctionSymbolNode(BuiltinFunction builtinFunction, string name, I public BuiltinFunction BuiltinFunction { get; } - public override BuiltinFunctionSymbolNode Clone() => new(BuiltinFunction, Name, Parameters.Select(p => p.Clone()), ReturnType, LineNumber); - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/BuiltinTypeSymbolNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/BuiltinTypeSymbolNode.cs index 5d1f3e8..937b6ab 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/BuiltinTypeSymbolNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/BuiltinTypeSymbolNode.cs @@ -12,8 +12,6 @@ public BuiltinTypeSymbolNode(BuiltinType builtinType, string name, int lineNumbe public BuiltinType BuiltinType { get; } - public override BuiltinTypeSymbolNode Clone() => new(BuiltinType, Name, LineNumber); - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/FunctionSymbolNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/FunctionSymbolNode.cs index 9f88daa..6eb0c0a 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/FunctionSymbolNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/FunctionSymbolNode.cs @@ -15,7 +15,5 @@ protected FunctionSymbolNode(string name, IEnumerable parameters, public ImmutableList Parameters { get; } public TypeNode? ReturnType { get; } - - public abstract override FunctionSymbolNode Clone(); } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/LocalVariableSymbolNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/LocalVariableSymbolNode.cs index 9bf673e..ca5e0f0 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/LocalVariableSymbolNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/LocalVariableSymbolNode.cs @@ -8,8 +8,6 @@ public sealed class LocalVariableSymbolNode : VariableSymbolNode { public LocalVariableSymbolNode(string name, TypeSymbolNode? type, int lineNumber) : base(name, type, lineNumber) { } - public override LocalVariableSymbolNode Clone() => new(Name, Type, LineNumber); - public void SpecifyType(TypeSymbolNode type) { Debug.Assert(Type == null); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/ParameterVariableSymbolNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/ParameterVariableSymbolNode.cs index 1ca8474..8b34fa3 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/ParameterVariableSymbolNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/ParameterVariableSymbolNode.cs @@ -3,7 +3,5 @@ public sealed class ParameterVariableSymbolNode : VariableSymbolNode { public ParameterVariableSymbolNode(string name, TypeSymbolNode? type, int lineNumber) : base(name, type, lineNumber) { } - - public override ParameterVariableSymbolNode Clone() => new(Name, Type, LineNumber); } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/SymbolNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/SymbolNode.cs index 03fcbad..8bc197b 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/SymbolNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/SymbolNode.cs @@ -2,13 +2,11 @@ { public abstract class SymbolNode : Node { - protected SymbolNode(string name, int lineNumber) : base(lineNumber) + protected private SymbolNode(string name, int lineNumber) : base(lineNumber) { Name = name; } public string Name { get; } - - public abstract override SymbolNode Clone(); } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/TypeSymbolNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/TypeSymbolNode.cs index ec2b6bb..857cc15 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/TypeSymbolNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/TypeSymbolNode.cs @@ -3,7 +3,5 @@ public abstract class TypeSymbolNode : SymbolNode { protected TypeSymbolNode(string name, int lineNumber) : base(name, lineNumber) { } - - public abstract override TypeSymbolNode Clone(); } } diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/VariableSymbolNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/VariableSymbolNode.cs index a255267..a23ee55 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/VariableSymbolNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Symbols/VariableSymbolNode.cs @@ -11,8 +11,6 @@ protected VariableSymbolNode(string name, TypeSymbolNode? type, int lineNumber) public virtual TypeSymbolNode? Type { get; protected set; } - public abstract override VariableSymbolNode Clone(); - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Types/IdentifierTypeNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Types/IdentifierTypeNode.cs index ff0719f..91a14e4 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Types/IdentifierTypeNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Types/IdentifierTypeNode.cs @@ -29,11 +29,6 @@ public void Bind(TypeSymbolNode symbol) IdentifierNode = new BoundIdentifierNode(Identifier, symbol, IdentifierNode.LineNumber) { Parent = this }; } - public override IdentifierTypeNode Clone() - { - return new(IdentifierNode.Clone(), LineNumber); - } - public override void PopulateBranches(List list) { list.Add(this); diff --git a/Source/Analysis/AbstractSyntaxTree/Nodes/Types/TypeNode.cs b/Source/Analysis/AbstractSyntaxTree/Nodes/Types/TypeNode.cs index b81ee92..17ddc30 100644 --- a/Source/Analysis/AbstractSyntaxTree/Nodes/Types/TypeNode.cs +++ b/Source/Analysis/AbstractSyntaxTree/Nodes/Types/TypeNode.cs @@ -2,8 +2,6 @@ { public abstract class TypeNode : Node { - protected TypeNode(int lineNumber) : base(lineNumber) { } - - public abstract override TypeNode Clone(); + protected private TypeNode(int lineNumber) : base(lineNumber) { } } } diff --git a/Source/Analysis/AbstractSyntaxTree/SyntaxTree.cs b/Source/Analysis/AbstractSyntaxTree/SyntaxTree.cs index 1b7a89b..af49a65 100644 --- a/Source/Analysis/AbstractSyntaxTree/SyntaxTree.cs +++ b/Source/Analysis/AbstractSyntaxTree/SyntaxTree.cs @@ -6,12 +6,12 @@ namespace Krypton.Analysis.AbstractSyntaxTree { public sealed class SyntaxTree : IEnumerable { - public SyntaxTree(ScriptNode root) + public SyntaxTree(ProgramNode root) { Root = root; } - public ScriptNode Root { get; } + public ProgramNode Root { get; } public IEnumerator GetEnumerator() { diff --git a/Source/Analysis/Grammatical/ScriptParser.cs b/Source/Analysis/Grammatical/ScriptParser.cs index 7760066..0663363 100644 --- a/Source/Analysis/Grammatical/ScriptParser.cs +++ b/Source/Analysis/Grammatical/ScriptParser.cs @@ -43,7 +43,7 @@ public ScriptParser(LexemeCollection lexemes) } StatementCollectionNode topLevelStatements = new(statements); - ScriptNode scriptNode = new(topLevelStatements, topLevelStatements.LineNumber); + ProgramNode scriptNode = new(topLevelStatements, topLevelStatements.LineNumber); return new SyntaxTree(scriptNode); } diff --git a/UnitTests/ScriptTests.cs b/UnitTests/ScriptTests.cs index 84b2e26..978dd6e 100644 --- a/UnitTests/ScriptTests.cs +++ b/UnitTests/ScriptTests.cs @@ -30,9 +30,9 @@ While True ... 3 SyntaxTree? tree = parser.ParseWholeScript(); Assert.NotNull(tree); - Assert.IsInstanceOf(tree!.Root); + Assert.IsInstanceOf(tree!.Root); - ScriptNode scriptNode = tree.Root; + ProgramNode scriptNode = tree.Root; Assert.AreEqual(4, scriptNode.TopLevelStatements.Count); diff --git a/UnitTests/SyntaxTreeTests.cs b/UnitTests/SyntaxTreeTests.cs index 54717b7..dea878a 100644 --- a/UnitTests/SyntaxTreeTests.cs +++ b/UnitTests/SyntaxTreeTests.cs @@ -18,14 +18,14 @@ public sealed class SyntaxTreeTests public void EnumeratingTest() { StatementNode node = (StatementNode)SampleNode(); - ScriptNode root = new(new StatementCollectionNode(Enumerable.Repeat(node, 1)), 1); + ProgramNode root = new(new StatementCollectionNode(Enumerable.Repeat(node, 1)), 1); SyntaxTree tree = new(root); IEnumerator enumerator = tree.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); - Assert.IsInstanceOf(enumerator.Current); + Assert.IsInstanceOf(enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.IsInstanceOf(enumerator.Current); @@ -40,20 +40,6 @@ public void EnumeratingTest() Assert.AreEqual(varDecl.Identifier, ((IdentifierNode)enumerator.Current).Identifier); } - [Test] - public void CloningTest() - { - Node root = SampleNode(); - Node clone = root.Clone(); - - Assert.IsFalse(ReferenceEquals(root, clone)); - - var varDeclA = (VariableDeclarationStatementNode)root; - var varDeclB = (VariableDeclarationStatementNode)clone; - - Assert.IsFalse(ReferenceEquals(varDeclA.Value, varDeclB.Value)); - } - [Test] public void PreviousAndNextForStatementsTest() {