Domain specific programming languages Context Free Art UC Santa Cruz CMPS 10 – Introduction to Computer Science www.soe.ucsc.edu/classes/cmps010/Spring11.

Slides:



Advertisements
Similar presentations
What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.
Advertisements

Programming for Beginners
GCSE Computing Lesson 5.
compilers and interpreters
Languages for IT & CS Pseudo-code What HTML isn’t Early history Compiling & interpreting Classifying languages The process of programming.
Tuan Tran. What is CISC? CISC stands for Complex Instruction Set Computer. CISC are chips that are easy to program and which make efficient use of memory.
Creating a Program In today’s lesson we will look at: what programming is different types of programs how we create a program installing an IDE to get.
Imperative and functional programming languages UC Santa Cruz CMPS 10 – Introduction to Computer Science
How the World Wide Web works UC Santa Cruz CMPS 10 – Introduction to Computer Science 9 May 2011.
Web applications. Javascript. Web 2.0: The dynamic, read-write web UC Santa Cruz CMPS 10 – Introduction to Computer Science
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Emergence of the internet. Basics of internetworking UC Santa Cruz CMPS 10 – Introduction to Computer Science
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
Programming. Software is made by programmers Computers need all kinds of software, from operating systems to applications People learn how to tell the.
1 CHAPTER 4 LANGUAGE/SOFTWARE Hardware Hardware is the machine itself and its various individual equipment. It includes all mechanical, electronic.
Course: Introduction to Computers
1 CS101 Introduction to Computing Lecture 19 Programming Languages.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Chapter 0: Introduction CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Introduction to High-Level Language Programming
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
CSC 142 A 1 CSC 142 Introduction to Java [Reading: chapter 0]
Introduction COMP104: Fundamentals and Methodology.
There are only 10 types of people in the world, those who understand binary and those who don't.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
High-level Languages.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Levels of Architecture & Language CHAPTER 1 © copyright Bobby Hoggard / material may not be redistributed without permission.
Introduction to Computers and Programming – Computer Programming.
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Introduction to Programming ICS2O Findlay. Learning Goals  We will learn  The definitions of a computer, program and programming language.  The different.
CS101 Introduction to Computing Lecture Programming Languages.
First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Visual C++ Programming: Concepts and Projects
Basic of Programming Language Skill Area Computer System Computer Program Programming Language Programmer Translators.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
What am I?. Translators Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and.
Java Basics 1 Brief History of Java and Overview of Langauge.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
Structured Programming (4 Credits)
Introduction to OOP CPS235: Introduction.
Course Instructor: Hira Farman Course : BY:HIRA FARMAN.
Some Computer Science Conceptual Background Material Doug Hogan This version for UIC Spring 2016 CS 107.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
CS 104 – Fall 2011 Exploring Computer Science Build Your Own Blocks September 19, 2011.
ICT PROGRAMMING INTRODUCTION. WHAT & WHY PROGRAMMING Programming is a process of developing computer programs Computer program is a set of instructions.
Programming Session 6 LBSC 690 Information Technology.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
JavaScript/ App Lab Programming:
Visit for more Learning Resources
Topic: Programming Languages and their Evolution + Intro to Scratch
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Introduction to programming
GC101 Introduction to computers and programs
CS101 Introduction to Computing Lecture 19 Programming Languages
Programming COMP104: Fundamentals and Methodology Introduction.
TRANSLATORS AND IDEs Key Revision Points.
CS190/295 Programming in Python for Life Sciences: Lecture 1
Introduction to Computers and Python
Software Programming J. Holvikivi 2014.
Central Processing Unit
Programming.
ICT Programming Lesson 1:
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Dept. of Computer & Information Sciences (Course Introduction)
1.3.7 High- and low-level languages and their translators
Running & Testing Programs :: Translators
Presentation transcript:

Domain specific programming languages Context Free Art UC Santa Cruz CMPS 10 – Introduction to Computer Science 4 May 2011

UC SANTA CRUZ Homework #3 Will be an assignment working with Context Free Art Described in class today Context Free Art is a domain specific programming language for creating computer-generated artwork Program is freely available, PC/Mac/Linux Standalone version works in PC labs (BE 109) In the assignment, you will 1.Take an existing context free art program and modify some of the numbers in it, and then describe the impact on the final artworks generated 2.In the same program, you will add a few new lines to the program, and then describe the impact on the final artworks 3.For extra credit, you can write a context free art program that is completely new (from scratch), describe how it works, and give an example of some artwork

UC SANTA CRUZ Homework #3 Assignment due Friday, May 13 Help sessions: Thursday, May 5, 4-5pm, E2 307 Tuesday, May 10, 3-5pm, E2 307 Thursday, May 12, 4-6pm, location TBD Assignment details will be posted on web by end of day

UC SANTA CRUZ Recap: Compilation Compilation process A programmer writes the source code of a program Source code: A file of text with programming language instructions A program called a compiler converts this text into assembly langauge An assembler then converts the assembly language into machine code Drawback The final machine code can only be executed on microprocessors that understand that specific type of machine code That is, machine code is microprocessor-specific 6502 machine code does not work on an 8080, etc. source code assembly machine code compiler assembler Microprocessor hardware can understand and execute

UC SANTA CRUZ Interpreted languages (compiled) Ideally, we would like the compiled code for a program to be able to run on any machine, no matter what machine code it uses That is, compile it once, but then run it anywhere This can be accomplished by creating a machine- independent assembly language and bytecode (machine code) Then, an interpreter can execute this machine code on each specific microprocessor source code machine-independent assembly machine code #2 compiler assembler machine-independent bytecode interpreter #2 No processing required, is input to Runs on top of machine code #1 interpreter #1

UC SANTA CRUZ Pros/Cons of interpreted languages Advantages A program can be compiled once, and then run on many different types of computer (types of microprocessor) Write once, run anywhere Java, C#, Flash/Actionscript are good examples of this Especially useful for web applications More control over execution environment Someone trying to break into a computer system needs to compromise the program, and then the interpreter Compare with just compromising the program, which then provides direct access to the machine Disadvantages Can be slower than languages that compile straight to machine code Some technologies exist to counteract this: JIT, just-in-time compilation Doesnt work for some kinds of applications (e.g., device drivers) that require direct access to the hardware

UC SANTA CRUZ Interpreters: emulators The interpreter part can be put into several different places in the program stack Emulator Machine code runs inside an emulator program (interpreter), instead of directly on hardware Examples: older game system emulators, MAME source code assembly machine code (original) compiler assembler emulator machine code (physical) No processing required, is input to Runs on top of Assembly source code for Chrono Trigger 65c816 machine code (original SNES) assembler SNES9X emulator Intel x86 machine code (physical) No processing required, is input to Runs on top of Assume was written in assembly; might have been C

UC SANTA CRUZ Directly interpreted languages Some languages completely avoid the compilation step These languages directly execute inside the interpreter Advantage Avoids compilation step (and time required to compile) Same program runs on many different machines A developer can make a change and quickly see its effect More interactive It is sometimes possible to change a program while it is running Disadvantage Typically runs much slower than compiled languages Examples: PHP, Javascript, Logo, Context Free Art source code compiler interpreter machine code (physical) Runs on top of

UC SANTA CRUZ Summary of different types of programming langs. Imperative Procedural C, FORTRAN (older versions) Object-oriented C++, Java, C#, PHP, Smalltalk Functional Haskell, Miranda Logic programming (not covered in class) Prolog Other (domain-specific)

UC SANTA CRUZ Domain specific programming languages Most programming languages we have examined so far are called general purpose langauges That is, they are designed so they are flexible enough to be capable of solving a wide range of problems The general idea is that most computational problems can be solved by writing a program in a general purpose language Sometimes solving a specific problem in a general purpose language is awkward That is, it can be done, but it requires a lot of code to accomplish a conceptually simple task In this case, sometimes it is possible to create a new programming language dedicated to just one type of task Such a language is not expected to be useful for solving a wide range of problems: it solves one problem, and does this well Such languages are known as domain-specific

UC SANTA CRUZ Context Free Art A example of a domain specific programming language Designed to make it easy to create computer-generated artwork startshape T rule T{ 4*{r 90}{ SU{} } } rule SU{ S{} SU{x -2.2 y 3.4 s.8 r -31.1} } rule S{ CIRCLE{} S{y.2 r 3 s.994} } By: joshij

UC SANTA CRUZ Execution model of Context Free Art A CFA program begins with a startshape directive It names the first rule to be executed In CFA, drawing instructions are given in the form of rules A rule consists of a series of 0 or more primitive drawing commands (e.g., CIRCLE) 0 or more rules A rule can call itself rule S { CIRCLE{} S {y.2 r 3 s.994} } Name of the rule is S Primitive drawing command (CIRCLE) A call to execute a rule, in this case rule S (i.e., call itself). An example of recursion. Definition of rule S

UC SANTA CRUZ Random Rule Selection For each rule, there can be one definition, or more than one definition How they are executed varies by each case One definition for a rule, R When another rule calls R, the one definition is executed More than one definition for a rule R: R 1, R 2, … R n When another rule calls R, one of the definitions is picked at random This is the main way randomness is added into CFA programs That is, use of multiple rules allows each picture to be different

UC SANTA CRUZ Example of multiple rule selection startshape SIX rule SIX { FOUR { }} rule FOUR { THREE { } FOUR { x 1 r 5 s 0.4 alpha } } rule FOUR { THREE { } FOUR { y 1 r -5 s 0.4 alpha hue 0.7 sat 0.9 b 1 skew } } rule THREE { TWO { } THREE { flip 32 s 0.99 alpha hue 0.7 sat 0.9 b 1 skew 2 0 } } rule THREE { TWO { } THREE { flip -32 s 0.99 alpha hue 0.9 sat 0.9 b 1 } } … Two examples of rule FOUR – CFA will pick one of these two when the rule FOUR is called (see rules SIX and FOUR) Either-or Two examples of rule THREE – CFA will pick one of these two when the rule THREE is called (see rule FOUR)

UC SANTA CRUZ What do all those letter and numbers mean? Consider this primitive shape CIRCLE {x 1 y 2 r 45} This means Add 1 to the current x position Add 2 to the current y position Rotate by 45 degrees Now draw a circle By shifting each drawn shape away from the current position, each shape ends up in a different location Without these position shifts, all shapes would just overwrite each other

UC SANTA CRUZ Primitive shapes Square A unit square SQUARE{} Circle A unit circle – diameter is the same as the side of a square CIRCLE{} Triangle Unit triangle. Same side length as squares TRIANGLE{} Defined in terms of path operations Not covered in class, can draw arcs, splines, etc.