Skip to content

fmark/Turtle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Turtle compiler.  The turtle language is described at 
http://cs.anu.edu.au/students/comp3610.2009/assignments/Assignment2-Turtle.pdf


To compile, type "make" at the command prompt.


Usage: turtle [options] [file]...
Options:
  -o FILE  --output=FILE  output FILE
  -m MODE  --mode=MODE    mode={parse|desugar|disasm|binary}


Turtle can read from and write to files, or to stdin and stdout.  If
no file is specified on the command-line, stdin is assumed for input.
If the -o option is omitted, stdout is assumed for output.


Turtle can produce output from various stages of the compilation
process.  The following compilation modes are supported:
  parse:   The input is only parsed for grammatic correctness
  deusgar: The input is parsed, and transformed into PDPlot's core
  	   language
  disasm:  The input is compiled, but the result is outputted in
  	   an assesmbly code like format
  binary:  The compiled input is outputted in as ASCII 16-bit words

If no mode is specified, binary mode is assumed.


Example usage:
	bin/./turtle -o test0.p tests/test0.t
	cat tests/test0.t | bin/./turtle
	bin/./turtle -m disasm tests/test0.t

Notable variations from the language specification include:
  * inclusion of an arithmetic division operator /
  * inclusion of usual comparison operators (>, >=, <=, !=) 
  * functions can be called before they are declared, without the need
  for pre-declarations. 
  * whitespace is completely arbitrary - newlines are interpretted in
  the same way as spaces
  * allow builtin drawing functions up and down to have trailing empty
  parens 


Example files to demonstrate implementation of new functionality:
	bin/./turtle mytests/divoperator.t -m desugar
	bin/./turtle mytests/comparators.t -m desugar

Example runs to demonstrate handling of syntatic errors:
	$ bin/turtle mytests/garbage.t
	turtle: lexical error

	$ bin/turtle mytests/trivial-syntax-error.t
	turtle: Parse error at line 2, column 8

	$ bin/turtle mytests/vardec-in-body.t
	turtle: Parse error at line 4, column 3

	$ bin/turtle mytests/no-cket.t
	turtle: Parse error at end of file, still expecting more tokens.

Example runs to demonstrate handling of semantic errors:
	$ bin/turtle mytests/global-var-redec.t 
	turtle: Global variable "x" declared more than once.

	$ bin/turtle mytests/local-param-clash.t
	turtle: Local variable "e" is already declared as a parameter in this function.a

	$ bin/turtle mytests/param-redec.t
	turtle: Parameter "c" is already declared in this function.

	$ bin/turtle mytests/local-var-redec.t
	turtle: Local variable "e" is already declared in this function.

	$ bin/turtle mytests/wrong-param-count.t
	turtle: Function "Oops" expects 2 parameters but was called with 1 parameters.

	$ bin/turtle mytests/undeclared-fun.t
	turtle: Undeclared function "oops" called.

	$ bin/turtle mytests/fun-redec.t
	turtle: Function "Oops" declared more than once.

	$ bin/turtle mytests/bad-return.t
	turtle: Return statement can only be used within a function.


To run tests that ensure that the output of PDPlot is the same for the 
provided, precompiled .p files as for the .p files produced by turtle, 
type "make test" at the command prompt. 


Author: 
Francis Markham (u2546226)
[email protected]
COMP3610, 2009

About

A compiler for the Turtle programming language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published