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 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 330 Homework 2 – due before Monday, February 13
See the PDF.
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 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 330 Lecture 3 – Regular expressions++
Agenda more wildcard characters developing on clark.cs.uwec.edu substitution slurping a file expressions as replacements Perl subroutines zero-width assertions Code emails.pl #!/usr/bin/perl open($in, ‘<‘, ‘getlist.txt’); while ($line = <$in>) { $line =~ s/^(\S+).*$/$1\@uwec.edu/; print($line); } close($in); page.html <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html> <head> <title></title> </head> <body> <h2>Foo</h2> <h3>Blech</h3> <h4>Scrumpt</h4> </body> </html> demote.pl […]
CS 330 Lecture 2 – Regular expressions
Agenda Activate your Piazza account! Adventure, Zork Imperative languages Scripting languages Perl Scripting languages John Ousterhout once said: Scripting languages are designed for different tasks than are system programming languages, and this leads to fundamental differences in the languages. System programming languages were designed for building data structures and algorithms from scratch, starting from the […]
CS 330 Homework 1 – due before Friday, February 3
See the PDF.