Skip to content

Sh-31/GazaScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GazaScript Compiler

GazaScript is a Basic Compiler implemented using Flex and Bison. This compiler translates custom source code written in the GazaScript language into executable instructions. The language supports basic arithmetic, logical operations, conditionals, loops, and variable assignments.

Table of Contents

  1. Project Overview
  2. Getting Started
  3. Installation
  4. Usage
  5. File Structure
  6. Grammar Overview
  7. Compilation Process
  8. Execution Details
  9. Sample Programs
  10. License
  11. Acknowledgments
  12. Contact Information

Project Overview

GazaScript is designed to be a simple yet powerful language for learning the basics of compiler construction. It supports fundamental programming constructs and serves as an educational tool for understanding lexing, parsing, and abstract syntax trees.

Getting Started

Clone the Repository

git clone https://github.com/your-username/GazaScript.git
cd GazaScript

Dependencies

Make sure you have Flex and Bison installed on your system. You can install them using your package manager:

sudo apt-get install flex bison   # For Ubuntu/Debian

Installation

Usage

Compile the Compiler

flex 1.l
bison -d 1.y
gcc -o a.exe  .\1.tab.c .\lex.yy.c .\SyntaxTree.c
a.exe

Run GazaScript Programs

./a.exe

File Structure

  • 1.l: Contains the lexical analyzer (Flex) definitions.
  • 1.y: Specifies the grammar rules and actions (Bison).
  • SyntaxTree.h and SyntaxTree.c: Define and implement the abstract syntax tree (AST) data structure.
  • in.txt: Input file for GazaScript programs. Place your source code here.
  • out.txt: Output file where the compiled program's result is stored.
  • outError.txt: Log file capturing any errors encountered during compilation or execution.
  • tree.txt: Text file representing the abstract syntax tree (AST) of the GazaScript program.
  • Commands.txt: Contains commands needed to run the GazaScript compiler and execute programs.

Grammar Overview

The GazaScript grammar includes terminals, non-terminals, rules, and semantic actions. Refer to the grammar section in the parser file (1.y) and Syntax-Directed-translation.pdf for a detailed breakdown.

Compilation Process

The compilation process involves using Flex to generate the lexer (lex.yy.c) and Bison to generate the parser (parser.tab.c). The Makefile streamlines this process.

Execution Details

The generated AST is traversed and executed to interpret GazaScript programs. The execute_ast function in SyntaxTree.c handles the interpretation logic.

Sample Programs

Sample one

in.txt out.txt tree.txt

Sample two

in.txt out.txt tree.txt

Sample tree

in.txt outError.txt

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Contact Information

For issues, suggestions, or inquiries, please contact [email protected].