pascalabcnet/_ParsePABC1/ParsePABC1/UniversalVisitors/DeleteRedundantBeginEnds.cs

37 lines
1 KiB
C#
Raw Permalink Normal View History

2015-06-28 10:53:10 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PascalABCCompiler.Errors;
using PascalABCCompiler;
using PascalABCCompiler.SyntaxTree;
namespace SyntaxVisitors
2015-06-28 10:53:10 +03:00
{
public class DeleteRedundantBeginEnds : BaseChangeVisitor
2015-06-28 10:53:10 +03:00
{
public override void Exit(syntax_tree_node st)
{
var stl = st as statement_list;
if (stl != null && UpperNode() is statement_list)
ReplaceStatement(stl, stl.subnodes);
var lst = st as labeled_statement;
if (lst != null)
{
var sttl = lst.to_statement as statement_list;
if (sttl != null)
{
sttl.subnodes[0] = new labeled_statement(lst.label_name, sttl.subnodes[0]); // а если [0] элемента вообще нет?
ReplaceStatement(lst,sttl.subnodes);
}
}
base.Exit(st);
}
}
}