All Projects → madmann91 → Slang

madmann91 / Slang

Licence: lgpl-3.0
A small, flexible and extensible front-end for GLSL.

Projects that are alternatives of or similar to Slang

Glsl
GLSL parser for Rust
Stars: ✭ 145 (+1350%)
Mutual labels:  parser, glsl
Surelog
SystemVerilog 2017 Pre-processor, Parser, Elaborator, UHDM Compiler. Provides IEEE Design/TB C/C++ VPI and Python AST API.
Stars: ✭ 116 (+1060%)
Mutual labels:  parser, preprocessor
Radon
A scripting language.
Stars: ✭ 22 (+120%)
Mutual labels:  parser
Html React Parser
📝 HTML to React parser.
Stars: ✭ 846 (+8360%)
Mutual labels:  parser
Metric Parser
📜 AST-based advanced mathematical parser written by Typescript.
Stars: ✭ 26 (+160%)
Mutual labels:  parser
Fieldplay
A vector field explorer
Stars: ✭ 922 (+9120%)
Mutual labels:  glsl
Hx Mathparser
Evaluates math expressions. Written in Haxe.
Stars: ✭ 7 (-30%)
Mutual labels:  parser
Graphql Mst
Convert GraphQL to mobx-state-tree models
Stars: ✭ 22 (+120%)
Mutual labels:  parser
2d Flat Shape Shader
Lets make a simple 2D shader
Stars: ✭ 10 (+0%)
Mutual labels:  glsl
Unity Xyz
C# lightweight tile viewer
Stars: ✭ 25 (+150%)
Mutual labels:  glsl
The Pursuit Demo
3D racing with physics powered by Marmalade SDK and Bullet Physics
Stars: ✭ 8 (-20%)
Mutual labels:  glsl
Librini
Rini is a tiny, non-libc dependant, .ini file parser programmed from scratch in C99.
Stars: ✭ 25 (+150%)
Mutual labels:  parser
Lisp Esque Language
💠The Lel programming language
Stars: ✭ 24 (+140%)
Mutual labels:  parser
Crt
Software composite PAL modulation/demodulation experiments
Stars: ✭ 8 (-20%)
Mutual labels:  glsl
Dsongo
Encoding, decoding, marshaling, unmarshaling, and verification of the DSON (Doge Serialized Object Notation)
Stars: ✭ 23 (+130%)
Mutual labels:  parser
Vector
A reliable, high-performance tool for building observability data pipelines.
Stars: ✭ 8,736 (+87260%)
Mutual labels:  parser
Jkt
Simple helper to parse JSON based on independent schema
Stars: ✭ 22 (+120%)
Mutual labels:  parser
Badx12
A Python Library for parsing ANSI ASC X12 files.
Stars: ✭ 25 (+150%)
Mutual labels:  parser
Parse Code Context
Parse code context in a single line of javascript, for functions, variable declarations, methods, prototype properties, prototype methods etc.
Stars: ✭ 7 (-30%)
Mutual labels:  parser
Itunes smartplaylist
iTunes Smart playlist parser with Python. Convert to Kodi xsp smart playlists.
Stars: ✭ 10 (+0%)
Mutual labels:  parser

Slang

A small, flexible and extensible front-end for GLSL.

Project goal

This project aims to provide a simple GLSL (OpenGL shading language) front-end, that is: a lexer, a preprocessor, a parser, and a semantic analyser. The system is designed to be simple and lightweight, and well documented. A thorough test suite is included.

Example

Here is a simple example describing how to parse a GLSL file :

using namespace slang;

bool parse_glsl(const std::string& filename) {
    // Open a stream for reading in text mode
    std::ifstream is(filename);
    if (!is) return false;

    // Generate list of available keywords (you can choose to exclude some of them at runtime)
    Keywords keys;
    keys.add_all_keywords();

    // Create a logger object, error messages can be redirected
    Logger logger(filename);
    // Create a lexer object, using the previously created set of keywords
    Lexer lexer(is, keys, logger);
    // Create a preprocessor that reads tokens from the lexer
    Preprocessor pp(lexer, logger);
    // Register __FILE__, __LINE__, and __VERSION__ builtin macros
    pp.register_builtin_macros();
    // Create a semantic object, that will be used during type checking
    Sema sema(logger);
    // Create a parser object that reads tokens from the preprocessor (can read directly from the lexer)
    Parser parser([&pp]() { return pp.preprocess(); }, sema, logger);

    // Parse the stream (errors will be reported in the logger)
    Ptr<ast::Module> module = parser.parse();

    // AST can be pretty-printed to an output stream
    Printer printer(std::cout);
    module->print(printer);
    
    return lexer.error_count()  == 0 &&
           pp.error_count()     == 0 &&
           parser.error_count() == 0 &&
           sema.error_count()   == 0;
}

Features

  • Configurable, standard-compliant lexer, preprocessor, parser and type checker
  • Provided as stand-alone executable and core library
  • Can parse different versions of GLSL
  • Only depends on the standard library
  • Builds on Windows, Mac and Linux with CMake
  • Documentation through doxygen
  • Precise error messages
  • Colored output and syntax highlighting
  • Test suite to check correctness

Examples

User defined macros

This example describes how to register custom macros into the preprocessor. Two new macros are introduced: One with a traditional production rule (i.e. identical to a macro declared with #define MACRO(x) ...), and a second macro which executes custom code.

Pattern matching on the AST

This example describes how to perform pattern matching on the AST. The program looks for expressions of the form A * B + C and replaces them by calls to fma().

Code obfuscation by renaming

This example describes how to perform a simple renaming pass on the AST. The code is obfuscated by finding new variable names on the fly. This can be used as a starting point for a complete obfuscation tool.

License

The code is distributed under the LGPL license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].