Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AST in Wonderland

AST in Wonderland

We read and write code every day to build maintainable software. To help us in our effort, we use and rely on numerous tools. As we write software for increasingly complex problems, our tooling should also evolve to support this. Like ancient craftsmen, we should not only improve our skills but also the tools we use.

In his presentation "AST in Wonderland", Jeroen will take you on an adventure, that started for him, with Abstract Syntax Trees. In his journey, he found new tools and techniques to help us in our code writing endeavor. He encountered mutants, lakes and even artificial life.
Join him and see how deep the rabbit hole goes...

Jeroen Herczeg

April 23, 2019
Tweet

More Decks by Jeroen Herczeg

Other Decks in Technology

Transcript

  1. What’s new in PHP7 • Scalar type hints • Return

    type declarations • Anonymous classes • Generator delegation • Generator return expressions • The null coalesce operator • The space ship operator • Throwables • Abstract syntax tree • The Integer division function • Uniform variable syntax
  2. What’s new in PHP7 • Scalar type hints • Return

    type declarations • Anonymous classes • Generator delegation • Generator return expressions • The null coalesce operator • The space ship operator • Throwables • Abstract syntax tree • The Integer division function • Uniform variable syntax
  3. Lexical analysis, lexing or tokenization is the process of converting

    a sequence of characters into a sequence of tokens. A program that performs lexical analysis is called a lexer, tokenizer, or scanner.
  4. <?php namespace Meetup\PHPLimburg; class Presentation { public function hello() {

    return 'Hello!'; } } T_OPEN_TAG T_WHITESPACE T_NAMESPACE T_WHITESPACE T_CLASS T_PUBLIC T_RETURN T_STRING T_STRING T_STRING T_FUNCTION T_STRING T_CONSTANT_ENCAPSED_STRING
  5. <?php namespace Meetup\function; class Namespace { public function **() {

    return 'return'; } } T_OPEN_TAG T_WHITESPACE T_NAMESPACE T_WHITESPACE T_CLASS T_PUBLIC T_RETURN T_STRING T_FUNCTION T_NAMESPACE T_FUNCTION T_POW T_CONSTANT_ENCAPSED_STRING
  6. <?php namespace Meetup\PHPLimburg; class Presentation { public function hello() {

    return 'Hello!'; } } T_OPEN_TAG T_WHITESPACE T_NAMESPACE T_WHITESPACE T_CLASS T_PUBLIC T_RETURN T_STRING T_STRING T_STRING T_FUNCTION T_STRING T_CONSTANT_ENCAPSED_STRING
  7. Parsing, syntax analysis, or syntactic analysis is the process of

    analysing tokens conforming to the rules of the grammar.
  8. https://www.youtube.com/watch?v=eF9qWbuQLuw - Bisqwit: Parser and Lexer PHP Parse error: syntax

    error, unexpected ';' in /Users/jeroenherczeg/Code/ast/Presentation.php on line 7
  9. <?php namespace Meetup\PHPLimburg; class Presentation { public function hello() {

    return 'Hello!'; } } T_OPEN_TAG T_WHITESPACE T_NAMESPACE T_WHITESPACE T_CLASS T_PUBLIC T_RETURN T_STRING T_STRING T_STRING T_FUNCTION T_STRING T_CONSTANT_ENCAPSED_STRING
  10. <?php namespace Meetup\PHPLimburg; class Presentation { public function hello() {

    return 'Hello!'; } } T_OPEN_TAG T_WHITESPACE T_NAMESPACE T_WHITESPACE T_CLASS T_PUBLIC T_RETURN T_STRING T_STRING T_STRING T_FUNCTION T_STRING T_CONSTANT_ENCAPSED_STRING
  11. ext-ast PHP-Parser Tolerant PHP Parser Extension Composer Composer Only version

    of PHP installed PHP >= 7.0 PHP5 - PHP7 PHP5 - PHP7 Fastest (C) Slower (PHP) Slower (PHP) Syntactically valid Partial AST Tolerant (IDE) https://github.com/nikic/php-ast https://github.com/nikic/PHP-Parser https://github.com/Microsoft/tolerant- php-parser
  12. Static code analysis is the analysis of source code that

    is performed without actually executing it.
  13. • Finding probable bugs • Locating “dead” code • Detecting

    performance issues • Improving code structure and maintainability
  14. Exakat - 9.572. Useless Return A return value inside a

    constructor is inaccessible. Codebase Codebase Codebase AST Functions/UselessReturn src/Presentation.php:7 Functions/UselessReturn src/Presentation.php:7
  15. Language Server Protocol The Language Server Protocol (LSP) defines the

    protocol
 used between an editor or IDE and a language server
 that provides language features like auto complete, go to definition, find all references etc. https://microsoft.github.io/language-server-protocol
  16. Mutation testing is used to measure the effectiveness of a

    test set in terms of its ability to detect faults. It involves modifying a program in small ways. Each mutated version is called a Mutant. If mutated program produces failing tests, this is called a killed mutant. If tests are green with mutated code, then we have an escaped mutant.
  17. A transpiler takes the source code of a program written

    in a programming language as its input and produces the equivalent source code in the same or a different programming language.
  18. Rector is a reconstructor tool. It does instant upgrades and

    instant refactoring of your code. Rector
  19. Vision Natural language processing (NLP) • Translation • Summarisation •

    Sentiment analysis • Dialogue • … • Classification • Object detection • Facial recognition • Generation • …
  20. In this project, you'll generate your own Simpsons TV scripts

    using RNNs. You'll be using part of the Simpsons dataset of scripts from 27 seasons. The neural network you'll build will generate a new TV script.
  21. Machine Learning on Source Code This new line of research

    is inherently interdisciplinary, uniting the machine learning and natural language processing communities with software engineering and programming language communities.
  22. 1. Request list of package names 2. Loop through list

    and request package information 3. Clone package using repository url