Вы находитесь на странице: 1из 28

PraNaMa Scripting Language in Kannada

Chapter 1
Introduction
In computer science, an interpreter [10] normally means a computer program that executes instructions written in a programming language. An interpreter may be a program that either 1. Executes the source code directly 2. Translates source code into some efficient intermediate representation (code) and immediately executes this 3. Explicitly executes stored precompiled code made by a compiler which is part of the interpreter system A scripting language [8],[9],[10] is a command set for controlling some specific piece of hardware, software, or operating system, often with rudimentary and in some cases more advanced programming-like control flow constructs, and is almost always usable from a stored format such as a simple text file, a section of read-only persistent storage in an embedded device, a deck of punched cards, or other mechanism. Stored sets of commands, especially those stored in files, can be generically called scripts, but usually have more specific names based upon some more conventional programming language, although a key differentiator is that even these scripting languages almost never use the normal tool chain characteristic of the language they resemble Kannada Scripting Language PRANAMA is one such application specific language which can be used to program in Kannada. The language provides a new wave in computer programming by facilitating the users who want to learn and implement computer programs in Kannada.

1.1 Kannada scripting language has some of the following features: Support for programming in a regional language Kannada and there by allow users who know the language edit and interpret programming in the same.
Dept. Of CS & E, GEC, Hassan Page 1

PraNaMa Scripting Language in Kannada

Well defined keywords, identifiers, functions implemented to support programming and use the same. Well defined set of rules to govern the syntax and semantics of programming. This makes programming much easier and stick to one particular pattern. Efficient GUI based editor to edit and also interpret the programs written. The editor also provides the features like file open, save as, save etc. A separate output window to display the executed results in Kannada itself in a user readable format. Efficient memory management techniques used to store and retrieve the values of variables used in the programs. A parser which handles the written program to be passed to computer understandable format and thereby process it to give out the results. A separate file extension for the files to be saved called .ks which can be recognized by the editor even when file is loaded.

This paper aims mainly at providing its users a programming experience in a regional language Kannada. The users can edit, interpret and thus observe the results also in Kannada.

Dept. Of CS & E, GEC, Hassan

Page 2

PraNaMa Scripting Language in Kannada

Chapter 2
System Design
The system architecture affects the performance, robustness, distributability and maintainability of a system. The particular style and structure chosen for an application may therefore depend on the non-functional system requirements: 1. Performance 2. Security 3. Safety 4. Availability 5. Maintainability

2.1 Design Considerations


The main aim is to provide a platform for those who want to program using a language that is typed not in English but in Kannada. This would aid those who are not well versed in English, who know Kannada and want to learn programming. Thus we have kept the features supported by PraNaMa as few as possible only retaining those features that would help the students of PraNaMa in learning higher level languages such as C, C++ in the future.

2.2 Designing PraNaMa:

Figure 1 Design/Flow of the PraNaMa

Dept. Of CS & E, GEC, Hassan

Page 3

PraNaMa Scripting Language in Kannada

The high-level design shows three major components: 1. First Pass 2. Second Pass 3. Meta Data

The first pass reads the input file and extracts information that will be used during the second pass and stores it as Meta Data. This information could be things like name, type and scope of variables, name and return type of functions and information about any files that are to be linked with the existing file. The second pass handles the major part of interpreting the program written. It handles various programming constructs like the conditional statements and looping constructs. Second pass also handles the evaluation of expressions, function calls and linking of files. A detailed explanation of each of the above components is given below.

2.3 Pass 1:
Figure 2 shows the flow/design of the first pass of the PraNaMa interpreter

The first pass scans each line of the program and identifies all lines that contain variable declarations and function calls. Important information such as the variable name, type and scope is stored as meta-data. This meta-data is crucial for in the second pass where the values of variables forming a part of function calls and expressions need to be retrieved in order to successfully call the functions and evaluate the expressions.

Dept. Of CS & E, GEC, Hassan

Page 4

PraNaMa Scripting Language in Kannada

2.4 Metadata:
Metadata is used in the second pass to retrieve values of variables, to retrieve function return types and to retrieve variable types and scope of variables. Two separate tables are used to store metadata about functions and variables. The details about the entries in each table are shown in table 1 and 2.

Table 1 Memory Table

2.5 Pass 2:
Each line from the file is read and analyzed. The analysis helps in identifying the next action that has to be performed. The action to be performed is based on the analysis of the current line. The line may be a function call, start of a loop, a conditional statement or an expression to be evaluated. Based on the type of the line an appropriate function is called to carry out the correct action. The function call may display a result or alter the memory table entries. Once the action appropriate for the current line is carried out , Pass 2 checks if there is another line that is to be read. If there is then it loops back to the step where the line is analyzed and this continues till an end of file is encountered.

Dept. Of CS & E, GEC, Hassan

Page 5

PraNaMa Scripting Language in Kannada

2.6 Identifying Keywords and operators An important step in designing any computer language is to identify the keywords[6] and determine the rules to be followed while writing the program in the new language. The sections that follow will give a brief description of the keywords.

2.7 Keywords
The following are the keywords that are to be used when writing a program.

2.8 Operators
Operators [6] form an important part of a programming language allowing us to perform Mathematical and logical operations. The following operators were identified as important and operators that ought to be supported by PraNaMa.

Dept. Of CS & E, GEC, Hassan

Page 6

PraNaMa Scripting Language in Kannada

Dept. Of CS & E, GEC, Hassan

Page 7

PraNaMa Scripting Language in Kannada

Chapter 3
System Working
3.1 Basic Logic of Parsing:
Each .ks file will be parsed [5] twice. The idea of two parses is to separate file including, function declaration from actual running of the program.

3.2 First Pass:


First parse handles four things.

later). This is analogous to the #include statement of a C program. This is done by appending each line of the included file to the present file.

appending of new files). 3.3 Second Pass: In Intrepreter.java the second pass is handled by: private int second pass (int scopeNum, int new_scope) function. Here new scope is used for handling user defined functions (as explained later) and scope Num is the scope number of the block which one wants to execute. The first call to this function is done as: second pass (0,-1) ; Here 0 is for global scope. The advantage of scopeNum lies in the fact that handling of if-else and while constructs becomes easy to implement. The function returns 1 on successful execution of function body or -1 when an error occurs.

Dept. Of CS & E, GEC, Hassan

Page 8

PraNaMa Scripting Language in Kannada

In second_pass function each line in the file is examined and the type of the line is determined. Depending on the type of the line appropriate functions are called to handle that type. Following things are handled in second pass:

-else and while.

3.4 Declaration of Statements:


The rule in Ganlipi is that every variable must be declared before it is used., every declaration statement can be of two types one for each different data type supported by ganaka i.e. Akshara ( string) and Sankhye ( float ). The type of variable declared is identified by first word in statement and appropriate variable declaration functions are called. User can declare a single variable or an array. A single variable can be initialized in declaration but an array cannot be initialized. The functions take care of allocation of memory for variables in memory table and initialization of values.

3.5 Handling of Expressions:


An expression statement is one of the following :

a = 10 ; b = a+10 ; c = a*b ; ( Operators can be logical, relational or arithmetic )


Dept. Of CS & E, GEC, Hassan Page 9

PraNaMa Scripting Language in Kannada

a = "hello"+"how"+"are"+"you"; b = a+ nice weather ; a=b=c=0; a;

When a line in the file is judged to be an expression statement the Exrpession.Evaluate function is called with the current line , memory object and current line number as parameters.Expression.java and ExpressionVal.java are generated using Byacc/J[2] with calc.y as input grammar and ExpressionLex.java is generated using Jflex[1] with calc.flex as input file. The Evaluate function basically tries to reduce one of the many grammar rules. Once a reduction is done the corresponding action associated with the grammar rule is executed.

Besides these, other tokens include: NUM = All real numbers. KANNUM = Real numbers in Kannada. CONSTANT = All characters within double quotes ( ).
Dept. Of CS & E, GEC, Hassan Page 10

PraNaMa Scripting Language in Kannada

NUMVAR = A variable which contains floating point value STRVAR = A variable which contains string value. Operator Precedence[6]:

Handling of implicit function: WRITE


The function is to print a statement given by the user. The statement may be a collection of String literals, literal Numbers, Sankhye and Akshara variables. Write functions analyses the statement access memory table to get values of variables and converts everything into a string to be displayed on Output window. On invoking write, the Output window GUI is initialized if it is not yet and the output is appended to display buffer.

Dept. Of CS & E, GEC, Hassan

Page 11

PraNaMa Scripting Language in Kannada

Handling of implicit function: READ


This function is used to take input from user. Currently it only supports input to a single variable. This function analysis the type of variable to which the value is to be read and the value given by users is stored into proper variables. On invoking a READ, the Output window GUI is initialized if it is not yet and a text-field is appended to output screen buffer so that user can enter data into text field. On pressing enter-key on text field, the text field is set to non-editable mode and the program continues. The Program does a blocked read for a READ command, i.e. on execution of READ command, the interpreter halts execution until user gives input.

3.6 Handling of User defined functions


Ganaka also supports function's as C, but the slight variation is every function declaration is followed by a keyword KAARYA (function) and every function call is to be called by an implicit CALL api KARE.

Function declaration:
Every function declaration must start with keyword FUNCTION followed by return type SANKHYE, AKSHARA or KHAALI ( void ) followed by a function name followed by parameter list in parenthesis. On parsing such a line, the function definition handler is called which puts all the details of function in function table (explained later). The logic of function must be enclosed in '{' '}' and the immediate block following the function declaration is skipped.

3.7 Function call and return value handling:


The function call is executed by 1) CALL (function_name (parameter list ) ); or 2) CALL (function_name (parameter list ) , RVariable );
Dept. Of CS & E, GEC, Hassan Page 12

PraNaMa Scripting Language in Kannada

In method 1, the return value if any is ignored, where as in method 2 the return value is expected and it is stored in RVariable. Such statements are handled by CallHandler function, which take care of parsing all the parameters to be sent, access their values, initialize the function block to execute the block. The return values from function are stored in appropriate variables. It is a mentionable fact that ganaka can handle recursion, and this is made possible by storing the current state of function and initializing the function with new values for execution, after the execution of function the old state of function is restored. The states of functions are handled with scope value.

3.8 Handling of Constructs


The constructs if, else-if, else and while have a condition stipulated to them that the body of the construct must be enclosed in flower brackets ({and}). This condition ensures that the body of the construct lies in a new scope. Hence by identifying the scope the body can be executed by calling the second_pass function with that scope as the parameter. int ifHandler(String line) During second pass if the current line contains an if statement then it invokes the ifHandler function passing the contents of the line in string format. The ifHandler will handle if, else-if and else constructs. This function returns the line number from where the execution must continue in second_pass function, in case of error it returns -1.

Algorithm used in if Handler function:


Step 1: From the string line extract conditional part of the if statement (within parentheses). Step 2: Call Expression.Evaluate function for the conditional expression and store the result. Step 3:If result is true do the following: o Find the scope of the next line (since blank lines are removed, the next line contains { ) which is done using paranPos() function.

Dept. Of CS & E, GEC, Hassan

Page 13

PraNaMa Scripting Language in Kannada

o Call second_pass function passing the scope number found in the previous step as parameter. o Skip all the corresponding else-if and else constructs associated with this if construct and return the line number from which execution should continue. Step 4: If result is false do the following: o Skip the if (or else-if ) block of statements. o Check if next statement contains else-if or else keyword. o If it does not then return that statement. o If it contains else-if statement do the following: Extract the expression part of else-if statement. Evaluate the expression. If it is true execute the corresponding block and skip the rest of else-if ladder and else block and return the appropriate line number from which execution will resume. If it is false go back to step 4. If it contain else statement do the following: Find the scope of the else block. Execute this block using second_pass function. Return the next line after the else block.

int whileHandler(String line)


This function is used to handle the while construct. Like the ifHandler this function returns the line number from where the execution must resume or -1 in case of an error. Likewise it also takes the contents of the statement as a parameter.

Algorithm for whileHandler function:


Step 1: From the string line extract conditional part of the while statement (within parentheses).
Dept. Of CS & E, GEC, Hassan Page 14

PraNaMa Scripting Language in Kannada

Step 2: Call Expression.Evaluate function for the conditional expression and store the result. Step 3: If result is true:

Step 4: If result is false return the line number immediately after the while loop.

3.9 The Memory Handling[6]:


All variables are stored in hash table for easy access, the hash table stores the variable name along with score number as key and the value part is a set of variable name, value in string and num format, scope num and other associated information. A noteworthy feature is both the string and numvalue of a variable are stored which makes coercing easier. On inserting a value into table, the number is coerced to string and it is stored as string value and a string is parsed if it has a number and its values is stored correspondingly , if it does not have a number, 0 is stored. The memory handling also provides function to store, access and alter variables. Any variable can be accessed by its name and the line number where it is used. Such an interface was developed as an interpreter executes line by line and this interface would make variable access easier. Another reason for creation of separate memory handling functions is that, Variables forms the soul of program, a variable is used in almost every line of program. Hence it was necessary to build a flawless and efficient handling of variables.

The auto coercing feature in memory table adds an advantage in various functions of parser. Example: WRITE handler.
Dept. Of CS & E, GEC, Hassan Page 15

PraNaMa Scripting Language in Kannada

3.10 The Function handling:


The function handling[4] mainly concentrates on handling data of functions. The function table (a hash table) stores all detail of function. The function handler provides interface to insert data regarding a function and also to access specific details regarding function whenever needed. The access queries may be to check if a function exists, which line the function is defined, what is the return type, what are the type of arguments the function expects and so on. The function handler makes the task of call handler easy and structured.

Dept. Of CS & E, GEC, Hassan

Page 16

PraNaMa Scripting Language in Kannada

Chapter 4
Usage guidelines
This section gives a description of various types of constants, data types, operators and control statements available in PraNaMa. It also gives a brief description of how the language includes function handling, array handling features in it. The following series of steps are to be followed before learning any computer programming language: 1. Learn the alphabet of the language. 2. Grouping characters from the alphabet set to form meaningful tokens. 3. Grouping meaningful tokens to form meaningful instructions. 4. Clustering the instructions in a meaningful and logical order to result in efficient computer programs.

PraNaMa is a programming language concentrating mainly on providing a programming feature in Kannada. Forming meaningful tokens here can lead to write efficient programs. The character set of Kannada PraNaMa is as follows. ). to of Kannada and 0 to 9 of English. efer table 8 for symbols used.

\t), new line (\n), carriage return (\r) etc.

Dept. Of CS & E, GEC, Hassan

Page 17

PraNaMa Scripting Language in Kannada

4.1 Tokens : A token is a smallest basic unit of a program. The tokens can be classified into the following groups :

might include _ underscore also. Example: , _ etc change when during the execution of the program. PraNaMa has the following constants.

alled the floating point constant.

constants.

stored, accessed or manipulated. The identifier which is used to store a value is called as variable. The variable is always different from that of keywords and no variable name can be same as that of a keyword. eration. Example : + , - , * , / etc
Dept. Of CS & E, GEC, Hassan Page 18

PraNaMa Scripting Language in Kannada

program. They are used along with well defined keywords or identifiers to give out special functions to the program. Example : {} , [ ] , etc

4.2 Data types: The data type[13] is a type of a variable that is stored in the memory while a variable is declared in the program. The general syntax for declaring variables of any datatype is as follows: Datatype variable1 = value1 , variable2 = value2 ,, variable = valuen ; PraNaMa is interpreted language and to give user a more generalized programming experience it includes only 3 basic datatypes as follows : ) : this datatype is a keyword that is used to define numbers. The numbers can be whole numbers, integers, floating point values. The data type is used to store the numeric values in the memory. Example : , = , ; () : this datatype is a keyword that is used to define strings. The variables declared of this datatype store string values in them and can be used for string manipulation purposes. PraNaMa considers even a single character as a string and there by provides wide string handling capability to the language. Example : =" " ; ) : this datatype is a keyword that is used to declare array of mixed datatype variables ( from above 2 types ). The array can include any values and can efficiently be used in reference type passing etc.

4.3 Operators:
Operators[12] are the symbols that are used to specify the particular operation on a set of variables. The operators can be classified into the following types:
Dept. Of CS & E, GEC, Hassan Page 19

PraNaMa Scripting Language in Kannada

Arithmetic Operators : The operators that are used to perform fundamental mathematical
operations like addition, subtraction, multiplication, division. PraNaMa accepts two operands for a particular arithmetic operator and thus gives out the result. There is a precedencerule to be followed by the operators which is BODMAS rule and can be explained as follows. o Brackets have the first precedence. o Of operators will have the second precedence. o Division operator will have third precedence. o Multiplication operator will have forth precedence. o Addition operator has the fifth precedence. o Subtraction operator has the sixth precedence.

Relational Operators : The relational operators are used to compare two operands and thus
return the result. The two operands can be variables or constants.

: As logical gates such as AND, OR and NOT whose ouput is 1 or 0, we also have logical operators. After evaluation, expression consisting of logical operators results in either true or false and hence such are called logical expressions.

into a memory location is called and assignment operator. Copying and storing into a memory location is called assigning and hence the name. the assignment operator is denoted by = sign.
Dept. Of CS & E, GEC, Hassan Page 20

PraNaMa Scripting Language in Kannada

4.4 Control statements : The order in which the statements are executed are called the control flow. The statements that are used to control the flow of execution of the program are called control statements. These statements alter the sequence of execution of the program. Based on the order in which the statements are executed, the various control statements are classified as follows.

4.5 Sequential statements :


The programmer writes a sequence of statements to do a specific activity. All these statements in a program are executed in order in which they appear in the program. These programming statements that are executed sequentially, that is one after the other, are called sequential control statements. The following program skeleton shows the sequence of flow of statements.

4.6 Branching statements :


In sequential execution of statements the computer surpasses every line and interprets it. Branching allows the skipping option of certain statements when its execution is not needed. There are five types of branching statements in PraNaMa and can be implemented according to the need. 1. The simple if statement( ) : It is a simple selection statement which allows for

skipping/executing of statements following it based on the condition mentioned to be true or false. Example :
Dept. Of CS & E, GEC, Hassan Page 21

PraNaMa Scripting Language in Kannada

2. The if else statement (

- - )

): The if- else statement is a selection statement.

If the condition mentioned is true the if scope is executed and if the condition is false the else scope is executed. Example :

3. The return statement ( ): The return statement returns the datatype mentioned in the function definition. Here the return statement can return the data types that are discussed already. Example:

Dept. Of CS & E, GEC, Hassan

Page 22

PraNaMa Scripting Language in Kannada

4.7 Loop statements :


The statements that allow the programmer to repeatedly execute a particular set of statements until a condition is true is called as loop statements. PraNaMa includes a loop statement called which is analogous to while loop in C. ( ( ): A set of statements might have to be repeated until a certain condition is reached and in such cases where a definite value is not known in prior the while statement is used. It allows the programmer to repeatedly execute a particular set of statements until a condition is true. Example

4.8 Arrays :
An array is a collection of data of same datatype. PraNaMa allows the user to add arrays in his/her programs which help in storing similar data items in a set format. The arrays here can be categorized into the following types : 1. Single dimensional arrays : The array which is a linear list of data items with only single array index to refer to them is called single dimension arrays. PraNaMa allows for the declaration of arrays with the following general syntax. Syntax : datatype variable[ index ] ; Example

Dept. Of CS & E, GEC, Hassan

Page 23

PraNaMa Scripting Language in Kannada

4.9 Functions

The language PraNaMa provides the feature of splitting up the program into well defined modules called functions (). The functions have a definite scope and canaccept parameters. They can even return results which can be stored on specific memory locations. There are two important elements for the functions in PraNaMa. They are as follows :

and a specific task is achieved. The function definition can be clearly understood with the following example.

is made in PraNaMa with a suffix of a keyword called

and then the function name with

the appropriate parameters. The function is thus called referring to the function table and executed. The function call looks something like this.

Dept. Of CS & E, GEC, Hassan

Page 24

PraNaMa Scripting Language in Kannada

Chapter 5
Screen Shots
1. Simple welcome program in PraNaMa.

2. Calculator program.

Dept. Of CS & E, GEC, Hassan

Page 25

PraNaMa Scripting Language in Kannada

Dept. Of CS & E, GEC, Hassan

Page 26

PraNaMa Scripting Language in Kannada

Chapter 6
Conclusion
PraNaMa is a scripting language interpreter which accepts input from a user and gives the output in Kannada. The application is implemented on Java platform and parses the scripts written in Kannada and generates results in the same language. The application allows the user to enjoy the scripting comfort in his/her language.

PraNaMa is primarily meant for those who can read and write only in their native language and those who are not well versed in English but are interested in learning computer programming. PraNaMa can be a stepping stone for those who do not know or know little English and plan to learn programming, by introducing them to the basic concepts of programming in their native language Kannada. Those who are used to conventional programming can also write programs using PraNaMa provided they know Kannada.

The interpreter scans every line written in the program and executes. The language has its own syntax which has to be followed when writing the script and is closely related to C language syntax. All important features that are expected of a scripting language are provided by the language, thus the user can use these small but powerful set of features to write programs and make himself familiar with programming before diving into much more complex languages like C, C++ and Java.

Dept. Of CS & E, GEC, Hassan

Page 27

PraNaMa Scripting Language in Kannada

References
[1] www.sourceforge.jflex.net-scanner generator for Java [2] http://byaccj.sourceforge.net/ - Yacc compatible parser [3] http://www.google.com/transliterate/Kannada - Transliteration APIs [4] www.sun.java.com- http://www.oracle.com/technetwork/java/api-141528.html [5] The Principles of Compiler Design, 4th edition by Jeffery Ulmann et.al. [6] The Complete Reference, Java by Herbert Schildt. [7]http://www.health.qld.gov.au/multicultural/interpreters/guidelines_int.pdf - Working with Interpreter Guidelines [8]http://www.stanford.edu/class/cs242/slides/2005/scripting.pdf - Scripting Languages [9] http://www.sensi.org/~ak/impit/studies/report.pdf - An overview of scripting languages [10] http://en.wikipedia.org/wiki/Interpreter_(computing) Advantages and disadvantages of using an Interpreter [11] http://en.wikipedia.org/wiki/Scripting_language - Working Guidelines for Scripting Languages [12]http://en.wikipedia.org/wiki/Operator- Precedence and associativity of operators [13]http://en.wikipedia.org/wiki/Data_type - Primitive and user-defined data types.

Dept. Of CS & E, GEC, Hassan

Page 28

Вам также может понравиться