-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvert.cs
39 lines (35 loc) · 1.07 KB
/
Convert.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Antlr4.Runtime.Misc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZhangShashaCSharp
{
public class Convert : sexprBaseVisitor<Node>
{
public override Node VisitSexpr([NotNull] sexprParser.SexprContext context)
{
return VisitList(context.list());
}
public override Node VisitList([NotNull] sexprParser.ListContext context)
{
var atom = VisitAtom(context.atom());
foreach (var c in context.item())
{
atom.children.Add(VisitItem(c));
}
return atom;
}
public override Node VisitItem([NotNull] sexprParser.ItemContext context)
{
var a = context.atom();
if (a != null) return VisitAtom(a);
else return VisitList(context.list());
}
public override Node VisitAtom([NotNull] sexprParser.AtomContext context)
{
return new Node() { label = context.GetText() };
}
}
}