Assignment 2: AspectJ - PowerPoint PPT Presentation

About This Presentation
Title:

Assignment 2: AspectJ

Description:

Expressions on the right hand side of assignment statements are arithmetic expressions; ... Arithmatic operators include , -, *, and /. There are no other operators. ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 9
Provided by: jiang79
Category:

less

Transcript and Presenter's Notes

Title: Assignment 2: AspectJ


1
Assignment 2 AspectJ
2
The simple language
  • Tiny program
  • y2
  • x2y3
  • zxy2
  • A program is a sequence of assignments
  • Expressions on the right hand side of assignment
    statements are arithmetic expressions
  • Assume variables are always of integer types
  • Arithmatic operators include , -, , and /.
    There are no other operators.
  • Assume input is always correct.

3
Parsing
  • The parser creates an abstract syntax tree
    represented in Program class
  • public class UseParser
  • public static void main(String args)
  • try
  • File inputFile new File("calc.tiny")
  • Calc2Parser parser new Calc2Parser(new
    Calc2Scanner(
  • new FileReader(inputFile)))
  • Program pm (Program) parser.parse().value
  • System.out.println(pm.toString())
  • catch (Exception e)
  • e.printStackTrace()

4
Parsing result
  •   lt?xml version"1.0" encoding"UTF-8" ?gt
  • - ltprogramgt
  • - ltassignmentgt
  •   ltlhsgtzlt/lhsgt
  • - ltrhsgt
  • - ltexprgt
  •   ltopgtlt/opgt
  • - ltleftgt
  • - ltexprgt
  •   ltprimitivegtxlt/primitivegt
  •   lt/exprgt
  •   lt/leftgt
  • - ltrightgt
  • - ltexprgt
  •   ltopgtlt/opgt
  • - ltleftgt
  • - ltexprgt
  •   ltprimitivegtylt/primitivegt
  •   lt/exprgt
  •   lt/leftgt
  • - ltrightgt
  • - ltexprgt
  •   ltprimitivegt2lt/primitivegt
  •   lt/exprgt
  •   lt/rightgt
  •   lt/exprgt
  •   lt/rightgt
  •   lt/exprgt
  •   lt/rhsgt
  •   lt/assignmentgt

Program.java Assignment.java Expr.java
5
Program class consists of a vector of statements
  • public class Program
  • private Vector ltStatementgt statements
  • public static HashtableltString, Exprgt
    varTablenew HashtableltString, Exprgt()
  • public Program(Statement s)
  • statements new Vector ltStatementgt()
  • statements.add(s)
  • public Program(Statement s, Program p)
  • statements p.getStatements()
  • statements.add(s)
  • public String toString()

6
Assignment class
  • public class Assignment extends Statement
  • private String lhs private Expr rhs
  • public Assignment(String l, Expr r)
  • lhsl
  • rhsr
  • Program.varTable.put(l,r)
  • public String getLHS() return lhs
  • public Expr getRHS() return rhs

7
Your tasks
  • Print out the parsed program
  •          y 2         x (2y3)         
    z (x(y2))
  • Hint Suppress printout in the parser by skipping
    calls to System.out.println(..) in UseParser
  • Hint Define your own print method in classes
    such as Expr, Assignment.
  • Print out the total number of expressions in this
    program
  • Hint count calls to constructors
  • Evaluate the program
  •       ygt2
  •       xgt8
  •       zgt12
  • Hint add evaluation method into Expr class
  • Print indented trace of the evaluation process
  • Hint check JoinPointTraceAspect in account
    example
  • Count the nested level

8
Your output
  • Assignment 2 is z(x(y2))
  • (x(y2))gt ?
  • xgt ?
  • (2(23))gt ?
  • 2gt ?
  • 2gt2
  • (23)gt ?
  • 2gt ?
  • 2gt2
  • 3gt ?
  • 3gt3
  • (23)gt6
  • (2(23))gt8
  • 8gt8
  • (y2)gt ?
  • ygt ?
  • 2gt ?
  • 2gt2
  • 2gt2
  • Assignment 0 is y2
  • 2gt ?
  • 2gt2
  • Assignment 1 is x(2(y3))
  • (2(y3))gt ?
  • 2gt ?
  • 2gt2
  • (y3)gt ?
  • ygt ?
  • 2gt ?
  • 2gt2
  • 2gt2
  • 3gt ?
  • 3gt3
  • (23)gt6
  • (2(23))gt8
Write a Comment
User Comments (0)
About PowerShow.com