boppi/doc/report-description.tex

157 lines
4.4 KiB
TeX
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

% Detailed language description. A systematic description of the features of your language, for each
% feature specifying
% Syntax, including one or more examples;
% Usage: how should the feature be used? Are there any typing or other restrictions?
% Semantics: what does the feature do? How will it be executed?
% Code generation: what kind of target code is generated for the feature?
% You may make use of your ANTLR grammar as a basis for this description, but note that not every
% rule necessarily corresponds to a language feature.
\subsection{Basic expressions}
At the very core of the language are basic arithmetic, logic and compound expressions and literals for fundamental types.
\subsubsection{Syntax}
\begin{minted}{antlr}
program: expr EOF;
expr
: singleExpr (COMPOUND singleExpr?)*
;
singleExpr
: PAROPEN expr PARCLOSE #parens
| BRAOPEN expr BRACLOSE #block
| op=(PLUS|MINUS|NOT) singleExpr #prefix1
| lhs=singleExpr op=(MULTIPLY|DIVIDE) rhs=singleExpr #infix1
| lhs=singleExpr op=(PLUS|MINUS) rhs=singleExpr #infix2
| lhs=singleExpr op=(LT|LEQ|GTE|GT|EQ|NEQ) rhs=singleExpr #infix3
| lhs=singleExpr AND rhs=singleExpr #infix4
| lhs=singleExpr OR rhs=singleExpr #infix5
| LITERAL10 #literalInteger
| CHAR #literalCharacter
| (TRUE|FALSE) #literalBoolean
;
\end{minted}
\paragraph{Examples}
\begin{minted}{boppi}
5;
4+(2*3/-1);
'c';;;;
{
true && false;
3
}+4;
\end{minted}
\subsubsection{Use}
\verb|#prefix1|, \verb|#infix1| and \verb|#infix2| restrict their operand types and result type to integers. \verb|#infix3| restricts their operand types to integers and sets its result type to boolean, except when the operator is EQ or NEQ, in which case the operands can be of any type as long as both have the same type. \verb|#infix4| and \verb|#infix5| restrict their operand types and result type to booleans.
\subsubsection{Semantics}
A program consists of one compound expression.
COMPOUND evaluates two expressions, discarding the result of the left hand side and passing the result of the right hand.
Both \verb|#parens| and \verb|#block| contain a compound expression, however \verb|#block| introduces a deeper scope for the expression within, as clarified in the next feature.
\subsubsection{Code generation}
The compound expression simply generates its inner expressions in order, the literals generate a \verb|loadI| instruction and the operators generate a single corresponding instruction.
\subsection{Variables}
\subsubsection{Syntax}
\begin{minted}{antlr}
singleExpr
: ...
| DECLARE type IDENTIFIER #declare
| <assoc=right> variable ASSIGN singleExpr #assign
| variable #variableExpr
;
type
: staticType=(INTTYPE | BOOLTYPE | CHARTYPE) #typeSimple
| variable #typeVariable
;
variable: IDENTIFIER;
\end{minted}
\paragraph{Examples}
\begin{minted}{boppi}
var int myInt;
myInt := 4;
var myInt otherInt;
otherInt := 4+(myInt := 2);
var bool aBool;
aBool := {
var int otherInt;
otherInt := 12;
myInt > otherInt
};
\end{minted}
\subsubsection{Use}
A variable can only be assigned and used after it has been declared and within the same scope or a deeper scope than where it is declared. A variable cannot be declared if the name is already used by another variable in the same scope.
\subsubsection{Semantics}
\verb|#declare| introduces a new variable to the current scope. This variable will be undeclared once the current scope is closed. The variable will be stored at an offset within the AR, thereby increasing the size of the AR.
\verb|#assign| evaluates the
\subsubsection{Code generation}
%wat voor ILOC wordt er gegenereerd voor deze functie?
\subsection{Input/Output}
\subsubsection{Syntax}
\begin{minted}{antlr}
singleExpr
: ...
| IN PAROPEN variable (LISTDELIM variable)* PARCLOSE #read
| OUT PAROPEN expr (LISTDELIM expr)* PARCLOSE #write
;
\end{minted}
\paragraph{Examples}
\begin{minted}{boppi}
\end{minted}
\subsubsection{Use}
%hoe gebruik je het? wat zijn de typerestricties?
\subsubsection{Semantics}
%semantiek
\subsubsection{Code generation}
%wat voor ILOC wordt er gegenereerd voor deze functie?
\subsection{}
\subsubsection{Syntax}
\begin{minted}{antlr}
\end{minted}
\paragraph{Examples}
\begin{minted}{boppi}
\end{minted}
\subsubsection{Use}
%hoe gebruik je het? wat zijn de typerestricties?
\subsubsection{Semantics}
%semantiek
\subsubsection{Code generation}
%wat voor ILOC wordt er gegenereerd voor deze functie?