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 {
XMLElement elem = (XMLElement)sem.rule.rhs(0).get();
// 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
XMLOutputFactory outFactory = XMLOutputFactory.newInstance();
......
......@@ -486,6 +486,7 @@ public class Generate
Action act = rule.onSucc[0];
inline(e,"reject(" + cache + ")");
if (tree) {
out.line("setVariant(0);");
out.line("sem.$TREE$"+rule.name+"();");
}
if (act==null)
......@@ -511,10 +512,9 @@ public class Generate
{
Action succ = rule.onSucc[i];
Action fail = rule.onFail[i];
String outtree="";
if (tree) outtree="sem.$TREE$"+rule.name+"();";
if (tree) outtree="setVariant("+i+");sem.$TREE$"+rule.name+"();";
if (succ==null)
out.line("if (" + ref(rule.rhs[i]) + ") { "+outtree+" return accept(" + cache + "); }");
else if (succ.and)
......@@ -829,7 +829,8 @@ public class Generate
out.line(" elems.add((XMLElement)rhs(i).get());");
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(" 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("}");
}
......
......@@ -179,6 +179,10 @@ public class ParserBase implements mouse.runtime.CurrentRule
current = p;
}
protected void setVariant(int var){
current.variant=var;
}
//-------------------------------------------------------------------
// Accept Rule
//-------------------------------------------------------------------
......
......@@ -149,7 +149,7 @@ public class ParserTest extends ParserMemo
//-------------------------------------------------------------------
// Accept Rule
//-------------------------------------------------------------------
protected boolean accept(Cache c)
protected boolean accept(Cache c)
{
super.accept();
traceAccept(c,traceRules);
......@@ -159,7 +159,7 @@ public class ParserTest extends ParserMemo
//-------------------------------------------------------------------
// Accept Inner
//-------------------------------------------------------------------
protected boolean acceptInner(Cache c)
protected boolean acceptInner(Cache c)
{
super.acceptInner();
traceAccept(c,traceInner);
......
......@@ -61,6 +61,7 @@ public class Phrase
final int start;
final int startline;
final int startcolumn;
int variant = -1;
int end;
int endline;
int endcolumn;
......@@ -142,6 +143,9 @@ public class Phrase
public int getEndColumn(){
return endcolumn;
}
public int getVariant(){
return variant;
}
//-----------------------------------------------------------------
// 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