public class SymphonieApp extends JApplet
構文解析を行い解析木をXML文字列またはjson文字列で得ます。
アプレットですが画面は持たず、構文解析関数のみ持ちます。 主にWEB上でJavascriptから呼び出すためのクラスです。
構文定義法、入力解析法などの総合的な説明を パッケージ otsu.symphonieの説明 で行ってありますので、まずご覧ください。
標準的使い方
標準的な使い方はHTML上で
例えば次のようなHTML記述で使用することができます。
<applet id="app" archive="../../../java/symphonie.jar" code="otsu.symphonie.SymphonieApp" width="1" height="1" display="none"></applet> <hr> <style type="text/css">math{ display:block }</style> <p id=m1><math><mfrac><mn>MathML</mn><mn>generator</mn></mfrac><math></p> <script type="text/javascript"> var syntax=[ '//#omit expression term-list term op-term math-list' ,'//#omit mrow_0s function paren func integ vect' ,'@ ::= ?"[ \\t\\n\\f\\r\\u3000]+"' ,'@ ::= ?"//.*$"' ,'@mn ::= ?"[0-9]+\\.[0-9]+" | ?"[0-9]+" ' ,'@mi ::= ?"[a-zA-Z][0-9a-zA-Z]*" | "π"/"π" | "ⅇ"' ,'@mo ::= "+" | "-" | "/" | "*" | "=" ' ... 省略 ... ,'math-list ::= {math &";"}' ,'math ::= expression' ,'expression::= {op-term}' ,'op-term ::= mo | term' ,'term ::= mn | mi | mrow | msqrt | mfrac | msup | msub | mroot |vect' ,' | integ | func | mrow.paren | munderover.sum | mrow.diff' ,'mrow ::= "{" expression "}"' ... 省略 ... ,'mrow.integ ::= mrow.0 mrow.diff']; function $E(id){ return document.getElementById(id); } var symphonie; function initSymp(appId){ symphonie= document.getElementById(appId); symphonie.readSyntaxLines(syntax); } function test(txt,target){ var math= symphonie.parseString(txt,"te"); alert(math); // MathML記述確認 $E(target).innerHTML=math; } initSymp('app'); </script> <input type=text id=in style="width:20em" value="a=1-d%{c-b}*(d+e)"> <input type=button value="MathMLに変換" onClick='test($E("in").value,"m1")'>
なお、アプレットのid直ではなく一旦getElementByIdでelementを 取得しているのは一部ブラウザではid直では動かない事があるから です。
symphonieで用意されるその他の解析法
SyntaxConverterの他、symphonieには
(1)構文解析を行い要素毎にアプリケーションに情報を上げる
SyntaxReader
(2)構文解析を行い、構文木文字列(XML/JSON)を得る
SyntaxConverter
(3)ファイルを解析し構文木を表示するコマンド
java -jar symphonie.jar syntax-check
(4)構文解析を行い、構文木をXML-Documentで得る
SyntaxDom
などを用意してあります。。
Component.BaselineResizeBehaviorBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| コンストラクタと説明 |
|---|
SymphonieApp() |
| 修飾子とタイプ | メソッドと説明 |
|---|---|
String |
parse(String source_,
String option_)
構文解析を行い構文木を得る.
|
String |
parseLines(String[] source_,
String option_)
文字列配列に入れられた文を解析する。
|
String |
parseStream(BufferedReader br_,
String option_) |
String |
parseString(String source_,
String option_)
構文解析を行い構文木を得る.
|
String |
readSyntaxLines(String[] syntax_)
構文定義をセットする.
|
String |
readSyntaxString(String syntax_)
構文定義をセットする.
|
String |
setSyntax(String syntax_)
構文定義をセットする.
|
getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, updatedestroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stopadd, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validateaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic String setSyntax(String syntax_)
Symphonie拡張BNF形式の構文定義をセットします。
セット完了後parse(String,String)により構文解析が
可能となります。
syntax_ - 構文定義文字列public String readSyntaxString(String syntax_)
Symphonie拡張BNF形式の構文定義をセットします。
セット完了後parse(String,String)により構文解析が
可能となります。
syntax_ - 構文定義文字列public String readSyntaxLines(String[] syntax_)
Symphonie拡張BNF形式の構文定義をセットします。
セット完了後parse(String,String)により構文解析が
可能となります。
配列の各要素は行と解釈されます。文字列自体に改行コードは不要です。
syntax_ - 構文定義文字列public String parseString(String source_, String option_)
readSyntaxString(String),
readSyntaxLines(String[])で設定された構文定義に従い、構文解析
を行います。
XMLの形式を指定するオプションがあります。オプションは文字列で
文字により指定します
| 指定文字 | 説明 |
| "t" |
トークン文字列をタグで囲みます。 指定が無い場合タグ内のtext属性に入ります。 t指定なし <op text="+"/> t指定あり <op>+</op> |
| "r" |
トークン名とトークンテキストが同じでもtext属性
を付加します。('t'オプションが無い場合)
r指定なし <and/> r指定あり <and text="and"/> |
| "e" |
&をエスケープしません
t指定なし <op>&PlusMinus;</op> t指定あり <op>&PlusuMinus;</op> |
| "j" | json形式で出力します(試験中)。この指定がある場合他の指定は無効です。 |
source_ - 解析対象文option_ - t:トークンをタグで囲む。e:&をエスケープしないpublic String parse(String source_, String option_)
parseString(String,String)と同じsource_ - 解析対象文option_ - t:トークンをタグで囲む。e:&をエスケープしないpublic String parseLines(String[] source_, String option_)
readSyntaxString(String),
readSyntaxLines(String[])で設定された構文定義に従い、
文字列配列に入れられた文を解析します。配列の各要素は行と解釈されます。
文字列そのものに改行は不要です。
source_ - 解析対象文option_ - オプションparseString(String,String)参照public String parseStream(BufferedReader br_, String option_)