antlr grammar and AST for il65

This commit is contained in:
Irmen de Jong 2018-08-10 02:58:41 +02:00
parent 7e511a1fe9
commit 1ccc73f1f8
6 changed files with 203 additions and 147 deletions

View File

@ -31,22 +31,22 @@ module : statement* EOF ;
statement : statement :
directive directive
| varinitializer
| vardecl
| constdecl | constdecl
| memoryvardecl | memoryvardecl
| vardecl
| varinitializer
| assignment | assignment
| augassignment | augassignment
; ;
directive : '%' singlename (directivearg? | directivearg (',' directivearg)*) ; directive : '%' identifier (directivearg? | directivearg (',' directivearg)*) ;
directivearg : singlename | integerliteral ; directivearg : identifier | integerliteral ;
vardecl: datatype arrayspec? singlename ; vardecl: datatype arrayspec? identifier ;
varinitializer : datatype arrayspec? singlename '=' expression ; varinitializer : datatype arrayspec? identifier '=' expression ;
constdecl: 'const' varinitializer ; constdecl: 'const' varinitializer ;
@ -59,40 +59,40 @@ arrayspec: '[' expression (',' expression)? ']' ;
assignment : assign_target '=' expression ; assignment : assign_target '=' expression ;
augassignment : augassignment :
assign_target ('+=' | '-=' | '/=' | '//=' | '*=' | '**=' | assign_target operator=('+=' | '-=' | '/=' | '//=' | '*=' | '**=' |
'<<=' | '>>=' | '<<@=' | '>>@=' | '&=' | '|=' | '^=') expression '<<=' | '>>=' | '<<@=' | '>>@=' | '&=' | '|=' | '^=') expression
; ;
assign_target: assign_target:
register register
| singlename | identifier
| dottedname | scoped_identifier
; ;
expression : expression :
unary_expression unaryexp = unary_expression
| '(' expression ')' | '(' precedence_expr=expression ')'
| expression '**' expression | left = expression '**' right = expression
| expression ('*' | '/' | '//' | '**') expression | left = expression ('*' | '/' | '//' | '**') right = expression
| expression ('+' | '-' | '%') expression | left = expression ('+' | '-' | '%') right = expression
| expression ('<<' | '>>' | '<<@' | '>>@' | '&' | '|' | '^') expression | left = expression ('<<' | '>>' | '<<@' | '>>@' | '&' | '|' | '^') right = expression
| expression ('and' | 'or' | 'xor') expression | left = expression ('and' | 'or' | 'xor') right = expression
| expression ('==' | '!=' | '<' | '>' | '<=' | '>=') expression | left = expression ('==' | '!=' | '<' | '>' | '<=' | '>=') right = expression
| literalvalue | literalvalue
| register | register
| dottedname | identifier
| singlename | scoped_identifier
; ;
unary_expression : unary_expression :
'~' expression operator = '~' expression
| ('+' | '-') expression | operator = ('+' | '-') expression
| 'not' expression | operator = 'not' expression
; ;
singlename : NAME ; identifier : NAME ;
dottedname : NAME ('.' NAME)+ ; scoped_identifier : NAME ('.' NAME)+ ;
register : 'A' | 'X' | 'Y' | 'AX' | 'AY' | 'XY' | 'SC' | 'SI' | 'SZ' ; register : 'A' | 'X' | 'Y' | 'AX' | 'AY' | 'XY' | 'SC' | 'SI' | 'SZ' ;

View File

@ -4,10 +4,24 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" /> <orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module-library">
<library name="JUnit5.2">
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-api-5.3.0-M1.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/opentest4j-1.1.0.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-platform-commons-1.3.0-M1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="org.hamcrest:hamcrest-library:1.2.1" level="project" />
</component> </component>
</module> </module>

View File

@ -11,8 +11,11 @@ fun main(args: Array<String>) {
// println("Reading source file: ${args[0]}") // println("Reading source file: ${args[0]}")
val input = CharStreams.fromString( val input = CharStreams.fromString(
"AX //= (5+8)*77\n" + "byte derp=3"
"X = -3.44e-99") // +
// "AX //= (5+8)*77\n" +
// "X = -3.44e-99"
)
val lexer = il65Lexer(input) val lexer = il65Lexer(input)
val tokens = CommonTokenStream(lexer) val tokens = CommonTokenStream(lexer)
val parser = il65Parser(tokens) val parser = il65Parser(tokens)

View File

@ -61,7 +61,7 @@ data class MemoryVarDecl(override val datatype: DataType,
data class Assignment(val target: AssignTarget, val aug_op : String?, val value: IExpression) : IStatement data class Assignment(val target: AssignTarget, val aug_op : String?, val value: IExpression) : IStatement
data class AssignTarget(val register: Register?, val singlename: String?, val dottedname: String?) : Node data class AssignTarget(val register: Register?, val identifier: String?, val scoped_identifier: String?) : Node
interface IExpression: Node interface IExpression: Node
@ -78,42 +78,45 @@ data class LiteralValue(val intvalue: Int?,
data class RegisterExpr(val register: Register) : IExpression data class RegisterExpr(val register: Register) : IExpression
data class DottedNameExpr(val dottedname: String) : IExpression data class Identifier(val name: String, val scope: String?) : IExpression
data class SingleNameExpr(val name: String) : IExpression
fun il65Parser.ModuleContext.toAst() = Module(this.statement().map { it.toAst() }) fun il65Parser.ModuleContext.toAst() = Module(this.statement().map { it.toAst() })
fun il65Parser.StatementContext.toAst() : IStatement { fun il65Parser.StatementContext.toAst() : IStatement {
val directive = this.directive()?.toAst()
if(directive!=null) return directive
val vardecl = this.vardecl() val vardecl = this.vardecl()
if(vardecl!=null) { if(vardecl!=null) {
return VarDecl(vardecl.datatype().toAst(), return VarDecl(vardecl.datatype().toAst(),
vardecl.arrayspec()?.toAst(), vardecl.arrayspec()?.toAst(),
vardecl.singlename().text, vardecl.identifier().text,
null) null)
} }
val varinit = this.varinitializer()
if(varinit!=null) {
return VarDecl(varinit.datatype().toAst(),
varinit.arrayspec()?.toAst(),
varinit.identifier().text,
varinit.expression().toAst())
}
val constdecl = this.constdecl() val constdecl = this.constdecl()
if(constdecl!=null) { if(constdecl!=null) {
val varinit = constdecl.varinitializer() val cvarinit = constdecl.varinitializer()
return ConstDecl(varinit.datatype().toAst(), return ConstDecl(cvarinit.datatype().toAst(),
varinit.arrayspec()?.toAst(), cvarinit.arrayspec()?.toAst(),
varinit.singlename().text, cvarinit.identifier().text,
varinit.expression().toAst()) cvarinit.expression().toAst())
} }
val memdecl = this.memoryvardecl() val memdecl = this.memoryvardecl()
if(memdecl!=null) { if(memdecl!=null) {
val varinit = memdecl.varinitializer() val mvarinit = memdecl.varinitializer()
return MemoryVarDecl(varinit.datatype().toAst(), return MemoryVarDecl(mvarinit.datatype().toAst(),
varinit.arrayspec()?.toAst(), mvarinit.arrayspec()?.toAst(),
varinit.singlename().text, mvarinit.identifier().text,
varinit.expression().toAst()) mvarinit.expression().toAst())
} }
val assign = this.assignment() val assign = this.assignment()
@ -122,22 +125,24 @@ fun il65Parser.StatementContext.toAst() : IStatement {
} }
val augassign = this.augassignment() val augassign = this.augassignment()
if (augassign!=null) { if (augassign!=null)
return Assignment( return Assignment(
augassign.assign_target().toAst(), augassign.assign_target().toAst(),
augassign.children[1].text, augassign.operator.text,
augassign.expression().toAst()) augassign.expression().toAst())
}
val directive = this.directive()?.toAst()
if(directive!=null) return directive
throw UnsupportedOperationException(this.text) throw UnsupportedOperationException(this.text)
} }
fun il65Parser.Assign_targetContext.toAst() = fun il65Parser.Assign_targetContext.toAst() =
AssignTarget(this.register()?.toAst(), this.singlename()?.text, this.dottedname()?.text) AssignTarget(this.register()?.toAst(), this.identifier()?.text, this.scoped_identifier()?.text)
fun il65Parser.RegisterContext.toAst() = Register.valueOf(this.text) fun il65Parser.RegisterContext.toAst() = Register.valueOf(this.text.toUpperCase())
fun il65Parser.DatatypeContext.toAst() = DataType.valueOf(this.text) fun il65Parser.DatatypeContext.toAst() = DataType.valueOf(this.text.toUpperCase())
fun il65Parser.ArrayspecContext.toAst() = ArraySpec( fun il65Parser.ArrayspecContext.toAst() = ArraySpec(
this.expression(0).toAst(), this.expression(0).toAst(),
@ -145,9 +150,9 @@ fun il65Parser.ArrayspecContext.toAst() = ArraySpec(
) )
fun il65Parser.DirectiveContext.toAst() = Directive(this.singlename().text, this.directivearg().map { it.toAst() }) fun il65Parser.DirectiveContext.toAst() = Directive(this.identifier().text, this.directivearg().map { it.toAst() })
fun il65Parser.DirectiveargContext.toAst() = DirectiveArg(this.singlename()?.text, this.integerliteral()?.toAst()) fun il65Parser.DirectiveargContext.toAst() = DirectiveArg(this.identifier()?.text, this.integerliteral()?.toAst())
fun il65Parser.IntegerliteralContext.toAst(): Int { fun il65Parser.IntegerliteralContext.toAst(): Int {
val terminal: TerminalNode = this.children[0] as TerminalNode val terminal: TerminalNode = this.children[0] as TerminalNode
@ -161,40 +166,33 @@ fun il65Parser.IntegerliteralContext.toAst(): Int {
fun il65Parser.ExpressionContext.toAst() : IExpression { fun il65Parser.ExpressionContext.toAst() : IExpression {
if(this.singlename()!=null) { if(this.identifier()!=null)
return SingleNameExpr(this.singlename().text) return Identifier(this.identifier().text, null)
}
val litval = this.literalvalue() val litval = this.literalvalue()
if(litval!=null) { if(litval!=null)
return LiteralValue(litval.integerliteral()?.toAst(), return LiteralValue(litval.integerliteral()?.toAst(),
litval.floatliteral()?.toAst(), litval.floatliteral()?.toAst(),
litval.stringliteral()?.text, litval.stringliteral()?.text,
litval.booleanliteral()?.toAst(), litval.booleanliteral()?.toAst(),
litval.arrayliteral()?.toAst() litval.arrayliteral()?.toAst()
) )
}
if(this.dottedname()!=null) { if(this.scoped_identifier()!=null)
return DottedNameExpr(this.dottedname().text) return Identifier(this.scoped_identifier().text, "SCOPE????") // todo!
}
if(this.register()!=null) { if(this.register()!=null)
return RegisterExpr(this.register().toAst()) return RegisterExpr(this.register().toAst())
}
if(this.unary_expression()!=null) { if(this.unaryexp!=null)
return UnaryExpression(this.unary_expression().children[0].text, this.unary_expression().expression().toAst()) return UnaryExpression(this.unaryexp.operator.text, this.unaryexp.expression().toAst())
}
if(this.expression().size == 2) { if(this.left != null && this.right != null)
return BinaryExpression(this.expression(0).toAst(), this.text, this.expression(1).toAst()) return BinaryExpression(this.left.toAst(), this.text, this.right.toAst())
}
// (....) // ( expression )
if(this.childCount == 3 && this.children[0].text=="(" && this.children[2].text==")") { if(this.precedence_expr!=null)
return this.expression(0).toAst() return this.precedence_expr.toAst()
}
throw UnsupportedOperationException(this.text) throw UnsupportedOperationException(this.text)
} }

View File

@ -33,13 +33,13 @@ public class il65Parser extends Parser {
RULE_vardecl = 4, RULE_varinitializer = 5, RULE_constdecl = 6, RULE_memoryvardecl = 7, RULE_vardecl = 4, RULE_varinitializer = 5, RULE_constdecl = 6, RULE_memoryvardecl = 7,
RULE_datatype = 8, RULE_arrayspec = 9, RULE_assignment = 10, RULE_augassignment = 11, RULE_datatype = 8, RULE_arrayspec = 9, RULE_assignment = 10, RULE_augassignment = 11,
RULE_assign_target = 12, RULE_expression = 13, RULE_unary_expression = 14, RULE_assign_target = 12, RULE_expression = 13, RULE_unary_expression = 14,
RULE_singlename = 15, RULE_dottedname = 16, RULE_register = 17, RULE_integerliteral = 18, RULE_identifier = 15, RULE_scoped_identifier = 16, RULE_register = 17,
RULE_booleanliteral = 19, RULE_arrayliteral = 20, RULE_stringliteral = 21, RULE_integerliteral = 18, RULE_booleanliteral = 19, RULE_arrayliteral = 20,
RULE_floatliteral = 22, RULE_literalvalue = 23; RULE_stringliteral = 21, RULE_floatliteral = 22, RULE_literalvalue = 23;
public static final String[] ruleNames = { public static final String[] ruleNames = {
"module", "statement", "directive", "directivearg", "vardecl", "varinitializer", "module", "statement", "directive", "directivearg", "vardecl", "varinitializer",
"constdecl", "memoryvardecl", "datatype", "arrayspec", "assignment", "augassignment", "constdecl", "memoryvardecl", "datatype", "arrayspec", "assignment", "augassignment",
"assign_target", "expression", "unary_expression", "singlename", "dottedname", "assign_target", "expression", "unary_expression", "identifier", "scoped_identifier",
"register", "integerliteral", "booleanliteral", "arrayliteral", "stringliteral", "register", "integerliteral", "booleanliteral", "arrayliteral", "stringliteral",
"floatliteral", "literalvalue" "floatliteral", "literalvalue"
}; };
@ -166,18 +166,18 @@ public class il65Parser extends Parser {
public DirectiveContext directive() { public DirectiveContext directive() {
return getRuleContext(DirectiveContext.class,0); return getRuleContext(DirectiveContext.class,0);
} }
public ConstdeclContext constdecl() {
return getRuleContext(ConstdeclContext.class,0);
}
public MemoryvardeclContext memoryvardecl() {
return getRuleContext(MemoryvardeclContext.class,0);
}
public VardeclContext vardecl() { public VardeclContext vardecl() {
return getRuleContext(VardeclContext.class,0); return getRuleContext(VardeclContext.class,0);
} }
public VarinitializerContext varinitializer() { public VarinitializerContext varinitializer() {
return getRuleContext(VarinitializerContext.class,0); return getRuleContext(VarinitializerContext.class,0);
} }
public ConstdeclContext constdecl() {
return getRuleContext(ConstdeclContext.class,0);
}
public MemoryvardeclContext memoryvardecl() {
return getRuleContext(MemoryvardeclContext.class,0);
}
public AssignmentContext assignment() { public AssignmentContext assignment() {
return getRuleContext(AssignmentContext.class,0); return getRuleContext(AssignmentContext.class,0);
} }
@ -208,28 +208,28 @@ public class il65Parser extends Parser {
enterOuterAlt(_localctx, 2); enterOuterAlt(_localctx, 2);
{ {
setState(57); setState(57);
constdecl(); vardecl();
} }
break; break;
case 3: case 3:
enterOuterAlt(_localctx, 3); enterOuterAlt(_localctx, 3);
{ {
setState(58); setState(58);
memoryvardecl(); varinitializer();
} }
break; break;
case 4: case 4:
enterOuterAlt(_localctx, 4); enterOuterAlt(_localctx, 4);
{ {
setState(59); setState(59);
vardecl(); constdecl();
} }
break; break;
case 5: case 5:
enterOuterAlt(_localctx, 5); enterOuterAlt(_localctx, 5);
{ {
setState(60); setState(60);
varinitializer(); memoryvardecl();
} }
break; break;
case 6: case 6:
@ -260,8 +260,8 @@ public class il65Parser extends Parser {
} }
public static class DirectiveContext extends ParserRuleContext { public static class DirectiveContext extends ParserRuleContext {
public SinglenameContext singlename() { public IdentifierContext identifier() {
return getRuleContext(SinglenameContext.class,0); return getRuleContext(IdentifierContext.class,0);
} }
public List<DirectiveargContext> directivearg() { public List<DirectiveargContext> directivearg() {
return getRuleContexts(DirectiveargContext.class); return getRuleContexts(DirectiveargContext.class);
@ -285,7 +285,7 @@ public class il65Parser extends Parser {
setState(65); setState(65);
match(T__0); match(T__0);
setState(66); setState(66);
singlename(); identifier();
setState(78); setState(78);
_errHandler.sync(this); _errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) { switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) {
@ -340,8 +340,8 @@ public class il65Parser extends Parser {
} }
public static class DirectiveargContext extends ParserRuleContext { public static class DirectiveargContext extends ParserRuleContext {
public SinglenameContext singlename() { public IdentifierContext identifier() {
return getRuleContext(SinglenameContext.class,0); return getRuleContext(IdentifierContext.class,0);
} }
public IntegerliteralContext integerliteral() { public IntegerliteralContext integerliteral() {
return getRuleContext(IntegerliteralContext.class,0); return getRuleContext(IntegerliteralContext.class,0);
@ -363,7 +363,7 @@ public class il65Parser extends Parser {
enterOuterAlt(_localctx, 1); enterOuterAlt(_localctx, 1);
{ {
setState(80); setState(80);
singlename(); identifier();
} }
break; break;
case DEC_INTEGER: case DEC_INTEGER:
@ -394,8 +394,8 @@ public class il65Parser extends Parser {
public DatatypeContext datatype() { public DatatypeContext datatype() {
return getRuleContext(DatatypeContext.class,0); return getRuleContext(DatatypeContext.class,0);
} }
public SinglenameContext singlename() { public IdentifierContext identifier() {
return getRuleContext(SinglenameContext.class,0); return getRuleContext(IdentifierContext.class,0);
} }
public ArrayspecContext arrayspec() { public ArrayspecContext arrayspec() {
return getRuleContext(ArrayspecContext.class,0); return getRuleContext(ArrayspecContext.class,0);
@ -426,7 +426,7 @@ public class il65Parser extends Parser {
} }
setState(88); setState(88);
singlename(); identifier();
} }
} }
catch (RecognitionException re) { catch (RecognitionException re) {
@ -444,8 +444,8 @@ public class il65Parser extends Parser {
public DatatypeContext datatype() { public DatatypeContext datatype() {
return getRuleContext(DatatypeContext.class,0); return getRuleContext(DatatypeContext.class,0);
} }
public SinglenameContext singlename() { public IdentifierContext identifier() {
return getRuleContext(SinglenameContext.class,0); return getRuleContext(IdentifierContext.class,0);
} }
public ExpressionContext expression() { public ExpressionContext expression() {
return getRuleContext(ExpressionContext.class,0); return getRuleContext(ExpressionContext.class,0);
@ -479,7 +479,7 @@ public class il65Parser extends Parser {
} }
setState(94); setState(94);
singlename(); identifier();
setState(95); setState(95);
match(T__2); match(T__2);
setState(96); setState(96);
@ -690,6 +690,7 @@ public class il65Parser extends Parser {
} }
public static class AugassignmentContext extends ParserRuleContext { public static class AugassignmentContext extends ParserRuleContext {
public Token operator;
public Assign_targetContext assign_target() { public Assign_targetContext assign_target() {
return getRuleContext(Assign_targetContext.class,0); return getRuleContext(Assign_targetContext.class,0);
} }
@ -712,9 +713,10 @@ public class il65Parser extends Parser {
setState(118); setState(118);
assign_target(); assign_target();
setState(119); setState(119);
((AugassignmentContext)_localctx).operator = _input.LT(1);
_la = _input.LA(1); _la = _input.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__14) | (1L << T__15) | (1L << T__16) | (1L << T__17) | (1L << T__18) | (1L << T__19) | (1L << T__20) | (1L << T__21) | (1L << T__22) | (1L << T__23) | (1L << T__24) | (1L << T__25) | (1L << T__26))) != 0)) ) { if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__14) | (1L << T__15) | (1L << T__16) | (1L << T__17) | (1L << T__18) | (1L << T__19) | (1L << T__20) | (1L << T__21) | (1L << T__22) | (1L << T__23) | (1L << T__24) | (1L << T__25) | (1L << T__26))) != 0)) ) {
_errHandler.recoverInline(this); ((AugassignmentContext)_localctx).operator = (Token)_errHandler.recoverInline(this);
} }
else { else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true; if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
@ -740,11 +742,11 @@ public class il65Parser extends Parser {
public RegisterContext register() { public RegisterContext register() {
return getRuleContext(RegisterContext.class,0); return getRuleContext(RegisterContext.class,0);
} }
public SinglenameContext singlename() { public IdentifierContext identifier() {
return getRuleContext(SinglenameContext.class,0); return getRuleContext(IdentifierContext.class,0);
} }
public DottednameContext dottedname() { public Scoped_identifierContext scoped_identifier() {
return getRuleContext(DottednameContext.class,0); return getRuleContext(Scoped_identifierContext.class,0);
} }
public Assign_targetContext(ParserRuleContext parent, int invokingState) { public Assign_targetContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState); super(parent, invokingState);
@ -770,14 +772,14 @@ public class il65Parser extends Parser {
enterOuterAlt(_localctx, 2); enterOuterAlt(_localctx, 2);
{ {
setState(123); setState(123);
singlename(); identifier();
} }
break; break;
case 3: case 3:
enterOuterAlt(_localctx, 3); enterOuterAlt(_localctx, 3);
{ {
setState(124); setState(124);
dottedname(); scoped_identifier();
} }
break; break;
} }
@ -794,6 +796,10 @@ public class il65Parser extends Parser {
} }
public static class ExpressionContext extends ParserRuleContext { public static class ExpressionContext extends ParserRuleContext {
public ExpressionContext left;
public Unary_expressionContext unaryexp;
public ExpressionContext precedence_expr;
public ExpressionContext right;
public Unary_expressionContext unary_expression() { public Unary_expressionContext unary_expression() {
return getRuleContext(Unary_expressionContext.class,0); return getRuleContext(Unary_expressionContext.class,0);
} }
@ -809,11 +815,11 @@ public class il65Parser extends Parser {
public RegisterContext register() { public RegisterContext register() {
return getRuleContext(RegisterContext.class,0); return getRuleContext(RegisterContext.class,0);
} }
public DottednameContext dottedname() { public IdentifierContext identifier() {
return getRuleContext(DottednameContext.class,0); return getRuleContext(IdentifierContext.class,0);
} }
public SinglenameContext singlename() { public Scoped_identifierContext scoped_identifier() {
return getRuleContext(SinglenameContext.class,0); return getRuleContext(Scoped_identifierContext.class,0);
} }
public ExpressionContext(ParserRuleContext parent, int invokingState) { public ExpressionContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState); super(parent, invokingState);
@ -843,7 +849,7 @@ public class il65Parser extends Parser {
case 1: case 1:
{ {
setState(128); setState(128);
unary_expression(); ((ExpressionContext)_localctx).unaryexp = unary_expression();
} }
break; break;
case 2: case 2:
@ -851,7 +857,7 @@ public class il65Parser extends Parser {
setState(129); setState(129);
match(T__27); match(T__27);
setState(130); setState(130);
expression(0); ((ExpressionContext)_localctx).precedence_expr = expression(0);
setState(131); setState(131);
match(T__28); match(T__28);
} }
@ -871,13 +877,13 @@ public class il65Parser extends Parser {
case 5: case 5:
{ {
setState(135); setState(135);
dottedname(); identifier();
} }
break; break;
case 6: case 6:
{ {
setState(136); setState(136);
singlename(); scoped_identifier();
} }
break; break;
} }
@ -896,18 +902,22 @@ public class il65Parser extends Parser {
case 1: case 1:
{ {
_localctx = new ExpressionContext(_parentctx, _parentState); _localctx = new ExpressionContext(_parentctx, _parentState);
_localctx.left = _prevctx;
_localctx.left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expression); pushNewRecursionContext(_localctx, _startState, RULE_expression);
setState(139); setState(139);
if (!(precpred(_ctx, 10))) throw new FailedPredicateException(this, "precpred(_ctx, 10)"); if (!(precpred(_ctx, 10))) throw new FailedPredicateException(this, "precpred(_ctx, 10)");
setState(140); setState(140);
match(T__29); match(T__29);
setState(141); setState(141);
expression(11); ((ExpressionContext)_localctx).right = expression(11);
} }
break; break;
case 2: case 2:
{ {
_localctx = new ExpressionContext(_parentctx, _parentState); _localctx = new ExpressionContext(_parentctx, _parentState);
_localctx.left = _prevctx;
_localctx.left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expression); pushNewRecursionContext(_localctx, _startState, RULE_expression);
setState(142); setState(142);
if (!(precpred(_ctx, 9))) throw new FailedPredicateException(this, "precpred(_ctx, 9)"); if (!(precpred(_ctx, 9))) throw new FailedPredicateException(this, "precpred(_ctx, 9)");
@ -922,12 +932,14 @@ public class il65Parser extends Parser {
consume(); consume();
} }
setState(144); setState(144);
expression(10); ((ExpressionContext)_localctx).right = expression(10);
} }
break; break;
case 3: case 3:
{ {
_localctx = new ExpressionContext(_parentctx, _parentState); _localctx = new ExpressionContext(_parentctx, _parentState);
_localctx.left = _prevctx;
_localctx.left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expression); pushNewRecursionContext(_localctx, _startState, RULE_expression);
setState(145); setState(145);
if (!(precpred(_ctx, 8))) throw new FailedPredicateException(this, "precpred(_ctx, 8)"); if (!(precpred(_ctx, 8))) throw new FailedPredicateException(this, "precpred(_ctx, 8)");
@ -942,12 +954,14 @@ public class il65Parser extends Parser {
consume(); consume();
} }
setState(147); setState(147);
expression(9); ((ExpressionContext)_localctx).right = expression(9);
} }
break; break;
case 4: case 4:
{ {
_localctx = new ExpressionContext(_parentctx, _parentState); _localctx = new ExpressionContext(_parentctx, _parentState);
_localctx.left = _prevctx;
_localctx.left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expression); pushNewRecursionContext(_localctx, _startState, RULE_expression);
setState(148); setState(148);
if (!(precpred(_ctx, 7))) throw new FailedPredicateException(this, "precpred(_ctx, 7)"); if (!(precpred(_ctx, 7))) throw new FailedPredicateException(this, "precpred(_ctx, 7)");
@ -962,12 +976,14 @@ public class il65Parser extends Parser {
consume(); consume();
} }
setState(150); setState(150);
expression(8); ((ExpressionContext)_localctx).right = expression(8);
} }
break; break;
case 5: case 5:
{ {
_localctx = new ExpressionContext(_parentctx, _parentState); _localctx = new ExpressionContext(_parentctx, _parentState);
_localctx.left = _prevctx;
_localctx.left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expression); pushNewRecursionContext(_localctx, _startState, RULE_expression);
setState(151); setState(151);
if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)"); if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)");
@ -982,12 +998,14 @@ public class il65Parser extends Parser {
consume(); consume();
} }
setState(153); setState(153);
expression(7); ((ExpressionContext)_localctx).right = expression(7);
} }
break; break;
case 6: case 6:
{ {
_localctx = new ExpressionContext(_parentctx, _parentState); _localctx = new ExpressionContext(_parentctx, _parentState);
_localctx.left = _prevctx;
_localctx.left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expression); pushNewRecursionContext(_localctx, _startState, RULE_expression);
setState(154); setState(154);
if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)"); if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)");
@ -1002,7 +1020,7 @@ public class il65Parser extends Parser {
consume(); consume();
} }
setState(156); setState(156);
expression(6); ((ExpressionContext)_localctx).right = expression(6);
} }
break; break;
} }
@ -1026,6 +1044,7 @@ public class il65Parser extends Parser {
} }
public static class Unary_expressionContext extends ParserRuleContext { public static class Unary_expressionContext extends ParserRuleContext {
public Token operator;
public ExpressionContext expression() { public ExpressionContext expression() {
return getRuleContext(ExpressionContext.class,0); return getRuleContext(ExpressionContext.class,0);
} }
@ -1047,7 +1066,7 @@ public class il65Parser extends Parser {
enterOuterAlt(_localctx, 1); enterOuterAlt(_localctx, 1);
{ {
setState(162); setState(162);
match(T__51); ((Unary_expressionContext)_localctx).operator = match(T__51);
setState(163); setState(163);
expression(0); expression(0);
} }
@ -1057,9 +1076,10 @@ public class il65Parser extends Parser {
enterOuterAlt(_localctx, 2); enterOuterAlt(_localctx, 2);
{ {
setState(164); setState(164);
((Unary_expressionContext)_localctx).operator = _input.LT(1);
_la = _input.LA(1); _la = _input.LA(1);
if ( !(_la==T__33 || _la==T__34) ) { if ( !(_la==T__33 || _la==T__34) ) {
_errHandler.recoverInline(this); ((Unary_expressionContext)_localctx).operator = (Token)_errHandler.recoverInline(this);
} }
else { else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true; if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
@ -1074,7 +1094,7 @@ public class il65Parser extends Parser {
enterOuterAlt(_localctx, 3); enterOuterAlt(_localctx, 3);
{ {
setState(166); setState(166);
match(T__52); ((Unary_expressionContext)_localctx).operator = match(T__52);
setState(167); setState(167);
expression(0); expression(0);
} }
@ -1094,17 +1114,17 @@ public class il65Parser extends Parser {
return _localctx; return _localctx;
} }
public static class SinglenameContext extends ParserRuleContext { public static class IdentifierContext extends ParserRuleContext {
public TerminalNode NAME() { return getToken(il65Parser.NAME, 0); } public TerminalNode NAME() { return getToken(il65Parser.NAME, 0); }
public SinglenameContext(ParserRuleContext parent, int invokingState) { public IdentifierContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState); super(parent, invokingState);
} }
@Override public int getRuleIndex() { return RULE_singlename; } @Override public int getRuleIndex() { return RULE_identifier; }
} }
public final SinglenameContext singlename() throws RecognitionException { public final IdentifierContext identifier() throws RecognitionException {
SinglenameContext _localctx = new SinglenameContext(_ctx, getState()); IdentifierContext _localctx = new IdentifierContext(_ctx, getState());
enterRule(_localctx, 30, RULE_singlename); enterRule(_localctx, 30, RULE_identifier);
try { try {
enterOuterAlt(_localctx, 1); enterOuterAlt(_localctx, 1);
{ {
@ -1123,20 +1143,20 @@ public class il65Parser extends Parser {
return _localctx; return _localctx;
} }
public static class DottednameContext extends ParserRuleContext { public static class Scoped_identifierContext extends ParserRuleContext {
public List<TerminalNode> NAME() { return getTokens(il65Parser.NAME); } public List<TerminalNode> NAME() { return getTokens(il65Parser.NAME); }
public TerminalNode NAME(int i) { public TerminalNode NAME(int i) {
return getToken(il65Parser.NAME, i); return getToken(il65Parser.NAME, i);
} }
public DottednameContext(ParserRuleContext parent, int invokingState) { public Scoped_identifierContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState); super(parent, invokingState);
} }
@Override public int getRuleIndex() { return RULE_dottedname; } @Override public int getRuleIndex() { return RULE_scoped_identifier; }
} }
public final DottednameContext dottedname() throws RecognitionException { public final Scoped_identifierContext scoped_identifier() throws RecognitionException {
DottednameContext _localctx = new DottednameContext(_ctx, getState()); Scoped_identifierContext _localctx = new Scoped_identifierContext(_ctx, getState());
enterRule(_localctx, 32, RULE_dottedname); enterRule(_localctx, 32, RULE_scoped_identifier);
try { try {
int _alt; int _alt;
enterOuterAlt(_localctx, 1); enterOuterAlt(_localctx, 1);
@ -1537,11 +1557,11 @@ public class il65Parser extends Parser {
"\3\2\2\2$\u00b5\3\2\2\2&\u00b7\3\2\2\2(\u00b9\3\2\2\2*\u00bb\3\2\2\2,"+ "\3\2\2\2$\u00b5\3\2\2\2&\u00b7\3\2\2\2(\u00b9\3\2\2\2*\u00bb\3\2\2\2,"+
"\u00c6\3\2\2\2.\u00c8\3\2\2\2\60\u00cf\3\2\2\2\62\64\5\4\3\2\63\62\3\2"+ "\u00c6\3\2\2\2.\u00c8\3\2\2\2\60\u00cf\3\2\2\2\62\64\5\4\3\2\63\62\3\2"+
"\2\2\64\67\3\2\2\2\65\63\3\2\2\2\65\66\3\2\2\2\668\3\2\2\2\67\65\3\2\2"+ "\2\2\64\67\3\2\2\2\65\63\3\2\2\2\65\66\3\2\2\2\668\3\2\2\2\67\65\3\2\2"+
"\289\7\2\2\39\3\3\2\2\2:B\5\6\4\2;B\5\16\b\2<B\5\20\t\2=B\5\n\6\2>B\5"+ "\289\7\2\2\39\3\3\2\2\2:B\5\6\4\2;B\5\n\6\2<B\5\f\7\2=B\5\16\b\2>B\5\20"+
"\f\7\2?B\5\26\f\2@B\5\30\r\2A:\3\2\2\2A;\3\2\2\2A<\3\2\2\2A=\3\2\2\2A"+ "\t\2?B\5\26\f\2@B\5\30\r\2A:\3\2\2\2A;\3\2\2\2A<\3\2\2\2A=\3\2\2\2A>\3"+
">\3\2\2\2A?\3\2\2\2A@\3\2\2\2B\5\3\2\2\2CD\7\3\2\2DP\5 \21\2EG\5\b\5\2"+ "\2\2\2A?\3\2\2\2A@\3\2\2\2B\5\3\2\2\2CD\7\3\2\2DP\5 \21\2EG\5\b\5\2FE"+
"FE\3\2\2\2FG\3\2\2\2GQ\3\2\2\2HM\5\b\5\2IJ\7\4\2\2JL\5\b\5\2KI\3\2\2\2"+ "\3\2\2\2FG\3\2\2\2GQ\3\2\2\2HM\5\b\5\2IJ\7\4\2\2JL\5\b\5\2KI\3\2\2\2L"+
"LO\3\2\2\2MK\3\2\2\2MN\3\2\2\2NQ\3\2\2\2OM\3\2\2\2PF\3\2\2\2PH\3\2\2\2"+ "O\3\2\2\2MK\3\2\2\2MN\3\2\2\2NQ\3\2\2\2OM\3\2\2\2PF\3\2\2\2PH\3\2\2\2"+
"Q\7\3\2\2\2RU\5 \21\2SU\5&\24\2TR\3\2\2\2TS\3\2\2\2U\t\3\2\2\2VX\5\22"+ "Q\7\3\2\2\2RU\5 \21\2SU\5&\24\2TR\3\2\2\2TS\3\2\2\2U\t\3\2\2\2VX\5\22"+
"\n\2WY\5\24\13\2XW\3\2\2\2XY\3\2\2\2YZ\3\2\2\2Z[\5 \21\2[\13\3\2\2\2\\"+ "\n\2WY\5\24\13\2XW\3\2\2\2XY\3\2\2\2YZ\3\2\2\2Z[\5 \21\2[\13\3\2\2\2\\"+
"^\5\22\n\2]_\5\24\13\2^]\3\2\2\2^_\3\2\2\2_`\3\2\2\2`a\5 \21\2ab\7\5\2"+ "^\5\22\n\2]_\5\24\13\2^]\3\2\2\2^_\3\2\2\2_`\3\2\2\2`a\5 \21\2ab\7\5\2"+
@ -1553,7 +1573,7 @@ public class il65Parser extends Parser {
"\177|\3\2\2\2\177}\3\2\2\2\177~\3\2\2\2\u0080\33\3\2\2\2\u0081\u0082\b"+ "\177|\3\2\2\2\177}\3\2\2\2\177~\3\2\2\2\u0080\33\3\2\2\2\u0081\u0082\b"+
"\17\1\2\u0082\u008c\5\36\20\2\u0083\u0084\7\36\2\2\u0084\u0085\5\34\17"+ "\17\1\2\u0082\u008c\5\36\20\2\u0083\u0084\7\36\2\2\u0084\u0085\5\34\17"+
"\2\u0085\u0086\7\37\2\2\u0086\u008c\3\2\2\2\u0087\u008c\5\60\31\2\u0088"+ "\2\u0085\u0086\7\37\2\2\u0086\u008c\3\2\2\2\u0087\u008c\5\60\31\2\u0088"+
"\u008c\5$\23\2\u0089\u008c\5\"\22\2\u008a\u008c\5 \21\2\u008b\u0081\3"+ "\u008c\5$\23\2\u0089\u008c\5 \21\2\u008a\u008c\5\"\22\2\u008b\u0081\3"+
"\2\2\2\u008b\u0083\3\2\2\2\u008b\u0087\3\2\2\2\u008b\u0088\3\2\2\2\u008b"+ "\2\2\2\u008b\u0083\3\2\2\2\u008b\u0087\3\2\2\2\u008b\u0088\3\2\2\2\u008b"+
"\u0089\3\2\2\2\u008b\u008a\3\2\2\2\u008c\u00a1\3\2\2\2\u008d\u008e\f\f"+ "\u0089\3\2\2\2\u008b\u008a\3\2\2\2\u008c\u00a1\3\2\2\2\u008d\u008e\f\f"+
"\2\2\u008e\u008f\7 \2\2\u008f\u00a0\5\34\17\r\u0090\u0091\f\13\2\2\u0091"+ "\2\2\u008e\u008f\7 \2\2\u008f\u00a0\5\34\17\r\u0090\u0091\f\13\2\2\u0091"+

21
il65/test/UnitTests.kt Normal file
View File

@ -0,0 +1,21 @@
package demo
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.hamcrest.CoreMatchers.`is` as Is
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestSource() {
@Test
fun f() {
assertThat(2, Is(equalTo(2)))
}
@Test
fun f2() {
assertThat(2, Is(equalTo(3)))
}
}