*# Italian Cuisine Inspired Programming Language
- Table of Contents
- Project Overview
- Authors
- Features
- Additional information & resources
- Getting Started
- Usage
- How It Works
- Develop a Lexer (Tokenizer)
- Header Files for Lexer (
token.h
andlexer.h
) - Compilation and Linking Commands
This project aims to create a simple, user-friendly programming language based on C, inspired by Italian cuisine and language. It is designed to be highly scalable, allowing for the easy addition of new tokens and the configuration of corresponding parser functions. The project currently supports basic arithmetic operations and print statements, providing a solid foundation for further development.
- Diana Rubaga
- Alberto Puliga
- Gregorio Orlando
- Italian Terms Syntax: Utilizes Italian terms for programming constructs, making it intuitive for our target audience.
- Simple and Educational: Ideal for beginners and educational purposes, particularly in Italian learning environments.
- Scalable: Easy addition of new tokens and configuration of parser functions for extensibility.
- Focus on Basic Programming Concepts: Emphasizes fundamental concepts in programming without the complexity of more advanced languages.
Please check out the ./documentation
folder to find a detailed PDF report and videos showing the functioning of each file.
- Basic understanding of programming concepts.
- C compiler (like GCC) installed on your system.
- Clone the repository:
git clone https://github.com/albipuliga/ItaloCode
- Compile the source files using your C compiler. Run this command to link lexer.c with parser.c thank to the header files we prepared.
gcc lexer.c parser.c -o myprogram
- Run the executable to start using the language interpreter.
Write your code using the Italian syntax. For instance:
stampa
for printing. Add what you want to print after the commandstampa
without spaces.piu
,meno
per
, anddiviso
for mathematical arithmetics.PS
for comments. If you writePS
, the interpreter will skipp everything in his line.!
for ending each line (with a blank space before it). At the end of each line a exclamation mark is needed.- Write everything in lower letter.
Refer to the documentation for detailed syntax and examples.
To compile and link the lexer implementation (lexer.c
) with the parser (parser.c
), use the following commands:
gcc lexer.c parser.c -o myprogram
This compiles both source files and links them into an executable named myprogram
. The header files (token.h
and lexer.h
) ensure that necessary declarations are available during compilation, promoting code organization and ease of maintenance.
- Each line of code in the input file (
input.txt
) should end with a " !" to denote the end of the line. - All lines in
input.txt
should be written in lowercase, and the use of parentheses does not have any specific meaning in the current implementation.
To perform arithmetic operations, follow the format:
number operation number !
for example:
5 + 3 !
Writing PS
you can write comments in to input.txt
. It means that the all line will be discarded and the interpreter (evaluate
) will skip to the next line. To use it, the grammar sintaz is:
PS this content will be discard !
This will allert you when running ./myprogram.exe
that there is a comment line, but his content will remain hiden.
To execute print statements, use the following format:
stampa what-u-want-to-print !
for example:
stampa ciao-come-stai? !
The lexer.c
file contains the implementation of the lexer, which is responsible for tokenizing the input code into meaningful components. Below are key functions and their descriptions:
Given a token type, this function returns the corresponding name of the token.
This function checks if a given string is a keyword and returns its token type.
This function tokenizes a single word, returning a Token
structure.
The main lexer function that takes an input string and tokenizes it using the specified delimiters.
A test function with an example input string to demonstrate the lexer.
To use the lexer, you can call the lexer
function with your input code.
The parser.c
file contains the implementation of the parser, which is responsible for building an Abstract Syntax Tree (AST) from the tokens generated by the lexer. Below are key components and their descriptions:
Enumeration of different node types in the Abstract Syntax Tree (AST), including Program, Expression, Operation, Literal, and Variable.
Structure defining the nodes of the Abstract Syntax Tree (AST), including the type of the node, the associated token, and pointers to left and right child nodes.
Function to create a new AST node with the specified type and token.
Functions responsible for parsing different parts of the code and constructing the AST, including parseLiteral
, parseProgram
, parseExpression
, parseTerm
, and parseFactor
.
Function to parse a literal, handling both numbers and variables.
Function to parse an entire program, typically an expression.
Function to parse an expression.
Function to parse a term, handling addition and subtraction.
Function to parse a factor, handling multiplication and division.
Functions for printing the AST in a readable format, including printAST
and printASTIndented
.
Function to print the AST in a simple format.
Function to print the AST with indentation for better readability.
Functions for evaluating the AST, including evaluate
and main
.
Function to evaluate the result of an AST node, supporting basic arithmetic operations.
The main function reads code from a file, tokenizes it using the lexer, parses it into an AST, prints the AST, and evaluates the result.
- Contents: Defines token types (
enum TokenType
) and the token structure (struct Token
). - Purpose: Provides clear token-related declarations for use in other source files.
- Contents: Includes
token.h
and declares function prototypes (tokenizeWord
andgetTokenTypeName
) used inlexer.c
. - Purpose: Enables importing lexer-related declarations in other source files (e.g.,
parser.c
) without exposing implementation details, promoting code organization and ease of maintenance.
To compile and link the lexer implementation (lexer.c
) with the parser (parser.c
), use the following commands:
gcc lexer.c parser.c -o myprogram
These commands compile both source files and link them into an executable named myprogram
. Header files ensure necessary declarations are available during compilation, allowing parser.c
to use functions and structures defined in lexer.c
.
*