Skip to content

Traverses the AST to perform static analysis, semantic checks, and error detection.

License

Notifications You must be signed in to change notification settings

je-es/ast-analyzer

Repository files navigation


ast-analyzer

A static analysis tool that traverses the AST
to perform semantic checks, validation, scope resolution, and error detection.

line
  • Install

    npm install @je-es/ast-analyzer
    import { Analyzer } from "@je-es/ast-analyzer";

    line
  • Usage

    // suppose we want to analyze the represented AST for this statement:
    pub let mut x: i32 = 42
    // [1] Create syntax
    const syntax = Syntax.create({ // :: using @je-es/syntax(parser/lexer)
            name     : 'Kemet',
            version  : '0.0.1',
            lexer    : lexerRules,
            parser   : parserRules,
            settings : parserSettings
        } as syntax.SyntaxConfig
    );
    
    // [2] Parsing the input
    const parser_result = syntax.parse('pub let mut x: i32 = 42');
    
    // [3] Create module using the parser result
    const main_module   = AST.Module.create( // :: using @je-es/ast
        // Name
        'main',
    
        // Statements
        parser_result.ast.length > 0
            // in my case, first item refers to an array of stmts.
            ? parser_result.ast[0].getCustomData()! as AST.StmtNode[]
            // otherwise, empty module.
            : [],
    
        // Metadata
        { path: './src/main.k' }
    );
    
    // [4] Create program with the created module
    const program = AST.Program.create([main_module], { entryModule: 'main', path: './' });
    
    // [5] Create analyzer for the created program
    const analyzer = Analyzer.create({ debug: 'off' });
    const analyzer_result = analyzer.analyze(program);

    line
  • Related


line

About

Traverses the AST to perform static analysis, semantic checks, and error detection.

Topics

Resources

License

Stars

Watchers

Forks