Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 18 Next »

SSLR stands for SonarSource Language Recognizer, this is a lightweight java library which provides all the required material to analyse any piece of source code. For the time being, by using SSLR you can quickly create a lexer, a parser and some AST visitors to implement for instance some quality rules or to compute some measures. This library is already used by the Sonar JavaScript, Cobol, C#, Python, PL/SQL, C, C++, Flex, ... plugins.

Source Codehttps://github.com/SonarSource/sslr

Download : from maven central

JIRAhttp://jira.sonarsource.com/browse/SSLR

Community support : feel free to ask any question on the Sonar Dev mailing list

Motivations

Why Another Tool for Language Recognition ? Why not reusing Open Source and well-know libraries like Antlr or javacc ? This is the first question asked by any developer discovering SSLR. Of course this option was seriously studied and had bid advantages but we decided to start from scratch for the following reasons :

  • The Sonar team is TDD addict and we think that existing tools don't fit well with TDD as they require some code generation and doesn't provide any simple and quick way to unit test all part of a source code analyser like a parsing rule for instance. 
  • The Sonar team is KISS addict and so we think that a java developer should be able to do anything from its favorite java IDE and directly in java.
  • This technology is also used to analyse some legacy languages like COBOL for instance which require some very specific lexing and preprocessing features. Implementing those features would have required to fully master the implementation of those existing tools and so we didn't benefit from a black box approach.
  • In any case, the ultimate goal of SSLR is to provide a complete stack for source code analyzing which goes far beyond parsing. SSLR will sooner or later provide out-of-the-box the required material to :
    • Feed and request a symbolic table
    • Feed and visit a control flow graph
    • Feed and request a complete graph of dependencies
    • ...

Features

Here are the main features of SSLR :

  • Easy integration and use
    • Just add a dependency on a jar file (or several jar according to what you want to use : lexer/parser, XPath request framework, common rules, ...)
    • No special step to add to the build process
    • No "untouchable" generated code
  • Everything in java
    • Definition of grammar and lexer directly in code using Java
    • No break in IDE support (syntax highlighting, code navigation, refactoring, etc)
  • Mature and production ready
    • This technology is already used in production to analyse millions of Cobol, PL/SQL, C, C#, ... lines of code
    • Good performances
  • Some common rules and basic metric computations available out-of-the-box
  • XPath framework to visit the AST
  • Development Kit to browse the AST of any source code

Limitations

SSLR evolves pretty quickly and we hope to remove those limitations sooner or later :

  • No way to inject some semantic actions
  • No way to tune the AST generation 
  • No way to create a lexerless parser

SSLR in Action

If you want to start working with SSLR, you must be familiar with the following standard concepts : Lexical Analysis, Parsing Expression Grammar and AST(Abstract Syntax Tree). From there you can directly have a look to the source code of the JavaScript (lexer/parser, rules), Flex (lexer/parser, rules) or Python (lexer/parser, rules) plugins to see how those languages are analysed with help of SSLR. 

SSLR also comes with a MiniC language which has been created to easily and simply test all SSLR features. This MiniC language can be a good starting point for a beginner to understand how to implement/define the different mandatory layers to analyse a source code  :

 

  • No labels