Vyaakaran Syntax

Vyaakaran's grammar syntax is based on the notations taught in colleges and found in various literatures. It is very easy to start writing grammars following this syntax. Below document goes over the complete syntax and notations used in Vyaakaran.

Reserved symbols

Before we go into the syntax of major tokens, it is important to understand the reserved symbols in the language and the special meaning they hold. This is because these symbols cannot be used in the non-terminals and terminals defined later on.

  • Epsilon, Lambda — defined by ε, λ or #. Used to denote the null symbol.
  • Follow symbol — defined by ->. Used to denote the expansion of a non-terminal.
  • Or symbol — defined by |. Used to merge productions that expand same non-terminal. These productions can be merged to single production separated by Or symbol.
  • Dot symbol — defined by .. Used to denote the end of a production and beginning of next production.
  • Other reserved symbols$. These symbols are reserved for internal use and currently serve no meaning when used in conjunction with other symbols

Non-terminals

Non-terminals are defined by tokens that start with an uppercase english character and optionally followed by any other non-reserved symbols. Following are examples of valid non-terminals.

S
        Abc
        Add_Term
        Multiply123
        Special_Symbol'
      

Terminals

Terminals are defined by tokens that start with any non uppercase english character and optionally followed by any other non-reserved symbols. Following are examples of valid terminals.

a
        123
        +
        _63
        small_Capital
      

Single line comments

Single line comments start with // followed by the comment. Multi-line comments are currently not supported. Example of comments is shown below.

// This is a comment...
      

Examples of valid Vyaakaran grammars

Following are few examples of grammars written according to Vyaakaran syntax.

Note: It is important that each production ends with Dot symbol . before starting a new production.

// This grammar accepts strings that ends with 1.
        S -> 0 S | 1 S | 1.
      
// This grammar matches a math expression with +, * and () operators.
        S -> Expr.
        Expr -> Expr + MulTerm | MulTerm.
        MulTerm -> MulTerm * Term | Term.
        Term -> 0 | 1 | ( Expr ).
      
// This grammar matches strings with characters in either
        // {a, b}, {b, c} or {a, c} sets.
        S -> # | a B | a C | b A | b C | c A | c B.
        A -> b A | c A | #.
        C -> a C | b C | #.
        B -> a B | c B | #.