Cross-Platform Low-Level Language CPL 3 - Language Overview Brian Westphal.

Slides:



Advertisements
Similar presentations
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Programming Languages and Paradigms The C Programming Language.
COSC 120 Computer Programming
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Top-Down Parsing using Regular Expressions A seminar by Brian Westphal.
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
C PROGRAMMING LECTURE C-language Computer Fundamentals.
Review of C++ Programming Part II Sheng-Fang Huang.
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
Computer Science 210 Computer Organization Introduction to C.
Imperative Programming
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
CoE3DJ4 Digital Systems Design
LLVM Compiler (2 of 3) Jason Dangel. Lectures High-level overview of LLVM (Katie) Walkthrough of LLVM in context of our project (Jason) –Input requirements.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
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.
1 C++ Syntax and Semantics, and the Program Development Process.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
CS212: Object Oriented Analysis and Design Lecture 2: Introduction to C++
Looping and Counting Lecture 3 Hartmut Kaiser
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
August 6, 2009 Data Types, Variables, and Arrays.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
Week 6: Functions - Part 2 BJ Furman 01OCT2012. The Plan for Today Comments on midterm exam (next week in lab!) Review of functions Scope of identifiers.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
C is a high level language (HLL)
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Topics for today: 1.Comments 2.Data types 3.Variable declaration.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Object Oriented Programming Lecture 2: BallWorld.
Chapter 5 Names, Bindings, Type Checking CSCE 343.
Information and Computer Sciences University of Hawaii, Manoa
Chapter 4 Assignment Statement
Data Transfers, Addressing, and Arithmetic
A bit of C programming Lecture 3 Uli Raich.
Chapter 3 Assignment Statement
C Short Overview Lembit Jürimägi.
Programmazione I a.a. 2017/2018.
MATLAB: Structures and File I/O
Introduction to Programming in Java
Conversions of the type of the value of an expression
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Introduction to CS Your First C Programs
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Programming Language C Language.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Java Programming Language
In this class, we will cover:
Programming Languages and Paradigms
C Language B. DHIVYA 17PCA140 II MCA.
INTRODUCTION to PERL PART 1.
Presentation transcript:

Cross-Platform Low-Level Language CPL 3 - Language Overview Brian Westphal

Design Overview Designed to be like assembly, except with structure Designed to be compatible as an intermediate language between many types of high level languages and Assembly Designed to be cross-platform compatible

Design Overview Supports: –Nested functions –Variable scoping - global, local (per function level) –Very strict typing –One-dimensional arrays –Function pointers All whitespace can be removed

Extended Design Overview Supports –Dynamic memory allocation/deallocation No deallocation is available with SPIM –I/O with stdin and stdout

Grammar Overview Given in EBNF format, compatible with my parser generator (available at Written in Java

Grammar Overview In the grammar file, instead of Rule : ‘a’ B ; B : ‘b’ B | ; There would be Rule ::= ‘a’ B* B ::= ‘b’

Grammar Overview Regular expressions are in single-quotes –There is no need for a separate scanner Rules are not in single-quotes –Rules can be followed by modifiers: *, +, ? –Other EBNF options are available but not used in this grammar (there are no epsilons or binary subtractions)

Grammar Overview Code can only exist in blocks immediately following a rule: //Supports types for casting and declarations. Type ::= '/(' (IntType | FloatType | CharType | AddressType) '/)' { RETree syntaxTree = (RETree) args; RETree type = (RETree) syntaxTree.get (1); return type.collapse (); }

Grammar Overview The first two sections (sections are denoted by ) are for import statements, and additional functions respectively. The third section is for productions. Other than those things, if you cannot read part of the grammar file, ask me - (and give me 12 to 24 hours to If you have suggestions for making CPL 3 better, (i.e. more complete) please send me as well.

Language Overview - by example: variables vars:;.func_main { return:(i); params:; vars:(i32)$x,(i32)$y; MOV $x (i32)100; MOV $y (i32)0; ADD $y $y $x; RET (i)0; }

Language Overview - by example: functions vars:; #This is a comment.func_main { return:(i); params:; vars:(i32)$fact; func_types:((i32):i32); MOV $1 (i32)5; CALL.func_factorial; MOV $fact $return; }

Language Overview - by example: functions.func_factorial { return:(i32); params:(i32)$value; vars:(i32)$t1; if $value == (i32)0 { RET (i32)1; }

Language Overview - by example: functions else { SUB $t1 $value (i32)1; func_types:((i32):i32); MOV $1 $t1; CALL.func_factorial; MOV $t1 $return; MULT $t1 $t1 $value; RET $t1; }

Language Overview - by example: dynamic memory vars:;.func_main { return:(i); params:; vars:(f32*)$floatArray,(i32)$index; ALLOC $floatArray (i32)100 sizeof(f32); MOV $index (i32)0;

Language Overview - by example: dynamic memory wloop $index < (i32)100 { MOV $floatArray[$index] (f32)0.0; ADD $index $index (i32)1; } DEALLOC $floatArray; RET (i)0; }

Language Overview - by example: nested functions vars:;.func_main { return:(i); params:; vars:(i)$x;.localfunc_increment { return:void; params:(i)$y; vars:;

Language Overview - by example: nested functions ADD $x $x $y; } func_types:((i):i); MOV $1 (i)10; CALL.localfunc_increment; RET (i)0; }

Language Overview - by example: function pointers vars:;.func_squareNum { return:(i); params:(i)$x; vars:(i)$y; MULT $y $x $x; RET $y; }

Language Overview - by example: function pointers.func_main { return:(i); params:; vars:(i)$x,(void*)$funcPointer; MOV $x (i)10; MOV $funcPointer.func_squareNum;

Language Overview - by example: function pointers func_types:((i):i); MOV $1 $x; CALL $funcPointer; MOV $x $return; RET (i)0; }

Language Overview - types //Signed int types. typedef int i; typedef char i8; typedef short i16; typedef int i32; typedef long long i64; typedef i si; typedef i8 si8; typedef i16 si16; typedef i32 si32; typedef i64 si64; //Unsigned int types. typedef unsigned int ui; typedef unsigned char ui8; typedef unsigned short ui16; typedef unsigned int ui32; typedef unsigned long long ui64; //Signed float types. typedef float f; typedef float f32; typedef double f64; typedef f sf; typedef f32 sf32; typedef f64 sf64; //Unsigned float types (no unsigned float in PowerPC or Intel). typedef float uf; typedef float uf32; typedef double uf64; //Char types. typedef char c; typedef char c8; typedef short c16;

Language Overview - variable and type examples (i32)$x(i32)10(i32)-10E6 (f32)$pi(f32) (f32)1.0E-6 (c)$letter(c)’a’(c16)0020 (i*)$pointer(c8*)a0000:B800 (c8)$string[1024]

Language Overview - strings Supported with the MOV statement only MOV $string “Hello World!\n\n”

Language Overview - conditions Conditions do not use parentheses –No complex conditions are allowed (i.e. no &&) The following operations are allowed: =, >, !=

Language Overview - built-in functions Math: ADD, SUB, MULT, DIV, REM, NEG Logical: EQ, GT, GE, LT, LE, NE, AND, NOT, NOR, OR, XOR Bitwise: SHL, SHR, BAND, BOR, BXOR Functions: RET, CALL Branching: JMP, JEZ Memory: ALLOC, DEALLOC Other: MOV, HALT

Language Extensions - I/O The following I/O functions are available via the blackbox programs PrintIntReadInt PrintFloatReadFloat PrintDoubleReadDouble PrintStringReadString

Language Extensions - by example: I/O func_types:(void:i32); MOV $1 (i32)100; CALL.PrintInt; MOV $storage “Hello, World!\n\n” func_types:(void:c8*); MOV $1 $storage; CALL.PrintString; func_types:((i32):void); CALL.ReadInt; MOV $storage $return; func_types:(void:c8*,i32); MOV $1 $storage; MOV $1 (i32)1024; CALL.ReadString;

Blackbox Programs Use the blackbox programs (available at to convert your CPL 3 code into an executable or into SPIM assembly. Will only say - error or no errors, no specific error messages Read the documentation; some things that the compiler allows for are not allowed in the language.

Language References Please see the language reference available at for additional information and examples. This presentation and example files for this presentation will also be posted on that site. Also, be sure to see the rest of the links from for information on my Java parser and regular expression packages.

Comments and Questions Please feel free to ask any additional questions and make any comments at this time