public override void EnterFieldDeclaration([NotNull] NovaParser.FieldDeclarationContext context) { NovaParser.MemberDeclarationContext parent = (NovaParser.MemberDeclarationContext)context.parent; ModifiersEnum modifiers = ParserUtils.ParseModifier(parent.modifier().classModifier().GetText()); VariableDeclaratorContext declarator = context.variableDeclarator(); string type = context.typeType().GetText(); string name = declarator.variableDeclaratorId().GetText(); Field field = new Field(Class, Class.PopFieldId(), modifiers, new Variable(name, type, context.variableDeclarator())); ExpressionNode value = new ExpressionNode(field); var initializer = declarator.variableInitializer(); if (initializer != null) { ExpressionContext expressionContext = initializer.expression(); ExpressionListener listener = new ExpressionListener(field); // same here foreach (var expression in expressionContext.GetRuleContexts <ParserRuleContext>()) { expression.EnterRule(listener); } value = listener.GetResult(); } field.Value = value; Class.Fields.Add(field.Name, field); }
public override void EnterLocalVariableDeclaration([NotNull] NovaParser.LocalVariableDeclarationContext context) { VariableDeclaratorContext declarator = context.variableDeclarator(); string type = context.typeType().GetChild(0).GetText(); string name = declarator.variableDeclaratorId().GetText(); DeclarationStatement statement = new DeclarationStatement(Parent, context); Variable variable = new Variable(name, type, context.variableDeclarator()); ExpressionNode value = new ExpressionNode(statement); VariableInitializerContext initializer = declarator.variableInitializer(); if (initializer != null) { ExpressionContext expressionContext = initializer.expression(); ExpressionListener listener = new ExpressionListener(statement); expressionContext.EnterRule(listener); value = listener.GetResult(); } statement.Variable = variable; statement.Value = value; Result.Add(statement); }
public override void EnterReturnStatement([NotNull] ReturnStatementContext context) { ReturnStatement returnStatement = new ReturnStatement(Parent, context); if (context.expression() != null) { ExpressionListener listener = new ExpressionListener(returnStatement); context.expression().EnterRule(listener); returnStatement.Value = listener.GetResult(); } Result.Add(returnStatement); }
public override void EnterStatementExpression([NotNull] StatementExpressionContext context) { ExpressionStatement statement = new ExpressionStatement(Parent, context); ExpressionListener listener = new ExpressionListener(statement); context.expression().EnterRule(listener); ExpressionNode value = listener.GetResult(); statement.Expression = value; Result.Add(statement); }
public override void EnterWhileStatement([NotNull] WhileStatementContext context) { WhileStatement whileStatement = new WhileStatement(Parent, context); ExpressionListener expressionListener = new ExpressionListener(whileStatement); context.parExpression().expression().EnterRule(expressionListener); whileStatement.Condition = expressionListener.GetResult(); StatementListener statementListener = new StatementListener(whileStatement); context.statement().EnterRule(statementListener); whileStatement.Statements = statementListener.Result; Result.Add(whileStatement); }
/* * Assignation * [Type] [Identifier] = [ExpressionNode] */ public override void EnterAssignationStatement([NotNull] AssignationStatementContext context) { AssignationStatement statement = new AssignationStatement(Parent, context); ExpressionListener listener = new ExpressionListener(statement); context.right.EnterRule(listener); ExpressionNode value = listener.GetResult(); statement.Value = value; listener = new ExpressionListener(statement); context.left.EnterRule(listener); statement.Target = listener.GetResult().Get <VariableNameExpression>(0); statement.Operator = '='; Result.Add(statement); }
private List <ExpressionNode> GetMethodCallParameters(IChild parent, ParserRuleContext context, ExpressionListContext expressionListContext) { List <ExpressionNode> results = new List <ExpressionNode>(); if (expressionListContext != null) { var parameters = expressionListContext.GetRuleContexts <ParserRuleContext>(); foreach (var parameter in parameters) { ExpressionListener listener = new ExpressionListener(parent); parameter.EnterRule(listener); ExpressionNode result = listener.GetResult(); results.Add(result); } } return(results); }
public override void EnterIfStatement([NotNull] IfStatementContext context) { IfStatement statement = new IfStatement(Parent, context); ExpressionListener listener = new ExpressionListener(statement); context.parExpression().expression().EnterRule(listener); statement.IfCondition = listener.GetResult(); StatementListener statementListener = new StatementListener(statement); context.ifSt.EnterRule(statementListener); statement.IfStatements = statementListener.GetResult(); if (context.elseSt != null) { statementListener = new StatementListener(statement); context.elseSt.EnterRule(statementListener); statement.ElseStatements = statementListener.GetResult(); } Result.Add(statement); }
public override void EnterForStatement([NotNull] ForStatementContext context) { ForStatement statement = new ForStatement(Parent, context); StatementListener statementListener = new StatementListener(statement); context.forControl().forInit.EnterRule(statementListener); statement.Init = statementListener.GetResult().First(); statementListener = new StatementListener(statement); context.statement().EnterRule(statementListener); statement.Statements = statementListener.GetResult(); ExpressionListener expressionListener = new ExpressionListener(statement); context.forControl().forCond.EnterRule(expressionListener); statement.Condition = expressionListener.GetResult(); statementListener = new StatementListener(statement); context.forControl().forUpdate.EnterRule(statementListener); statement.Update = statementListener.GetResult().First(); Result.Add(statement); }