This repository hosts the development of a compiler for FORT500, a high-level language resembling FORTRAN with structured commands and record structures, supporting recursive subprogram definition.
The FORT500 compiler project is divided into two main components: the Lexical Analyzer and the Syntax Analyzer. These components work together to analyze and process FORT500 source code.
The Lexical Analyzer, also known as the lexer or scanner, is responsible for breaking down the input source code into tokens. These tokens are the smallest meaningful units of the FORT500 language, such as keywords, identifiers, constants, and operators.
The Syntax Analyzer, also known as the parser, analyzes the structure of the source code according to the rules of the FORT500 grammar. It checks whether the sequence of tokens generated by the Lexical Analyzer follows the syntax rules defined by the language's grammar. If the sequence of tokens forms valid syntactic constructs, the Syntax Analyzer produces a parse tree or syntax tree, which represents the hierarchical structure of the program.
Lexical Analyzer/
: Contains the source code for the Lexical Analyzer component.Syntax Analyzer/
: Contains the source code for the Syntax Analyzer component.LICENSE.txt
: The license under which this project is distributed.README.md
: This README file providing an overview of the project.CONTRIBUTING.md
: Guidelines for contributing to the project.
- Clone the repository:
git clone https://github.com/your-username/fort500-compiler.git
- Navigate to the project directory:
cd fort500-compiler
- Build the Lexical Analyzer:
# Navigate to the Lexical Analyzer directory cd "Lexical Analyzer/" # Compile the Lexical Analyzer flex lexer.l gcc -o lexer lex.yy.c -lm # Execute the lexical analyzer ./lexer fort500test1.f ./lexer fort500test2.f
- Build the Syntax Analyzer:
# Navigate to the Syntax Analyzer directory cd "Syntax Analyzer/" # Generate syntax.tab.c and syntax.tab.h using Bison bison -v -d syntax.y # Compile the Syntax Analyzer gcc -o parser syntax.tab.c lex.yy.c hashtbl.c -lm # Return to the main project directory cd ..
- Clone the repository:
git clone https://github.com/your-username/fort500-compiler.git
- Navigate to the project directory:
cd fort500-compiler
- Build the compiler.
- Execute the compiler with a FORT500 source file as input:
./fort500-compiler <input_file.f500>
The FORT500 compiler follows a typical compilation pipeline involving the Lexical Analyzer and Syntax Analyzer:
-
Lexical Analysis: The Lexical Analyzer scans the input FORT500 source code, breaking it down into tokens representing keywords, identifiers, constants, and operators.
-
Syntax Analysis: The Syntax Analyzer parses the sequence of tokens generated by the Lexical Analyzer according to the rules of the FORT500 grammar. It ensures that the tokens form valid syntactic constructs and may produce a parse tree or syntax tree representing the program's structure.
These components work together seamlessly to process FORT500 source code and generate executable programs.
The development of the FORT500 compiler leverages the following tools:
- Bison: Used for generating the Syntax Analyzer from the FORT500 grammar specifications.
- Flex: Utilized for creating the Lexical Analyzer to tokenize the input source code.
Contributions are welcome! Please refer to the contribution guidelines for more information on how to contribute to this project.
This project is licensed under the MIT License.