Slide 1

Slide 1 text

Deru a multilingual programing language made with python Daniel Arango

Slide 2

Slide 2 text

Who am I? DD -I made this talking Colombia. -PyCon Colombia Lightning Talk -Novo Hamburgo University, Simultaneous Multilingual Translation Systems -I won 3 competitions at my uni with my projects. -Leader of ML group in Eafit University.

Slide 3

Slide 3 text

What is Deru Lisp dialect in De-> Deustche Spreche (German language) Ru->Русский язык (Russian language) My Motivations

Slide 4

Slide 4 text

John MCcarthy Lisp Paper LISt Procecing What is lisp? Not a programming Language Is a metaprogramming language

Slide 5

Slide 5 text

Lisp Dialects Scheme Clojure Common lisp Emacs lisp

Slide 6

Slide 6 text

Examples print("hello word") (печать "привет Мир") print("hello word") print("hello",input("how is your name")) This is not an esoteric programing language, is more powerful than that, but I didn't see the future for this programming language, except for learning how to make a programing language

Slide 7

Slide 7 text

More Examples of Deru You have Control sctructures

Slide 8

Slide 8 text

More Examples of Deru You can create Functions

Slide 9

Slide 9 text

More Examples of Deru Mixing different natural languages

Slide 10

Slide 10 text

Notes All is in parentheses. (Parentheses mean it is a list).

Slide 11

Slide 11 text

Notes The first element is the function. The others are arguments. (F a1 a2 a3 … ax) F is a function name. a1 ... ax are arguments.

Slide 12

Slide 12 text

Notes Deru is not a pure Functional Programming because it has side effects and monads are not implemented Is interpreted Is not Complicated, sorry I mean Compiled

Slide 13

Slide 13 text

https://github.com/kanaka/mal How to make a lisp Dialect in python Index • step1_REPL • step2_eval • step3_lexical,syntaxis and semantic analysis • step4_Environment • step5_Control_Structures • … and more https://github.com/kanaka/mal

Slide 14

Slide 14 text

Repl (Read-Eval-Print Loop) relp is the entry point to your programming language

Slide 15

Slide 15 text

Eval Python eval() is different from this eval. Lisp (F a1 a2 a3 … ax) How to convert Sintaxis of the functions Python F ( a1 a2 a3 … ax ) The EVAL function processes Lisp code as structured lists, treating them as directly evaluable syntax. It interprets constructs dynamically, supporting macros, conditionals without an explicit AST.

Slide 16

Slide 16 text

Tokenization How look the code tokenized Regular expression for tokenization H code NOT Tokenized The process of separating the string into substrings (referred to as tokens) organizes the information that is being passed to the parser.

Slide 17

Slide 17 text

Syntax's analysis •The process for verifying that our grammar is being followed •Normally Syntax Analysis builds an abstract syntax tree •Here no, you traverse the tree with the eval recursion

Slide 18

Slide 18 text

Grammar • A grammar is a set of rules that describe how tokens can be combined to form valid statements and expressions in the language.

Slide 19

Slide 19 text

S-expressions There are two kinds of S-expression, atoms and lists. S-expressions express your program and manipulate it the same way an interpreter would. This lets you add your own language features without modifying the compiler or interpreter.

Slide 20

Slide 20 text

Semantics Semantic Analysis makes sure that declarations and statements of a program have a correct structure and give the meaning to the tokens.

Slide 21

Slide 21 text

Type checking We assign the types by validating the string with regular expressions, regular expressions create Automata

Slide 22

Slide 22 text

Symbol table In lisp dialects we don't use Symbol table

Slide 23

Slide 23 text

ENViroment We save Quadrat function in the enviroment (python dictionary) Python Dictionary Complexity O(1) get item O(1) set item O(1) delete item We use dictonaries because their operations have O(1) complexity and let you change some predefined functions programing

Slide 24

Slide 24 text

A programing language for all languages? (2)add intermediate step for translation before access to the environment that must be in English, in English because is and Interligua and most the translators use it as intermediate language for optimizing translations You have 2 ways to do this (1) add all instructions translations to the environment

Slide 25

Slide 25 text

macros The rule or pattern that specifies how a certain input should be mapped to a replacement output. Python doesn't have macros but we can create it with eval () Everything in lisp is a macro

Slide 26

Slide 26 text

Macros VS Functions

Slide 27

Slide 27 text

Variables and Functions "Let" adds value to the symbol table The third argument of the function is the code of the function, which will insert the AST We are inheriting the environment to manage public and private variables.

Slide 28

Slide 28 text

Control structures We use the "if" of deru passing the values to the "if" of python , it is in the eval() Function

Slide 29

Slide 29 text

WHere are the "for or while"? In functional programming languages, 'while' and 'for' are not used.

Slide 30

Slide 30 text

WHere are the "for or while"? I know I'm a terrible person for leaving `while` commented out, but we need to learn how to make fast recursions.

Slide 31

Slide 31 text

Finally, we have a programming language

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

TCO (Tail call optimization) Benefits: • Avoids unnecessary stack manipulation operations. • No stack overflow • Improved Performance

Slide 35

Slide 35 text

TCO (Tail call optimization) Tail call optimization in Python is not natively supported due to Python's recursion limit and the lack of tail call optimization in its interpreter. However, it can be simulated using a loop to replace recursive calls with iterative ones and with externals tools. Programing languages like haskell , Scala, Clojure, Erlang, and Elixir have TCO

Slide 36

Slide 36 text

"TCO (Tail call optimization)" simulated focus on "while" addition

Slide 37

Slide 37 text

Trampolines Trampolines allow to replicate tail call optimization by wrapping function calls into a special object using the @trampoline decorator.

Slide 38

Slide 38 text

¿HOW to archive real TCO? ctypes Rust TCO cargo package didn't work and had no documentation With Ctypes you can connect C and python using the TCO to C

Slide 39

Slide 39 text

Extra features quotes Try catch

Slide 40

Slide 40 text

Extra features quotes Quotes and comments

Slide 41

Slide 41 text

Common Problems when we create a programing language

Slide 42

Slide 42 text

Finally, we have a programing language Conclusions

Slide 43

Slide 43 text

end jero98772 Follow me as https://github.com/jero98772/Deru References: https://pastebin.com/aynprhjU