SlideServe
Menu
Préférences
© SlideServe · v2026

Enhancements to Visitor-Based HMM: Abstract Syntax Tree and Functional Visitor Patterns

aira avatar
10 diapositives · 258 Views · Jul 30, 2014

This document outlines recent enhancements to the Visitor-Based Hierarchical Memory Model (HMM) by authors Israel Perez, Fayz Rahman, and Chinedu Egboh. Key updates include the implementation of the Visitor Interface for abstract syntax tree (AST) node classes, enabling the addition of various visitors such as PrinterVisitor, StaticTypeCheckVisitor, and InterpreterVisitor. Furthermore, the Souvenir class standardizes return types across different contexts. The report discusses the advantages of using the Visitor Pattern for extending functionalities without modifying existing structures, as demonstrated through several use cases.

Enhancements to Visitor-Based HMM: Abstract Syntax Tree and Functional Visitor Patterns - slide 1
01 / 10Enhancements to Visitor-Based HMM: Abstract Syntax Tree and Functional Visitor Patterns
1 / 17

Télécharger la présentation

Enhancements to Visitor-Based HMM: Abstract Syntax Tree and Functional Visitor Patterns
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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)