SB Syntax analysis How ScriptBasic performs Syntax analysis.

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Symbol Table.
Intermediate Code Generation
Chapter 8 Intermediate Code Generation. Intermediate languages: Syntax trees, three-address code, quadruples. Types of Three – Address Statements: x :=
1 Compiler Construction Intermediate Code Generation.
The Assembly Language Level
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code.
Introduction to C Programming
Gary MarsdenSlide 1University of Cape Town Statements & Expressions Gary Marsden Semester 2 – 2000.
Chapter 14: Overloading and Templates C++ Programming: Program Design Including Data Structures, Fifth Edition.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
VBA Modules, Functions, Variables, and Constants
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 Problem 2 A Scanner / Parser for Simple C. 2 Outline l Language syntax for SC l Requirements for the scanner l Requirement for the parser l companion.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Chapter 2: Introduction to C++.
C++ for Engineers and Scientists Third Edition
Introduction to C Programming
Chapter 15: Operator Overloading
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Imperative Programming
MIPS coding. SPIM Some links can be found such as:
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
SB Implementing ScriptBasic Multi- Thread How to embed ScriptBasic multi-thread?
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Verilog Language Concepts
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
SB Symbol table handling in ScriptBasic The Module sym.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Introduction to Computer Programming
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
SB How ScriptBasic works Introduction to ScriptBasic Modules.
Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
SAP DEVELOPMENT BASICS Bohuslav Tesar. TRAINING OVERVIEW Amazing life of ABAP developer ;) SAP introduction ABAP basics ABAP Reporting.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
FUNCTIONS (CONT). Midterm questions (21-30) 21. The underscore can be used anywhere in an identifier. 22. The keyword void is a data type in C. 23. Floating.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Chapter Topics The Basics of a C++ Program Data Types
Topics Introduction to Functions Defining and Calling a Void Function
Context-Sensitive Analysis
A Simple Syntax-Directed Translator
Completing the Problem-Solving Process
Basic Elements of C++.
C Language VIVA Questions with Answers
Introduction to C++.
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Basic Elements of C++ Chapter 2.
11/10/2018.
Chapter 2: Introduction to C++.
Presentation transcript:

SB Syntax analysis How ScriptBasic performs Syntax analysis

SB Contents What is the role of syntax analysis What is the assumed syntax of a program What tables drive syntax analysis Creating the tables Pseudo terminals

SB Who this presentation is for Curious (why things happen?) Want to learn and understand how ScriptBasic works Want to modify ScriptBasic NOT for those, who just want to program in scriba

SB Role of syntax analysis Reader Lexer SYNTAX ANALYSIS Builder Execution

SB General purpose The syntax analyzer is a general purpose table driven syntax analyzer that could be used for other syntaxes not hard coded for ScriptBasic The first definition that fits is used. Easy to maintain but slower than special purpose analyzer

SB Syntax assumed Program is series of lines Lines are (usually) terminated by new line A line is series of terminal and pseudo- terminal symbols No block of code { } or BEGIN END –handled by go|come_forward|backward pseudo terminals Predefined pseudo terminal symbols, like ‘expression’

SB Tables defining syntax Binary operators Unary operators Built-in functions Commands –List of commands in the order syntax analyzer checks them against the lines

SB Creating the tables syntax.def is a readable format syntaxer.pl creates the syntax.c headerer.pl creates the syntax.h files.

SB Terminals and pseudo terminals ‘module’ is a terminal symbol (keyword) nl is terminal symbol (character) float is terminal symbol lval, expression are pseudo terminals –can create complex code ( one way street with dead end effect! ) –can have side effect

SB Code generated Code is array of nodes A node contains OpCode –list of command parameters (each is a node) –operands list (operators or function) –value (constant node) –Serial number (variable node) –start point and arguments (user defined function) –car and cdr values for list head nodes See builder.c struct _cNODE;

SB Example GOTO: 'goto' label nl OpCode: CMD_GOTO –Parameter.CommandArgument.Argument.pNode contains the node id of the line for label

SB Example ELSIF: 'else' 'if' * expression 'then' come_forward(IF) go_forward(IF) nl OpCode: CMD_ELSIF –Parameter.CommandArgument.Argument.pNode contains the node id of the expression –Parameter.CommandArgument.next next paremeter node: Parameter.CommandArgument.Argument.pNode where to go if expression fails

SB Pseudo terminals 1/10 nl tab These are the simplest pseudo-terminal symbols, because they are real terminals, just hard to write into a text file.

SB Pseudo terminals 2/10 expression expression_list Handles an expression or a comma separated list of expressions and creates nodes. OWSWDE

SB Pseudo terminals 3/10 string integer float These are simple terminals.

SB Pseudo terminals 4/10 symbol a symbol (in name space) absolute_symbol an absolute symbol name_space an absolute symbol that sets the name space (no code) end_name_space end a name space (no code)

SB Pseudo terminals 5/10 lval a left value lval_list a left value list separated by commas local local variable local_list list of local variables

SB Pseudo terminals 6/10 function a function name where it is defined thisfn the name of the currently defined function or procedure arg_num placeholder to store the number of arguments local_start starts a local scope local_end ends of local scope

SB Pseudo terminals 7/10 label a label used in goto label_def a label when defined

SB Pseudo terminals 8/10 cname constant name cval constant value corresponding to constant name These do not generate code, have only side effects defining a constant. ( cval defines a constant for the name last appeared for cname )

SB Pseudo terminals 9/10 go_back creates code go_forward creates code come_back has side effect come_forward has side effect These are used instead of code bracketing. There is a jump stack where node pointers are pushed and taken from.

SB Pseudo terminals 10/10 * star character OWSWDE noexec no code is generated from the line

SB Special commands All lines are analyzed by the C function ex_IsCommandThis except those defining special analysis function CALL/CALL ( ex_IsCommandCALL ) OPEN/OPEN ( ex_IsCommandOPEN )

SB Thank you for listening