140 likes | 239 Views
Implementation Design. Interpreted Dynamic Types Reserved “Library” Distinct Statements Test Suite. Interpreter. Yeah! DruL is an interpreted language. Trying to write a compiler seemed like a waste of energy, since there isn't much concern about performance.
E N D
Implementation Design • Interpreted • Dynamic • Types • Reserved “Library” • Distinct Statements • Test Suite
Interpreter • Yeah! DruL is an interpreted language. • Trying to write a compiler seemed like a waste of energy, since there isn't much concern about performance. • Of course complex calculations are possible in DruL, however not an intended use of language. • The interpreter was named drul; makes sense.
drul Input • 'drul' can work as no argument command in which it acts like an inline interpreter, accepting input from std in. • 'drul' can also take filename as an argument and interpret the contents of the file. • The extension for the file doesn't matter, as our platform is UNIX based, all 'drul' cares about is the code inside the file.
drul output • 'drul' can produce output to the std out (may be useful for debugging purposes) • 'drul' also outputs to the files, using a method named output. • MIDI , Text and pdf(Lily pond) are three output formats for the output files. • The above mentioned files are created if they don't exist, with the name specified by 'output' method.
Dynamic Language • Dynamic everything! • Hence, no static checks. • Did mean to add the easy checks. • DruL types map very easily to Ocaml types. • Therefore they were reasonably easy to define. • Both types and scoping are dynamic.
a = 345 ; print(a); a = pattern(“010101”); print(a); mapper a (c){ if(c.note( )){return pattern(“ ”);} else { return pattern(“0”);}} b = map(pattern(“010”)) a; Dynamic Types Demonstration
type drul_t = Void | Int of int | Str of string | Bool of bool | Pattern of pattern | Clip of pattern array | Mapper of (string * string list * statement list) | PatternAlias of pattern_alias | Beat of pattern_alias * int | Instruments of string list | InstrumentAssignment of string * pattern DruL Types
Strict Syntax Tree • There is mutual recursion among maps, expressions and statements. • Above three are main part of the AST. • We do have distinct operator types for boolean, integer and comparison in AST, which are used by expressions. • We do tag expressions with an int 'lineno' , so we can give a line number to user with the errors in code.
Keywords, Functions and Methods • Reasonably small set of keywords. • Very helpful built in functions. • Different methods for different DruL types. • Function and method names can be used as identifiers for variables, but it is advised to avoid it for it will cause confusion.
Helper Functions • Lots of helpers. • Most useful when constructing the framework for maps. • Also used for updating symbol table and also for clips. • There are helpers for every functionality we implemented; effort to modularize the code.
Statements? • Distinct types of statements • Perhaps because of restrictions on expressions. • Types: Expression, Assignment, Selection, Mapper definitions, return and (Instr Def?) • Blocks are not statements in DruL.
Test Suite • Testing software was written in python by Thierry Bertin-Mahieux. • Yes, we do use our own test program:) • Wrote tests on the language feature that got implemented, on the way. • There are tests on parser as well. • Implemented feature; wrote test; saw it fail; fixed the code; NICE ALGORITHM:)
Implementation Time line? • Started with AST ( accepting professor's advice) • Got the scanner in parallel to the AST. • Finished(?) parser pretty quickly. • Had hello world ready; arithmetic and logic very soon after. • Another comment on similarity towards micro C :)
Time Line continued... • After the basics, the work was done in parallel mostly. • Along the way there were several changes in the AST, Scanner and Parser. • Mapper was being worked on while functions and methods were added to the language. • In the end the clips and the file outputs were added to the language; And here we are....