LogicScript Compiler is a lightweight interpreter-based compiler developed using Lex (Flex) and Yacc (Bison). The project is designed to process and execute a custom logic-based scripting language while demonstrating the fundamental concepts of compiler design, including lexical analysis, syntax parsing, and execution.
The compiler supports multiple core functionalities required for a simple scripting language. It performs lexical analysis using Lex and syntax parsing using Yacc. The system allows variable declaration and assignment, evaluates arithmetic and boolean expressions, and supports conditional statements such as if-else. A basic execution engine is implemented to process and display results.
The project is implemented using the C programming language along with compiler construction tools such as Lex (Flex) for tokenization and Yacc (Bison) for parsing. GCC is used as the primary compiler for building and running the project.
To execute the project, follow these steps:
-
Compile the project using the Makefile: make
-
Run the compiled program: ./logic
The project is organized into multiple components that represent different phases of a compiler:
- main.c: Entry point of the program
- logicscript.l: Lex file responsible for token generation
- logicscript.y: Yacc file responsible for parsing rules
- lex.yy.c: Generated lexical analyzer code
- logicscript.tab.c: Generated parser implementation
- logicscript.tab.h: Header file generated by Yacc
- Makefile: Build configuration file
The compiler operates in three main phases. First, lexical analysis converts the input program into tokens. Next, syntax parsing checks whether the token sequence follows the defined grammar rules. Finally, the execution phase evaluates expressions and executes statements based on the parsed structure.
x = 10 y = 20 if (x < y) { print(x) }
10
This project provides practical experience in understanding compiler design principles. It covers lexical analysis, parsing techniques, syntax validation, and execution of a custom scripting language. It also demonstrates how different compiler phases are integrated into a working system.
Md. Asif Khandoker GitHub: https://github.com/nafis-ak
This project is licensed under the MIT License.