Grammar evaluation of the MMJS language

6 downloads 17922 Views 185KB Size Report
HTML tags (using HTML instructions inside the code in MMJS) ... tipka x=120 y=150 datoteka=pocetak.jpg kamo=pocetak kanal=7 tipka x=195 ... This program converts list of letters, which is output of read_file/1 predicate into nested list. The.
Topic 10 : Multimedia Systems __________________________________________________________________________________________

Grammar evaluation of the MMJS language Alen Lovrenčić University of Zagreb Faculty for organization and informatics, Varaždin e-mail:[email protected]

Danijel Radošević University of Zagreb Faculty for organization and informatics, Varaždin e-mail:[email protected] Abstract: Multimedial Scripting Language of Higher Level (MMJS- from abbreviation of "Multimedijski jezik skripata više razine") is a new programming language. It's also a new multimedia technique, which tries to solve some problems with present technologies. MMJS is based on current trends in programming languages development, on development of multimedia systems and on needs of the third disciplines, like intelligent systems. The system where MMJS works consists of intelligent module which sends the instructions in MMJS to multimedial module, which executes that instructions, and gives the return information according to user input. There are three versions of MMJS interpreters today, and the current version works in network environment of Web. Keywords: MMJS, grammar evaluation, programming, multimedia, scripting languages

1. INTRODUCTION

Multimedial Scripting Language of Higher Level (MMJS- from abbreviation of "Multimedijski jezik skripata više razine") is a new programming language. It's also a new multimedia technique, which tries to solve some problems with present technologies. MMJS is based on current trends in programming languages development, on development of multimedia systems and on needs of the third disciplines, like intelligent systems. The current multimedia tools are not always useful for intelligent systems. Also, the current tools for making intelligent systems often have the lack of multimedia possibilities. There some other problems, like portability of intelligent multimedial applications, including the personalised multi-modal applications [1]. MMJS typically works in a system of two basic modules, one is called "Intelligent module" and covers the logic part of the program, and another is called "Multimedial module". The multimedial module covers multimedial presentation and interaction to users. It works as an interpreter for the MMJS (figure 1).

264

Topic 10 : Multimedia Systems __________________________________________________________________________________________

Figure 1: The system of two modules The intelligent module sends the instructions in communication language (MMJS) to multimedial module, which executes instructions, and put back information according to user input. There three versions of MMJS interpreters today, and they work in different multimedial environments (Macromedia Director, Windows operating systems and Web). The current version works in network environment of Web (figure 2).

Figure 2: MMJS in the web environment

2. AN OVERVIEW OF MMJS 2.1 Language concepts MMJS uses following language concepts: c.) concepts from structural programming languages: - control structures, - subroutines and - basic datatypes b.) concepts from scripting languages: - easy syntax, which improves programmers productivity, - using default values of parameters, which shortens the program code, - MMJS is an interpreter, like most of the scripting languages c.) other concepts:

265

Topic 10 : Multimedia Systems __________________________________________________________________________________________

- channels; each graphic element belongs to some channel (this concept is overtaken from Lingo, the language inside the Macromedia Director), - graphic objects (text, picture, button and input field) and - HTML tags (using HTML instructions inside the code in MMJS) 2.2 Language syntax MMJS has following syntax, according to [2]: [=]* Parameters define properties of multimedia objects and their values can be numeric or string constants. All parameters are optional, and their order gratuitous. All parameters whose value is not specified, has their previous values, or default values, if used for first. Such syntax is the same for all instructions, which simplifies programming. Instruction example: picture channel=3 file="Bye.jpg” x=250 y=200 This instruction puts the picture on the computer screen. The channel 3 is used (only one content of the same type can be on a screen at the same time), content is defined in file "Bye.jpg", and the center of picture is on coordinates 250,200. If there is following content after induced program line: picture file=”Simbols.jpg” all other parameters, which are not induced here will stay the same as in the previous line, i.e. the new picture (defined by a file "Simbols.jpg") will appear on the screen on the same position like previous. 2.3 The structure of multimedial application in MMJS Multimedial application in MMJS consists of a main program file (with extension .mms) and of modules files (with extension .mmm). Program modules are called by hyperlinks, which user activates by a mouse-click.

Figure 3: The structure of multimedial application in MMJS

266

Topic 10 : Multimedia Systems __________________________________________________________________________________________

2.4 The structure of a singular program module The singular program module (including the main program file) consists of the common part, which defines settings for all pages inside the series, and of procedures, which define particular pages. // Common part of the program module procedura . procedura Figure 3: The structure of a singular program module The common part usually defines background color, navigation buttons, font, size, style and color of characters, and also text in the heading and footer part of every page inside the series. Each procedure defines one singular slide inside the series. 2.5 The elements of multimedial application in MMJS The multimedial application in MMJS consists of one or more series of pages. Each series is defined by it's own program module. Elements of particular page are as follows [3]: - text - hyperlinks (calls of program modules and calls of html pages) - picture - animation - sound (which continues on a following pages) - button and - HTML tags (all other multimedial presentation elements can be reached by the HTML tags). Language instructions represent the most used multimedia functions and provide the implementation of elements mentioned above, as shown in the table 1. Instruction pisi postavi procedura slika tipka //

Meanings writes text, hyperlinks; sounds, html tags setting of the parameters defines one singular frame defines pictures, animations defines navigation button comment

Table 1: Sample of instructions of the MMJS

267

Topic 10 : Multimedia Systems __________________________________________________________________________________________

Parameters connected to instructions above are shown in the following table: Parameters Meanings X, Y object coordinates kanal channel of the graphic object sirina width of the graphic object tekst text for writting veza address of program module or html document datoteka file name (with content like text or picture) font font of characters velicina size of characters boja color of characters boja_pozadine slide background color kamo destination slide for navigation button Table 2: Sample of parameters of the MMJS instructions

3. EXAMPLE OF THE PROGRAM CODE IN MMJS This example represents the series of three slides. First of them is shown at figure 6. The full example can be reached at http://www.foi.hr/mmjs/example/ . postavi boja=#000000 visina=5 sirina=5 tipka x=120 y=150 datoteka=pocetak.jpg kamo=pocetak kanal=7 tipka x=195 y=150 datoteka=nazad.jpg kamo=nazad kanal=8 tipka x=270 y=150 datoteka=upitnik.jpg kamo=sadrzaj kanal=6 tipka x=345 y=150 datoteka=naprijed.jpg kamo=naprijed kanal=9 tipka x=420 y=150 datoteka=kraj.jpg kamo=kraj kanal=10 tipka x=495 y=150 datoteka=povratak.jpg kamo=povratak kanal=11

Common part of the program module (navigation keys,

procedura Poruka dekana pisi tekst="#frame1.html" procedures

procedura Temeljne informacije pisi tekst="#frame2.html" procedura Tehnička osnovica pisi tekst="#frame3.html"

Figure 5: The example of a singular program module

268

Topic 10 : Multimedia Systems __________________________________________________________________________________________

Figure 6: The first of the slides in example

4. GRAMMAR EVALUATION OF MMJS LANGUAGE In this paper definite clause grammar (DCG) is chosen for grammatical representation of MMJS language. DCG is a grammar that is implemented in modern Prolog-like languages. In this paper we are going to use DCG implemented in XSB HiLog, Prolog-like language of higher-order syntax. It gives us possibility to use XSB’s build-in grammar evaluation. All details about DCG and its evaluation in XSB can be found in [4]and [5]. 3.1. Preparing text for grammatical evaluation Before it is possible to evaluate an MMJS program with DCG it is necessary to prepare text of the program. Whole program has to be converted into the list of commands that are represented as lists of words. Firstly, it is necessary to read program from text file. That is the function of following predicate. It reads text file that represents the code of a program and creates simple list of letters from it. Program 1: read_file(LO):- get0(Y), Y \= -1 , read_file(LO1), atom_codes(Z,[Y]), LO = [Z|LO1]. read_file([]):-seen. The next task is to convert the flat list of letters into list of MMJS commands. Because MMJS is standard programming language and its code does not contain any special characters, it is easy to convert MMJS program into list of commands. Let us see the following program Program 2: atomize([X|LI],[[[X|G]|Z]|R]):- X\='=',X \= ' ', X\='"', atom_codes(X,[Y]), Y \= 13, atomize(LI,[[G|Z]|R]). 269

Topic 10 : Multimedia Systems __________________________________________________________________________________________

atomize([X|LI],[[[X]]|R]):- X\='=',X \= ' ', X\='"', atom_codes(X,[Y]), Y \= 13, atomize(LI,[[]|R]). atomize([' '|LI],[[[]|Y]|R]):- atomize(LI,[Y|R]). atomize(['='|LI],[[[],['=']|Y]|R]):-atomize(LI,[Y|R]). atomize(['"'|LI],[[['"'|G]|Z]|R]):atomize_string(LI,[[G|Z]|R]). atomize([X,_|LI],[[]|Z]):- atom_codes(X,[Y]), Y= 13, atomize(LI,Z). atomize([],[[]]). atomize_string([X|LI],[[[X|G]|Z]|R]):- X\='"', atomize_string(LI,[[G|Z]|R]). atomize_string(['"'|LI],[[['"'|G]|Z]|R]):atomize(LI,[[G|Z]|R]). atomize_string(['"'],[[['"']]]). This program converts list of letters, which is output of read_file/1 predicate into nested list. The output list from this predicate contains lists that represent commands of MMJS language. MMJS instruction begins at the beginning of the row and end with carriage return. So, one command of MMJS is one row of the text. The sixth atomize/2 clause recognizes carriage returns and separates commands of the language. Every command contains atoms or words of the language. Generally, words are separated with spaces. The third atomize/2 clause recognizes spaces and creates atoms of language. Specially, in MMJS, atom “=” is defined. This atom separates two other atoms, but between these three atoms there are no spaces. The fourth atomize/2 clause solves this case. atomize/2 predicate transforms atoms of the language into simple list of letters. The first and the second atomize/2 clauses create atoms of the language. The second one begins a new command, while the first one is used when atom is not first atom of the command. Another way to define an atom is to put it into quotas. Everything between quotas is string, and every string has to be treated as a single atom. When the first quota occurs, the fifth atomize/2 clause calls atomize_string/2. This predicate creates a single atom that begins with quota, goes through text and ends with another quota. When the second quota is found, control is return back to the atomize/2 predicate. It is easy to separate commands of the program and evaluate every command separately. For the syntactic evaluation of the command the grammar will be used. But, before we define the grammar, it is necessary to convert list that represents command again. Atoms that are represented as lists of letters have to be converted into strings. Following predicate does that. Program 3: prep_com([LI|R],[X|LOR]):-atom_chars(X,LI),prep_com(R,LOR). prep_com([],[]). The predicate comm/2 that takes from input list that represents the code of input program every single command and checks if the command is correct according to syntax of MMJS is defined in the following program. Program 4: comm([LI|R]):-prep_com(LI,LO),command(LO,[]),comm(R). comm([]). And finally, now we are ready to present the grammar that recognizes MMJS commands. As it can be seen from program above, main predicate that is called from outside of the grammar is predicate command/2.

270

Topic 10 : Multimedia Systems __________________________________________________________________________________________

Program 5: command command command command

--> --> --> -->

command_name. command_name,params. proc_def. comment.

proc_def --> ['procedura'],proc_params. proc_params --> [X], proc_params --> [X],proc_params,

{atom(X)}. {atom(X)}.

comment --> ['//'],proc_params.

command_name --> ['pisi'] | ['postavi'] | ['slika'] | ['tipka']. params --> param. params --> param,params. param --> param_channel | param_x |param_y | param_text | param_font | param_size | param_color | param_connection | param_file | param_width | param_height | param_back_color.

param_channel --> ['kanal','=',X], {atom_chars(X,L),number_chars(Y,L), integer(Y),Y>0,Y ['x','=',X], {atom_chars(X,L),number_chars(Y,L), integer(Y),Y>0}. param_y --> ['y','=',X], {atom_chars(X,L),number_chars(Y,L), integer(Y),Y>0}. param_text --> ['text','=',X],

{string(X)}.

param_font --> ['font','=',X],

{string(X)}.

param_size --> ['velicina','=',X], {atom_chars(X,L),number_chars(Y,L), integer(Y),Y>0}. param_color --> ['boja','=',X],

{hex_no(X)}.

param_connection --> ['veza','=',X],

{atom(X)}.

param_file --> ['datoteka','=',X],

{atom(X)}.

param_width --> ['sirina','=',X], {atom_chars(X,L),number_chars(Y,L), integer(Y),Y>0}. 271

Topic 10 : Multimedia Systems __________________________________________________________________________________________

param_height --> ['visina','=',X], {atom_chars(X,L),number_chars(Y,L), integer(Y),Y>0}. param_back_color --> ['boja_pozadine','=',X],{hex_no(X)}. As it can be seen from the grammar some predicates are used, that are not build-in predicates of XSB, so they have to be defined in order to grammar works properly. Predicates that have to be defined are string/1 and hex_no/1. The first of these two predicates checks if X is a string, within quotas, while the second one checks if X is a hexadecimal number, i.e. the atom that starts with ‘#’ character, followed by digits and letters from a to f. These two predicates enclose whole program that recognizes MMJS programs.

Program 6: string(X):-atom_chars(X,L),first(L,'"'),last(L,'"'). first([X|_],X). last([X],X). last([_|R],Y):-R\=[],last(R,Y). hex_no(X):-atom_chars(X,['#'|R]),hex(R). hex([G|R]):-hexa(G),hex(R). hex([]). hexa('0'). hexa('1'). hexa('2'). hexa('3'). hexa('4'). hexa('5'). hexa('6'). hexa('7'). hexa('8'). hexa('9'). hexa('a'). hexa('b'). hexa('c'). hexa('d'). hexa('e'). hexa('f'). hexa('A'). hexa('B'). hexa('C'). hexa('D'). hexa('E'). hexa('F'). Now, in order to check the syntax of some program in MMJS, it is necessary to open the file that contains the code of the program by build-in predicate see/1. After that, predicate read_file/1 that reads from the input file has to be called. After read_file/1 predicate atomize/2 is 272

Topic 10 : Multimedia Systems __________________________________________________________________________________________

called. This predicate transforms flat list of characters into list that contains lists that represent MMJS commands. After that predicate comm/1 is called. This predicate transforms an input list and calls grammar that checks grammatical correctness of commands from input file. And at the end, input file has to be closed by using seen/0 build-in predicate. That is done in the following command: Program 6: :-read(X),see(X),read_file(LO),atomize(LO,LA),comm(LA),seen.

5. CONCLUSION MMJS is a new programming language, based on current trends in programming languages development, on development of multimedia systems and on needs of the third disciplines, especially intelligent systems for better multimedial presentation of information. MMJS has only a few instructions, but it's level is extremely high, which increases programmers productivity. Some of the language concepts are overtaken from structural programming languages, some from the scripting languages, and some from existing multimedia tools. The system where MMJS works consists of intelligent module that sends the instructions in MMJS to multimedial module, which executes that instructions, and gives the return information according to user input. There three versions of MMJS interpreters today, and the current version works in network environment of Web. The future development should include some new language concepts, enlarge the instruction set and give more efficient interpreter.

6. REFERENCES [1] Kliček, B. (1997), "Modeli i procedure inteligentnog sustava za personalizaciju multimedijskih prezentacija", Medijska istraživanja, Vol. 4, No. 2, 173-198 [2] Radošević, D. (2000), "Multimedijski jezik skripata više razine", master thesis, Faculty of organization and informatics, Varaždin [3] Radošević, D.,Kliček B. (2001), "Development of a Higher-level Multimedia Scripting Language", submitted to Iti 2001 Conference, june 19.-22. 2001, Pula, Croatia [4] Sagonas, K.; Swift, T.; Warren, D.S.; Friere, J.; Rao, P; Dawson, S.; Kifer, M. (2000): The XSB System Version 2.2: Volume 1: Programmers Manual, XSB Group, Department of Computer Science at SUNY at Stony Brooks [5] Warren, D. S. (1995): Programming in Tabled Prolog. (very) DRAFT, Department of Computer Science at SUNY at Stony Brooks, New York,

273