Anglr Software Package

Overview


The documentation on this website describes the Anglr software package. This software package is used to create syntax analyzers used in compilers and other text analyzers. Anglr is a label for several terms:

  • programming language Anglr: set of formal rules which should be used to produce syntax rules of particular programming language. These rules are usually stored in so-called anglr files. These files have an .anglr extension.
  • Anglr compiler: software tool which should be used to compile syntax rules of programming language. Anglr compiler translates the contents of anglr files into a set of source files. These files can be used to create syntax and semantic analyzers of a particular programming language.
  • Microsoft VisualStudio Anglr extension: Language Server Protocol extension, used to edit the contents of anglr files.
  • Microsoft VisualStudio Anglr project template: used to automate the translation of anglr files and source files generated by an anglr compiler.

The Anglr programming language plays a central role in software packages mentioned above.

Example of an .anglr file:

[ Description Text='definitions of tokens and regular expressions used to define sntax']
[ Description Text='of simple arithmetic expressions']
[ CompilationInfo ClassName='MathDecls' NameSpace='Math.Declarations' Access='public']
%declarations mathDecls
%{
    %regex
    {
        decimal-digit [0-9]
        number {decimal-digit}+
    }

    %terminal
    {
        NUMBER
        add '+'
        sub '-'
        mul '*'
        div '/'
        lb '('
        rb ')'
        unknown
    }
%}

[ Description Text='definition of scanner, which extracts comments from input string']
[ Declarations Id='mathDecls' ]
[ CompilationInfo ClassName='CommentRegex' NameSpace='Math.ScannerLib' Access='public']
%scanner commentScanner
%{
[\*]+\/
    pop
[\n\r]
    skip
[^\*]+
    skip
[\*]+
    skip
%}

[ Description Text='definition of scanner, which extracts terminal symbols from input string']
[ Declarations Id='mathDecls' ]
[ CompilationInfo ClassName='MathRegex' NameSpace='Math.ScannerLib' Access='public']
%scanner mathScanner
%{
\/\*
    push commentScanner
{number}
    terminal NUMBER
\+
    terminal add
\-
    terminal sub
\*
    terminal mul
\/
    terminal div
\(
    terminal lb
\)
    terminal rb
[ \t]+
    skip
[\n\r]
    skip
.
    skip
%}

[ Description Text='Lexer for anglr file' Hover='true' ]
[
    UseScanner
        ScannerId='commentScanner'
        InitialScanner='mathScanner'
        Hover='true'
]
[ CompilationInfo ClassName='MathLexer' NameSpace='Math.Lexer' Access='public' Hover='true' ]
%lexer mathLexer
%{

%}

[ Description Text='definition of parser for simple arithmetic expressions']
[ Declarations Id='mathDecls' ]
[ Lexer Id='mathLexer' ]
[ CompilationInfo ClassName='MathParser' NameSpace='Math.Parser' Access='public']
%parser mathParser1
%{

[ Start ]
expression
    : additive-expression
    ;

additive-expression
    : multiplicative-expression
    | additive-expression '+' multiplicative-expression
    | additive-expression '-' multiplicative-expression
    ;

multiplicative-expression
    : unary-expression
    | multiplicative-expression '*' unary-expression
    | multiplicative-expression '/' unary-expression
    ;

unary-expression
    : NUMBER
    | '(' expression ')'
    ;

%}
                        

Above example defines programming language which should be used to compile simple arithemic expressions for addition, subtraction, multiplication and division. This example (or different modifications of it) will be used in many cases on this website.