Skip to content

nafis-ak/LogicScript-Compiler

Repository files navigation

LogicScript Compiler

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.

Features

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.

Technologies Used

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.

How to Run

To execute the project, follow these steps:

  1. Compile the project using the Makefile: make

  2. Run the compiled program: ./logic

Project Structure

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

How It Works

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.

Sample Input

x = 10 y = 20 if (x < y) { print(x) }

Output

10

Learning Outcomes

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.

Author

Md. Asif Khandoker GitHub: https://github.com/nafis-ak

License

This project is licensed under the MIT License.

About

Developed a custom compiler using Lex and Yacc for a logic-based scripting language. The project implements lexical analysis, syntax parsing, and code execution, demonstrating core concepts of compiler design and language processing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors