OSDN Git Service

いろいろと変更。
authorhikarupsp <hikarupsp@users.sourceforge.jp>
Wed, 16 Oct 2013 17:38:29 +0000 (02:38 +0900)
committerhikarupsp <hikarupsp@users.sourceforge.jp>
Wed, 16 Oct 2013 17:38:29 +0000 (02:38 +0900)
独自言語をOSECPUバイナリにコンパイルする機能を実装中。

ai.js
aiext.js
aimemory.js
aisub.js
aithink.js
elcc.js [new file with mode: 0644]
index.html
memory.txt
test.elc [new file with mode: 0644]

diff --git a/ai.js b/ai.js
index 455a5df..e3c3da0 100644 (file)
--- a/ai.js
+++ b/ai.js
@@ -1,6 +1,6 @@
 //AI004
 
-function AI(){
+function AI(messageBoxDOMObject, debugBoxDOMObject){
        //ブラウザチェック
        this.checkBrowser();
        //サブクラス
@@ -19,28 +19,87 @@ function AI(){
        this.debugBoxBuffer = "";
        this.maxDebugStringLength = 0xffff;
        this.downloadBox = null;
+       //
+       this.setMessageBoxDOMObject(messageBoxDOMObject);
+       this.setDebugBoxDOMObject(debugBoxDOMObject);
+       this.modeList = [
+               this.UUID_Mode_Standard,
+               this.UUID_Mode_ReadMemory,
+               this.UUID_Mode_SaveMemory,
+               this.UUID_Mode_InternalConsole,
+               this.UUID_Mode_CompileELCHNOS_OSECPU,
+       ];
+       this.modeProcessList = [
+               this.inputProcess_Standard,
+               this.inputProcess_ReadMemory,
+               this.inputProcess_SaveMemory,
+               this.inputProcess_InternalConsole,
+               this.inputProcess_CompileELCHNOS_OSECPU,
+       ];
+       this.mode = this.UUID_Mode_Standard;
+       this.processByMode = this.inputProcess_Standard;
+
+       this.debug("AI system initialized.\n");
 }
 AI.prototype = {
-       UUID_MemoryFile: "42e11880-62b8-46ea-a1c4-481264d4440d",
+       UUIDStrLen: 36,
+       UUID_Mode_Standard: "1186f6f2-c7c4-4532-8f8f-c7dea883825f", 
+       UUID_Mode_ReadMemory: "42e11880-62b8-46ea-a1c4-481264d4440d",
+       UUID_Mode_SaveMemory: "52360c62-6a8a-4f6e-8bdd-43381996e996",
+       UUID_Mode_InternalConsole: "4ca6ed1a-e62e-470b-9d7b-e332f709e48f",
+       UUID_Mode_CompileELCHNOS_OSECPU: "17ddde48-7d4c-498f-98d8-3e73f8845028",
        sendToAI: function(str){
+               var p, strbaseindex;
+               
                this.debug("**** Start inputting ****\n");
                
-               this.debug("input:[" + str + "]\n");
-               this.input.appendInput(str);
-               this.think.inputting = true
+               //まず入力文字を#で分割したリストを取得
+               var ary = str.split("#");
+               //モードを確認しつつ実行
+               p = -(this.UUIDStrLen + 1);
+               for(;;){
+                       strbaseindex = p + 1 + this.UUIDStrLen;
+                       p = str.indexOf("#", strbaseindex);
+                       if(p == -1){
+                               //終端まで到達
+                               //それ以前の文字列を入力
+                               this.processByMode(str.substring(strbaseindex));
+                               break;
+                       }
+                       //まずはモード変更の直前までの文字列を入力
+                       this.processByMode(str.substring(strbaseindex, p));
+                       //モード変更要求
+                       this.changeMode(str.substring(p + 1, p + 1 + this.UUIDStrLen));
+               }
                
                this.debug("**** End inputting ****\n");
        },
-       sendTextFromFileToAI: function(str, name, modDate){
-               this.debug("sendTextFromFileToAI: " + modDate.toLocaleString() + " [" + name + "]\n");
-               if(str.indexOf(this.UUID_MemoryFile) == 0){
-                       //UUID_MemoryFileが先頭にあるならば、これは記憶データファイルである。
-                       this.debug("UUID_MemoryFile Found.\n");
-                       this.memory.loadMemory(str);
+       changeMode: function(modeUUIDStr){
+               for(var i = 0, iLen = this.modeList.length; i < iLen; i++){
+                       if(this.modeList[i] == modeUUIDStr){
+                               break;
+                       }
+               }
+               if(this.modeList.length <= i){
+                       this.debug("Unknown mode-UUID. Mode was NOT changed.\n");
+                       return;
+               }
+               if(this.modeList[i] === this.UUID_Mode_SaveMemory){
+                       this.debug("Mode exectute for this once.\n    uuid:" + this.modeList[i] + "\n");
+                       this.modeProcessList[i].call(this);
                } else{
-                       //まるごとAIへ入力してみる
-                       this.sendToAI(str);
+                       this.debug("Mode changed\n    from:" + this.mode + "\n    to  :" + this.modeList[i] + "\n");
+                       this.mode = this.modeList[i];
+                       this.processByMode = this.modeProcessList[i];
                }
+               
+       },
+       sendTextFromFileToAI: function(str, name, modDate){
+               //ファイルからの読み込み時は、読み込み終了後に読み込み以前のモードに戻る。
+               this.debug("sendTextFromFileToAI: " + modDate.toLocaleString() + " [" + name + "]\n");
+               var oldmode = this.mode;
+               this.sendToAI(str);
+               this.changeMode(oldmode);
        },
        setMessageBoxDOMObject: function(mBoxObj){
                this.messageBox = mBoxObj;
@@ -92,4 +151,52 @@ AI.prototype = {
                        this.message("System> このブラウザは記憶保存(HTML5FileAPI)に対応していません。", true);
                }
        },
+       inputProcess_Standard: function(str){
+               this.debug("**** Start Processing (Standard) ****\n");
+               
+               this.debug("input:[" + str + "]\n");
+               this.input.appendInput(str);
+               this.think.inputting = true;
+               
+               this.debug("**** End Processing (Standard) ****\n");
+       },
+       inputProcess_ReadMemory: function(str){
+               this.debug("**** Start Processing (ReadMemory) ****\n");
+               
+               this.memory.loadMemory(str);
+               
+               this.debug("**** End Processing (ReadMemory) ****\n");
+       },
+       inputProcess_SaveMemory: function(str){
+               this.debug("**** Start Processing (SaveMemory) ****\n");
+               
+               this.memory.saveMemory();
+               
+               this.debug("**** End Processing (SaveMemory) ****\n");
+       },
+       inputProcess_InternalConsole: function(str){
+               this.debug("**** Start Processing (InternalConsole) ****\n");
+               if(str == "exit"){
+                       this.debug("Exit InternalConsole.\n");
+                       this.changeMode(this.UUID_Mode_Standard);
+               } else if(str == "show cwl"){
+                       //show candidateWordList
+                       this.wordRecognition.sortCandidateWordListByWordCount();
+                       this.wordRecognition.computeEachWordLevel();
+                       this.wordRecognition.sortCandidateWordListByWordLevel();
+                       this.wordRecognition.debugShowCandidateWordList();
+               } else{
+                       this.debug("Unknown command [" + str + "].\n");
+               }
+               
+               this.debug("**** End Processing (InternalConsole) ****\n");
+       },
+       inputProcess_CompileELCHNOS_OSECPU: function(str){
+               this.debug("**** Start Processing (CompileELCHNOS_OSECPU) ****\n");
+               
+               var cc = new ELCHNOSCompiler(this);
+               cc.compile(str);
+               
+               this.debug("**** End Processing (CompileELCHNOS_OSECPU) ****\n");
+       },
 }
index 809f107..dddfb12 100644 (file)
--- a/aiext.js
+++ b/aiext.js
@@ -122,7 +122,18 @@ Array.prototype.stableSort = function(f){
        for(var i = 0;i < this.length;i++){
                delete this[i].__id__;
        }
-};
+}
+
+Array.prototype.splitByArray = function(separatorList){
+       //Array中の文字列をseparatorList内の文字列でそれぞれで分割し、それらの文字列が含まれた配列を返す。
+       var retArray = new Array();
+       
+       for(var i = 0, iLen = this.length; i < iLen; i++){
+               retArray = retArray.concat(this[i].splitByArray(separatorList));
+       }
+       
+       return retArray;
+}
 
 //文字列関連
 String.prototype.replaceAll = function(org, dest){
@@ -141,6 +152,7 @@ String.prototype.compareLeftHand = function (search){
 }
 String.prototype.splitByArray = function(separatorList){
        //リスト中の文字列それぞれで分割された配列を返す。
+       //separatorはそれ以前の文字列の末尾に追加された状態で含まれる。
        var retArray = new Array();
        retArray[0] = this;
        
@@ -150,7 +162,7 @@ String.prototype.splitByArray = function(separatorList){
                        tmpArray[k] = retArray[k].split(separatorList[i]);
                        if(tmpArray[k][tmpArray[k].length - 1] == ""){
                                tmpArray[k].splice(tmpArray[k].length - 1, 1);
-                               if(tmpArray[k] && tmpArray.length > 0){
+                               if(tmpArray[k] && tmpArray[k].length > 0){
                                        for(var m = 0; m < tmpArray[k].length; m++){
                                                tmpArray[k][m] += separatorList[i];
                                        }
@@ -167,6 +179,35 @@ String.prototype.splitByArray = function(separatorList){
        
        return retArray;
 }
+
+String.prototype.splitByArraySeparatorSeparated = function(separatorList){
+       //リスト中の文字列それぞれで分割された配列を返す。
+       //separatorも分割された状態で含まれる。
+       var retArray = new Array();
+       retArray[0] = this;
+       
+       for(var i = 0; i < separatorList.length; i++){
+               var tmpArray = new Array();
+               for(var k = 0; k < retArray.length; k++){
+                       var tmpArraySub = retArray[k].split(separatorList[i]);
+                       tmpArray[k] = new Array();
+                       for(var m = 0, mLen = tmpArraySub.length - 1; m < mLen; m++){
+                               if(tmpArraySub[m] != ""){
+                                       tmpArray[k].push(tmpArraySub[m]);
+                               }
+                               tmpArray[k].push(separatorList[i]);
+                       }
+                       if(tmpArraySub[tmpArraySub.length - 1] != ""){
+                               tmpArray[k].push(tmpArraySub[m]);
+                       }
+               }
+               retArray = new Array();
+               retArray = retArray.concat.apply(retArray, tmpArray);
+       }
+       
+       return retArray;
+}
+
 String.prototype.trim = function(str){
        return this.replace(/^[       ]+|[          ]+$/g, "").replace(/\n$/g, "");
 }
index d10e929..b1136d9 100644 (file)
@@ -9,7 +9,7 @@ function AI_Memory(env){
 AI_Memory.prototype = {
        saveMemory: function(){
                var m = this.env.IOManager;
-               var s = this.env.UUID_MemoryFile + "\n";
+               var s = "#" + this.env.UUID_Mode_ReadMemory + "\n";
                var cl = this.root;
                for(var i = 0, iLen = cl.length; i < iLen; i++){
                        if(cl[i] instanceof AI_MemoryTag){
@@ -34,6 +34,9 @@ AI_Memory.prototype = {
                                this.env.debug(i + ": " + e + "\n");
                                continue;
                        }
+                       if(d === undefined){
+                               continue;
+                       }
                        q = d.type;
                        if(q == AI_MemoryTag.prototype.Type_CandidateWord){
                                t = new AI_CandidateWordTag();
@@ -50,7 +53,7 @@ AI_Memory.prototype = {
                var s = this.root.isIncluded(tag, function(a, b){ return (a.uuid == b.uuid); });
                if(s){
                        this.env.debug("appendMemoryTag: duplicated UUID " + tag.uuid + ", overwritten.\n");
-                       this.root.removeAnObject(s);
+                       this.removeMemoryTagByObject(s);
                }
                //ルートに追加
                this.root.push(tag);
@@ -59,4 +62,8 @@ AI_Memory.prototype = {
                        this.candidateWordList.push(tag);
                }
        },
+       removeMemoryTagByObject: function(obj){
+               this.root.removeAnObject(obj);
+               this.candidateWordList.removeAnObject(obj);
+       },
 }
index c130caa..c913029 100644 (file)
--- a/aisub.js
+++ b/aisub.js
@@ -30,8 +30,9 @@ AI_Input.prototype = {
                "?",
                "\n",
        ],
-       appendInput: function(str){
-               var sList = str.splitByArray(this.sentenceSeparator);
+       appendInput: function(input){
+               //inputはStringとArrayが使用できる
+               var sList = input.splitByArray(this.sentenceSeparator);
                
                this.sentenceList = this.sentenceList.concat(sList)
        },
index 68d62ed..9d1c08a 100644 (file)
@@ -13,12 +13,6 @@ AI_Think.prototype = {
                                if(s === undefined){
                                        this.inputting = false;
                                        
-                                       this.env.wordRecognition.sortCandidateWordListByWordCount();
-                                       this.env.wordRecognition.computeEachWordLevel();
-                                       this.env.wordRecognition.sortCandidateWordListByWordLevel();
-                                       this.env.wordRecognition.debugShowCandidateWordList();
-                                       this.env.memory.saveMemory();
-                                       
                                        break;
                                }
                                this.env.message("User> " + s + "\n", true);
diff --git a/elcc.js b/elcc.js
new file mode 100644 (file)
index 0000000..c2719f3
--- /dev/null
+++ b/elcc.js
@@ -0,0 +1,417 @@
+// ELCHNOSCompiler for AI004
+
+function ELCHNOSCompiler(env){
+       this.env = env;
+       
+       this.structure = new Array();
+       this.currentStructure = this.structure;
+       this.structureStack = new Array();
+}
+ELCHNOSCompiler.prototype = {
+       keyWordList: [
+               "\n",
+               "\t",
+               " ",
+               "{",
+               "}",
+               "(",
+               ")",
+               ";",
+               "//",
+               "/*",
+               "*/",
+               ",",
+               "[",
+               "]",
+               "=",
+               "+",
+               "-",
+               "*",
+               "/",
+       ],
+       errorMessageList: [
+               "Trap.",
+               "Incompatible value attribute.",
+               "Unexpected identifier."
+       ],
+       
+       Flag_Sign_Signed                        : 0x00000001,
+       Flag_Sign_Unsigned                      : 0x00000002,
+       
+       compile: function(str){
+               var line = str.split("\n");
+               var separated = str.splitByArraySeparatorSeparated(this.keyWordList);
+               
+               //コメント削除
+               var commentLineStartIndex = -1;
+               var commentBlockStartIndex = -1;
+               var commentBlockCount = 0;
+               var linesInCommentBlock = 0;
+               for(var i = 0, iLen = separated.length; i < iLen; i++){
+                       var s = separated[i];
+                       if(commentLineStartIndex == -1){
+                               if(s == "//"){
+                                       //行コメント開始
+                                       commentLineStartIndex = i;
+                               }
+                       } else{
+                               if(s == "\n"){
+                                       //行コメント終了
+                                       var len = i - commentLineStartIndex;
+                                       separated.splice(commentLineStartIndex, len);
+                                       iLen -= len;
+                                       i -= len;
+                                       commentLineStartIndex = -1;
+                               }
+                       }
+                       if(s == "/*"){
+                               //ブロックコメント開始
+                               if(commentBlockCount == 0){
+                                       commentBlockStartIndex = i;
+                               }
+                               commentBlockCount++;
+                       } else if(s == "*/"){
+                               //ブロックコメント終了
+                               commentBlockCount--;
+                               if(commentBlockCount == 0){
+                                       var len = i - commentBlockStartIndex + 1;
+                                       var padding = new Array();
+                                       padding.push(commentBlockStartIndex);
+                                       padding.push(len);
+                                       for(var j = 0, jLen = linesInCommentBlock; j < jLen; j++){
+                                               padding.push("\n");
+                                       }
+                                       separated.splice.apply(separated, padding);
+                                       i -= len;
+                                       iLen -= len;
+                                       linesInCommentBlock = 0;
+                               } else if(commentBlockCount < 0){
+                                       this.env.debug("Too many block comment closure [].\n");
+                                       return;
+                               }
+                       } else if(commentBlockCount < 0 && s == "\n"){
+                               linesInCommentBlock++;
+                       }
+               }
+               
+               //不要な文字を削除
+               separated.removeAllObject("\t");
+               separated.removeAllObject(" ");
+               
+               var currentExpression = null;
+               var numValSignFlag = 0;
+               var numValBits = 0;
+               var pointerCount = 0;
+               var lineCount = 1;
+               var blockLevel = 0;
+               var DestinationOperand = null;
+               var mode = 0;
+               var unexpected = false;
+               var errno = 2;
+               var o;
+               var f;
+                       //次に期待する値を示す。
+                       // 0: 何が来るかわからない
+                       //
+                       //10: 変数・定数の前置属性・型・または識別子
+                       //11: 変数・定数の識別子またはポインタ属性
+                       //12: 変数・定数の後置属性・初期化式または終端記号、もしくは連続した変数宣言の区切り
+                       //13: 変数・定数の初期化式または終端記号、もしくは連続した変数宣言の区切り
+                       //14: 配列長の数値部分
+                       //15: 配列長指定終了の閉じ括弧
+                       //16: 初期化式の開始括弧もしくは値
+                       //17: 初期化式の値部分または終了括弧
+                       //18: 初期化式の区切りまたは終了括弧
+                       //19: 終端記号
+                       //
+                       //50: 関数名
+                       //51: 引数開始括弧
+                       //52: 引数or引数終了括弧
+                       //53: 引数区切りor引数終了括弧
+                       //54: 関数内部開始括弧
+                       //
+                       //60: 識別子に対する何らかの操作の開始
+                       //
+                       //71: 評価式の内容または終端記号
+                       
+               for(var i = 0, iLen = separated.length; i < iLen; i++){
+                       var s = separated[i].toLowerCase();
+                       //this.env.debug((i + 1) + ":" + s + "\n");
+                       
+                       if(s == "\n"){
+                               //デバッグ用行数カウント
+                               lineCount++;
+                               continue;
+                       //予約語
+                       } else if(s == "signed" && (mode == 0 || mode == 10)){
+                               //符号あり
+                               if(numValSignFlag == 0){
+                                       numValSignFlag |= this.Flag_Sign_Signed;
+                                       mode = 10;
+                               } else{
+                                       unexpected = true;
+                                       errno = 1;
+                               }
+                       } else if(s == "unsigned" && (mode == 0 || mode == 10)){
+                               //符号なし
+                               if(numValSignFlag == 0){
+                                       numValSignFlag |= this.Flag_Sign_Unsigned;
+                                       mode = 10;
+                               } else{
+                                       unexpected = true;
+                                       errno = 1;
+                               }
+                       } else if(s == "char"  && (mode == 0 || mode == 10 || mode == 11)){
+                               //char 8bit符号あり
+                               numValBits = 8;
+                               mode = 11;
+                       } else if(s == "int" && (mode == 0 || mode == 10 || mode == 11)){
+                               //int 8bit符号あり
+                               numValBits = 32;
+                               mode = 11;
+                       } else if(s == ";" && (mode == 0 || mode == 12 || mode == 13 || mode == 19 || mode == 71)){
+                               if(mode == 12 || mode == 13 || mode == 19){
+                                       //変数または定数の定義終了
+                                       numValBits = 0;
+                                       numValSignFlag = 0;
+                                       console.log(currentExpression);
+                                       currentExpression = null;
+                                       mode = 0;
+                               } else if(mode == 71){
+                                       //評価式終端
+                                       console.log(currentExpression);
+                                       currentExpression = null;
+                                       mode = 0;
+                               } else{
+                                       unexpected = true;
+                               }
+                       } else if(s == "=" && (mode == 13 || mode == 60)){
+                               if(mode == 13){
+                                       //変数・定数初期化式開始
+                                       mode = 16;
+                               } else if(mode == 60 && DestinationOperand){
+                                       //代入操作追加
+                                       var f = new ELCHNOSCompiler_ExpressionStructure_Expression(this.env);
+                                       f.pushOperand(DestinationOperand);
+                                       f.pushOperator(s);
+                                       
+                                       this.currentStructure.push(f);
+                                       currentExpression = f;
+                                       
+                                       DestinationOperand = null;
+                                       mode = 71;
+                               } else{
+                                       unexpected = true;
+                               }
+                       } else if(s == "*" && (mode == 11)){
+                               //ポインタ属性の付加
+                               pointerCount++;
+                       } else if(s == "," && (mode == 18 || mode == 12 || mode == 13)){
+                               if(mode == 18){
+                                       //初期化式の区切り
+                                       mode = 17;
+                               } else if(mode == 12 || mode == 13){
+                                       //連続した変数宣言の区切り
+                                       console.log(currentExpression);
+                                       currentExpression = null;
+                                       mode = 11;
+                               } else{
+                                       unexpected = true;
+                               }
+                       //括弧系
+                       } else if(s == "[" && (mode == 12)){
+                               //配列の長さの定義開始
+                               mode = 14;
+                       } else if(s == "]" && (mode == 15)){
+                               //配列の長さの定義終了
+                               mode = 13;
+                       } else if(s == "{" && (mode == 16 || mode == 54)){
+                               if(mode == 16){
+                                       //初期化式の開始括弧
+                                       mode = 17;
+                               } else if(mode == 54){
+                                       //54: 関数内部開始括弧
+                                       currentExpression = null;
+                                       mode = 0;
+                               } else{
+                                       unexpected = true;
+                               }
+                       } else if(s == "}" && (mode == 17 || mode == 18 || mode == 0)){
+                               if(mode == 17 || mode == 18){
+                                       //初期化式の終了括弧
+                                       mode = 19;
+                               } else if(mode == 0){
+                                       if(this.structureStack.length > 0){
+                                               console.log(this.currentStructure);
+                                               this.restoreCurrentStructure;
+                                       } else{
+                                               unexpected = true;
+                                       }
+                               }
+                       } else if(s == "(" && (mode == 51)){
+                               //51: 引数開始括弧
+                               mode = 52;
+                       } else if(s == ")" && (mode == 52 || mode == 53)){
+                               //52: 引数or引数終了括弧
+                               //53: 引数区切りor引数終了括弧
+                               mode = 54;
+                       //リストにない予約語
+                       } else if(s == "procedure" && (mode == 0)){
+                               //関数宣言
+                               var f = new ELCHNOSCompiler_ExpressionStructure_Function();
+                               this.changeCurrentStructure(f.structure)
+                               currentExpression = f;
+                               
+                               mode = 50;
+                       //予約語以外
+                       } else if(mode == 11){
+                               //変数または定数の宣言
+                               var v = new ELCHNOSCompiler_ExpressionStructure_Variable();
+                               v.bits = numValBits;
+                               v.isSigned = (numValSignFlag == 0) ? false : (0 != (numValSignFlag & this.Flag_Sign_Signed));
+                               s = separated[i];
+                               v.isPointer = (pointerCount != 0) ? true : false;
+                               pointerCount = 0;
+                               if(s.length > 0){
+                                       v.identifier = s;
+                                       
+                                       this.currentStructure.push(v);
+                                       currentExpression = v;
+                                       
+                                       mode = 12;
+                               } else{
+                                       unexpected = true;
+                               }
+                       } else if(mode == 14){
+                               currentExpression.length = parseInt(s);
+                               mode = 15;
+                       } else if(mode == 17){
+                               //定数値のみ対応
+                               currentExpression.initValue.push(parseInt(s));
+                               mode = 18;
+                       } else if(mode == 50){
+                               currentExpression.identifier = s;
+                               mode = 51;
+                       } else{
+                               //現在のスコープを検索
+                               o = this.currentStructure.isIncluded(s, function(aryobj, obj){ return (aryobj.identifier == obj) });
+                               if(!o){
+                                       //グローバルスコープを検索
+                                       o = this.structure.isIncluded(s, function(aryobj, obj){ return (aryobj.identifier == obj) });
+                               }
+                               if(mode == 0){
+                                       //DestinationOperandから操作式は始まる
+                                       if(o){
+                                               DestinationOperand = o;
+                                               mode = 60;
+                                       } else{
+                                               unexpected = true;
+                                       }
+                               } else if(mode == 71){
+                                       //評価式オペランド
+                                       if(o){
+                                               currentExpression.pushOperand(o);
+                                       } else if(!isNaN(s)){
+                                               currentExpression.pushOperand(s);
+                                       } else{
+                                               unexpected = true;
+                                       }
+                               } else{
+                                       unexpected = true;
+                               }
+                       }
+                       if(unexpected){
+                               //期待されていない値
+                               this.raiseError(2, lineCount, [s, mode]);
+                               return;
+                       }
+               }
+       },
+       raiseError: function(errno, lineCount, infoArray){
+               if(errno < 0 || this.errorMessageList.length <= errno){
+                       this.env.debug(lineCount + ":Error" + errno.toString().toUpperCase() + ":Unknown\n");
+               } else{
+                       this.env.debug(lineCount + ":Error" + errno.toString().toUpperCase() + ":" + this.errorMessageList[errno] + "\n");
+               }
+               if(infoArray){
+                       this.env.debug("  ErrorInfo:" + infoArray.toString() + "\n");
+               }
+       },
+       changeCurrentStructure: function(newstructure){
+               this.structureStack.push(this.currentStructure);
+               this.currentStructure = newstructure;
+       },
+       restoreCurrentStructure: function(){
+               this.currentStructure = this.structureStack.pop();
+       }
+}
+
+function ELCHNOSCompiler_ExpressionStructure_Variable(){
+       this.bits = 0;
+       this.length = 0;
+       this.isSigned = false;
+       this.isPointer = false;
+       this.identifier = null;
+       this.initValue = new Array();
+}
+ELCHNOSCompiler_ExpressionStructure_Variable.prototype = {
+
+}
+
+function ELCHNOSCompiler_ExpressionStructure_Function(){
+       this.structure = new Array();
+       this.identifier = null;
+}
+ELCHNOSCompiler_ExpressionStructure_Function.prototype = {
+
+}
+
+function ELCHNOSCompiler_ExpressionStructure_Expression(env){
+       this.env = env;
+       this.evalStack = new Array();
+       this.evalOperatorStack = new Array();
+       this.lastOperatorPriority = ELCHNOSCompiler_ExpressionStructure_Expression.prototype.operatorPriorityList.length;
+}
+ELCHNOSCompiler_ExpressionStructure_Expression.prototype = {
+       operatorPriorityList: [
+               "/",
+               "*",
+               "-",
+               "+",
+               //"/=",
+               //"+=",
+               //"-=",
+               //"+=",
+       ],
+       pushOperand: function(identifier){
+               this.evalStack.push(identifier);
+       },
+       pushOperator: function(operator){
+               var p = this.getOperatorPriority(operator);
+               if(this.lastOperatorPriority >= p){
+                       //とりあえずとっておく
+                       this.evalOperatorStack.push(operator);
+               } else{
+                       //優先順位がより高い演算子を先に積んでおき、そのあと自分をとっておく
+                       for(var i = 0, iLen = this.evalOperatorStack.length; i < iLen; i++){
+                               var o = this.evalOperatorStack.pop();
+                               if(this.getOperatorPriority(o) < p){
+                                       this.evalStack.push(o);
+                               } else{
+                                       this.evalOperatorStack.push(o);
+                                       break;
+                               }
+                       }
+                       this.evalOperatorStack.push(operator);
+               }
+               this.lastOperatorPriority = p;
+       },
+       getOperatorPriority: function(operator){
+               for(var i = 0, iLen = this.operatorPriorityList.length; i < iLen; i++){
+                       if(this.operatorPriorityList[i] == operator){
+                               break;
+                       }
+               }
+               return i;
+       },
+}
\ No newline at end of file
index 6b550cf..153d112 100644 (file)
 <script type="text/javascript" src="./aimemtag.js" charset="UTF-8"></script>
 <script type="text/javascript" src="./aithink.js" charset="UTF-8"></script>
 <script type="text/javascript" src="./aiwrcgnz.js" charset="UTF-8"></script>
+<script type="text/javascript" src="./elcc.js" charset="UTF-8"></script>
 <script type="text/javascript">
 var mainAI = null;
 var inputBoxObj = null;
 onload = function() {
-       mainAI = new AI();
+       mainAI = new AI(document.getElementById("messageBox"), document.getElementById("debugBox"));
        inputBoxObj = document.getElementById("inputBox");
        inputBoxObj.onkeydown = sendToAI;
-       mainAI.setMessageBoxDOMObject(document.getElementById("messageBox"));
-       mainAI.setDebugBoxDOMObject(document.getElementById("debugBox"));
        mainAI.downloadBox = document.getElementById("downloadBox");
        // Setup the dnd listeners.
        var dropZone = document.getElementById('inputBox');
index 3c6c041..9fc205c 100644 (file)
@@ -1,4 +1,4 @@
-42e11880-62b8-46ea-a1c4-481264d4440d
+#42e11880-62b8-46ea-a1c4-481264d4440d
 var t={id:'c0c70830-9447-8c0e-c684-889e05d7a458',type:'2fba8fc1-2b9a-46e0-8ade-455c0bd30637',cDate:'Mon, 23 Sep 2013 15:28:40 GMT',data:{s:'人工知能',c:3,l:1}};t;
 var t={id:'27fb9485-7f03-61a3-bdf4-f94cc93b8145',type:'2fba8fc1-2b9a-46e0-8ade-455c0bd30637',cDate:'Mon, 23 Sep 2013 15:28:40 GMT',data:{s:'ia',c:1,l:1}};t;
 var t={id:'7456f248-3791-d60d-cfe3-b8c8ee5e7dec',type:'2fba8fc1-2b9a-46e0-8ade-455c0bd30637',cDate:'Mon, 23 Sep 2013 15:28:40 GMT',data:{s:'知能',c:3,l:1}};t;
diff --git a/test.elc b/test.elc
new file mode 100644 (file)
index 0000000..a3eaa3b
--- /dev/null
+++ b/test.elc
@@ -0,0 +1,37 @@
+#17ddde48-7d4c-498f-98d8-3e73f8845028
+
+unsigned char table[32] = {
+       196, 100, 187,  61, 164,  29, 129,   9,
+        90,   5,  53,  17,  23,  44,   7,  81,
+         7, 119,  23, 156,  53, 183,  90, 195,
+       129, 191, 164, 171, 187, 139, 196, 100,
+};
+
+procedure main()
+{
+       int x0, y0, x1, y1, col, i, j;
+       unsigned char *p, *q;
+
+       p = table;
+       for (i = 0; i != 15; i++) {
+               x0 = *p;
+               p++
+               y0 = *p;
+               p++
+               
+               q = table;
+               for (j = -8; j != 8; j++) {
+                       x1 = *q;
+                       q++;
+                       x1 = *q;
+                       q++;
+                       col = i - j;
+                       if (col <= 0){
+                               col = 1 - col;
+                       }
+                       if (col <= 7) {
+                               junkApi_drawLine(1 + 4, x0, y0, x1, y1, col);
+                       }
+               }
+       }
+}
\ No newline at end of file