products/Sources/formale Sprachen/VDM/VDMSL/ProgLangSL image not shown  

Quellcode-Bibliothek

© Kompilation durch diese Firma

[Weder Korrektheit noch Funktionsfähigkeit der Software werden zugesichert.]

Datei: ast.vdmsl   Sprache: VDM

Original von: VDM©

\section{Informal Language Definition}

Below the abstract syntax of the language is given in VDM-SL. 
In order to keep the language simple, only Integer and Boolean types are
defined.  
 
A program consists of a declaration part followed by a statement.
\begin{vdm_al}
module AST

exports all

definitions

types

  Program :: decls : seq of Declaration
             stmt  : Stmt;
\end{vdm_al}

A (variable) declaration consists of an identifier, an associated
type and an optional initial value.

\begin{vdm_al}
  Declaration :: id  : Identifier
                 tp  : Type
                 val : [Value];
\end{vdm_al}

An identifier is a sequence of characters. In our language two types
are known, Boolean and Integer. The two types of values in the language are
modeled as the corresponding VDM-SL types {\tt booland {\tt int}. 

\begin{vdm_al}
  Identifier = seq1 of char;

  Type = <BoolType> | <IntType> ;

  Value = BoolVal | IntVal;

  BoolVal :: val : bool;

  IntVal :: val : int;
\end{vdm_al}
Our simple language only knows four kinds of statements: block
statements, assignments, a conditional statement, a for-loop and a 
repeat-loop\footnote{A while loop was not part of the assignment,
because it has served as a demonstrating example for loop semantics
during the course. It is left as an exercise to the reader.}.

\begin{vdm_al}
  Stmt = BlockStmt | AssignStmt | CondStmt | ForStmt | RepeatStmt;
\end{vdm_al}

A block statement consists of local variable declarations and a
non-empty sequence of statements. 

\begin{vdm_al}
  BlockStmt :: decls : seq of Declaration
               stmts : seq1 of Stmt;
\end{vdm_al}
The left-hand side of an assignment is a variable, which is simply
an identifier. The right-hand side is defined as an expression. 
 
\begin{vdm_al}
  AssignStmt :: lhs : Variable
                rhs : Expr;

  Variable :: id : Identifier;
\end{vdm_al}
An expression could be a binary expression, a value or a variable.
A binary expression consists of a left-hand expression, an operator
and a right-hand expression.

\begin{vdm_al}
  Expr = BinaryExpr | Value | Variable;

  BinaryExpr :: lhs : Expr
                op  : Operator
                rhs : Expr;
\end{vdm_al}
The numeric operators of the language are addition, subtraction, 
Integer-division, and multiplication. The Boolean operators are 
less-than, greater-then, equality, conjunction, and finally disjunction.

\begin{vdm_al}
  Operator = <Add> | <Sub> | <Div> | <Mul> | <Lt> | <Gt> | <Eq> | <And> | <Or>;
\end{vdm_al}
A conditional if-statement consists of a guard predicate, the
then- and else-branch.  

\begin{vdm_al}
  CondStmt :: guard  : Expr
              thenst : Stmt
              elsest : Stmt;
\end{vdm_al}

The for-loop consists of an initial assignment to the 
loop-variable, followed by an expression, which defines the stop 
value of the loop-variable, and the statement to be repeated. It is allowed to modify the loop-variable inside the body of the loop. 

\begin{vdm_al}
  ForStmt :: start : AssignStmt
             stop  : Expr
             stmt  : Stmt;
\end{vdm_al}
Finally, the repeat-loop consists of the statement to be repeated
and its stop condition. 

\begin{vdm_al}
  RepeatStmt :: repeat : Stmt
                until  : Expr;
                
end AST
\end{vdm_al}

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet)  ¤





Download des
Quellennavigators
Download des
sprechenden Kalenders

in der Quellcodebibliothek suchen




Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.


Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.


Bot Zugriff