CS 541 — Fall 2021

Total Page:16

File Type:pdf, Size:1020Kb

CS 541 — Fall 2021 CS 541 — Fall 2021 Programming Assignment 2 CSX_go Scanner Your next project step is to write a scanner module for the programming language CSX_go (Computer Science eXperimental: Go-like syntax). Use the JFlex scanner- generation tool ( ased on !ex). "uture assignments will invol#e a $%& parser' type checker and code generator. The CSX Scanner Generate the $%&(go scanner' a mem er of class Yylex' using JFlex. Your main task is to create the )le csx_go.jflex' the input to *"lex. +he jflex )le specifies the regular expression patterns for all the $%&(go tokens' as well as any special processing re,uired y tokens. When a #alid $%& token is matched y mem er function yylex()' it returns an o ject that is an instance of class java_cup.runtime.Symbol (the class our parser ex- pects to receive from the scanner). Symbol contains an integer )eld sym that identifies the token class just matched. .ossible #alues of sym are identified in the class sym1. Symbol also contains a )eld value,which contains token information eyond the token’s identity. "or $%&(go' the value )eld references an instance of class CSXToken (or a su class of CSXToken). CSXToken contains the line num er and column num er at which each token was found. +his information is necessary to frame high-,uality error messages. +he line num er on which a token appears is stored in linenum. +he column num er at which a token egins is stored in colnum. +he column num er counts tabs as one character' e#en though they expand into se#eral lanks when #iewed. You must also store auxiliary information for identifiers' integer literals' character literals and string literals. "or identifiers' class CSXIdentifierToken' a su class of CSXToken' contains the identifier/s name in )eld identifierText. "or integer liter- als' class CSXIntLitToken' a su class of CSXToken' contains the literal/s numeric 1 Java class names normally are capitalized. However, certain classes created by the tool Java CUP ignore this convention. #alue in )eld intValue. "or character literals' class CSXCharLitToken' a su class of CSXToken' contains the literal/s character #alue in )eld charValue. "or string literals' class CSXStringLitToken' a su class of CSXToken' contains a )eld stringText, the full text of the string (with enclosing dou le ,uotes and internal escape se,uences included as they appeared in the original string text that was scanned). CSX_go Tokens +he $%&_go language uses the following classes of tokens: 0 +he reserved words of the $%&(go language: bool break char const continue else for func if int package print read return var +he break and continue reser#ed words are optional; compilers that include them receive extra credit. 0 Identifiers. 2n identifier is a se,uence of 2%$33 letters and digits starting with a letter' excluding reser#ed words. 3d 45 4(2 6 B | … | 8 | a 6 b | … z) (2 | B | … 6 Z 6 a | | … 9 | 0 6 1 | … 9)= - Reser#ed 0 Integer Literals. 2n integer literal is a se,uence of digits' optionally preceded y a ?. 2 ? denotes a negati#e #alue. 443nteger!it4 544(? 6 l) (0 6 ; 6 … 6 9)@ 0 String Literals. 2 string literal is any se,uence of printable 2%$33 characters' delimited y dou le ,uotes. 2 dou le ,uote within the text of a string must e escaped (as \”) to avoid eing misinterpreted as the end of the string. +abs and newlines within a string must e escaped (\n is newline and \t is tab). 7ackslashes within a string must also e escaped (as ((). Ao other escaped characters are allowed. %trings may not cross line oundaries. %tring!it 5 B ( Aot(B 6 C 6 Unprintable$har) 6 CB 6 Cn 6 Ct 6 CC )= B 0 Character Literals. 2 character literal is any printable character' enclosed within single ,uotes. 2 single ,uote within a character literal must e escaped (as \') to avoid eing misinterpreted as the end of the literal. 2 tab or newline must e escaped (D\nD is a newline and D\tD is a tab). 2 ackslash must also e escaped (as D(('). Ao other escaped characters are allowed. Char!it 5 ' ( Aot(' 6 C 6 Unprintable$har) 6 C' 6 Cn 6 Ct 6 CC ) D 0 Boolean Literals. +he two 7oolean literals are true and false (case insensitive). 0 Other Tokens. +hese are miscellaneous one- or two-character sym ols representing operators and delimiters. ( ) [ ] = ; + - * / == != && || < > <= >= , ! { } 8 +he colon (:) is only re,uired if you do the extra-credit break and continue. 0 End-of- ile !EO " Token. +he EF" token is automatically returned y yylex() when it reaches the end of )le while scanning the )rst character of a token. Comments and white space' as de)ned elow' are not tokens ecause they are not re- turned y the scanner. Ae#ertheless' they must e matched (and skipped) when they are encountered. 0 # Single Line Co$$ent. 2s in $@@' *ava, and Go' this style of comment egins with a pair of slashes and ends at the end of the current line. 3ts ody can include any character other than an end-of-line. !ineComment4 54 GG Aot(Eol)= 4Eol 0 # %&lti-Line Co$$ent. +his comment egins with the pair 99 and ends with the pair 99. 3ts ody can include any character se,uence other than two consecutive 9/s. 7lockComment4 54 HH ( (H6l) Aot(H) )= 4HH 0 White S(ace. White space separates tokens1 otherwise it is ignored. White%pace 5 ( 7lank 6 +ab 6 Eol) @ 2ny character that cannot e scanned as part of a #alid token, comment or white space is invalid and should generate an error message. Considerations)*eq&irements • 7ecause reser#ed words look like identifiers' you must e careful not to miss-scan them as identi)ers. You should include distinct token de)nitions for each reser#ed word before your de)nition of identifiers. • Upper- and lower-case letters are e,uivalent in reser#ed words ut not in identifiers. When you print a reser#ed word' print its conversion to lower case. • .rint character and string literals as they are input, that is' with the escaped characters shown as Cn, CC' or whate#er' and with the surrounding ,uotes. Iowe#er' you should also store the eJective #alues of character and string literals' in which escaped characters are replaced y their meaning' and surrounding ,uotes are remo#ed. • You can use the Unix command “man ascii” for a list of 2%$33 characters in order to uild a regular expression for printable 2%$33 characters. • You should not assume any limit on the length of identifiers. • You should not assume any limit on the length of input lines that are scanned. • You may use *ava 2.3 classes to convert strings representing integer literals to their corresponding integer #alues. 7e careful though; in *ava a minus sign, -, and not ? represents a negative #alue. You must detect and report o#erflow in a system- independent fashion, perhaps using the constants MIN_VALUE and MAX_VALUE in class Integer. No not halt on o#erflow1 print an error message and return MAX_VALUE or MIN_VALUE as the K#alueL of the literal. 2n online reference manual for *"lex may e found in the “Useful .rogramming +oolsL section of the class homepage. • 2lthough *"lex/s regular expression syntax is designed to e #ery similar to that of !ex or .erl' it is not identical. >ead the *"lex manual carefully. ◦ 2 lank should not e used within a character class (i.e.' ) and *). You may use ( ?@? (which is the character code for a lank). ◦ 2 dou le ,uote is meaningful within a character class (i.e.' ) and *). ◦ You should not use yy egin or any explicit states. • 2s was the case in project ;' javac re,uires an environment #aria le CLASSPATH to de)ne the directories to e searched to )nd .class )les stored in libraries. JFlex and JavaCup (in the next assignment) use CLASSPATH to tell *ava where to )nd the classes that they use. Fnce again, the Makefile we supply places all .class )les in su directory classes. • %keleton )les and a :akefile are in the directory ~raphael/. courses/cs541/public/proj2/startup.1 they are also availa le through the class homepage. No not assume that the *ava coding is up to modern standard1 use a style checker to impro#e the code. What to hand in %u mit your project electronically y uploading proj2.tar.gz to Canvas. .lease run make clean )rst to remo#e all .class )les. Your tar all (or zip )le or other archi#e) should contain: (1) the csx_go.jflex )le you create' (2) any other classes you create' (3) the test data you use to test your scanner' (4) the outputs produced using your test data, (4) a G><H:> )le' (5) a Makefile ' and (6) all source )les necessary to uild an executable #ersion of your program (.java )les and a csx_go.jflex )le). Aame the class that contains your main()routine P2.java. Your scanner test program should act like the test program illustrated elow' reading a stream of characters from the command line )le and printing out the tokens matched to the standard output' one per line in the following format: line:column token "or identi)ers' include the text of the identifier1 for integer literals' include the literal’s numeric #alue1 for character and string literals' include the literal’s full text (with enclosing ,uotes and escape se,uences). Use the following format line:column token (value) "or example' if the contents of the )le is: var T { // hello, This is // a test coNst cnst "hello\n" ^ ?10; You should produce: 1:1 Reserved (var) 1:5 Identifier (T) 1:7 Symbol ({) 4:1 Reserved (const) 5:4 Identifier (cnst) 6:1 String literal ("hello\n") 7:1 Invalid token (^) 8:1 Integer literal (-10) 8:4 Symbol (;) Your program should try to follow this format to ease grading.
Recommended publications
  • Delimited Escape Sequences
    Delimited escape sequences Document #: D2290R2 Date: 2021-07-15 Programming Language C++ Audience: EWG, SG-22 Reply-to: Corentin Jabot <[email protected]> Abstract We propose an additional, clearly delimited syntax for octal, hexadecimal and universal character name escape sequences. Revisions R2 • Improve wording • Add a note about feature macros (we do not need one) • Mention that a paper will be submitted to the C committee R1 • Remove obsolete note about wording Motivation universal-character-name escape sequences As their name does not indicate, universal-character-name escape sequences represent Uni- code scalar values, using either 4, or 8 hexadecimal digits, which is either 16 or 32 bits. However, the Unicode codespace is limited to 0-0x10FFFF, and all currently assigned code- points can be written with 5 or less hexadecimal digits (Supplementary Private Use Area-B non-withstanding). As such, the ~50% of codepoints that needs 5 hexadecimal digits to be expressed are currently a bit awkward to write: \U0001F1F8. 1 Octal and hexadecimal escape sequences have variable length \1, \01, \001 are all valid escape sequences. \17 is equivalent to 0x0F while \18 is equivalent to "0x01" "8" While octal escape sequences accept 1 to 3 digits as arguments, hexadecimal sequences accept an arbitrary number of digits applying the maximal much principle. This is how the Microsoft documentation describes this problem: Unlike octal escape constants, the number of hexadecimal digits in an escape sequence is unlimited. A hexadecimal escape sequence terminates at the first character that is not a hexadecimal digit. Because hexadecimal digits include the letters a through f, care must be exercised to make sure the escape sequence terminates at the intended digit.
    [Show full text]
  • C Constants and Literals Integer Literals Floating-Point Literals
    C Constants and Literals The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well. The constants are treated just like regular variables except that their values cannot be modified after their definition. Integer literals An integer literal can be a decimal, octal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, 0 for octal, and nothing for decimal. An integer literal can also have a suffix that is a combination of U and L, for unsigned and long, respectively. The suffix can be uppercase or lowercase and can be in any order. Here are some examples of integer literals: Floating-point literals A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. You can represent floating point literals either in decimal form or exponential form. While representing using decimal form, you must include the decimal point, the exponent, or both and while representing using exponential form, you must include the integer part, the fractional part, or both. The signed exponent is introduced by e or E. Here are some examples of floating-point literals: 1 | P a g e Character constants Character literals are enclosed in single quotes, e.g., 'x' and can be stored in a simple variable of char type. A character literal can be a plain character (e.g., 'x'), an escape sequence (e.g., '\t'), or a universal character (e.g., '\u02C0').
    [Show full text]
  • Lexical Structure
    j.book Page 13 Monday, May 23, 2005 11:36 AM CHAPTER 3 Lexical Structure Lexicographer: A writer of dictionaries, a harmless drudge. —Samuel Johnson, Dictionary (1755) THIS chapter specifies the lexical structure of the Java programming language. Programs are written in Unicode (§3.1), but lexical translations are provided (§3.2) so that Unicode escapes (§3.3) can be used to include any Unicode charac- ter using only ASCII characters. Line terminators are defined (§3.4) to support the different conventions of existing host systems while maintaining consistent line numbers. The Unicode characters resulting from the lexical translations are reduced to a sequence of input elements (§3.5), which are white space (§3.6), comments (§3.7), and tokens. The tokens are the identifiers (§3.8), keywords (§3.9), literals (§3.10), separators (§3.11), and operators (§3.12) of the syntactic grammar. 3.1 Unicode Programs are written using the Unicode character set. Information about this character set and its associated character encodings may be found at: http://www.unicode.org The Java platform tracks the Unicode specification as it evolves. The precise ver- sion of Unicode used by a given release is specified in the documentation of the class Character. Versions of the Java programming language prior to 1.1 used Unicode version 1.1.5. Upgrades to newer versions of the Unicode Standard occurred in JDK 1.1 (to Unicode 2.0), JDK 1.1.7 (to Unicode 2.1), J2SE 1.4 (to Unicode 3.0), and J2SE 5.0 (to Unicode 4.0). The Unicode standard was originally designed as a fixed-width 16-bit charac- ter encoding.
    [Show full text]
  • PYTHON NOTES What Is Python?
    PYTHON NOTES What is Python? Python is a popular programming language. It was created in 1991 by Guido van Rossum. It is used for: web development (server-side), software development, mathematics, system scripting. What can Python do? Python can be used on a server to create web applications. Python can connect to database systems. It can also read and modify files. Python can be used to handle big data and perform complex mathematics. Python can be used for production-ready software development. Why Python? Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). Python has a simple syntax similar to the English language. Python has syntax that allows developers to write programs with fewer lines than some other programming languages. Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. Good to know The most recent major version of Python is Python 3, which we shall be using in this tutorial. However, Python 2, although not being updated with anything other than security updates, is still quite popular. Python Syntax compared to other programming languages Python was designed to for readability, and has some similarities to the English language with influence from mathematics. Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose. Python Install Many PCs and Macs will have python already installed.
    [Show full text]
  • Variables and Calculations
    ¡ ¢ £ ¤ ¥ ¢ ¤ ¦ § ¨ © © § ¦ © § © ¦ £ £ © § ! 3 VARIABLES AND CALCULATIONS Now you’re ready to learn your first ele- ments of Python and start learning how to solve programming problems. Although programming languages have myriad features, the core parts of any programming language are the instructions that perform numerical calculations. In this chapter, we’ll explore how math is performed in Python programs and learn how to solve some prob- lems using only mathematical operations. ¡ ¢ £ ¤ ¥ ¢ ¤ ¦ § ¨ © © § ¦ © § © ¦ £ £ © § ! Sample Program Let’s start by looking at a very simple problem and its Python solution. PROBLEM: THE TOTAL COST OF TOOTHPASTE A store sells toothpaste at $1.76 per tube. Sales tax is 8 percent. For a user-specified number of tubes, display the cost of the toothpaste, showing the subtotal, sales tax, and total, including tax. First I’ll show you a program that solves this problem: toothpaste.py tube_count = int(input("How many tubes to buy: ")) toothpaste_cost = 1.76 subtotal = toothpaste_cost * tube_count sales_tax_rate = 0.08 sales_tax = subtotal * sales_tax_rate total = subtotal + sales_tax print("Toothpaste subtotal: $", subtotal, sep = "") print("Tax: $", sales_tax, sep = "") print("Total is $", total, " including tax.", sep = ") Parts of this program may make intuitive sense to you already; you know how you would answer the question using a calculator and a scratch pad, so you know that the program must be doing something similar. Over the next few pages, you’ll learn exactly what’s going on in these lines of code. For now, enter this program into your Python editor exactly as shown and save it with the required .py extension. Run the program several times with different responses to the question to verify that the program works.
    [Show full text]
  • Delimited Escape Sequences
    Delimited escape sequences Document #: N2785 Date: 2021-07-28 Project: Programming Language C Audience: Application programmers Proposal category: New feature Reply-to: Corentin Jabot <[email protected]> Aaron Ballman <[email protected]> Abstract We propose an additional, clearly delimited syntax for octal, hexadecimal and universal character name escape sequences to clearly delimit the boundaries of the escape sequence. WG21 has shown an interest in adjusting this feature, and this proposal is intended to keep C and C++ in alignment. This feature is a pure extension to the language that should not impact existing code. Motivation universal-character-name escape sequences As their name does not indicate, universal-character-name escape sequences represent Uni- code scalar values, using either 4, or 8 hexadecimal digits, which is either 16 or 32 bits. However, the Unicode codespace is limited to 0-0x10FFFF, and all currently assigned code- points can be written with 5 or less hexadecimal digits (Supplementary Private Use Area-B non-withstanding). As such, the ~50% of codepoints that need 5 hexadecimal digits to be expressed are currently a bit awkward to write: \U0001F1F8. Octal and hexadecimal escape sequences have variable length \1, \01, \001 are all valid escape sequences. \17 is equivalent to "0x0F" while \18 is equivalent to "0x01" "8" While octal escape sequences accept 1 to 3 digits as arguments, hexadecimal sequences accept an arbitrary number of digits applying the maximal much principle. This is how the Microsoft documentation describes this problem: 1 Unlike octal escape constants, the number of hexadecimal digits in an escape sequence is unlimited.
    [Show full text]
  • Character Data
    CHARACTER DATA A variable of the data type char can hold one keyboard character. Its value is stored in memory as a 16-bit binary code using the Unicode encoding scheme. Unicode has 65,536 codes of which approximately 35,000 are in use. It is designed to handle all characters in all written languages. Character literals are typed as single quotation marks (') delimiting a single keyboard character. Example Unicode value shown in hexadecimal char a, b, c, d, e; a 0063 a = 'c'; b 0032 b = '2'; c 006E c = 'n'; d 0025 d = '%'; e 0022 e = '"'; Inside a character literal, you sometimes need to specify a character that is either invisible (e.g. a line ending) or cannot be found on many keyboards (e.g. the symbol £). To do this, you use an escape sequence. The syntax is: \u character code character code is the 4-digit hexadecimal Unicode value denoting the desired character. Example This code fragment outputs Temperature:70°F. char degreeSymbol = '\u00B0'; int temp = 70; System.out.println("Temperature:" + temp + degreeSymbol + "F"); Example This code fragment outputs London Pizza £9.25. double price = 9.25; System.out.println( "London Pizza " + '\u00A3' + price ); Character Data Page 1 Since the ' delimits a character literal, you must use the escape character if you want the ' to stand for itself. Since the \ signals an escape character, you must use two together if you want it to stand for itself. The line ending character is the special escape sequence \n. Example Unicode value shown in hexadecimal char a, b, c; a 0027 a = '\''; b 005C b = '\\'; c 000A c = '\n'; Beginner Errors using Character Data Examples char letter = "n"; Error! " cannot delimit a character literal.
    [Show full text]
  • C Programming Tutorial
    C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i COPYRIGHT & DISCLAIMER NOTICE All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] ii Table of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ............................................................................................ 3 Installation on Unix/Linux ............................................................................
    [Show full text]
  • Visual Basic .NET Language
    Visual Basic .NET Language #vb.net Table of Contents About 1 Chapter 1: Getting started with Visual Basic .NET Language 2 Remarks 2 Versions 2 Examples 2 Hello World 2 Hello World on a Textbox upon Clicking of a Button 3 Region 4 Creating a simple Calculator to get familiar with the interface and code. 5 Chapter 2: Array 13 Remarks 13 Examples 13 Array definition 13 Zero-Based 13 Declare a single-dimension array and set array element values 14 Array initialization 14 Multidimensional Array initialization 14 Jagged Array Initialization 14 Null Array Variables 15 Referencing Same Array from Two Variables 15 Non-zero lower bounds 15 Chapter 3: BackgroundWorker 17 Examples 17 Using BackgroundWorker 17 Accessing GUI components in BackgroundWorker 18 Chapter 4: ByVal and ByRef keywords 19 Examples 19 ByVal keyword 19 ByRef keyword 19 Chapter 5: Classes 21 Introduction 21 Examples 21 Creating classes 21 Abstract Classes 21 Chapter 6: Conditions 23 Examples 23 IF...Then...Else 23 If operator 23 Chapter 7: Connection Handling 25 Examples 25 Public connection property 25 Chapter 8: Console 26 Examples 26 Console.ReadLine() 26 Console.WriteLine() 26 Console.Write() 26 Console.Read() 26 Console.ReadKey() 27 Prototype of command line prompt 27 Chapter 9: Data Access 29 Examples 29 Read field from Database 29 Simple Function to read from Database and return as DataTable 30 Get Scalar Data 31 Chapter 10: Date 32 Examples 32 Converting (Parsing) a String to a Date 32 Converting a Date To A String 32 Chapter 11: Debugging your application 33 Introduction
    [Show full text]
  • UTF and Character, Wide Character, Wide Wide Character Unicode
    ER for ADA 2018-01-03 1(9) Enhancement Request for ADA John-Eric Söderman Summary 1. A more strict specification of &-operator 2. Wide_Wide_String literal (page 6 ) 3. Wide_Wide_Character literal (page 6 ) Examples are based on the work with the GNAT compiler. The request is directed to the standard, because the change of the compiler should be the result of changes in the standard. In this request the Y2018, with it’s sub package “Y2018.Text” should not be considered as a part of the request for change. Problem (1) Facts and the standard The “&” operator should result in an array type. Here are some not so clear questions 1. if left argument is a non-array type and right argument is an array type or a container type then the result should be an array type of the left argument (and not a container type) 2. if left argument is an array type and right argument is of the a array type or a container type then the result should be of the same array type as the left argument 3. if left argument is a container type and right argument is of the a array type or a container type then the result should be of the same container type as the left argument 4. the container types are not array types. Because you cannot specify a simple array indexing to a container type (ct.Element(I) is not the same as ct(I) ) There seems to be some confusion about this in the ADA Standard package and in the GNAT library.
    [Show full text]
  • Regular Expressions the Following Are Sections of Different Programming Language Specifications
    Regular Expressions The following are sections of different programming language specifications. Write the corresponding regular expressions for each of the described lexical elements. 1) C Identifiers [Kernighan] An identifier is a sequence of letters and digits. The first character must be a letter; the underscore _ is considered a letter. Uppercase and lowercase letters are considered different. 2) Java 6 and previous Integer Literals [Gosling] An integer literal may be expressed in decimal (base 10), hexadecimal (base 16), or octal (base 8). An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int. The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one). A decimal numeral is either the single ASCII character 0, representing the integer zero, or consists of an ASCII digit from 1 to 9, optionally followed by one or more ASCII digits from 0 to 9, representing a positive integer. An hexadecimal numeral consists of the leading ASCII characters 0x or 0X followed by one or more ASCII hexadecimal digits and can represent a positive, zero, or negative integer. Hexadecimal digits with values 10 through 15 are represented by the ASCII letters a through f or A through F, respectively; each letter used as a hexadecimal digit may be uppercase or lowercase. An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 and can represent a positive, zero, or negative integer. Note that octal numerals always consist of two or more digits; 0 is always considered to be a decimal numeral-not that it matters much in practice, for the numerals 0, 00, and 0x0 all represent exactly the same integer value.
    [Show full text]
  • Unit II PYTHON  VARIABLES and OPERATORS
    CHAPTER 5 Unit II PYTHON VARIABLES AND OPERATORS Learning Objectives Aft er studying this lesson, students will be able to: • Appreciate the use of Graphical User Interface (GUI) and Integrated Development Environment (IDE) for creating Python programs. • Work in Interactive & Script mode for programming. • Create and assign values to variables. • Understand the concept and usage of diff erent data types in Python. • Appreciate the importance and usage of diff erent types of operators (Arithmetic, Relational and Logical) • Creating Python expression (s) and statement (s). 5.1 Introduction Python is a general purpose programming language created by Guido Van Rossum from CWI (Centrum Wiskunde & Informatica) which is a National Research Institute for Mathematics and Computer Science in Netherlands. Th e language was released in I991. Python got its name from a BBC comedy series from seventies- “Monty Python’s Flying Circus”. Python supports both Procedural and Object Oriented programming approaches. 5.2 Key features of Python It is a general purpose programming language which can be used for both scientifi c and non-scientifi c programming. It is a platform independent programming language. Th e programs written in Python are easily readable and understandable. 47 The version 3.x of Python IDLE (Integrated Development Learning Environment) is used to develop and run Python code. It can be downloaded from the web resource www.python.org. 5.3 Programming in Python In Python, programs can be written in two ways namely Interactive mode and Script mode. The Interactive mode allows us to write codes in Python command prompt (>>>) whereas in script mode programs can be written and stored as separate file with the extension .py and executed.
    [Show full text]