From 256f898cce65af055b9732403c145e6bdbfd0177 Mon Sep 17 00:00:00 2001 From: c-my Date: Sun, 23 Dec 2018 10:24:47 +0800 Subject: [PATCH] update struct --- res/SimpleGrammar.txt | 3 ++- src/com/compiler/parser/LLParser.java | 4 ++-- src/com/compiler/parser/ParserGenerator.java | 2 ++ src/com/compiler/parser/Symbol.java | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/res/SimpleGrammar.txt b/res/SimpleGrammar.txt index 38c6ec1..25b1fb3 100644 --- a/res/SimpleGrammar.txt +++ b/res/SimpleGrammar.txt @@ -36,7 +36,8 @@ third->second third1 third1->second_operator PUSH second GEQ third1|$ second->first second1 second1->first_operator PUSH first GEQ second1|$ -first->IDENTIFIER PUSH|CONSTANT PUSH|( calculation ) +first->IDENTIFIER PUSH maybe_struct|CONSTANT PUSH|( calculation ) +maybe_struct->. IDENTIFIER PUSH_MEMBER|$ type_name->INT|FLOAT|DOUBLE|CHAR diff --git a/src/com/compiler/parser/LLParser.java b/src/com/compiler/parser/LLParser.java index ea6174e..3e9be05 100644 --- a/src/com/compiler/parser/LLParser.java +++ b/src/com/compiler/parser/LLParser.java @@ -56,7 +56,6 @@ abstract class LLParser { Stack capacityStack = new Stack<>(); Stack structStack = new Stack<>(); - boolean isStruct = false; String currentStruct = ""; str.add(endSym); @@ -225,7 +224,8 @@ abstract class LLParser { break; case END_STRUCUT: currentStruct = ""; - isStruct = false; + break; + case PUSH_MEMBER: break; } continue; diff --git a/src/com/compiler/parser/ParserGenerator.java b/src/com/compiler/parser/ParserGenerator.java index 58f657b..c658cee 100644 --- a/src/com/compiler/parser/ParserGenerator.java +++ b/src/com/compiler/parser/ParserGenerator.java @@ -69,6 +69,8 @@ public class ParserGenerator { 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")) + symbolString.add(new Symbol(sym, Symbol.ActionType.PUSH_MEMBER)); else if (ParserTest.isTerminal(sym)) symbolString.add(new Symbol(sym, Symbol.SymbolType.Terminal)); else diff --git a/src/com/compiler/parser/Symbol.java b/src/com/compiler/parser/Symbol.java index 6b6161a..5fbb27f 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 + , GEQ_IF, END_IF, BEGIN_ELSE, GEQ_WHILE, END_WHILE, GEQ_PRINT, GEQ_BREAK, GEQ_CONTINUE, BEGIN_STRUCT, END_STRUCUT, PUSH_MEMBER } public String getId() {