Beispiel #1
0
        private bool TryParseAssign(out Node result)
        {
            if (Tokens.CurrentToken == TokenType.Symbol)
            {
                string name = Tokens.CurrentSymbol;

                Tokens.ReadNext();
                if (Tokens.CurrentToken == TokenType.Assign)
                {
                    Node lhs = new NodeVariable(name);

                    Tokens.ReadNext();
                    Node rhs = ParseOr();
                    result = new NodeAssign(lhs, rhs);
                    return(true);
                }
            }

            Tokens.Reset();
            result = default;
            return(false);
        }
Beispiel #2
0
 void ASTVisitor.Accept(NodeAssign value)
 {
     Accept(value);
 }
Beispiel #3
0
 internal void Accept(NodeAssign assign)
 {
     // There are only a few ways to assign, sooo
     var target = assign.target;
     if (target is NodeIdentifier)
     {
         assign.value.Visit(this);
         builder.currentLineNumber = target.EndLine;
         builder.Store((target as NodeIdentifier).image, false);
     }
     else if (target is NodeIndex)
     {
         var index = target as NodeIndex;
         index.target.Visit(this);
         index.args.ForEach(arg => arg.Visit(this));
         assign.value.Visit(this);
         builder.currentLineNumber = index.EndLine;
         builder.OpIStore((uint)index.args.Count);
     }
     else if (target is NodeOperatorIndex)
     {
         var opIndex = target as NodeOperatorIndex;
         opIndex.target.Visit(this);
         assign.value.Visit(this);
         builder.currentLineNumber = opIndex.target.EndLine;
         builder.OpOIStore(opIndex.op);
     }
     // TODO other things when I add them
     if (!assign.isResultRequired)
         builder.OpPop();
 }