Compiler
The compiler is build from scratch with module :-
• Lexical analyser
• Parser
• Intermediate Code Generator
• Error handling
• Symbol table
• First program is run on the source file and then the code is broken into the list of distinct lines.
• at the start of each non-whitespace character, the frst character is used to determine the type of the
token to expect.
• The token is returned if the type is matched without any issue Otherwise, a scanner warning is thrown.
• The scanner warnings are never fatal, though syntactically the tokens returned may cause a parser error.
• For instance, if a string literal has no end quote a warning will be thrown and a quote will be assumed at the end of the line.
• The left recursive from the grammar is removed.
• Type-checking is performed in expressions by returning the types from the expression tree functions and evaluating types for compatibility if an operation is performed.
• Parser resync points are used throughout the compiler to continue parsing if an error is encountered without propagating spurious error messages.
• Note that once a fatal error or any kind is encountered, code will no longer be generated.
• Memory and registers for the operation of the program are defned and used as 32-bit integer arrays.
• All non-integer types present in the program are cast as integers for storage in the memory spaces.
• To ensure that pointers are 32-bit and may be cast to integer without issue, the gcc
compiler fag -m32
is used.
• Future improvements could be made to “push back” register allocation to the frst register (R[0]
) at the end of each scope.
the program \
define \
body
\
fnish program
function \
\
body
\
if (\
\
else
\
finsh if
for (counter = counter + 1e counter \<= num_loops)<\br>
\
fnish for<\br>
\
• int – Integer
• bool – Boolean
• str – String
• foat – Float
• putstr(“Enter 1st Integer:”)
• getint(variable)
• putint(result)
• getstr(“enter string”)
• getbool(testbool)
• putbool(testbool)
• getfoat(testfoat)
• putfoat(testfoat)
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
‘finish’ ‘if’
\
\
\
\
\
\
\
\
\
\
\
\
\
$ sudo apt update
$ sudo apt install apache2
$ sudo apt-get install python3
<\br>
$ sudo systemctl stop apache2.service
$ sudo systemctl start apache2.service
$ sudo systemctl enable apache2.service
$ sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-zip php7.2-curl
Copy the HTML, PHP, CSS, input.txt and test.src file in /var/www/html/ and type the localhost/index1.php in browser.
Edit the Path of the file compiler.py
in index1.php
if the program doesnot work then run $ sudo chmod 777 *
in /var/www/html/
if you wish to make RDDS as a command then open the bashrc file(sudo gedit ~/.bashrc) and write the command alias RDDS ='python3 /home/raghav/Downloads/compiler/2compiler/compiler.py -o OUT'
in this you need to replace the path of compiler.py file.
use the command RDDS rdds_test/simple_add.src
and ./a.out
to see the output