Giter VIP home page Giter VIP logo

turtle's Introduction

What is this C project ?

In computer science, when you have "inputs" sharing the same grammar, it is useful to make them understandable by your programs. We can turn the input into an Abstract Syntax Tree, then go through the tree performing any needed process, this project is a basic example about it.

The hardest part of the work, which are lexing and parsing are done using the well known tools Flex and Bison. We can write efficient, clear and readable programs using Flex and Bison, it's not easy to do the same job without them, especially in low level languages (C have no automatic memory management).

This project take Turtle programs as input, they are files.

What is this software currently used for? This project interprets the Turtle programs provided in input and print as output the instructions that a basic drawer automaton needs. For this exercise, the drawer automaton is represented by another program called the turtle-viewer.

In case of error, when the inputs are wrong, everything should be OK, the error is detected, no output is displayed on stdout (the standard output), only a basic explanation is displayed on stderr (the error output).

What could be a real use for this type of software? Reading configuration files to start a process.

Ubuntu usage

If you don't know how to get an executable, try to follow this procedure :

  • Open a Terminal in the downloaded directory, for example using a right-click or the cd command
  • Ubuntu assures you that a C/C++ compiler is available when you run the command sudo apt install build-essential

Execute the following installation commands :

sudo apt-get update 
sudo apt-get upgrade
sudo apt install cmake flex bison

If you plan to use the Turtle viewer also execute the following command :

sudo apt install libsndio7.0

Compile your executable by executing the following instructions (you are still located in the downloaded directory) :

cmake .
make all

Your turltle executable is ready, it's locaded at ./turtle. You can basically test it using echo -e "print random(2, 2.5)" | ./turtle, it should print a random number between 2 and 2.5 inclusive. Another syntax is to use ./turtle < program.turtle if you filled the program.turtle file with print random(2, 2.5).

The command./turtle < ./default-hello.turtle will interpret the default-hello.turtle file using the turtle executable showing you the result on the standard output (often named stdout).

When you perform some changes in the program source, you just have to execute make all to keep updated your Turtle executable.

Windows usage

It's possible to download Flex and Bison for Windows, then to request a JetBrains CLion demo, this IDE like some others will help you compiling your executable like as Ubuntu. Only the viewer isn't avaliable for Windows.

The versions i used during Windows development are :

  • flex.exe 2.6.4
  • bison (GNU Bison) 3.8.2

See the top of CMakeLists.txt file to manage the Flex.exe and Bison.exe paths.

How to use the viewer ?

The turtle viewer is avaliable for Ubuntu users, it requires libsndio7.0.

sudo apt install libsndio7.0  
chmod 700 ./turtle
chmod 700 ./turtle-viewer  
./turtle < ./default-hello.turtle | ./turtle-viewer

Where :

  • ./turtle is your turtle interpreter (which is compiled using the given C source code)
  • ./program.turtle is your Turtle program that must be submited to your interpreter (samples draws are provided)
  • ./turtle-viewer is the provided viewer

If the Ubuntu permissions are OK (chmod), you can check my own programs using the following command :

./turtle < ./my-fougeres.turtle | ./turtle-viewer

What to do ?

You can take this project as example, update its source code, and/or create your own works (turtle programs).

Take a look at my Barnsley fern drawing below, it only takes 100 lines of Turtle code to display it using the turtle-viewer.

my Barnsley fern draw

Thank you

  • my professors at University of Franche-Comté ❤️
  • GitHub users reporting issues

turtle's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.