Commit 6391d95b authored by Konrad Pröll's avatar Konrad Pröll
Browse files

Grammar rules changed for different types of codeblocks.

parent 9821195e
package de.in.tum.www2.cup.ast;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
......@@ -20,18 +21,27 @@ import java_cup.runtime.SyntaxTreeTransform;
public class JavaCompiler {
private static String[] blacklist = { "VariableDeclaratorId" };
public static XMLElement parseJava(String blob, CodeBlock codeblock) {
public static XMLElement parseJava(String blob, CodeBlock codeblock) throws NoSuchMethodException, SecurityException, IllegalAccessException, InvocationTargetException {
SourceString src = new SourceString(blob);
JavaParser parser = new JavaParser();
boolean ok = false;
switch (codeblock.getBt()) {
case Action: // ?
case Action:
ok = parser.parse(src, "Action");
break;
case Parser:
ok = parser.parseClassBody(src);
ok = parser.parse(src, "Parser");
break;
case Init:
ok = parser.parse(src, "InitWith");
break;
default:// Init, Scan, ActionCodeBlock
ok = parser.parseMethodBody(src);
case Scan:
ok = parser.parse(src, "ScanWith");
break;
case ActionCode:
ok = parser.parse(src, "ActionCode");
break;
}
if (ok) {
......
......@@ -2,10 +2,8 @@ package de.in.tum.www2.cup.ast;
//=========================================================================
//
// This skeleton was generated by Mouse 1.7 at 2016-11-10 09:01:55 GMT
// from grammar
// 'C:\workspace\mouse-with-syntaxtree\examples\example11\Java.1.8.peg'.
//
// This skeleton was generated by Mouse 1.7 at 2016-11-16 14:29:13 GMT
// from grammar '/home/konrad/git/mouse/examples/example11/Java.1.8.peg'.
//
//=========================================================================
......@@ -34,6 +32,91 @@ class JavaSemantics extends mouse.runtime.SemanticsBase implements JavaSemantics
else lhs().put(new XMLElement.NonTerminal("Compilation",0,elems.toArray(new XMLElement[0])));
}
//=====================================================================
// Action = StartClassBody ;
//=====================================================================
void $TREE$Action(){
LinkedList<XMLElement> elems = new LinkedList<>();
for (int i=0;i<rhsSize();i++) {
if (rhs(i).get()==null) continue;
if (rhs(i).isTerm()){
Phrase p= rhs(i);
elems.add(new XMLElement.Terminal(new Location(p.getStartLine(),p.getStartColumn(),p.getStartPos()),"terminal",rhs(i).text(),new Location(p.getEndLine(),p.getEndColumn(),p.getEndPos())));
}
else
elems.add((XMLElement)rhs(i).get());
}
if (elems.size()==0) lhs().put(new XMLElement.Terminal(new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos()),"Action",lhs().text(),new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos())));
else lhs().put(new XMLElement.NonTerminal("Action",0,elems.toArray(new XMLElement[0])));
}
//=====================================================================
// Parser = StartClassBody ;
//=====================================================================
void $TREE$Parser(){
LinkedList<XMLElement> elems = new LinkedList<>();
for (int i=0;i<rhsSize();i++) {
if (rhs(i).get()==null) continue;
if (rhs(i).isTerm()){
Phrase p= rhs(i);
elems.add(new XMLElement.Terminal(new Location(p.getStartLine(),p.getStartColumn(),p.getStartPos()),"terminal",rhs(i).text(),new Location(p.getEndLine(),p.getEndColumn(),p.getEndPos())));
}
else
elems.add((XMLElement)rhs(i).get());
}
if (elems.size()==0) lhs().put(new XMLElement.Terminal(new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos()),"Parser",lhs().text(),new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos())));
else lhs().put(new XMLElement.NonTerminal("Parser",0,elems.toArray(new XMLElement[0])));
}
//=====================================================================
// InitWith = StartMethodBody ;
//=====================================================================
void $TREE$InitWith(){
LinkedList<XMLElement> elems = new LinkedList<>();
for (int i=0;i<rhsSize();i++) {
if (rhs(i).get()==null) continue;
if (rhs(i).isTerm()){
Phrase p= rhs(i);
elems.add(new XMLElement.Terminal(new Location(p.getStartLine(),p.getStartColumn(),p.getStartPos()),"terminal",rhs(i).text(),new Location(p.getEndLine(),p.getEndColumn(),p.getEndPos())));
}
else
elems.add((XMLElement)rhs(i).get());
}
if (elems.size()==0) lhs().put(new XMLElement.Terminal(new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos()),"InitWith",lhs().text(),new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos())));
else lhs().put(new XMLElement.NonTerminal("InitWith",0,elems.toArray(new XMLElement[0])));
}
//=====================================================================
// ScanWith = StartMethodBody ;
//=====================================================================
void $TREE$ScanWith(){
LinkedList<XMLElement> elems = new LinkedList<>();
for (int i=0;i<rhsSize();i++) {
if (rhs(i).get()==null) continue;
if (rhs(i).isTerm()){
Phrase p= rhs(i);
elems.add(new XMLElement.Terminal(new Location(p.getStartLine(),p.getStartColumn(),p.getStartPos()),"terminal",rhs(i).text(),new Location(p.getEndLine(),p.getEndColumn(),p.getEndPos())));
}
else
elems.add((XMLElement)rhs(i).get());
}
if (elems.size()==0) lhs().put(new XMLElement.Terminal(new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos()),"ScanWith",lhs().text(),new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos())));
else lhs().put(new XMLElement.NonTerminal("ScanWith",0,elems.toArray(new XMLElement[0])));
}
//=====================================================================
// ActionCode = StartMethodBody ;
//=====================================================================
void $TREE$ActionCode(){
LinkedList<XMLElement> elems = new LinkedList<>();
for (int i=0;i<rhsSize();i++) {
if (rhs(i).get()==null) continue;
if (rhs(i).isTerm()){
Phrase p= rhs(i);
elems.add(new XMLElement.Terminal(new Location(p.getStartLine(),p.getStartColumn(),p.getStartPos()),"terminal",rhs(i).text(),new Location(p.getEndLine(),p.getEndColumn(),p.getEndPos())));
}
else
elems.add((XMLElement)rhs(i).get());
}
if (elems.size()==0) lhs().put(new XMLElement.Terminal(new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos()),"ActionCode",lhs().text(),new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos())));
else lhs().put(new XMLElement.NonTerminal("ActionCode",0,elems.toArray(new XMLElement[0])));
}
//=====================================================================
// StartClassBody = Spacing ClassBodyDeclaration* SUB? EOT ;
//=====================================================================
void $TREE$StartClassBody(){
......
Supports Markdown
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