Skip to content
Snippets Groups Projects
Commit 9377baea authored by Johannes Mey's avatar Johannes Mey
Browse files

add support for NTAs

parent 38f37081
Branches
Tags
No related merge requests found
......@@ -51,6 +51,9 @@ aspect BackendAbstractGrammar {
public String OptComponent.generateAbstractGrammar() {
return "[" + super.generateAbstractGrammar() + "]";
}
public String NTAComponent.generateAbstractGrammar() {
return "/" + super.generateAbstractGrammar() + "/";
}
public String TokenComponent.generateAbstractGrammar() {
return "<" + getID() + ":" + getTypeUse() + ">";
}
......
......@@ -6,6 +6,7 @@ abstract SimpleTypeComponent : Component ::= TypeUse:SimpleTypeUse;
NormalComponent : SimpleTypeComponent;
ListComponent : SimpleTypeComponent;
OptComponent : SimpleTypeComponent;
NTAComponent : SimpleTypeComponent;
TokenComponent : Component ::= TypeUse;
abstract TypeUse ::= <ID>;
......@@ -19,4 +20,4 @@ OptionalRelationComponent : RelationComponent;
ManyRelationComponent : RelationComponent;
abstract Direction;
RightDirection : Direction;
Bidirectional : Direction;
\ No newline at end of file
Bidirectional : Direction;
Program goal =
Program goal =
type_decls.t relations.r {: return new Program(t, r); :}
| STRING_LITERAL STAR {: return new Program(); :}
;
......@@ -9,9 +9,9 @@ List type_decls =
;
TypeDecl type_decl =
ID type_decl_super.s components_opt.c SCOL
ID type_decl_super.s components_opt.c SCOL
{: return new TypeDecl(ID, false, s, c); :}
| ABSTRACT ID type_decl_super.s components_opt.c SCOL
| ABSTRACT ID type_decl_super.s components_opt.c SCOL
{: return new TypeDecl(ID, true, s, c); :}
;
......@@ -55,6 +55,9 @@ Component component =
// Opt
| LBRACKET ID COL s_type_use.u RBRACKET {: return new OptComponent(ID, u); :}
| LBRACKET s_type_use.u RBRACKET {: return new OptComponent(u.getID(), u); :}
// NTA
| SLASH ID COL s_type_use.u SLASH {: return new NTAComponent(ID, u); :}
| SLASH s_type_use.u SLASH {: return new NTAComponent(u.getID(), u); :}
// Token
| LT ID COL type_use.u GT {: return new TokenComponent(ID, u); :}
| LT ID GT {: return new TokenComponent(ID, new SimpleTypeUse("String")); :}
......
......@@ -9,8 +9,8 @@ import org.jastadd.relast.ast.RelAstParser.Terminals;
%class RelAstScanner
%extends beaver.Scanner
%type beaver.Symbol
%function nextToken
%type beaver.Symbol
%function nextToken
%yylexthrow beaver.Scanner.Exception
%scanerror RelAstScanner.ScannerError
......@@ -18,7 +18,7 @@ import org.jastadd.relast.ast.RelAstParser.Terminals;
%column
%{
private StringBuilder stringLitSb = new StringBuilder();
private beaver.Symbol sym(short id) {
return new beaver.Symbol(id, yyline + 1, yycolumn + 1, yylength(), yytext());
}
......@@ -27,12 +27,12 @@ import org.jastadd.relast.ast.RelAstParser.Terminals;
return new beaver.Symbol(id, yyline + 1, yycolumn + 1, yylength(), text);
}
public static class ScannerError extends Error {
public ScannerError(String message) {
super(message);
}
}
}
%}
WhiteSpace = [ ] | \t | \f | \n | \r | \r\n
......@@ -62,6 +62,7 @@ ID = [a-zA-Z$_][a-zA-Z0-9$_]*
">" { return sym(Terminals.GT); }
"[" { return sym(Terminals.LBRACKET); }
"]" { return sym(Terminals.RBRACKET); }
"/" { return sym(Terminals.SLASH); }
"?" { return sym(Terminals.QUESTION_MARK); }
"->" { return sym(Terminals.RIGHT); }
"<->" { return sym(Terminals.BIDIRECTIONAL); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment