teaching machines

CS 330 Lecture 9 – Calculator + functions

Agenda evaluating expressions persistence of memory adding in functions avoiding reparsing with abstract syntax trees (ASTs) Code Flop.g grammar Flop; @header { import java.util.HashMap; } @members { HashMap<String, Integer> memory; public void setMemory(HashMap<String, Integer> memory) { this.memory = memory; } } stat : ID EQUALS expr {memory.put($ID.text, $expr.value);} | expr {System.out.println($expr.value);} ; expr returns [int […]

CS 145 Lecture 5 – Methods

Agenda print vs. println Scanner oddities don’t repeat yourself methods: hide details encapsulate repeatable processes parameters and return types Code CharacterArithmetic.java package preexam1; public class CharacterArithmetic { public static void main(String[] args) { char c = ‘m’; System.out.print(c + 5); System.out.println(” <- the sum”); c = (char) (c + 5); System.out.println(c); char avgLetter = (‘a’ […]

CS 330 Lecture 8 – A calculator language

Agenda writing a calculator language — with variables! forcing precedence the hazard of recursive descent generalizing rules in make Code … Haiku

CS 330 Lecture 7 – Finishing SLOWGO, a first Makefile, and a calculator

Agenda smart compilation with Make add drawing in to SLOWGO Code makefile ANTLRWORKS = $(HOME)/bin/antlrworks-1.4.3.jar SLOWGOInterpreter.class: SLOWGOInterpreter.java SLOWGOLexer.class SLOWGOParser.class javac -cp $(ANTLRWORKS):. SLOWGOInterpreter.java SLOWGOLexer.class: SLOWGOLexer.java javac -cp $(ANTLRWORKS) SLOWGOLexer.java SLOWGOParser.class: SLOWGOParser.java javac -cp $(ANTLRWORKS) SLOWGOParser.java SLOWGOLexer.java SLOWGOParser.java: SLOWGO.g java -cp $(ANTLRWORKS) org.antlr.Tool SLOWGO.g clean: rm -f *.class SLOWGO.g grammar SLOWGO; @members { private int x […]

CS 145 Lecture 4 – String problems and our first method

Agenda extracting names: “LASTNAME, FIRSTNAME MIDDLENAME …” lock the web: does a URL end in .edu? separate a comma-separated list turn “1,234,567” into 1234567 abstraction: hiding details abstracting SVG Code NameFixerUpper.java package preexam1; public class NameFixerUpper { public static void main(String[] args) { String name = “STEINMEYER, JOEL EDWARD”; // names in bad order! // […]

CS 330 Lecture 6 – Lexing, parsing, and translating

Agenda lexing recursive descent parsing writing interpreter glue adding state to ANTLR adding actions in ANTLR Code SLOWGO.g grammar SLOWGO; @members { private int x = 0; private int y = 0; private int theta = 0; private boolean isDrawing = false; } program @init { System.out.println(“axis equal”); System.out.println(“hold on”); } : command+ ; command […]

CS 145 Lecture 3 – Algorithms

Agenda algorithm pseudocode program this an early algorithm, a la Euclid primitives have operators objects have methods API String methods Program this You are indecisive. So are your friends. One quiet Monday night, you all decide one night to come up with a list of restaurants, each accompanied by a probability of how often you […]

CS 330 Lecture 5 – Our first language

Agenda your Logo their Logo our Logo hi, ANTLR recursive descent parsing Your Logo Design with a partner a little language that lets you move around in 2-D and draw things. Write down: your instructions an example program Their Logo From Papert’s NSF grant: The word constructionism is a mnemonic for two aspects of the […]

CS 330 Lecture 4 – Regex to NFA to DFA to fail

Agenda how to implement a regex engine what’s an NFA? converting a regex to an NFA converting an NFA to a DFA the limits of DFA-recognized languages the pumping lemma context-free grammars balancing parentheses a calculator language parse tree Regex to NFA concatenation alternation Kleene star NFA to DFA DFA’s start state is set of […]

CS 145 Lecture 2 – More data, more instructions

Agenda what does this do? literals vs. variables a few more types (int, char, boolean) penny RAM a few more instructions (cos, pow) Javadoc String What does this do? Code Day2.java package preexam1; public class Day2 { public static void main(String[] args) { double myNum = 6.7; int brettsFavoriteNumber = 9; char debrasFavoriteLetter = ‘d’; […]

1 102 103 104 105 106 110