Commit d4655f1c authored by Dr. Michael Petter's avatar Dr. Michael Petter

first part of variants integrated

parent 1b86cf3d
...@@ -30,7 +30,7 @@ public class Compiler { ...@@ -30,7 +30,7 @@ public class Compiler {
XMLElement elem = (XMLElement)sem.rule.rhs(0).get(); XMLElement elem = (XMLElement)sem.rule.rhs(0).get();
// Remove unwanted unary branch chains from the syntax tree // Remove unwanted unary branch chains from the syntax tree
elem = SyntaxTreeTransform.removeUnaryChains(elem); //elem = SyntaxTreeTransform.removeUnaryChains(elem);
// Dump DoM into XML-String via output stream // Dump DoM into XML-String via output stream
XMLOutputFactory outFactory = XMLOutputFactory.newInstance(); XMLOutputFactory outFactory = XMLOutputFactory.newInstance();
......
...@@ -486,6 +486,7 @@ public class Generate ...@@ -486,6 +486,7 @@ public class Generate
Action act = rule.onSucc[0]; Action act = rule.onSucc[0];
inline(e,"reject(" + cache + ")"); inline(e,"reject(" + cache + ")");
if (tree) { if (tree) {
out.line("setVariant(0);");
out.line("sem.$TREE$"+rule.name+"();"); out.line("sem.$TREE$"+rule.name+"();");
} }
if (act==null) if (act==null)
...@@ -511,10 +512,9 @@ public class Generate ...@@ -511,10 +512,9 @@ public class Generate
{ {
Action succ = rule.onSucc[i]; Action succ = rule.onSucc[i];
Action fail = rule.onFail[i]; Action fail = rule.onFail[i];
String outtree=""; String outtree="";
if (tree) outtree="sem.$TREE$"+rule.name+"();"; if (tree) outtree="setVariant("+i+");sem.$TREE$"+rule.name+"();";
if (succ==null) if (succ==null)
out.line("if (" + ref(rule.rhs[i]) + ") { "+outtree+" return accept(" + cache + "); }"); out.line("if (" + ref(rule.rhs[i]) + ") { "+outtree+" return accept(" + cache + "); }");
else if (succ.and) else if (succ.and)
...@@ -829,7 +829,8 @@ public class Generate ...@@ -829,7 +829,8 @@ public class Generate
out.line(" elems.add((XMLElement)rhs(i).get());"); out.line(" elems.add((XMLElement)rhs(i).get());");
out.line(" }"); out.line(" }");
out.line(" if (elems.size()==0) lhs().put(new XMLElement.Terminal(new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos()),\""+rule.name+"\",lhs().text(),new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos())));"); out.line(" if (elems.size()==0) lhs().put(new XMLElement.Terminal(new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos()),\""+rule.name+"\",lhs().text(),new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos())));");
out.line(" else lhs().put(new XMLElement.NonTerminal(\""+rule.name +"\",0,elems.toArray(new XMLElement[0])));");
out.line(" else lhs().put(new XMLElement.NonTerminal(\""+rule.name +"\",lhs().getVariant(),elems.toArray(new XMLElement[0])));");
out.line("}"); out.line("}");
} }
......
...@@ -179,6 +179,10 @@ public class ParserBase implements mouse.runtime.CurrentRule ...@@ -179,6 +179,10 @@ public class ParserBase implements mouse.runtime.CurrentRule
current = p; current = p;
} }
protected void setVariant(int var){
current.variant=var;
}
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Accept Rule // Accept Rule
//------------------------------------------------------------------- //-------------------------------------------------------------------
......
...@@ -149,7 +149,7 @@ public class ParserTest extends ParserMemo ...@@ -149,7 +149,7 @@ public class ParserTest extends ParserMemo
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Accept Rule // Accept Rule
//------------------------------------------------------------------- //-------------------------------------------------------------------
protected boolean accept(Cache c) protected boolean accept(Cache c)
{ {
super.accept(); super.accept();
traceAccept(c,traceRules); traceAccept(c,traceRules);
...@@ -159,7 +159,7 @@ public class ParserTest extends ParserMemo ...@@ -159,7 +159,7 @@ public class ParserTest extends ParserMemo
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Accept Inner // Accept Inner
//------------------------------------------------------------------- //-------------------------------------------------------------------
protected boolean acceptInner(Cache c) protected boolean acceptInner(Cache c)
{ {
super.acceptInner(); super.acceptInner();
traceAccept(c,traceInner); traceAccept(c,traceInner);
......
...@@ -61,6 +61,7 @@ public class Phrase ...@@ -61,6 +61,7 @@ public class Phrase
final int start; final int start;
final int startline; final int startline;
final int startcolumn; final int startcolumn;
int variant = -1;
int end; int end;
int endline; int endline;
int endcolumn; int endcolumn;
...@@ -142,6 +143,9 @@ public class Phrase ...@@ -142,6 +143,9 @@ public class Phrase
public int getEndColumn(){ public int getEndColumn(){
return endcolumn; return endcolumn;
} }
public int getVariant(){
return variant;
}
//----------------------------------------------------------------- //-----------------------------------------------------------------
// Get text // Get text
//----------------------------------------------------------------- //-----------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment