發表文章

目前顯示的是有「compiler」標籤的文章

[compiler]hw7 參考資料

作業規定 操作測試流程  java Yuhina < test.yu  ( 產生 test.j) java -jar  jasim123.jar < test.j java test     要可以執行成功 實作方法 1. 紀錄使用的register跟變數的對應關係 2.做好IR  跟jasmincode 的對應 3. 根據AST利用 IR表示轉成jasmin code 參考資料 0. intermediate code OP( e1 , e2 )   => string op(string operator , string  e1, string e2); =>OP:= ADD | SUB |  MUL | DIV | MOD //arithmetic | AND | OR                                     //bit logic | EQ | NEQ | LT | GT | LE | GE      //comparisons NAME(n) =>string name(string n );  //return register number or labol ESEQ(s,e) =>  strimg eseq(string s,string e); //return e CODE(i) => string code(string i );//constant integer MEM(e) => load e register CALL(ef , e0 , e1 , e2,... ) => function call  string call( string fName,string[] args) MOVE(dest , e) => string move(string dest,string e ) => move(dese,e):=dest = TEMP(t) //assign to temporary t | dest = MEM(e) // assign to location e EXP(e) => string exp(e) 執行e 忽略結果 SEQ(s1,s2 , ... ,sn) => string seq(str...

[hw5]作業規定與參考資料

[語法檢查] 建置一個symble table    1.作 type - vriable name之間的關連 2.function name - parameters, result type and local variables 之間的關連 3. function parameter -type之間的關連 4.class name - variable declarations之間的關連 [yuhina types] int , boolean , string , int[] ,class name [error check] 1. Check for undeclared variables 根據目前的scope 查詢symbol table檢查是否宣告 2.Multiple variable declarations 根據目前的scope 查詢symbol table檢查是否宣告 3.Type checking [必須提供的type check] 1. arithmetic expression 2.assignment statement 3. function call [java doc] hashtable http://java.sun.com/j2se/1.5.0/docs/api/java/util/Hashtable.html symboltable http://www.jstatcom.com/javadoc/com/jstatcom/model/SymbolTable.html [reference] jtb document   http://compilers.cs.ucla.edu/jtb/jtb-2003/docs.html Types and Type Checking http://lambda.uta.edu/cse5317/notes/node30.html

[hw2]YuhianLexer

specification : identify : 由letter digit '_'(underscore)組成 key word : "globle" , "variables" , "prototypes" , "classes" , "classdef" , "class" ,"int" , "boolean", "string" , "true" , "false" , "unless" , "else" , "else" , "do" , "while", "print" , "return", "readInt" , "readString". Keywords and identifiers must be separated by white space or a token that is neither a keyword or an identifier. skip: " "(white space) ,"\t"(tab),"\n"(newline) operator : Binary : && , || , == , < , > , + , - , * , / , % . Unary operator : ! Other special characters: “{“, “}”, “(“, “)”, “[“, “]”, “;”, “,”, “.”, “=“ command : line comment // comment /**/ Unclosed comments are lexical errors String : "string"=>sequece of characters en...