Programming Language Theory(1)

김동규·2023년 9월 6일
1

This is the course of Programming Language Theory(PLT).

What is the Language? The Language is a tool of comunicate with others. In this aspect, Programming Language is a tool of comunicate with computer.

This is the flow of program. There are two ways, one is using Interpreter and the other is using compiler.

As we know in this picture, there are 4 steps to create computer program. Most important step of them is Design a program. Programmers must have a lot of time in this step.

Write the program by a programming language step is the next step of Design a program step. In this step, there are very important keyword "syntax" and "semantic".

The syntax is related grammer and structure.

The semantic is related to meaning.

If we create variable named by myAge, we can do like int myAge = 10;
In this code, int, myAge and 10 is just syntax. They are type, name, and initializer value. However, the group of these syntax, it is semantic. It's mean is "to create variable myAge that type is int and initializer value is 10.
In programming language, it is very important.

The next step is Interpret or compile the program step.

Finally, we can run program and see the results.


Human's languages have a lot of forms different from each other. So, if we want to make programming language in all types of human languages, it will be very hard process.

For that reason, programming language uses the parser. Parser can convert different programming languages to same AST(Abstract Syntax Tree) form.


They are similar syntax code in different programming languages. They are very similar in their syntax. However, their semantic is not similar. If they are same syntax each other, it doesn't ensure they are doing same actions.

For example, in Java language, if we access index number of 26, it will return error. However, in C language, it will return garbage value not error. So, syntax is not most important point. Then, what is the most important point of programming language?

The answer is "semantic"

Then, how can we create semantics of Interpreter? It is simple. Just write an interpreter to explain a language. The important point in this is that an interpreter is a program.


In this picture, we can know there are many form of expression. However, they have same semantic that is 3 + 4. In these form, we can abstrac syntax in a tree form like this.

This is a purpose of parser.

Also, there can be another expression in number position. It depends on grammer likes BNF and we can make type like this.

In this picture, we use the type of lhs and rhs AE. Because there can be num or add or sub. If the type of lhs and rhs is num, we can't make more deep codes like this.

Next, what is parser? A parser is a component in an interpreter or compiler. By using parser, we can create concrete syntax into AST. If parser does parse source codes, parser follows the rules of some grammar like BNF.

We can represent abstract syntax in racket.

By using this structure, we can parse source code in AST structure. In BNF grammar, there are two type terminal and non-terminal. Non-terminal type can be represent in other words. However terminal type can't.

If we use a parser in this example, we can make a parser like this.

However, this parse code have a problem. That is exception case. We want the input type is specific expression like (+ 1 2), but there are some case that not follow our rules like (+ 1 2 3). Then, how can we do in this case?


In this case, we can make more condition in the function and by adding else structure we can throw exceptions like Java. By doing so, we can convert expressions to our semantic grammar that used in Interpreter.


The next step is convert AE(our semantic grammer define-type) to real number(calculate function of source codes).

We can define interpreter like this. If input value of an-ae's type is AE, we can use AE type-case section. In this section, there are 3 varients num, add and sub. If the cases of add or sub, there will be two small expressions. So, we must re-parse into same interpreter to create AST.

profile
안녕하세요 :)

1개의 댓글

comment-user-thumbnail
2023년 12월 11일

Great information. Thank you for telling us about this programming language. I’m currently studying to become a programmer and I’m interested in absolutely everything connected with it. True, sometimes I have difficulties and I turn to https://programmingdoer.com/do-my-r-homework I liked that, firstly, they have step-by-step instructions on their website, let’s say how to get help with my coding assignment. After placing a couple of orders, I came to the conclusion that these specialists know how to work on complex R problems and with strict deadlines. This is the most important thing for me and suits me completely.

답글 달기