0% found this document useful (0 votes)
26 views5 pages

FAF 233 Nicolai Petcov 8

The document describes implementing a domain specific language (DSL) including a lexer, parser, and interpreter. It details the tasks of implementing each component and provides an example of how the parser orders expressions in a binary tree. It concludes the DSL demonstrated creating a simple programming language and provided insights into language processing.

Uploaded by

petcovnicola
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

FAF 233 Nicolai Petcov 8

The document describes implementing a domain specific language (DSL) including a lexer, parser, and interpreter. It details the tasks of implementing each component and provides an example of how the parser orders expressions in a binary tree. It concludes the DSL demonstrated creating a simple programming language and provided insights into language processing.

Uploaded by

petcovnicola
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Ministry of Education of Republic of Moldova

Technical University of Moldova

Faculty of Computers, Informatics and Microelectronics

Software Engineering Department

Computer Programming
Laboratory work #7

Domain Specific Language

Author: Verified:
George Răbus, Alexandru Furdui
std. gr. FAF-233
Nicolae Petcov
std. gr. FAF-233

Chis, inău 2023


FAF-233 Name Surname; Laboratory Work №7 2

Theory Background
A Domain-Specific Language (DSL) is a programming or specification language
dedicated to a particular problem domain, a particular problem representation technique,
and/or a particular solution technique. Unlike general-purpose programming languages,
which are designed to be broadly applicable, DSLs are crafted for a specific application
domain or problem set. The goal of DSLs is to provide a more expressive and concise
means for addressing problems within their designated scope. The lexer first tokenizes
the syntax, then the parser orders the operations with binary tree algorithm and the
interpreter executes the code

grammar/syntax
The DSL has the following operators:

add - addition
sub - substraction
mult - multiplication
div - division
init - initialize integer
fl - initialize float
The program should start with ”START” and end with ”END”
Every line should end with ”;”
print(x) - printing a variable
auto zero after initialization of variable
if (n>x) necessary bracets for all conditions

This is how the parser works in binary tree algorithm:


FAF-233 Name Surname; Laboratory Work №7 3

The Task
Describe your task, and enumerate the task/tasks you have implemented:

1. Implement a lexer
A lexer, short for lexical analyzer, is a crucial component in the process of compiling
or interpreting programming languages. Its primary purpose is to take the source
code of a program (a sequence of characters) and break it down into a stream of
tokens. Tokens are the smallest units of meaning in a programming language and
represent the building blocks of the language’s syntax.

2. Implement a parser
A parser, short for parser generator or syntactic analyzer, is a crucial component
in the process of interpreting or compiling programming languages. Its primary
purpose is to analyze the syntactic structure of the source code and generate a hier-
archical representation, typically in the form of an abstract syntax tree (AST). The
FAF-233 Name Surname; Laboratory Work №7 4

parser ensures that the input adheres to the grammatical rules of the programming
language.

3. Implement the interpreter


An interpreter is a program or software component designed to execute source
code written in a high-level programming language directly, without the need for
a separate compilation step. It reads the source code, analyzes it, and performs
the specified operations as dictated by the code. Here are the main purposes and
characteristics of an interpreter:

Technical implementation
Here is an example where the parser is ordering the expression in binary tree algoritm
TreeNode * Parser :: parseExpression ()
{
TreeNode * left = parseTerm () ;
if ( currentToken - > type == TOKEN_ADDITION || currentToken
- > type == TOKEN_SUBTRACTION )
{
wasMinusOperation = true ;
Token op = * currentToken ;
currentToken ++;
TreeNode * right = parseTerm () ;
left = createBinaryOpNode ( op . value , left , right ) ;
}
wasMinusOperation = false ;
return left ;
}

github project: https://github.com/gelordo/DSL

Results
Describe your results.
As a result we got a semi-functional DSL system where the user can input any operations
and get the correct answer.
FAF-233 Name Surname; Laboratory Work №7 5

Conclusion
The DSL project demonstrated the creation of a simple programming language with
a lexer, parser, and interpreter. The lexer efficiently tokenizes source code, the parser
constructs a binary tree-based Abstract Syntax Tree, and the interpreter executes the
code. Incorporating basic arithmetic operations and control flow statements, the project
illustrated the fundamental principles of language processing. While this DSL is limited,
it provides a foundation for understanding how compilers and interpreters handle code,
making it an insightful exercise for anyone delving into programming language design
and implementation.

Bibliography

1. stackoverflow.com

2. chat.openai.com

3. geekforgeeks.com

4. youtube.com

5. github.com

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy