An open API service indexing awesome lists of open source software.

https://github.com/raghav714/rdds-online-compiler

Compiler
https://github.com/raghav714/rdds-online-compiler

cloud-computing compiler compiler-construction compiler-design grammar language-processing online-compiler parse parser-combinators programing-language scanner

Last synced: 4 months ago
JSON representation

Compiler

Awesome Lists containing this project

README

        

# RDDS-online-compiler
The compiler is build from scratch with module :-
• Lexical analyser
• Parser
• Intermediate Code Generator
• Error handling
• Symbol table
## LEXICAL ANALYSER AND SCANNER
• 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.
## PARSER
• 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.
## INTERMEDIATE CODE GENERATOR
• 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.
## LANGUAGE SYNTAXPROGRAM BODY
the program \ is
define \
body
\
fnish program
## FUNCTION DEFINITION
function \(\ \ in, \ \ out) is
\
body
\finsh functione;
## IF ELSE STATEMENT
if (\) then
\
else
\
finsh if
## LOOP
for (counter = counter + 1e counter \<= num_loops)<\br>
\<\br>
fnish for<\br>
## FUNCTION CALL
\(\,\)
## DATA TYPE
• int – Integer
• bool – Boolean
• str – String
• foat – Float
## FUNCTION
• putstr("Enter 1st Integer:")
• getint(variable)
• putint(result)
• getstr(“enter string”)
• getbool(testbool)
• putbool(testbool)
• getfoat(testfoat)
• putfoat(testfoat)
## GRAMMAR
\ ::= \ \
\ ::= ‘ the’ 'program' \ 'is'
\ ::= ‘ define’( \ ';' )* 'body' ( \ ';' )* 'finish' 'program'
\ ::= [ 'global' ] \ [ 'global' ] \
\ ::=\ \ [ '[' \ ']' ]
\ ::= 'int’' | 'float' | 'bool' | 'str'
\ ::= \ \
\ ::='function' \ '(' [ \ ] ')' ’is’
\ ::= ( \ ';' )* ‘ body' ( \
\ ::= \ ',' \ |\
\ ::= \ ( 'in' | 'out' )
\ ::= \ | \ | \ | \ |
\
\ ::= \ '=' \
\ ::= 'if' '(' \ ')' 'then' ( \ ';' )+ [ 'else' ( \ ';' )+ ]
'finish' 'if'
\ ::= 'for' '(' \ ';' \ ')' ( \ ';' )* 'finish' 'for'
\ ::= \ '(' [ \ ] ')'
\ ::= \ ',' \ |\
\ ::= \ [ '[' \ ']' ]
\ ::= \ '&' \ | \ '|' \ | [ 'not' ] \
\ ::= \ '+' \ | \ '-' \ |\
\ ::= \ '\<' \ | \ '\>' \ | \ '\>=' \ | \ '\<=' \ |\ '==' \ |\ '!=' \ |\
\ ::= \ '*' \ | \ '/' \ | \
\ ::= '(' \ ')' | [ '-' ] \ | [ '-' ] \ | \ | 'true' | 'false' |
\ ::= \ [ '[' \ ']' ]
\ ::= [a-zA-Z][a-zA-Z0-9_]*
\ ::= [0-9][0-9_]*[.[0-9_]*]?
\ ::= "[a-zA-Z0-9 _,;:.']*"
## GUI
![compiler1](https://user-images.githubusercontent.com/29707542/49634701-85c6d580-fa23-11e8-852b-89079215d67c.png)
![compiler2](https://user-images.githubusercontent.com/29707542/49634708-8b242000-fa23-11e8-9363-0aef06a62514.png)

### STEPS to run the program
$ `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