How many have to redo? In short, please tell us what steps are needed for this. For example, I really like the language of Julia, but the static typing is incomplete there.

Closed due to the fact that the question is too common for participants insolor , AK , 0xdb , user192664, aleksandr barakin 7 Oct '18 at 14:20 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Is it possible to describe a little more in the question? Do you want to remake Julia was with static typing? Or do you want to rewrite the whole code from Julia into a static-typed language? If the first, then nothing complicated - just in the description of each variable you put its type and check it at run time. If the type does not match, mandatory type casting is required. Casting is just a couple of key language constructs. - Axenow
  • Transform a language with dynamic typing into a language with static typing. Refers to the language of the compiler. - Merlin
  • Add type casting and data type for each variable. When compiling to check that the types match, if not - an error. - Axenow
  • Well, make an answer, which you write in the comments) - Merlin

1 answer 1

As a matter of fact, for this it is necessary to add and realize several possibilities:

  1. Add to the structure that describes each variable information about the type of this variable. This can be either a primitive, or an object, an interface, etc.
  2. Add the possibility of casting one type of variables to others. An example of this from Java:

    long l = 100000; int i = (int) l;

  3. On this type of compilation, check the data type, if it does not match or cannot be converted by a type tree, then an error.

  4. You also have to store the class tree if the language supports OOP. This is necessary so that the subclasses can be used as parameters and vice versa. A small example from java

    public class Animal { public void eat() { // ... } } public class Cat extends Animal { public void eat() { // ... } public void meow() { // ... } } Cat cat = new Cat(); Animal animal = cat; animal = (Animal) cat;