SlideServe
Menu
Préférences
© SlideServe · v2026

Java Script Interpreter using DOM API

hakan avatar
7 diapositives · 200 Views · Sep 15, 2014

Develop a Java interpreter using DOM API to execute XML scripts defining variables and functions. Complete missing parts in HW2.java to load and execute XML scripts.

Java Script Interpreter using DOM API - slide 1
01 / 7Java Script Interpreter using DOM API
1 / 17

Télécharger la présentation

Java Script Interpreter using DOM API
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Homework 2 • Reference DTD (xmath.dtd): • http://xml.cs.ncuc.edu.tw/courses/xmlta/xmlta2009/HWs/hw2/xmath.dtd • Reference sample xmath script: • http://xml.cs.ncuc.edu.tw/courses/xmlta/xmlta2009/HWs/hw2/script1.xmath • The above dtd defines a simple script language for defining double variables and single-variable polynomial function.

  2. Sample script : Script1.xml • non-xml version: a = -2 define f(x) = 3x^2 - 5x + 7 define g(x) = 3x^3 -5x^2 +2 combine h = f + g list functions list variables print "The value of f(1) is" f(1) "." print "The value of f(a) is " f(a) "." print "The derivative of g' is " g' "."

  3. Expected output a = -2.0 f(x) = 3x^2 - 5x + 3 g(y) = 3y^3 - 5y^2 + 2 h(x) = 3x^3 - 2x^2 - 5x + 5 The value of f(1) is 1.0. The value of h(a) is -17.0. The derivative of g is g'(y) = 9y^2 - 10y.

  4. Script1.xml : XMLVersion <?xml version="1.0" ?> <!DOCTYPE script SYSTEM "xmath.dtd" > <script> <assign var="a"><number>-2</number></assign> <define name="f" var="x" > <polynomial var="x" > <term c="3" exp="2" /> <term c="-5" exp="1" /> <term c="3" exp="0" /> </polynomial> </define> <define name="g" var="y" > <polynomial var="y" > <term c="3" exp="3" /> <term c="-5" exp="2" /> < term c="2" exp="0" /> </polynomial></define>

  5. <combine name="h" type="add" fun1="f" fun2="g" /> <list option="variables" /> <list option="functions" /> <print> <literal>The value of f(1) is </literal> <funEval name="f" ><number>1</number></funEval> <literal>.</literal> </print> <print><literal>The value of h(a) is </literal> <funEval name="h"><varRef>a</varRef></funEval> <literal>.</literal></print> <print><literal>The derivative of g is </literal> <derivative>g</derivative><literal>.</literal></print> </script>

  6. HW2 • HW2 : • This homework is about using DOM API to write a Java interpreter that can load a script file in XML format that are valid w.r.t the previous DTD, and then execute it and produce correct result. • We have prepare an almost-completed program HW2.java for you. • Read carefully and try to understand how this program works. • Complete all missing part in HW2.java

  7. Notes • We have prepared 3 classes for representing polynomial, terms and functions, respectively. • see http://xml.cs.nccu.edu.tw/courses/xmlta/xmlta2009/hws/hw2/src/xmlta/xmath" • To help grading, please remember that your main java classes should be named as HW2. it should have a main(String[]) method accepting as input an input file name. So we can invoke them as follows: >java HW2 script1.xmath • I have packaged all related files into one eclipse project hw2.zip, which you can download and import it into your local eclipse workspace. • After completing your homework, you need just submit HW2.java to c3@cs.ncuc.edu.tw.