コード例 #1
0
 public void OutputElement(int d, ScopeSyntax s)
 {
     OutputString(Spaces(d));
     if (s == null)
     {
         throw new Exception("ggggggggg");
     }
     if (s is ParamsScopeSyntax)
     {
         OutputString(s.ToString() + ": ");
         if (s.Symbols.Count > 0)
         {
             OutputlnString(string.Join(", ", s.Symbols.Select(x => x.ToString())));
         }
     }
     else
     {
         OutputlnString(s.ToString());
         if (s.Symbols.Count > 0)
         {
             OutputlnString(Spaces(d + 2) + string.Join(", ", s.Symbols.Select(x => x.ToString())));
         }
     }
     foreach (var sc in s.Children)
     {
         OutputElement(d + 2, sc);
     }
 }
コード例 #2
0
 public override void Exit(syntax_tree_node st)
 {
     switch (st)
     {
     case program_module p:
     case procedure_definition pd:
     case formal_parameters fp:
     case statement_list stl:
     case for_node f:
     case foreach_stmt fe:
     case class_definition cd:
     case record_type rt:
     case function_lambda_definition fld:
     //case repeat_node rep:
     case case_node cas:
         Current = Current.Parent;
         break;
     }
 }
コード例 #3
0
        public override void Enter(syntax_tree_node st)
        {
            ScopeSyntax t = null;

            switch (st)
            {
            case program_module p:
            case unit_module u:
                t    = new GlobalScopeSyntax();
                Root = t;
                break;

            case procedure_definition p:
                var name = p.proc_header?.name?.meth_name;
                if (name == null)
                {
                    name = "create";
                }
                var attr = p.proc_header.class_keyword ? Attributes.class_attr : 0;
                if (name != null)
                {
                    if (p.proc_header is function_header)
                    {
                        AddSymbol(name, SymKind.funcname, null, attr);
                    }
                    else
                    {
                        AddSymbol(name, SymKind.procname, null, attr);
                    }
                }
                t = new ProcScopeSyntax(name);
                break;

            //case formal_parameters p:// Это неправильный Scope - он закрывался при выходе из секции формальных параметров, что неправильно
            //    t = new ParamsScopeSyntax();
            //    break;
            case statement_list p:
                t = new StatListScopeSyntax();
                break;

            case for_node p:
                t = new ForScopeSyntax();
                break;

            case foreach_stmt p:
                t = new ForeachScopeSyntax();
                break;

            /*case repeat_node p: // не надо т.к. это StatListScope
             *  t = new RepeatScopeSyntax();
             *  break;*/
            case case_node p:
                t = new CaseScopeSyntax();
                break;

            case class_definition p:
                var td    = p.Parent as type_declaration;
                var tname = td == null ? "NONAME" : td.type_name;
                if (p.keyword == class_keyword.Class)
                {
                    AddSymbol(tname, SymKind.classname);
                    t = new ClassScopeSyntax(tname);
                }
                else if (p.keyword == class_keyword.Record)
                {
                    AddSymbol(tname, SymKind.recordname);
                    t = new RecordScopeSyntax(tname);
                }
                else if (p.keyword == class_keyword.Interface)
                {
                    AddSymbol(tname, SymKind.interfacename);
                    t = new InterfaceScopeSyntax(tname);
                }
                break;

            case function_lambda_definition p:
                t = new LambdaScopeSyntax();
                break;
            }
            if (t != null)
            {
                t.Parent = Current;
                if (Current != null)
                {
                    Current.Children.Add(t);
                }
                Current = t;
                if (st is procedure_definition p)
                {
                    if (p.proc_header is function_header fh)
                    {
                        AddSymbol(new ident("Result"), SymKind.var, fh.return_type);
                    }
                }
            }
        }