Giter VIP home page Giter VIP logo

compiler's Introduction

Compiler

Lexical Analysis:

Lexical analysis, also known as scanning, is the first phase in compiling or interpreting a programming language. It is a crucial step that involves breaking down the source code into a stream of tokens. Tokens are the smallest meaningful units of the programming language, such as keywords, identifiers, literals (constants), operators, and punctuation symbols. The primary purpose of lexical analysis is to simplify the subsequent phases of the compiler or interpreter by converting the source code into a format that is easier to process.

The lexical analyzer, often called a lexer or scanner, scans the source code character by character, recognizing and classifying sequences of characters into tokens based on a set of predefined rules defined by the programming language's grammar. Whitespace and comments are typically removed during this process as they are unnecessary for further analysis. The output of the lexical analysis is a sequence of tokens that represent the source code's linguistic structure, which is then fed into the next phase of the compilation or interpretation process: parsing.

Parsing:

Parsing is the second phase in compiling or interpreting a programming language. It takes the stream of tokens generated by the lexical analysis and organizes them into a hierarchical structure based on the language's grammar rules. This hierarchical structure is often represented in the form of a syntax tree or abstract syntax tree (AST).

During parsing, the parser analyzes the relationships and connections between tokens and groups them into higher-level language constructs like expressions, statements, and declarations. The parser ensures that the source code adheres to the syntax and semantics of the language, reporting any syntax errors if the code does not conform to the specified grammar rules.

The output of the parsing phase is an abstract representation of the source code, which is easier to analyze and manipulate. The syntax tree or AST generated by parsing is used in subsequent stages of the compilation or interpretation process, such as semantic analysis, optimization, and code generation.

Together, lexical analysis and parsing form the front end of the compiler or interpreter, responsible for processing the source code and transforming it into a form suitable for further analysis and translation into machine code or an intermediate representation. These initial phases play a vital role in ensuring the correctness and efficiency of the final compiled or interpreted program.

compiler's People

Contributors

vg31 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.