ParserVal class public class ParserVal {   public int ival;   public double dval;   public String sval;   public Object obj;   public ParserVal(int.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Lecture 4 More on Java® Data Types, Control Structures.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Object Initialization in X10 Yoav Zibin David Cunningham Igor Peshansky Vijay Saraswat IBM research in TJ Watson.
For(int i = 1; i
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
What is output line of the following C++ code? Please trace int i = 1, QP; DATA: 4, B, 3, A double credit, totCredit=0.0; double num = 0.0; string LG;
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Objects contains data and methods Class – type of object Create class first Then object or instance String – defined class String s; // creates instance.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
SORTING AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Spring 2014 File searchSortAlgorithms.zip on course website (lecture notes for lectures 12, 13) contains.
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
Paradigmer i Programmering 4 a. Java 1.5 -Generics -Autoboxing/unboxing -New for sætning -Static imports -enum.
Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)
CS 112 Intro to Computer Science II Sami Rollins Spring 2007.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
Lecture 2: Lexical Analysis CS 540 George Mason University.
CS 1110 Final Exam: Review Session 2 Part 1 : Inheriting classes 1. Inheritance Facts 2. Constructors in Subclasses BREAK : 10 sec. Part 2 : Working with.
CS 536 Spring Learning the Tools: JLex Lecture 6.
ADSA: Subtypes/ Advanced Data Structures and Algorithms Objective –explain how subtyping/subclassing and generics are combined in Java –introduce.
Class and Object. Class vs Object Let us consider the following scenario… Class defines a set of attributes/fields and a set of methods/services. Object.
CS 2430 Day 26. Announcements Exam #2: Wednesday, April 3 –Review in lab on Tuesday, April 2 –Sample problems sent via .
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
Introduction to Computation and Problem Solving Class 9: Static Methods and Data Members Prof. Steven R. Lerman and Dr. V. Judson Harward.
SE-1010 Dr. Mark L. Hornick 1 Some Java Classes using & calling methodsS.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
ROUND 1 Name a method associated with class String 1.) 15 compareTo() 26 indexOf() 34 length() 2.) 3.) 4.) 3 toUpper() 7 substring() 11 charAt() 5.)
Comparative Programming Languages Language Comparison: Scheme, Smalltalk, Python, Ruby, Perl, Prolog, ML, C++/STL, Java, Haskell.
Lecture 6: YACC and Syntax Directed Translation CS 540 George Mason University.
Writing Static Methods Up until now, we have been USING (calling) static methods that other people have written. Now, we will start CREATING our own static.
Introduction to YACC CS 540 George Mason University.
A: A: double “4” A: “34” 4.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
` $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
1 8.Compiler Generators 8.1Overview 8.2Yacc 8.3Lex 8.4Coco/R.
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Interface.
CS 536 / Fall 2017 Introduction to programming languages and compilers
Java Generics Lecture 17 CS2110 – Spring 2017
Function Call Trace public class Newton {
More About Objects and Methods CS140: Introduction to Computing 1 Savitch Chapter 6 10/16/13.
Methods Additional Topics
Review Operation Bingo
null, true, and false are also reserved.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Arrays of Objects Fall 2012 CS2302: Programming Principles.
AP Java Warm-up Boolean Array.
Arrays of Objects Fall 2012 CS2302: Programming Principles.
Object-Oriented Programming
Java Lesson 36 Mr. Kalmes.
Summary.
Code Animation Examples
Recursive GCD Demo public class Euclid {
CS2011 Introduction to Programming I Methods (II)
Java’s Central Casting
Introduction to Object-Oriented Concepts in Java
Subtype Substitution Principle
Random Numbers while loop
Exception Objects An exception is an abnormal condition that arises in a code sequence at rum time. Exception is a way of signaling serious problem.
Recursive example 1 double power(double x, int n) // post: returns x^n
Presentation transcript:

ParserVal class public class ParserVal {   public int ival;   public double dval;   public String sval;   public Object obj;   public ParserVal(int val) { ival=val; }   public ParserVal(double val) { dval=val; }   public ParserVal(String val) { sval=val; }   public ParserVal(Object val) { obj=val; } } CS 440/540 Spring 2008 GMU

If ParserVal won’t work… Can define and use your own Semantic classes: /home/u1/white/byacc -Jsemantic=Semantic gen.y CS 440/540 Spring 2008 GMU

Grid Example (Java) /home/u1/white/byacc -Jsemantic=Semantic gen.y %% grid : seq {System.out.println("Done: " + $1.ival1 + " " + $1.ival2);} ; seq : seq instr {$$.ival1 = $1.ival1 + $2.ival1; $$.ival2 = $1.ival2 + $2.ival2;} | BEGIN instr : N | S | E | W ; public static final class Semantic { public int ival1 ; public int ival2 ; public Semantic(Semantic sem) { ival1 = sem.ival1; ival2 = sem.ival2; } public Semantic(int i1,int i2) { ival1 = i1; ival2 = i2; } public Semantic() { ival1=0;ival2=0;} } Grid Example (Java) /home/u1/white/byacc -Jsemantic=Semantic gen.y CS 440/540 Spring 2008 GMU

Grid Example (Java) %% B {yyparser.yylval = new Parser.Semantic(0,0); return Parser.BEGIN;} N {yyparser.yylval = new Parser.Semantic(0,1); return Parser.N;} S {yyparser.yylval = new Parser.Semantic(0,-1); return Parser.S;} E {yyparser.yylval = new Parser.Semantic(1,0); return Parser.E;} W {yyparser.yylval = new Parser.Semantic(-1,0); return Parser.W;} [ \t\n] {;} CS 440/540 Spring 2008 GMU