From c366dacc334fe2e35835164f5a37d3eebb2ca6d5 Mon Sep 17 00:00:00 2001 From: adam Date: Wed, 11 Jan 2006 00:33:35 -0500 Subject: [PATCH] checkpoint harmony darcs-hash:20060111053335-5007d-295b23e9726b5c25815915709f7bae60c027d792.gz --- TODO | 3 - src/edu/berkeley/sbp/GSS.java | 20 +++--- src/edu/berkeley/sbp/Parser.java | 1 - tests/regression.tc | 127 +++++++++++++++++++++----------------- 4 files changed, 76 insertions(+), 75 deletions(-) diff --git a/TODO b/TODO index b383c90..d03ba8a 100644 --- a/TODO +++ b/TODO @@ -13,9 +13,6 @@ Immediately - more natural phrasing of metagrammar? - finalize metagrammar and rdp-op's - - should Union.add() be there? - - should Atom.top() be there? - - decent/better error messages - fix the location stuff, it's broken diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java index e4859d4..cff543d 100644 --- a/src/edu/berkeley/sbp/GSS.java +++ b/src/edu/berkeley/sbp/GSS.java @@ -39,7 +39,7 @@ class GSS { public Forest.Ref finalResult; /** all nodes, keyed by the value returned by code() */ - /*private*/ HashMap hash; /* ALLOC */ + /*private*/ IntPairMap hash; /* ALLOC */ /** the number of nodes in this phase */ private int numNodes; @@ -70,7 +70,7 @@ class GSS { tail.clear(); waiting.clear(); performed.clear(); - hash = new HashMap(); + hash = new IntPairMap(); good = false; closed = false; numNodes = 0; @@ -172,7 +172,7 @@ class GSS { * @param start the earliest part of the input contributing to this node (used to make merging decisions) */ public boolean newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction) { - Node p = hash.get(code(state, parent==null?null:parent.phase())); + Node p = hash.get(state, parent==null?null:parent.phase()); if (p != null) return newNode2(p, parent, pending, state, fromEmptyReduction); else return newNode3(parent, pending, state, fromEmptyReduction); } @@ -273,9 +273,8 @@ class GSS { reducing = true; if (reducing_list==null || reducing_list.length < hash.size()) reducing_list = new Phase.Node[hash.size() * 4]; - Collection hv = hash.values(); - hv.toArray(reducing_list); - int num = hv.size(); + hash.toArray(reducing_list); + int num = hash.size(); for(int i=0; i { int count = 1; for(;;) { loc = input.getLocation(); - //current.checkFailure(); current.reduce(); Forest forest = current.token==null ? null : shiftedToken((T)current.token, loc); GSS.Phase next = gss.new Phase(current, this, current, input.next(count, gss.resets, gss.waits), loc, forest); diff --git a/tests/regression.tc b/tests/regression.tc index e2ae422..ae452e9 100644 --- a/tests/regression.tc +++ b/tests/regression.tc @@ -69,6 +69,16 @@ testcase { } testcase { + input "aabb"; + output "xbx:{abab:{a b}}"; + + x !::= ~[] + s ::= x* b x* => xbx + b ::= [ab][ab] => abab + &~ ( "aa" | "bb" ) +} + +testcase { input "12111211"; output "ac:{{2 1 2 1}}"; //output "a:{{2 1 2 1}}"; @@ -255,61 +265,62 @@ testcase { q ::= [a-z]++ => "q" } -testcase { - - input " - - - - while x>0 - while y>0 - foo() - bar() - - - while x>0 - while y>0 - foo() - bar() - - - -"; - output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}} while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}"; - -indent !::= ww -outdent !::= " " outdent " " - | " " (~[]*) "\n" - -w !::= " " | "\n" | "\r" -ws !::= w* -ww !::= sp* -sp !::= " " -any !::= ~[]* - -s ::= ws statement ws statement ws => smt - -block ::= "\n" indent blockBody - &~ "\n" outdent ~[\ ] ~[]* - -blockBody ::= statement - > statement ws blockBody => "sbb" - -statement ::= call - | ^"while" expr block /ws - -expr ::= ident - | call - | expr ^">" expr /ws - | num - -call ::= expr "()" /ws - -num ::= [0-9]++ - -ident ::= [a-z]++ &~ keyword -keyword ::= "if" | "then" | "else" | "while" - - - -} +//testcase { +// +// input " +// +// +// +// while x>0 +// while y>0 +// foo() +// bar() +// +// +// while x>0 +// while y>0 +// foo() +// bar() +// +// +// +//"; +// output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}} while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}"; +// +//indent !::= ww +//outdent !::= " " outdent " " +// | " " (~[]*) "\n" +// +//w !::= " " | "\n" | "\r" +//ws !::= w* +//ww !::= sp* +//sp !::= " " +//any !::= ~[]* +// +//s ::= ws statement ws statement ws => smt +// +//block ::= "\n" indent blockBody +// &~ "\n" outdent ~[\ ] ~[]* +// +//blockBody ::= statement +// > statement ws blockBody => "sbb" +// +//statement ::= call +// | ^"while" expr block /ws +// +//expr ::= ident +// | call +// | expr ^">" expr /ws +// | num +// +//call ::= expr "()" /ws +// +//num ::= [0-9]++ +// +//ident ::= [a-z]++ &~ keyword +//keyword ::= "if" | "then" | "else" | "while" +// +// +// +//} +// \ No newline at end of file -- 1.7.10.4