Description
A front-end compiler is responsible for taking source code written in a high-level programming language and translating it into an intermediate representation, which can then be further processed by other components of the compiler. The front-end typically includes the following components:
- Lexer (also called a tokenizer): This component takes the source code as input and breaks it down into a series of tokens. Tokens are the smallest units of meaning in a programming language, such as identifiers, keywords, operators, and punctuation marks.
- Parser: The parser takes the output of the lexer and uses it to build a parse tree, which is a hierarchical representation of the program's structure. The parser ensures that the code is syntactically correct and assigns meaning to each construct.
- Semantic Analyzer: This component takes the parse tree and performs semantic analysis to ensure that the program makes sense from a semantic perspective. It checks for things like type mismatches, undeclared variables, and other issues that may lead to errors.
- Intermediate Code Generator: This component takes the output of the semantic analyzer and generates intermediate code, which is a low-level representation of the program that can be further optimized before being compiled into machine code. In this case Intermediate Code is C.
- Symbol Table: This component maintains a record of all the symbols used in the program, such as variables, functions, and classes. The symbol table is used by the semantic analyzer to resolve references and ensure that the program is well-formed.
- Error Handler: This component is responsible for detecting and reporting errors in the source code. It provides error messages that help programmers identify and fix problems in their code.
These components work together to ensure that the front-end of the compiler accurately represents the source code and prepares it for further processing by the back-end of the compiler.
Goal of the project: develop the front-end of the compiler Some info
Information
- Category: Front-end Compiler
- Client: University
- Project date: Gen 2022
- GitHub: github.com/GerardoIuliano/Compiler
Technologies
- JavaCup: is a system for generating LALR parsers from simple specifications. A parser is a software component that takes input data (frequently text) and builds a data structure – often some kind of parse tree, abstract syntax tree or other hierarchical structure, giving a structural representation of the input while checking for correct syntax.
- JFlex: is a lexical analyzer generator. It takes as input a specification with a set of regular expressions and corresponding actions. It generates a program (a lexer) that reads input, matches the input against the regular expressions in the spec file, and runs the corresponding action if a regular expression matched.