diff --git a/report/sections/4_semantic_analysis/1_design_decisions.tex b/report/sections/4_semantic_analysis/1_design_decisions.tex index 85035c6..2cb6673 100644 --- a/report/sections/4_semantic_analysis/1_design_decisions.tex +++ b/report/sections/4_semantic_analysis/1_design_decisions.tex @@ -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} @@ -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. @@ -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. diff --git a/report/sections/4_semantic_analysis/2_implementation.tex b/report/sections/4_semantic_analysis/2_implementation.tex index 05c8e34..1e80904 100644 --- a/report/sections/4_semantic_analysis/2_implementation.tex +++ b/report/sections/4_semantic_analysis/2_implementation.tex @@ -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} diff --git a/report/sections/4_semantic_analysis/3_validation.tex b/report/sections/4_semantic_analysis/3_validation.tex index 3949bd9..4493046 100644 --- a/report/sections/4_semantic_analysis/3_validation.tex +++ b/report/sections/4_semantic_analysis/3_validation.tex @@ -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} diff --git a/report/sections/appendices/4_semantic_analysis.tex b/report/sections/appendices/4_semantic_analysis.tex index 8c97bf0..ff36a9c 100644 --- a/report/sections/appendices/4_semantic_analysis.tex +++ b/report/sections/appendices/4_semantic_analysis.tex @@ -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}