Level compiler is designed for learning how to make a computer language. In this article we explain main components of a compiler. We use links to GitHub project files that you can visualize. Level compiler has comments in code so you can understand each component.

Formal grammar

In computer science a language is defined by formal gramar. In formal language theory, a grammar is a set of production rules for strings that form a language. The rules describe how to form strings from the language alphabet that are valid according to the language syntax.

See also: wikipedia formal grammar

Grammar description

We use several specific notations to describe grammar.

  1. We enclose identifier names in angle brackets <>;
  2. Identifiers are starting with a letter and contain letter or numbers;
  3. We enclose optional elements in squared brackets [];
  4. We represent alternative (or) using the vertical bar “|”;
  5. A repeating sequence of elements is represented using 3 dots: “…”

Mathematical Expressions

Is a finite combination of symbols that is well-formed according to rules that depend on the context. Mathematical symbols can designate numbers elements, operators or tokens: {constants, variables, operations, functions, punctuation, grouping}, and some other aspects of logical syntax.

Well-formed (syntax)

A well-formed expression is a syntactic concept. A syntax is a set of rules, principles, and processes that govern the structure of a given language.

In a correct expression the operators must have the correct number of inputs in the correct places, the characters that make up these inputs must be valid. Enumeration of symbols that violate syntax rules are not well-formed and are not valid mathematical expressions.

For example, in the usual notation of arithmetic, the expression 2 + 3 is well-formed, but the following expression is not: \times4)x+,/y.

Expression form (semantic)

Mathematical expressions include multiple forms of expressions: {arithmetic, polynomial, algebraic, closed-form, and analytical}. The form of an expression is a semantics concept.Semantics is the study of meaning. Formal semantics is about attaching meaning to expressions.

Expression evaluation

An expression may be used to designate a value, which might depend on variables occurring in the expression. The determination of this value depends on the semantics attached to the symbols of the expression.

Certain expressions do not designate any value, for instance when they involve division by 0; such expressions are said to have an undefined value, but they are well-formed expressions nonetheless.

Logical expressions

In general the meaning of expressions is not limited to designating values; for instance, an expression might designate a condition, or an equation that is to be solved, or it can be viewed as an object in its own right that can be manipulated according to certain rules.

How compiler works?

 In order to build a compiler for Level I have started my research several weeks ago. Until now I have understood some basic concepts and I have started to implement the compiler components. Next I wil present the compiler components created for project Level-PY. That is a python compiler for Level-3.

You need to login to view the rest of the content. Please . Not a Member? Join Us