Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.
/ drawparser Public archive

[CLOSED] Parse a grammar and draw - Bachelor Java Project (2nd year - Spring 2015)

Notifications You must be signed in to change notification settings

geekymoose/drawparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Draw Parser

Download and test it: DrawParser.zip

img

Description

May 2015

University project for the automata topic during my second year of Bachelor in Computer Science.

DrawParser allow to draw on the screen according to a code following specific grammar.

The grammar allow us to draw from basic instructions like moving, rotating etc. Most of Java instruction are also implemented like while loop and if conditions. (Note my while manage only '==' statement). The parsing process generate the draw and display it on the screen.

Various tools enable us to handle the draw result. For instance, by temporary disabling an instruction and compare the result, or adding an instruction without modifying the source file...)

Installation

Clone this project on your computer using git clone https://github.com/GeekyMoose/drawparser.git

Run the project

On Linux

Simply execute the script exec.sh
Don't forget to give the execution right (With chmod 755 exec.sh for example)

On Windows

The easiest way is by downloading the executable zip file.

On Mac

Follow the same step than Linux. Note that I didn't check if it's actually working, I know some people had trouble with the exec.sh encoding.

Features

The 3 main buttons allow to:

  • Run Start the parsing process (From the text editor at the left)
  • Load Load a code from an existing file (Beware, current code will be lost)
  • Print Create a PNG image of the current screen parsing render

The command line block (Bottom-Left corner) allow to add instructions without modifying the source code.
The right component display the list of resulting drawing actions. It enable us to disable a specific action an watch the result without modifying the source code. When hover an element, the next elements (Which are going to be affected if the current is changed) are displayed with a yellow color.

How does it work

The grammar is parsed from a file (Which can be loaded and edited using the left editor panel). A JFlex file initially parse the file and create a list of token which are used by the parser.
The final result is a ArrayList with all the draw actions. This object can be displayed and processed.

Syntax error management

The parsing process detect the syntax error and display it. If many error occurred, the first one will be displayed. The line, found token and expected one are displayed.
This process work both with source code parsing and command line parsing.

Grammar

The grammar used is inspired by Java

Prog -> Declar inst
Declar -> VAR INDENTIFIER ; Declar | EOF

Inst -> FORWARD Exp | ROTATE Exp | UP | DOWN | IDENTIFIER = Exp | START BlocInst END
BlocInst -> Inst ; BlocInst | EOF

exp -> NUMBER ExpFollow | INDENTIFIER ExpFollow | (Exp) ExpFollow
ExpFollow -> Operator ExpFollow | EOF
Operator -> + Exp | - Exp | * Exp | / Exp

INDENTIFIER -> [a-z][a-zA-Z0-9]*
NUMBER -> [1-9][0-9]* | 0

Screenshots

A full list of screenshots can be found in the screenshots folder

Warning!

A folder called data must be in the same directory as the .jar file. (This folder can be empty). This is required since a temporary file called tmp.txt will be created inside with the current source code. However, I'm aware it's not the best way to do so and a more 'transparent' way could be done.

Author

Constantin MASSON GeekyMoose

About

[CLOSED] Parse a grammar and draw - Bachelor Java Project (2nd year - Spring 2015)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published