Abstract

When creating a programming language, it is necessary to determine its syntax and semantics. The main task of syntax is to describe all constructions that are elements of the language. For this purpose, a specific syntax highlights syntactically correct sequences of characters of the language alphabet. Most often it is a finite set of rules that generate an infinite set of all construction languages, such as the extended Backus-Naur (BNF) form.To describe the semantics of the language, the preference is given to the abstract syntax, which in real programming languages is shorter and more obvious than specific. The relationship between abstract syntax objects and the syntax of the program in compilers solves the parsing phase.Denotational semantics is used to describe semantics. Initially, it records the denotations of the simplest syntactic objects. Then, with each compound syntactic construction, a semantic function is associated, which by denotations of components of a design calculates its value – denotation. Since the program is a specific syntactic construction, its denotation is possible to determine using the appropriate semantic function. Note that the program itself is not executed when calculating its denotation.The denotative description of a programming language includes the abstract syntax of its constructions, denotations – the meanings of constructions and semantic functions that reflect elements of abstract syntax (language constructions) in their denotations (meanings).The use of the functional programming language Haskell as a metalanguage is considered. The Haskell type system is a good tool for constructing abstract syntax. The various possibilities for describing pure functions, which are often the denotations of programming language constructs, are the basis for the effective use of Haskell to describe denotational semantics.The paper provides a formal specification of a simple imperative programming language with integer data, block structure, and the traditional set of operators: assignment, input, output, loop and conditional. The ability of Haskell to effectively implement parsing, which solves the problem of linking a particular syntax with the abstract, allows to expand the formal specification of the language to its implementation: a pure function — the interpreter.The work contains all the functions and data types that make up the interpreter of a simple imperative programming language.

Highlights

  • При створенні мови програмування необхідно визначити її синтаксис і семантику

  • Опис імперативної мови програмування у Haskell applyBo :: Op -> Integer -> Integer -> Integer applyBo Plus v1 v2 = v1 + v2 applyBo Minus v1 v2 = v1 - v2 applyBo Times v1 v2 = v1 * v2 applyBo Div v1 v2 = if v2 /= 0 div v1 v2 else error «DivOnZero» applyBo Mod v1 v2 = if v2 /= 0 mod v1 v2 else error «ModOnZero» Наприклад, абстрактним синтаксисом цілого виразу 5 + 4 * 3 є вираз типу Expr ex1 :: Expr ex1 = BinOp Plus (Const 5) (BinOp Times (Const 4) (Const 3)) Його денотат обчислюється функцією eExpr: eExpr ex1 = 17 У Haskell можна ефективно реалізувати синтаксичний аналіз виразу, використавши, наприклад, бібліотеку синтаксичних аналізаторів parsec

  • The ability of Haskell to effectively implement parsing, which solves the problem of linking a particular syntax with the abstract, allows to expand the formal specification of the language to its implementation: a pure function — the interpreter

Read more

Summary

ОПИС ІМПЕРАТИВНОЇ МОВИ ПРОГРАМУВАННЯ У HASKELL

Розглянуто використання функціональної мови програмування Haskell як метамови. Наведено повну формальну специфікацію простої імперативної мови програмування з цілими даними, блочною структурою та операторами: присвоєння, введення, виведення, циклу і умовний. На основі специфікації побудовано інтерпретатор мови програмування. Ключові слова: мова програмування, синтаксис, денотат, семантична функція, Haskell, синтаксичний аналіз, інтерпретатор

Загальний метод опису мов програмування
Мова цілих виразів
Мова зміни стану
Семантичні функції
Синтаксичний аналіз
DESCRIPTION OF THE IMPERATIVE PROGRAMMING LANGUAGE IN HASKELL
Full Text
Paper version not known

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.