Table identifiers

There is one problem with the compiler in its current state: it does nothing to save a variable when we declare it. So the compiler will quietly allocate memory for several variables with the same name. Вы можете легко убедиться в этом набрав строку типа pvavavabe. Here we declared A variable A three times. Как вы можете […]

Boolean logic

The next step should also be familiar to you. We need to add Boolean expressions and operators relations. Again, as we worked with them more than once, I won't detail all of them except, in which they differ from, what we did before. Again, мы не будем просто копировать их из других файлов потому […]

Control structures

We're almost home. Having a Boolean expression it is easy to add control structures. For TINY we solve only two of them, IF and WHILE: <if> ::= IF <bool-expression> <block> [ ELSE <block>] ENDIF <while> ::= WHILE <bool-expression> <block> ENDWHILE Еще раз позвольте мне разъяснить решения, implied in this syntax, which is very different from the syntax of C or Pascal. In […]

Doable approval

By this time, we can generate an empty program, which has some variables declared and possibly initialized. But until we have generated a single line of executable code. Do you believe or not, but we almost have a usable compiler! Missing only the executable code, to log in the main program. Но этот код – это только операции […]

Initializers

While we worked with the ad data, I was worried about one thing – , what Pascal does not allow you to initialize data in the ad. This feature admittedly is kind of overkill, and it may not be in the language, which is considered the minimum language. But it is also so simple to add, it would be a shame not to do it. BPF becomes: […]

Ads and IDs

This looks pretty good, but we still only generated an empty program. This assembler should give assembler directives to allocate memory for variables. Now it's really time to get some code. With a little extra code it is easy to make in the procedure Decl. Change it as follows: Parse and Translate a Data Declaration procedure Decl; var Name: char; begin […]

Preparation

Many years ago there were languages, called Tiny BASIC, Tiny Pascal, and Tiny C, each was a subset of its parent full language. Tiny BASIC, for example, had only single-character variable names and global variables. He supported only one data type. Sounds familiar? At this point, we have almost all the tools, необходимые для создания компилятора подобного […]

Ads procedures/functions

Obviously the next step is to solve, what do we mean by announcement. I intend to have two kinds of ads: variables and procedures/functions. On the upper level is permitted only global declarations, just like in C. Now there can only be variable declarations, identified by the keyword VAR (abbreviated “v”). <top-level decls> ::= ( <data declaration> )* <data declaration> ::= […]

Ads

The BNF for Pascal declarations in this: <declarations> ::= ( <label list> | <constant list> | <type list> | <variable list> | <procedure> | <function> )* (Note, I'm using a more liberal definition, used in Turbo Pascal. In the definition of standard Pascal, each of these parts should follow in a specific order relative to other). Как обычно давайте позволим […]

The Structure Is Si

The C language is quite another matter, as you will see. Books on C rarely include a BNF definition of the language. Maybe that's, it is very difficult to describe in BNF. One of the reasons that I'm showing you these structures now is that I can impress you with two facts: 1. The definition of the language drives the structure of a compiler. That […]