Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:mewmew/uc into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sangisos committed May 4, 2016
2 parents 47aeebd + 7b87cad commit f352144
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
19 changes: 8 additions & 11 deletions report/sections/4_semantic_analysis/1_design_decisions.tex
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
\subsection{Design Decisions}

% TODO:
% * what information you associate with identifiers in the environment
% * how you chose to implement the environment (symbol table)
% * how you handle delimited scopes (restoring the environment when leaving the scope)
% * the typing rules you have implemented for expression operators
%
% Also give some test runs with incorrect programs. If there is one semantic error you had trouble detecting, include the corresponding test program.

\subsubsection{Multi-pass Identifier Resolution}

Expand All @@ -18,7 +14,8 @@ \subsubsection{User-defined Type Definitions}

\subsubsection{Typing Rules}

%============ from assignment 2 ==============
\subsection{Nested Functions}

\begin{lstlisting}[language=C,style=c,caption={\label{fig:nested_func_decl}Nested function declarations.}]
int add(int a, int b) {
// Nested function declarations are syntactically valid.
Expand All @@ -29,15 +26,15 @@ \subsubsection{Typing Rules}
}
\end{lstlisting}

The static checker of the semantic analysis phase will ensure that functions contain no nested function declarations, unless the relevant GNU extension has been enabled\footnote{Add support for nested functions (GNU extension): \url{https://github.com/mewmew/uc/issues/43}}.
%============ from assignment 2 end ==============
The static checker of the semantic analysis phase ensures that functions contain no nested function declarations, unless the relevant GNU extension has been enabled\footnote{Add support for nested functions (GNU extension): \url{https://github.com/mewmew/uc/issues/43}}. The nested functions GNU extension is enabled by default, and may be disabled through the \texttt{-no-nested-functions} flag.

\subsubsection{Scope}
\label{sec:scope}

The type-checker has a notion of two distinct scopes, the file scope and the block scope.
The type-checker has a notion of two distinct scopes, the file scope and the block scope. Within the file scope, variable declarations are considered tentative definitions, unless defined with an initializer. The file scope may contain multiple tentative definitions of the same identifier as long as they are of equivalent types.

Compound statements form lexically nested block scopes, in which variable declarations represent definitions. The bodies (i.e. compound statements) of function definitions are treated as regular block scopes with one exception, any parameters declared by the function signature are added to the environment of the block scope. The block scopes of global function definition bodies, have the file scope as their immediately surrounding outer scope.

% // The last tentative definition becomes the definition, unless defined
% // explicitly (e.g. having an initializer or function body).
Identifiers are resolved by searching for their corresponding declarations starting from the current (read innermost) scope, and successivly searching outer scopes, until either the closest declaration is located or the outermost scope has been reached.

\subsubsection{Environment}
To handle user-defined type definitions, a \textit{universe} pseudo-scope has been added, in which keyword types (e.g. \texttt{int}) are pre-declared. The \textit{universe} scope is the immediately surrounding outer scope of the file scope, and the \textit{universe} scope has no outer scope.
4 changes: 3 additions & 1 deletion report/sections/4_semantic_analysis/2_implementation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ \subsubsection{Type Representations}

See Appendix~\ref{app:semantic/types_doc}.

%\subsubsection{Typing Rules}
\subsubsection{Type Deduction of Expressions}



\subsubsection{Symbol Table, Scope, Declarations and Identifiers}

Expand Down
6 changes: 3 additions & 3 deletions report/sections/4_semantic_analysis/3_validation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ \subsubsection{Incorrect Test Cases}
For listings, see Appendix~\ref{app:semantic/incorrect}: \nameref{app:semantic/incorrect}:
\input{inc/usem/incorrect/semantic/listref.tex}

%\subsubsection{Extra Test Cases}
\subsubsection{Extra Test Cases}

% For listings, see Appendix~\ref{app:semantic/extra}: \nameref{app:semantic/extra}:
%\input{inc/usem/extra/semantic/listref.tex}
For listings, see Appendix~\ref{app:semantic/extra}: \nameref{app:semantic/extra}:
\input{inc/usem/extra/semantic/listref.tex}
8 changes: 4 additions & 4 deletions report/sections/appendices/4_semantic_analysis.tex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ \subsubsection{Incorrect Test Cases}

\input{inc/usem/incorrect/semantic/listing.tex}

%\subsubsection{Extra Test Cases}
%\label{app:semantic/extra}
%
%\input{inc/usem/extra/semantic/listing.tex}
\subsubsection{Extra Test Cases}
\label{app:semantic/extra}

\input{inc/usem/extra/semantic/listing.tex}

0 comments on commit f352144

Please sign in to comment.