1 Assignment 2: AspectJ. 2 The simple language Tiny program y=2; x=2+y*3; z=x+y*2; –A program is a sequence of assignments; –Expressions on the right.

Slides:



Advertisements
Similar presentations
JavaCUP JavaCUP (Construct Useful Parser) is a parser generator
Advertisements

1 JavaCUP JavaCUP (Construct Useful Parser) is a parser generator Produce a parser written in java, itself is also written in Java; There are many parser.
Object-Oriented Programming MISM/MSIT Carnegie Mellon University Professor Roehrig’s Notes.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
1 Basic control structures Overview l Relational and Logical Operations l Selection structures »if statement »switch statement l Preview:
1 AspectJ Assignment. 2 The simple language Tiny program y=2; x=2+y*3; z=x+y*2; –A program is a sequence of assignments; –Expressions on the right hand.
Grammars and Parsing. Sentence  Noun Verb Noun Noun  boys Noun  girls Noun  dogs Verb  like Verb  see Grammars Grammar: set of rules for generating.
Language Translators - Lee McCluskey LANGUAGE TRANSLATORS: WEEK 21 LECTURE: Using JavaCup to create simple interpreters
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
1 Top Down Parsing. CS 412/413 Spring 2008Introduction to Compilers2 Outline Top-down parsing SLL(1) grammars Transforming a grammar into SLL(1) form.
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Java ProgrammingtMyn1 Java Programming Timo Mynttinen Mikkeli University of Applied Sciences.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
BUILDING JAVA PROGRAMS CHAPTER 2 Days of For Loops Past.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
COMP Parsing 3 of 4 Lectures 23. Using the Scanner Break input into tokens Use Scanner with delimiter: public void parse(String input ) { Scanner.
CPS 506 Comparative Programming Languages Syntax Specification.
Anatomy.1 Anatomy of a Class & Terminology. Anatomy.2 The Plan Go over MoveTest.java from Big Java Basic coding conventions Review with GreeterTest.java.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
More about Java Chapter 2 9/8 & 9/9 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
Decisions, Decisions, Decisions Conditional Statements In Java.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
1 JavaCUP JavaCup (Construct Useful Parser) is a parser generator; Produce a parser written in java, itself is also written in Java; There are many parser.
The Assignment operator tMyn1 The Assignment Operator The result of a calculation can be stored in a variable using the assignment operator =. Because.
User Defined Methods Methods are used to divide complicated programs into manageable pieces. There are predefined methods (methods that are already provided.
Building java programs, chapter 3 Parameters, Methods and Objects.
Application development with Java Lecture 6 Rina Zviel-Girshin.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
1 CSE 142 Final Exam Review Problems. 2 Question Types expressions array mystery inheritance mystery file processing array programming Critters classes.
Catie Welsh February 14,  Program 2 Due Tonight by 11:59pm  Program 3 Assigned 2.
CSE 501N Fall ’09 07: Iteration 17 September 2009 Nick Leidenfrost.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Chapter 3 – Describing Syntax
Sixth Lecture ArrayList Abstract Class and Interface
JavaCUP JavaCUP (Construct Useful Parser) is a parser generator
Chapter 7 User-Defined Methods.
Chapter 10 – Exception Handling
© 2016, Mike Murach & Associates, Inc.
CS 3304 Comparative Languages
Expression Trees Eric Roberts CS 106B March 4, 2013.
Lecture 2: Data Types, Variables, Operators, and Expressions
2.5 Another Java Application: Adding Integers
RADE new features via JAVA
Accessing Files in Java
CMPE 152: Compiler Design April 5 Class Meeting
Chapter 5: Control Structures II
Java 24th sep /19/2018 CFILT.
CS 302 Week 15 Jim Williams, PhD.
Syntax Analysis Sections :.
OPERATORS (1) CSC 111.
With Assignment Operator
Java Language Basics.
C H A P T E R T W O Syntax.
Syntax-Directed Translation
One step equation with Multiplication and Division
Exception Handling in Java
The Recursive Descent Algorithm
Chapter 11 Inheritance and Polymorphism Part 1
Conditionals and Loops
CSS161: Fundamentals of Computing
Presentation transcript:

1 Assignment 2: AspectJ

2 The simple language Tiny program y=2; x=2+y*3; z=x+y*2; –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 - z x - * - y - 2 … Program.java Assignment.java Expr.java

5 Program class consists of a vector of statements public class Program { private Vector statements; public static Hashtable varTable=new Hashtable (); public Program(Statement s) { statements = new Vector (); 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){ lhs=l; rhs=r; 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 = (2+y*3); z = (x+(y*2)); –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 y===>2 x===>8 z===>12 –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 0 is: y=2 2==> ? 2==>2 Assignment 1 is: x=(2+(y*3)) (2+(y*3))==> ? 2==> ? 2==>2 (y*3)==> ? y==> ? 2==> ? 2==>2 3==> ? 3==>3 (2*3)==>6 (2+(2*3))==>8 Assignment 2 is: z=(x+(y*2)) (x+(y*2))==> ? x==> ? (2+(2*3))==> ? 2==> ? 2==>2 (2*3)==> ? 2==> ? 2==>2 3==> ? 3==>3 (2*3)==>6 (2+(2*3))==>8 8==>8 (y*2)==> ? y==> ? 2==> ? 2==>2 2==> ? 2==>2 (2*2)==>4 (8+(2*2))==>12 Number of Expressions:11