예제 #1
0
        private IEnumerable<AstNode> ParseAssignment(CommonTree node)
        {
            var target = ParseAntlrNode(node.XChildren()[0]).Single();
            if (!(target is VariableExpression))
            {
                throw new SemanticErrorException(ElfCode, node, ElfExceptionType.InvalidAssignmentLhs);
            }

            var expression = (Expression)ParseAntlrNode(node.XChildren()[1]).Single();
            yield return new AssignmentExpression((VariableExpression)target, expression);
        }
예제 #2
0
 private IEnumerable<AstNode> ParseRegularInvocation(CommonTree node)
 {
     CheckIfLoophole(node);
     yield return new InvocationExpression(node.XChildren()[0].Text,
         ParseAntlrNode(node.XChildren()[1].Children).Cast<Expression>());
 }
예제 #3
0
        private IEnumerable<AstNode> ParseIf(CommonTree node)
        {
            var test = (Expression)ParseAntlrNode(node.XChildren()[0]).Single();
            var then = (Block)ParseAntlrNode(node.XChildren()[1]).Single();

            if (node.XChildren().Count() == 2)
            {
                yield return new IfStatement(test, then);
            }
            else
            {
                var @else = (Block)ParseAntlrNode(node.XChildren()[2]).Single();
                yield return new IfStatement(test, then, @else);
            }
        }
예제 #4
0
 private IEnumerable<AstNode> ParseParexpr(CommonTree node)
 {
     yield return ParseAntlrNode(node.XChildren().ElementAt(0)).Single();
 }
예제 #5
0
 private IEnumerable<AstNode> ParseRet(CommonTree node)
 {
     if (node.XChildren().Count() == 0)
     {
         yield return new ReturnStatement();
     }
     else
     {
         yield return new ReturnStatement((Expression)ParseAntlrNode(node.XChildren()[0]).Single());
     }
 }
예제 #6
0
 private IEnumerable<AstNode> ParseVar(CommonTree node)
 {
     foreach(var varDecl in node.XChildren())
     {
         if (varDecl.XChildren().Count() == 0)
         {
             yield return new VarStatement(varDecl.Text);
         }
         else
         {
             yield return new VarStatement(varDecl.XChildren()[0].Text);
             yield return new ExpressionStatement(
                 (AssignmentExpression)ParseAntlrNode(varDecl).Single());
         }
     }
 }
예제 #7
0
 private IEnumerable<AstNode> ParseExpr(CommonTree node)
 {
     yield return new ExpressionStatement((Expression)ParseAntlrNode(node.XChildren()[0]).Single());
 }
예제 #8
0
        private IEnumerable<AstNode> ParseFunc(CommonTree node)
        {
            var decl = node.XChildren().Single(c => c.Token.Type == ElfParser.DECL);
            var name = decl.XChildren()[0].Text;
            var args = decl.XChildren()[1].XChildren().Select(c => c.Text);
            var bodyBlock = node.XChildren()[1];

            yield return new FuncDef(name, args, (Block)ParseAntlrNode(bodyBlock).Single());
        }
예제 #9
0
        private IEnumerable<AstNode> ParseClass(CommonTree node)
        {
            var decl = node.XChildren().Single(c => c.Token.Type == ElfParser.DECL);
            var name = decl.XChildren()[0].Text;
            var rtimpl = decl.XChildren()[1].XChildren().ElementAt(0).Text;

            yield return new ClassDef(name, rtimpl, ParseAntlrNode(node.XChildren().Skip(1)).Cast<FuncDef>());
        }