diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2021-11-15 15:33:39 +0000 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2021-11-15 15:33:39 +0000 |
commit | e998428ee62ec119c9e46c688f2949346990af60 (patch) | |
tree | f32b7ab72a694f000db5cf9b5b9bd6c764c11da7 | |
parent | 03380520e95699ca41c74439f6216685ab8da6b7 (diff) | |
download | esotericFORTRAN-e998428ee62ec119c9e46c688f2949346990af60.tar.gz esotericFORTRAN-e998428ee62ec119c9e46c688f2949346990af60.zip |
added testing of previous sprints to repository
-rw-r--r-- | report/esoteric_project_report.pdf | bin | 202851 -> 229660 bytes | |||
-rw-r--r-- | report/esoteric_project_report.tex | 198 | ||||
-rw-r--r-- | src/.vscode/launch.json | 9 |
3 files changed, 205 insertions, 2 deletions
diff --git a/report/esoteric_project_report.pdf b/report/esoteric_project_report.pdf Binary files differindex edc2800..4139b03 100644 --- a/report/esoteric_project_report.pdf +++ b/report/esoteric_project_report.pdf diff --git a/report/esoteric_project_report.tex b/report/esoteric_project_report.tex index a347d87..b8c4f93 100644 --- a/report/esoteric_project_report.tex +++ b/report/esoteric_project_report.tex @@ -322,11 +322,207 @@ blablabla In this chapter you cover the actual implementation of your project. Implementation will be done in sprints so you may wish to use different sub-sections for each sprint and then dedicate a section to your final deliverable. Section \ref{Figures} with figures should not remain in the final report. +The long string following the sprint number is the git commit at the point in the git repository at which the tests were conducted. + \section{Early sprints} -\subsection{Sprint 1} +\subsection{Sprint 1 - \texttt{cb29252f1e0d29d555fb232f39d343930fc76105}} +The first functional program version was a simple lexical analyser. At this stage no calculations were done. For example: + +\begin{verbatim} +Code: 3-1+2 +\end{verbatim} +Produces the output: +\begin{verbatim} +NUMBER 3 3.0 +MINUS - null +NUMBER 1 1.0 +PLUS + null +NUMBER 2 2.0 +\end{verbatim} +A more complex example: +\begin{verbatim} +Code: (36/2 + 45.2) * 3 +\end{verbatim} +Produces the result: +\begin{verbatim} +LEFT_PAREN ( null +NUMBER 36 36.0 +SLASH / null +NUMBER 2 2.0 +PLUS + null +NUMBER 45.2 45.2 +RIGHT_PAREN ) null +STAR * null +NUMBER 3 3.0 +\end{verbatim} + +\subsection{Sprint 2 - \texttt{69b0ad07bac30beca1397ff187468e7597203c44}} +This version added simple variable declaration and assignment, as well as a simple calculator. It also added reading from files. For example, running \texttt{java Interpreter.Language example2.txt} where \texttt{example2.txt} is the following: + +\begin{verbatim} +var :: a +a=5 +a=a+1 +print a +\end{verbatim} +Produces the result: +\begin{verbatim} +6.0 +\end{verbatim} +Testing involved making sure the program worked with the rules of left-associativity; for example, the program: +\begin{verbatim} +var :: a +a=3-1+2 +print a +\end{verbatim} +Produces the result \texttt{4.0}. +We also tested BIDMAS rules by using complex expressions: +\begin{verbatim} +var :: a +a=(36/2 + 45.2) * 3 +print a +\end{verbatim} +Returns \texttt{189.60000000000002}, which is correct considering the inaccuracy of floating points in computers. Finally, a test of a more complex program: +\begin{verbatim} +var :: a +a=5 +a=a+1 +print a + +a=7 +a=a*2 +print a + +var :: b +b = 10 +print a+b +\end{verbatim} +Produces the result: +\begin{verbatim} +6.0 +14.0 +24.0 +\end{verbatim} +You can test the error handling in several ways. For example the program +\begin{verbatim} +a=3 +print a +\end{verbatim} +Uses an undefined variable \texttt{a}. The output of running this is: +\begin{verbatim} +An error was encountered +Variable undefined +\end{verbatim} +You can also try and run a program with a syntax error, for example: +\begin{verbatim} +var :: a +a=3+ +print a +\end{verbatim} +Produces: +\begin{verbatim} +An error was encountered +Expected Expression +\end{verbatim} +This is how it reacts to using an undefined token: +\begin{verbatim} +var :: a +a=3 +pprint a +\end{verbatim} +Produces: +\begin{verbatim} +An error was encountered +Undefined Variable +\end{verbatim} + +\subsection{Sprint 3 - \texttt{a12094123dcacee41a7472031db6fe6027b083a7}} +This version added full compilation to a binary by translating to a C program and using gcc to compile it straight away. It also added strings as lists of characters, and simple if statements. For example running \texttt{java Compiler.Language example.txt} where \texttt{example.txt} is the program: +\begin{verbatim} +character (len=10)::hello +hello="hello" +if 5==5 then +hello="goodbye " +endif +print *,hello,6," test" endprint +\end{verbatim} +Produces, in the \texttt{build/} folder, \texttt{example.c}: +\begin{verbatim} +#include <stdio.h> +#include <string.h> +int main(){ +char hello[11]; +strcpy(hello,"hello"); +if(5==5){ +strcpy(hello,"goodbye "); +} +printf("%s%d%s",hello,6," test"); +} +\end{verbatim} +It also compiles this file automatically, checking for errors during the process, and produces the executable binary \texttt{example.exe} in windows, or \texttt{./example} if run in a distribution of GNU+Linux. It then runs the binary straight away, checking for runtime errors. The output of running this binary is: +\begin{verbatim} +goodbye 6 test +\end{verbatim} +Here's an example of a program which produces a runtime error: +\begin{verbatim} +character (len=3)::hello +hello="hello" +if 5==5 then +hello="goodbye " +endif +print *,hello,6," test" endprint +\end{verbatim} +It produces a runtime error since the character string is too short. When it's run, it says: +\begin{verbatim} +An error was encountered +Runtime Error +\end{verbatim} +This version also added better error messages. For example \texttt{hello="hello} produces: +\begin{verbatim} +An error was encountered +Strings must end with " +\end{verbatim} +Moreover, the program +\begin{verbatim} +character (len=10)::hello +hello="hello" +if 5==5 then +hello="goodbye " +print *,hello,6," test" endprint +\end{verbatim} +Produces the error message: +\begin{verbatim} +An error was encountered +endif missing +\end{verbatim} +Finally, lets test if statements with another program: +\begin{verbatim} +character (len=10)::hello +hello="hello" +if 4==5 then +hello="goodbye " +endif +print *,hello,6," world" endprint +\end{verbatim} +Produces the result: +\begin{verbatim} +include <stdio.h> +#include <string.h> +int main(){ +char hello[11]; +strcpy(hello,"hello"); +if(4==5){ +strcpy(hello,"goodbye "); +} +printf("%s%d%s",hello,6," world"); +} + +hello6 world +\end{verbatim} \subsection{Sprint n} + \section{Final implementation} \section{Figures, tables, etc.} diff --git a/src/.vscode/launch.json b/src/.vscode/launch.json index a4b8347..f36d26d 100644 --- a/src/.vscode/launch.json +++ b/src/.vscode/launch.json @@ -6,6 +6,13 @@ "configurations": [ { "type": "java", + "name": "Launch Language", + "request": "launch", + "mainClass": "Compiler.Language", + "projectName": "" + }, + { + "type": "java", "name": "Launch Current File", "request": "launch", "mainClass": "${file}" @@ -16,7 +23,7 @@ "request": "launch", "mainClass": "Compiler.Language", "projectName": "src_1da2a030", - "args":"example.txt" + "args": "example.txt" } ] }
\ No newline at end of file |