diff --git a/res/SimpleGrammar.txt b/res/SimpleGrammar.txt index 25b1fb3..647cf0a 100644 --- a/res/SimpleGrammar.txt +++ b/res/SimpleGrammar.txt @@ -1,7 +1,7 @@ program->struct_declear program|declear program|calculation ; program|condition program|cycle program|array_declear program|print_func ; program|break_keyword ; program|$ -print_func->PRINT calculation GEQ_PRINT +print_func->PRINT calculation GEQ_PRINT|PRINTLN calculation GEQ_PRINTLN declear->type_name PUSH IDENTIFIER PUSH declear1 declear1->; FILL|= declear2 diff --git a/src/com/compiler/Main.java b/src/com/compiler/Main.java index cbfe7db..73c8f95 100644 --- a/src/com/compiler/Main.java +++ b/src/com/compiler/Main.java @@ -32,7 +32,7 @@ public class Main { catch (Exception e){ e.printStackTrace(); } -// System.out.println(result); + System.out.println(result); // System.out.println(Tables.SymbolTable); // System.out.println(Tables.quaternaryList); diff --git a/src/com/compiler/parser/LLParser.java b/src/com/compiler/parser/LLParser.java index 23b9713..d489741 100644 --- a/src/com/compiler/parser/LLParser.java +++ b/src/com/compiler/parser/LLParser.java @@ -191,6 +191,10 @@ abstract class LLParser { Symbol prntSym = semStack.pop(); Tables.quaternaryList.add(new Quaternary("PRINT", "", "", prntSym.getValue())); break; + case GEQ_PRINTLN: + Symbol prntlnSym = semStack.pop(); + Tables.quaternaryList.add(new Quaternary("PRINTLN", "", "", prntlnSym.getValue())); + break; case FILL_EMPTY_ARRAY: var emptyArrayCapacity = Integer.parseInt(capacityStack.pop().getValue()); var arrayTypeSym = semStack.pop(); diff --git a/src/com/compiler/parser/ParserGenerator.java b/src/com/compiler/parser/ParserGenerator.java index c658cee..0c80d4b 100644 --- a/src/com/compiler/parser/ParserGenerator.java +++ b/src/com/compiler/parser/ParserGenerator.java @@ -65,11 +65,13 @@ public class ParserGenerator { symbolString.add(new Symbol(sym, Symbol.ActionType.GEQ_CONTINUE)); else if (sym.equals("GEQ_PRINT")) symbolString.add(new Symbol(sym, Symbol.ActionType.GEQ_PRINT)); + else if (sym.equals("GEQ_PRINTLN")) + symbolString.add(new Symbol(sym, Symbol.ActionType.GEQ_PRINTLN)); else if (sym.equals("BEGIN_STRUCT")) symbolString.add(new Symbol(sym, Symbol.ActionType.BEGIN_STRUCT)); else if (sym.equals("END_STRUCT")) symbolString.add(new Symbol(sym, Symbol.ActionType.END_STRUCUT)); - else if(sym.equals("PUSH_MEMBER")) + else if (sym.equals("PUSH_MEMBER")) symbolString.add(new Symbol(sym, Symbol.ActionType.PUSH_MEMBER)); else if (ParserTest.isTerminal(sym)) symbolString.add(new Symbol(sym, Symbol.SymbolType.Terminal)); diff --git a/src/com/compiler/parser/Symbol.java b/src/com/compiler/parser/Symbol.java index 5fbb27f..d38ff57 100644 --- a/src/com/compiler/parser/Symbol.java +++ b/src/com/compiler/parser/Symbol.java @@ -40,7 +40,7 @@ public class Symbol { , FILL_EMPTY_ARRAY //填空数组 , PUSH_CAPACITY //将数组容量压栈 , GEQ //生成运算四元式 - , GEQ_IF, END_IF, BEGIN_ELSE, GEQ_WHILE, END_WHILE, GEQ_PRINT, GEQ_BREAK, GEQ_CONTINUE, BEGIN_STRUCT, END_STRUCUT, PUSH_MEMBER + , GEQ_IF, END_IF, BEGIN_ELSE, GEQ_WHILE, END_WHILE, GEQ_PRINTLN ,GEQ_PRINT, GEQ_BREAK, GEQ_CONTINUE, BEGIN_STRUCT, END_STRUCUT, PUSH_MEMBER } public String getId() { diff --git a/src/com/compiler/utils/StringSet.java b/src/com/compiler/utils/StringSet.java index 256e326..e12cf35 100644 --- a/src/com/compiler/utils/StringSet.java +++ b/src/com/compiler/utils/StringSet.java @@ -15,7 +15,7 @@ public class StringSet { "goto", "if", "int", "long", - "print", + "print", "println", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef",