1 / 10

Visitor-Based HMM

Visitor-Based HMM. Israel Perez, Fayz Rahman , Chinedu Egboh. Changes to HMM. Edited AbstractSyntaxTree class All “node” classes now have accept methods. Added VisitorIF interface

aira
Download Presentation

Visitor-Based HMM

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visitor-Based HMM Israel Perez, FayzRahman, ChineduEgboh

  2. Changes to HMM • Edited AbstractSyntaxTree class • All “node” classes now have accept methods. • Added VisitorIF interface • Defines an interface for a Visitor. Has visit methods for all “node” classes in AST. Not all are used, but they are there if needed in the future. • Edited Hmm.java • Edited to utilize our new additions.

  3. Changes to HMM • Added PrinterVisitor • A Visitor that prints out the Abstract Syntax Tree. • Added StaticTypeCheckVisitor • A Visitor that performs static-type checking on the Abstract Syntax Tree. • Added InterpreterVisitor • A Visitor that interprets the Abstract Syntax Tree and “runs” the program.

  4. Changes to HMM • Added Souvenir class • Some AST nodes return different things in different contexts. This class holds returns of type boolean, Value, and Type. Used as a unified return type for each method in the visitor interface. • Added additional test programs

  5. Why the Visitor Pattern? • We are separating Functionality from Structure. • We can add a new operation to an existing structure of objects without having to alter the classes of those objects. • In our project, we added PrintVisitor, StaticTypeCheckVisitor, and InterpreterVisitor. All use the same AST, but do very different things.

  6. Interpretation in HMM Old HMM Visitor-Based HMM Evaluates global variables Finds main method, gets its body, creates new Visitor, calls runStatement(Visitor) Visitor finds correct visitor for specific node type, and does whatever it needs to for that node. Possibly recursive. • Evaluates global variables • Finds main method, gets its body, calls runStatement(body) • Goes through list of if/elseifinstanceof blocks, and do whatever it needs to for that node. Possibly recursive. • If node is an Expression, call runExpression • go through more if/elseifinstanceof blocks. Possibly recursive.

  7. Demo Time?

  8. Refresher: Features of HMM • List Comprehension • Support for Tuples and Lists • Support for Strings • Built-in functions: • print • println int main() { list test = createTest(); list select = [(name1, name2) | (name1, name2) <- test, name1 == “Fayz” ]; println("Group Members: ”, test); println("Member: “, select); } list createTest() { return[("Fayz", "Rahman"), ("Nick", "Egboh"), ("Israel", "Perez")]; }

  9. Refresher: Features ofHMM • Lambda Expressions • For-each loop int main() { list count = [1,2,3]; for (n <- count) { intdoubleFunc = application(n, (\x -> x*2) ); println("(\x -> (2*x)) applied to ", n, " = ", doubleFunc); } } int application(object x, (object, object) a) { intresult = a(x); return result; }

  10. Refresher: Features of HMM int main() { list count = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]; intx = 10; list output = selector(count, lambdaFilter()); println("Count: ", count); println("Filtered: ", output); } (object, bool) lambdaFilter() { intx = 30; return (\y -> y < x); } list selector(list nums, (object, bool) filter) { return [ x | x <- nums, filter(x) ]; } • Static Scoping • Static Binding (variables in lambdas)

More Related