Lexical Structure (Chapter 3, JLS)

Similar documents
Types, Values and Variables (Chapter 4, JLS)

Java Basic Datatypees

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Visual C# Instructor s Manual Table of Contents

PYTHON- AN INNOVATION

Lexical Considerations

CS313D: ADVANCED PROGRAMMING LANGUAGE

Getting started with Java

6.096 Introduction to C++ January (IAP) 2009

Lexical Considerations

Full file at

Introduction to Programming (Java) 2/12

3. Java - Language Constructs I

Java Notes. 10th ICSE. Saravanan Ganesh

CS260 Intro to Java & Android 03.Java Language Basics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Computational Expression

Lecture 3. More About C

Full file at

VARIABLES AND TYPES CITS1001

Java Primer 1: Types, Classes and Operators

Language Fundamentals Summary

Introduction to Programming Using Java (98-388)

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Types and Expressions. Chapter 3

Programming Lecture 3

Programming with Java

ARG! Language Reference Manual

Key Differences Between Python and Java

Declaration and Memory

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

VARIABLES AND CONSTANTS

Basic Operations jgrasp debugger Writing Programs & Checkstyle

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Operators. Java operators are classified into three categories:

Chapter 2 Working with Data Types and Operators

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

Language Reference Manual

Chapter 2: Introduction to C++

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Fundamental of Programming (C)

Basics of Java Programming

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Primitive Data Types: Intro

Reserved Words and Identifiers

A flow chart is a graphical or symbolic representation of a process.

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

UNIT- 3 Introduction to C++

1 Lexical Considerations

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Fundamentals of Programming

4 Programming Fundamentals. Introduction to Programming 1 1

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

RTL Reference 1. JVM. 2. Lexical Conventions

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Introduction to C. Winter 2019

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

Language Reference Manual simplicity

LECTURE 02 INTRODUCTION TO C++

Chapter 2: Using Data

COMP Primitive and Class Types. Yi Hong May 14, 2015

Fall 2017 CISC124 9/16/2017

Chapter 3: Operators, Expressions and Type Conversion

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Java Fall 2018 Margaret Reid-Miller

An Introduction to Processing

Datatypes, Variables, and Operations

JAVA OPERATORS GENERAL

Language Reference Manual

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

LECTURE 17. Expressions and Assignment

JAVA Programming Fundamentals

PROGRAMMING FUNDAMENTALS

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Operators in java Operator operands.

Lecture 2 Tao Wang 1

Chapter 12 Variables and Operators

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Lesson 3 Introduction to Programming in C

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Bits, Words, and Integers

Programming. Syntax and Semantics

SECTION II: LANGUAGE BASICS

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

ECE 122 Engineering Problem Solving with Java

Review of the C Programming Language for Principles of Operating Systems

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03

Flow Control. CSC215 Lecture

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Transcription:

Lecture Notes CS 140 Winter 2006 Craig A. Rich Lexical Structure (Chapter 3, JLS) - A Java source code file is viewed as a string of unicode characters, including line separators. - A Java source code file is segregated into recognizable substrings known as input elements. - Some input elements white space and comments are ignored. - Some input elements identifiers, literals, separators and operators are relevent. White Space ( HT LF VT FF CR ) + - ignored by the compiler - serves to delimit other input elements - subject to conventions on indentation, spacing, empty lines Comment /*...*/ //...(CR LF CR LF) /**...*/ - ignored by the compiler - traditional, end-of-line and documentation comments Identifier (Letter _ $)(Letter Digit _ $) - names a variable or method (beginning conventionally with a lower-case letter) - names a class (beginning conventionally with an upper-case letter) - some identifiers are reserved, known as keywords

Integer Literal 0 1 9Digit [l L] 0(x X)(Digit a f A F) [l L] 0(0 7) + [l L] - represents an integer number - decimal, hexadecimal and octal integer literals Floating-Point Literal Digit +.Digit [f F d D] Digit +.Digit (e E)[+ -]Digit + [f F d D].Digit + [f F d D].Digit + (e E)[+ -]Digit + [f F d D] Digit + (f F d D) Digit + (e E)[+ -]Digit + [f F d D] - represents an (approximate) real number - decimal or scientific notation floating-point literals Boolean Literal true false

Character Literal Character - represents a single Unicode character - characters and\are represented in a string by\ and\\ String Literal "Character " - represents a finite sequence of Unicode characters - characters " and\are represented in a string by\" and\\ - characters HT, LF, FF and CR are represented in a string by\t,\n, \f and\r Separator Operator ( ) [ ] { } ;,. = > <! ~? : == <= >=!= && ++ -- + - * / & ^ % << >> >>> += -= *= /= &= = ^= %= <<= >>= >>>=

Types, Values and Variables (Chapter 4, JLS) Primitive Types Values Representation boolean {false,true} 1-bit (possibly padded to 1 byte) Numeric Types Integral Types Z byte 2 7...(2 7 1) 8-bit signed two s complement short 2 15...(2 15 1) 16-bit signed two s complement int 2 31...(2 31 1) 32-bit signed two s complement long 2 63...(2 63 1) 64-bit signed two s complement char 0..(2 16 1) 16-bit Unicode (www.unicode.org) Floating-Point Types R float 32-bit ANSI/IEEE Standard 754 double 64-bit ANSI/IEEE Standard 754 Reference Types Class Type e.g. Object e.g. String Array Type e.g. int[] e.g. String[] Values user-defined objects sequence of Type

Variables Primitive Types Value stored in variable e.g. boolean x = true; e.g. int y = 5; e.g. char z = A ; Default value stored isfalse or 0 e.g. boolean x; e.g. int y; final variables can be assigned at most once e.g. final int SIZE = 10; e.g. final char EXCELLENT = A ; e.g. final float PI = 3.14159; Reference Types Reference (i.e., pointer) to value (i.e., object) stored in variable e.g. String x = "hello"; e.g. Widget y = new Widget(); e.g. int[] z = {3, 2, 4, 5}; Default reference stored isnull, which refers to nothing e.g. String x; e.g. int[] y; final variables can be assigned at most once; however, objects to which they refer can be modified e.g. final String GREETING = "hello"; e.g. final int[] CUTOFFS = {90, 80, 70, 60};

Expressions (Chapter 15, JLS) Literals Variables Operations: Prec./Assoc. Category Operator Operand(s) Result high n/a Postfix ++ -- numeric variable numeric value, before side effect n/a Prefix ++ -- numeric variable numeric value, after side effect numeric (+ -) 32-bit numeric value Unary + - ~! integral ( ~ ) 32-bit integral value boolean (!) boolean value Multiplicative * / % numeric, numeric 32-bit numeric value Additive + - numeric, numeric 32-bit numeric value Shift << >> >>> integral, integral 32-bit integral value n/a Relational < > <= >= numeric, numeric boolean value boolean, boolean Equality ==!= numeric, numeric boolean value reference, reference & { { boolean, boolean boolean value Bitwise ^ integral, integral 32-bit integral value { Boolean && boolean, boolean boolean value, short-circuit Conditional?: boolean, any, any value, short-circuit low Assignment = *= /= %= += -= <<= >>= >>>= &= ^= = variable, any (=) numeric variable, numeric (*= /= %= += -=) Order of operations determined by 1) parentheses 2) precedence 3) associativity Evaluation: result (and possible side effect) obtained by 1) evaluating left operand 2) evaluating right operand (unless short-circuit) 3) applying operation integral variable, integral (<<= >>= >>>= &= ^= =) boolean variable,boolean (&= ^= =) value, after side effect

Statements (Chapter 14, JLS) Block { Statement } - used to execute a sequence of statements Empty statement ; - has no effect Labeled statement Identifier:Statement - used with labeledbreak andcontinue statements Local variable declaration [final] Type Identifier [= Expression](, Identifier [= Expression]) ; - used to create local variable(s) and optionally assign initial value(s) - scope of variable is from point of declaration to end of block in which declared Expression Expression; - Expression must have a side effect if statement if( Expression) Statement [else Statement] - condition Expression must be of typeboolean switch statement switch(expression){((case Expression:) + Statement + ) [default:statement + ]} - condition Expression must be integral - case Expression(s) must be integral constant (literal or final variable)

while statement while ( Expression) Statement - condition Expression must be of typeboolean do statement do Statement while ( Expression); - condition Expression must be of typeboolean for statement for([expression(, Expression) ]; [Expression]; [Expression(, Expression) ])Statement for(localvariabledeclaration; [Expression]; [Expression(, Expression) ])Statement - initial Expression(s) must have a side effect - condition Expression must be of typeboolean - update Expression(s) must have a side effect break statement break [Identifier]; - must occur inside aswitch, while, do orfor statement continue statement continue [Identifier]; - must occur inside awhile, do orfor statement

Arrays (Chapter 10, Sections 15.10 and 15.13, JLS) - Arrays are objects that contain zero or more component variables. - Arrays are homogeneous components have the same type. - Arrays are created dynamically (as the program executes). - The length of an array is the number of components therein; it does not change after creation. Array type Type ([]) + - component type may be any Type (including array types) - dimension is number of pairs of[] Array initializer { [Expression (, Expression) ] [,]} { [ArrayInitializer (, ArrayInitializer) ] [,]} - creates an array - components are assigned from expression values - length is number of expressions or array initializers Array creation expression new ArrayType ArrayInitializer - creates an array having a specific component type - dimension, length and compatible component values can be given new Type ([ Expression]) + ([]) - dimension and lengths (in some dimensions) can be given by expression values Array type local variable declaration [final] ArrayType Identifier [= Expression](, Identifier [= Expression]) ; [final] ArrayType Identifier [= ArrayInitializer](, Identifier [= ArrayInitializer]) ; - used to create local array variable(s) and optionally assign initial component value(s) - expressions must be array creation expressions - scope of variable is from point of declaration to end of block in which declared Array access expression Expression[Expression] - array reference expression must be array type and have non-null value - index expression must be integral type and have value between0andlength-1 - first, second, third,... components are accessed by index expression values 0, 1, 2,... Array length expression Identifier.length