Skip to content

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LISP-like Interpreter

This code is a Computer Engineering project from Genoa in which the programming of a C++ interpreter for a 'Context-free grammar' was required, as described below.

Structure of project

First, the program performs a lexical analysis that returns a sequence of tokens; subsequently, through a syntactic analysis, a syntax tree is created. Finally, by utilizing the Visitor design pattern, the tree is evaluated, thus interpreting the code.

Usage

After compiling the program, it should be executed using the following command:


./interpreter.exe -[path to the file with the lisp code]

The command may vary slightly depending on the operating system and how the code is compiled.

In cmake-build-debug folder there's already inside a test file called test.txt

Other

In the project there's also the UML schema called UML.pdf

Abstract Grammar

Program

program        → stmt_block 
stmt_block     → statement | ( BLOCK statement_list ) 
statement_list → statement statement_list | statement 

Statement

statement → variable_def | io_stmt | cond_stmt | loop_stmt
  
variable_def → ( SET variable_id num_expr )
io_stmt      → ( PRINT num_expr ) | ( INPUT variable_id )
cond_stmt    → ( IF bool_expr stmt_block stmt_block )
loop_stmt    → ( WHILE bool_expr stmt_block )

Numerical Expression

num_expr → ( ADD num_expr num_expr ) | ( SUB num_expr num_expr ) | ( MUL num_expr num_expr ) 
         | ( DIV num_expr num_expr ) | number | variable_id

Boolean Expression

bool_expr → ( LT num_expr num_expr ) | ( GT num_expr num_expr ) | ( EQ num_expr num_expr ) 
          | ( AND bool_expr bool_expr ) | ( OR bool_expr bool_expr ) | ( NOT bool_expr ) | TRUE | FALSE

Variable name e Number

variable_id → alpha_list
alpha_list  → alpha alpha_list | alpha
alpha       → a | b | c | . . . | z | A | B | C | . . . | Z

number    → - posnumber | posnumber
posnumber → 0 | sigdigit rest
sigdigit  → 1 | . . . | 9
rest      → digit rest | ε
digit     → 0 | sigdigit

About

Interpreter for a custom LISP dialect supporting variables, loops, conditionals, and math operations. Built in C++ using Visitor Pattern architecture.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages