public void BeginVisit(AstNode node)
    {
      var definition = node as ScriptFunctionDefinition;
      if (definition == null || string.IsNullOrEmpty(definition.Name)) return;

      definition._owner = _script;
      _script.Context.SetItem(definition.Name, definition);

      EventBroker.RegisterFunction(definition, _script);
    }
    public CodeObject Compile(AstNode syntaxNode, CodeProgram prog)
    {
      var syntax = (ScriptCompoundStatement)syntaxNode;

      var block = new CodeBlockStatement();

      foreach (var syntaxStatement in syntax.Statements)
        block.Statements.Add(
          (CodeStatement)AstDomCompiler.Compile(syntaxStatement, prog));

      return block;
    }
Ejemplo n.º 3
0
    public void BeginVisit(AstNode node)
    {
      var elements = node as ScriptElements;
      if (elements == null) return;

      var modified = new List<AstNode>();
      foreach (var child in elements.ChildNodes)
      {
        modified.Add(new DebugNode());
        modified.Add(child);
      }

      elements.ChildNodes.Clear();
      elements.ChildNodes.AddRange(modified);
    }
    public CodeObject Compile(AstNode syntaxNode, CodeProgram prog)
    {
      var syntax = (ScriptSwitchRootStatement)syntaxNode;

      var condition = AstDomCompiler.Compile<CodeExpression>(syntax.Expression, prog);

      var cases = new List<CodeSwitchCase> ();
      foreach (var statement in syntax.Switch.Cases)
      {
        cases.Add(new CodeSwitchCase(
          AstDomCompiler.Compile<CodeExpression>(statement.Condition, prog),
          AstDomCompiler.Compile<CodeStatement>(statement.Statement, prog)));
      }
      
      if (syntax.Switch.DefaultCase != null)
      {
        cases.Add(new CodeSwitchCase(
            null,
            AstDomCompiler.Compile<CodeStatement>(syntax.Switch.DefaultCase.Statement, prog)));
      }

      var code = new CodeSwitchStatement(condition, cases);
      return code;
    }
Ejemplo n.º 5
0
 public void Push(AstNode node, ParserState state)
 {
   _data.Add(new ParserStackElement(node, state));
 }
Ejemplo n.º 6
0
 public ParserStackElement(AstNode node, ParserState state)
 {
   Node = node;
   State = state;
 }
 public void EndVisit(AstNode node)
 {
 }
Ejemplo n.º 8
0
    private AstNode CreateNode(ActionRecord reduceAction, SourceSpan sourceSpan, AstNodeList childNodes)
    {
      IGrammarTerm nonTeminal = reduceAction.NonTerminal;
      AstNode result;

      AstNodeArgs args = new AstNodeArgs(nonTeminal, sourceSpan, childNodes);
 
      Type ntNodeType = nonTeminal.NodeType ?? typeof(AstNode);

      bool isList = nonTeminal.IsSet(TermOptions.IsList);
      if (isList && childNodes.Count > 1 && childNodes[0].Term == nonTeminal)
      {
        result = childNodes[0];
        AstNode newChild = childNodes[childNodes.Count - 1];
        newChild.Parent = result;
        result.ChildNodes.Add(newChild);
        return result;
      }

      if (nonTeminal.IsSet(TermOptions.IsStarList) && childNodes.Count == 1)
      {
        childNodes = childNodes[0].ChildNodes;
      }

      if (!isList && !nonTeminal.IsSet(TermOptions.IsPunctuation) && childNodes.Count == 1)
      {
        Type childNodeType = childNodes[0].Term.NodeType ?? typeof(AstNode);
        if (childNodeType == ntNodeType || childNodeType.IsSubclassOf(ntNodeType))
          return childNodes[0];
      }

      result = null;
      if (ntNodeType == typeof(AstNode))
      {
        result = new AstNode(args);
      }
      else
      {
        ConstructorInfo ctor = ntNodeType.GetConstructor(new Type[] { typeof(AstNodeArgs) });
        if (ctor == null)
          throw new Exception("Failed to located constructor: " + ntNodeType.ToString() + "(AstNodeArgs args)");

        result = (AstNode)ctor.Invoke(new object[] { args });
      }

      return result;
    }