Skip to content

Mathy Grammar

cs18b047 edited this page May 8, 2021 · 4 revisions

The following is the Context Free Grammar of the Mathy Language

program ->   statements;


statements  ->   statements statement

            |   %empty;


final       ->   NEWLINE

            |   END;


statement   ->   NEWLINE

            |   expression final;


identifier  ->   IDENTIFIER  dimensions;


dimensions  ->   dimensions LEFTSQR offset RIGHTSQR

            |   %empty;


offset  ->   offset_type

        |   offset OPERATOR offset_type;


intermediate_expr   ->   OPERATOR expression

                    |   %empty;


expression  ->   term

            |   term OPERATOR expression

            |   identifier EQUALS expression

            |   SQRT LEFTPAR expression RIGHTPAR

            |   LEFTPAR expression RIGHTPAR  intermediate_expr

            |   forall_stmt

            |   prod_sum_stmt;


term    ->   identifier

        |   number;


forall_stmt ->   FORALL LEFTPAR IDENTIFIER RIGHTPAR WHERE bound LEFTCURLY NEWLINE statements RCURL;


prod_sum_stmt  ->   control LEFTPAR expression RIGHTPAR WHERE bound;


control ->  PRODUCT 

        |  SIGMA;


offset_type ->   INTCONST

            |   IDENTIFIER;


number      ->   INTCONST

            |   FLOATCONST;


bound   ->  expression COMPARISON IDENTIFIER COMPARISON expression;
Clone this wiki locally