PRI-(BASIC2) Preliminary Reference Information Mod date 3. Jun. 2015



Similar documents
Sources: On the Web: Slides will be available on:

Install Java Development Kit (JDK) 1.8

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

Chapter 13 Storage classes

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Ruby - A Brief History

Moving from CS 61A Scheme to CS 61B Java

PL / SQL Basics. Chapter 3

Conversion Constructors

OpenOffice.org 3.2 BASIC Guide

Lecture 5: Java Fundamentals III

Visual Basic Programming. An Introduction

ECE 341 Coding Standard

Chapter 2: Elements of Java

Introduction to Python

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

CAPIX Job Scheduler User Guide

Programming Database lectures for mathema

The C Programming Language course syllabus associate level

13 Classes & Objects with Constructors/Destructors

National Database System (NDS-32) Macro Programming Standards For Microsoft Word Annex - 8

Object Oriented Software Design

Many applications consist of one or more classes, each containing one or more methods. If you become part of a development team in industry, you may

The programming language C. sws1 1

Chapter 5 Names, Bindings, Type Checking, and Scopes

Using the For Each Statement to 'loop' through the elements of an Array

FEEG Applied Programming 5 - Tutorial Session

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Connecting to an Excel Workbook with ADO

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Java Crash Course Part I

Object Oriented Software Design

Exercise 4 Learning Python language fundamentals

Introduction to Python

Bash shell programming Part II Control statements

Machine-Code Generation for Functions

Microsoft Windows PowerShell v2 For Administrators

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Chapter One Introduction to Programming

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

Chapter 13 - The Preprocessor

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

One Dimension Array: Declaring a fixed-array, if array-name is the name of an array

PHP Tutorial From beginner to master

Software Development (CS2500)

Pemrograman Dasar. Basic Elements Of Java

Data Tool Platform SQL Development Tools

Installing and Sending with DocuSign for NetSuite v2.2

Visual Basic and Databases

Comp151. Definitions & Declarations

Web development... the server side (of the force)

C Coding Style Guide. Technotes, HowTo Series. 1 About the C# Coding Style Guide. 2 File Organization. Version 0.3. Contents

Java CPD (I) Frans Coenen Department of Computer Science

[1] Learned how to set up our computer for scripting with python et al. [3] Solved a simple data logistics problem using natural language/pseudocode.

Consulting. Personal Attention, Expert Assistance

Advanced Bash Scripting. Joshua Malone

SQL Server Array Library László Dobos, Alexander S. Szalay

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Exceptions to the Rule: Essbase Design Principles That Don t Always Apply

MISRA-C:2012 Standards Model Summary for C / C++

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

Chapter 4 OOPS WITH C++ Sahaj Computer Solutions

Add an Audit Trail to your Access Database

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Appendix K Introduction to Microsoft Visual C++ 6.0

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Government Girls Polytechnic, Bilaspur

Using the Command Line Interface (CLI)

Using Casio Graphics Calculators

Moving from C++ to VBA

Maintaining Stored Procedures in Database Application

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn Claus Führer Simulation Tools Automn / 65

White Paper

Oracle Database: SQL and PL/SQL Fundamentals

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

CSE 308. Coding Conventions. Reference

Athena Knowledge Base

Embedded SQL programming

Introduction to Java

Semantic Checker (Part I)

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

Dialog planning in VoiceXML

Java Interview Questions and Answers

Changing the Display Frequency During Scanning Within an ImageControls 3 Application

CSE 130 Programming Language Principles & Paradigms

Application Streaming To App-V Conduit

Computer Programming C++ Classes and Objects 15 th Lecture

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Data Integrator. Pervasive Software, Inc B Riata Trace Parkway Austin, Texas USA

Informatica e Sistemi in Tempo Reale

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Learn Perl by Example - Perl Handbook for Beginners - Basics of Perl Scripting Language

Oracle Database: SQL and PL/SQL Fundamentals NEW

Typo3 Extension API. mysqldump --password=[password] [database name] [tablename] --add-drop-table >./ext_tables_static.sql

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

CS 111 Classes I 1. Software Organization View to this point:

Compiler Construction

Transcription:

PRI-(BASIC2) Table of content Introduction...2 New Comment...2 Long variable...2 Function definition...3 Function declaration...3 Function return value...3 Keyword return inside functions...4 Function parameters...4 Function call...5 Passing arguments by reference...5 Recursive function call...6 Local labels...7 Local variables...7 Misc... 8 Goto... 8 MEMORY( prog var tot )...8 TYPE$( varname )...8 PRI-(BASIC2)_v2 Page 1/8

Introduction The aim of this document is to provide additional information about the new BASIC 2. Basically, everything working in the Script Editor (previous tool to code some BASIC) will work in the BASIC 2. Key features of BASIC 2: long name variable new comment syntax function definition function call new BASIC instructions New Comment You can still use the old REM keyword but we added a more standard one: // REM this is a comment // this is also a comment Long variable You can now define long name for variables typed as INTEGER or STRING Compared to the Script Editor, where only a one character variable (A% or A$) could be used, it's a big improvement in terms of readability and code refactoring. Variable names are case insensitive (myint% and MyInt% are the same variable). Long names are also applicable on ARRAY ex: DIM arrayofstring(25,80) A% = 2 // old way to define an Integer, only 26 possible variables my_variable% = 1 // new way to define an Integer, unlimited number of variables DIM A$(25,80) // old way, only 26 array of strings DIM arrayofstring(25,80) // new way, unlimited number of array of strings DIM A(25,80) // old way, only 26 array of floats DIM arrayoffloat(25,80) // new way, unlimited number of array of floats PRI-(BASIC2)_v2 Page 2/8

Function definition Function declaration To declare a function, you now have two keywords: Function Function is used to start the function definitions and is followed on the same line by the function name. is used to end the function definitions. Function my_function print my_string // function definition begin // function definition end Function return value You specify the function return value using the following function name convention: If your function returns an integer: Function my_function% If your function returns a string: Function my_function$ If your function returns a float: Function my_function To specify the return value of a function, an implicit variable is created automatically based on your function name. When your function exits, the return value is the last value of this variable. The Following function will print my_string on your console but the return value will be 2. Because we initialized $my_function to 1 and add 1 to this variable. When the function exits (after the print), the last value of $my_function is 2. Function my_function $my_function = 1 $my_function = $my_function + 1 print my_string PRI-(BASIC2)_v2 Page 3/8

Keyword return inside functions You can use the keyword return at any place inside a function to end it. The current value of the return value ($FunctionName) will be returned as if we reached the. Function my_function if (global_var%=1) then $my_function = 1.0 return endif $my_function = 0.0 Function parameters You can define and apply parameters to your function. These parameters are typed (same way as functions). Here is a definition of a function with three parameters: Function my_function($param1, $param2%, $param3$) $my_function = $param2% + $param1 + 1 print @my_function(3, 3, 3 ) Properties of this parameters: Parameters are put between parenthesis and separated by a coma. Parameters are, by default, passed by value. Parameters type is deduced by the naming convention '$' at the end for string '%' at the end for integer nothing at the end for float Parameters are local variables in the function scope. These function parameters don't exist outside the function. To clarify this distinction with standard variables: every parameter variable begins with '$' in the declaration and inside the function. This allows you to manipulate global and local variable with the same name without messing up. PRI-(BASIC2)_v2 Page 4/8

Function call To call a function, you just need to write '@' followed by the function name and between parenthesis the parameters values. If there is no parameters, you can also omit the parenthesis. Function my_function($param1) print call of [my_function] with param [ ;$param1; ] Function my_function2() print my_function2() Function my_function3 print my_function3() @my_function(3) @my_function2 @my_function3() // call of a function without parameters // call of a function without parameters Pay attention to float and int parameters, if you give a float as an integer parameter (or the opposite), an implicit cast will occur. Function my_function($param1%) print call of [my_function] with param [ ;$param1; ] @my_function(3) // OK @my_function(3.4) // KO Passing arguments by reference By default the parameters are passed by value. This means that you cannot execute side effects. But sometimes, you want side effects to exist. A simple example would be a function where you want to return 3 values. PRI-(BASIC2)_v2 Page 5/8

If you precede the parameters with '@', they will be passed by reference. You can then use them as a normal parameter inside your function. The only difference compared to a normal parameter (passed by value) is that all changes made inside the function will be visible outside this function. In this case, types of parameters are Function my_function(@$param1,@$param2,@$param3$) $param1 = $param1 * 2 $param2 = $param2 * 2 $param3$ = "my_function_string" v1 = 1.5 v2% = 2 v3$ = "my_string" @my_function(v1, v2%, v3$) print v1 print v2% print v3$ Recursive function call You can call a function inside a function: function exp($x, $n%) if ($n% = 1) then $exp = $x else if ($n% mod 2 = 0) then $exp = @exp($x * $x, $n% / 2) else $exp = $x * @exp($x * $x, ($n% - 1) / 2) endif endif endfn exec: print @exp(3, 3) PRI-(BASIC2)_v2 Page 6/8

Local labels Sometimes, it's useful to have labels only inside your function to ease the flow control, but without polluting the name spaces of your program. To solve this, you are able to define local labels in your functions. To declare a local label, the syntax is the following: begin with '$', followed by your label name and end it by ':'. You can now use 'goto' inside your function to move to this label ('goto $YOUR_LABEL_NAME'). Outside the function, this label doesn't exist. Function test_label(): $a% = 1 goto $exit $a% = 2 $exit: $test_label = $a% endfn print @test_label() Local variables Local variables are used to define variables visible only in the function scope. Just declare a standard variable but precede it with the '$' character inside your function. function a() $b = 3 // local variable b $a = $b + 3 endfn exec: print @a() // here, @a() exists, but not $b. PRI-(BASIC2)_v2 Page 7/8

Misc Goto The goto function will move your execution cursor to a defined label. You can even pass string in a goto. my_label: print my_string end goto my_label A$ = my_label goto A$ MEMORY( prog var tot ) Returns the free memory of the Basic. prog will return the free memory of the program zone var will return the free memory of the variable zone tot will return prog + var TYPE$( varname ) Return the type of a variable. Will be string, float, or integer PRI-(BASIC2)_v2 Page 8/8