Skip to content

Commit 67da6ef

Browse files
committed
import optimize
1 parent e71a487 commit 67da6ef

File tree

12 files changed

+31
-28
lines changed

12 files changed

+31
-28
lines changed

src/CodeGenerator/CodeGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import Syntax.Expression;
77
import Syntax.Operator;
88
import Syntax.Program;
9-
import Syntax.Type;
109

1110
import java.io.File;
1211
import java.io.FileWriter;
1312
import java.io.IOException;
14-
import java.util.*;
15-
import java.util.concurrent.TimeUnit;
13+
import java.util.ArrayList;
14+
import java.util.HashMap;
15+
import java.util.HashSet;
16+
import java.util.LinkedHashMap;
1617

1718

1819
public class CodeGenerator {

src/CodeGenerator/DefinedFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import Semantic.FunctionSet;
55
import Syntax.FunctionDeclaration;
66
import Syntax.ParamDeclaration;
7-
import Syntax.Statements;
87
import Syntax.Type;
98

109
import java.lang.reflect.InvocationTargetException;
@@ -255,6 +254,7 @@ protected static void timeToSec() {
255254
CodeGenerator.genCode("retv");
256255
CodeGenerator.genCode("end");
257256
}
257+
258258
protected static void makeTime() {
259259
CodeGenerator.genFunc("makeTime", 3, 2, 2);
260260
CodeGenerator.genCode("sym", 2, 1, 1);

src/Parser/Parser.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ private Program program() {
4747
Type t = type();
4848

4949
if (t.equals(Type.INT) && isMain()) {
50-
match(TokenType.Main); // int main
51-
match(TokenType.LeftParen); // (
52-
match(TokenType.RightParen); // )
53-
s = statements(); // Statements
50+
match(TokenType.Main); // int main
51+
match(TokenType.LeftParen); // (
52+
match(TokenType.RightParen); // )
53+
s = statements(); // Statements
5454
} else {
5555
String id = match(TokenType.Identifier);
5656

@@ -215,31 +215,31 @@ private Statement statement() {
215215
match(TokenType.Semicolon);
216216
return new Skip();
217217

218-
} else if (isIf()) { //if
218+
} else if (isIf()) { //if
219219
return IfStatement();
220220

221-
} else if (isLeftBrace()) { //block
221+
} else if (isLeftBrace()) { //block
222222
return block();
223223

224-
} else if (token.type().equals(TokenType.While)) { // while
224+
} else if (token.type().equals(TokenType.While)) { // while
225225
return WhileStatement();
226226

227-
} else if (token.type().equals(TokenType.Switch)) { // switch
227+
} else if (token.type().equals(TokenType.Switch)) { // switch
228228
return SwitchStatement();
229229

230-
} else if (token.type().equals(TokenType.For)) { // for
230+
} else if (token.type().equals(TokenType.For)) { // for
231231
return ForStatement();
232232

233-
} else if (token.type().equals(TokenType.Return)) { // return
233+
} else if (token.type().equals(TokenType.Return)) { // return
234234
return Return();
235235

236-
} else if (token.type().equals(TokenType.Break)) { // break
236+
} else if (token.type().equals(TokenType.Break)) { // break
237237
return Break();
238238

239-
} else if (token.type().equals(TokenType.Continue)) { // continue
239+
} else if (token.type().equals(TokenType.Continue)) { // continue
240240
return Continue();
241241

242-
} else { // expression
242+
} else { // expression
243243
return expression();
244244
}
245245
}

src/Syntax/Binary.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void display(int lev) {
4848
* 양 변이 void type인지 확인
4949
* <p>
5050
* 변수에 type에 맞게 해당 연산자를 맞게 불러오도록 함
51-
*
5251
*/
5352
@Override
5453
protected void V(HashMap<String, Init> declarationMap) {
@@ -590,7 +589,7 @@ public void genCode() {
590589
check(false, "Compiler error. never reach here. Binary genCode()");
591590
}
592591
break;
593-
592+
594593

595594
}
596595
}

src/Syntax/DateValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected void V(HashMap<String, Init> declarationMap) {
6262

6363
check(year >= 0, "year can not be negative value");
6464
check(month >= 0, "month can not be negative value");
65-
check(day >=0, "day can not be negative value");
65+
check(day >= 0, "day can not be negative value");
6666

6767
calendar = new GregorianCalendar(year, month - 1, day);
6868

src/Syntax/FunctionDeclaration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package Syntax;
22

33
import CodeGenerator.CodeGenerator;
4-
import CodeGenerator.SymbolTableElement;
54
import Semantic.FunctionInfo;
65

76
import java.util.ArrayList;
@@ -99,7 +98,7 @@ void display(int lev) {
9998

10099
/**
101100
* global 변수의 table을 가져와 해당 함수의 변수를 table에 추가
102-
* <p>
101+
* <p>
103102
* 추가된 table의 길이가 맞는지 확인
104103
* <p>
105104
* 함수 내부의 실행문의 v 호출

src/Syntax/IfStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void genCode() {
198198

199199
elseIfs.get(i).condition.genCode();
200200

201-
if (i == len - 1) {
201+
if (i == len - 1) {
202202
if (elses != null) {
203203
CodeGenerator.fjp(CodeGenerator.getElseBranch(ifNum));
204204

src/Syntax/Init.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract public class Init extends AbstractSyntax {
1212
/**
1313
* 변수의 type <tt>Type</tt>객체로 저장한다.
1414
*
15-
* @see Type
15+
* @see Type
1616
*/
1717
protected Type type;
1818
/**
@@ -53,6 +53,7 @@ public void genCode() {
5353
* 좌변 우변의 type이 타당한지 검사
5454
* <p>
5555
* 자동 형변환 까지 가능한 경우까지 검사
56+
*
5657
* @param init
5758
* @param variableType
5859
*/

src/Syntax/Operator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ void display(int lev) {
383383

384384
/**
385385
* 해당 type에 맞는 연산자를 반환
386+
*
386387
* @param op
387388
* @param type
388389
* @return

src/Syntax/Return.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class Return extends Statement {
2020

2121
/**
2222
* return 값이 있을 때의 생성자
23+
*
24+
* @param returnValue 반환 할 객체
2325
*/
2426
public Return(Expression returnValue) {
2527
this.returnValue = returnValue;
@@ -65,8 +67,8 @@ protected void V(HashMap<String, Init> declarationMap, Type functionType) {
6567
check(functionType.equals(Type.VOID),
6668
"must not have return value in void function.");
6769
} else {
68-
check(!functionType.equals(Type.VOID),
69-
"void function can not have return value");
70+
check(!functionType.equals(Type.VOID),
71+
"void function can not have return value");
7072

7173
returnValue.V(declarationMap);
7274

src/Syntax/SwitchStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void addCase(Value caseLiteral, ArrayList<Statement> statements) {
5555
* <p>
5656
* 두번 실행도리 경우(구문이 덮어씌여질 경우) 에러가난다.
5757
*
58-
* @param defaults 설정할 default의 <tt>Statement</tt>들의 <tt>ArrayList</tt>
58+
* @param defaults 설정할 default의 <tt>Statement</tt>들의 <tt>ArrayList</tt>
5959
*/
6060
public void setDefault(ArrayList<Statement> defaults) {
6161
check(defaults != null, "duplicated default in switch");

src/Syntax/Value.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/**
66
* 변수가 아닌 리터럴을 나타내는 구문
7-
*
7+
* <p>
88
* Abstract Syntax :
99
* Value = IntValue | BoolValue | FloatValue | CharValue | TimeValue | DateValue
1010
*/

0 commit comments

Comments
 (0)