Represents an identifier.
Inheritance: NodeExpr
Beispiel #1
0
 public void Visit(NodeId id)
 {
     log.Error(id.Span, "An identifier is not valid in this placement. Perhaps you meant to put it in a function?");
 }
Beispiel #2
0
 public NodeIndex(NodeExpr target, Token spDot, NodeId index)
 {
     this.target = target;
     this.spDot = spDot;
     this.index = index;
 }
Beispiel #3
0
 public void Visit(NodeId id)
 {
     throw new NotImplementedException();
 }
Beispiel #4
0
 public void Visit(NodeId id)
 {
     var sym = walker.Current.Lookup(id.Image);
     Push(sym.Ty);
 }
Beispiel #5
0
 public void Visit(NodeId id)
 {
     var name = id.Image;
     var sym = walker.Current.Lookup(name);
     var val = BuildLoad(builder, (LLVMValueRef)sym.userdata, "");
     Push(id.Span, sym.Ty, val);
 }
Beispiel #6
0
 public void Visit(NodeId id)
 {
 }
Beispiel #7
0
 public void Visit(NodeId id)
 {
     Write(id.Image);
 }
Beispiel #8
0
        private NodeExpr ParsePrimaryExpr(bool isEnclosed, bool doError = true)
        {
            if (!HasCurrent)
            {
                log.Error(GetLastSpan(), "Expected a primary expression, got end of file.");
                return null;
            }

            NodeExpr result;
            switch (Current.type)
            {
                case IF:
                {
                    var @if = new NodeIf();
                    while (Check(IF))
                    {
                        Advance();
                        @if.conditions.Add(new NodeIf.IfBlock(ParseExpr(), ParseBlock()));
                        if (Check(EL))
                        {
                            if (!Check(IF))
                            {
                                @if.fail = ParseBlock();
                                break;
                            }
                            else Advance();
                        }
                    }
                    result = @if;
                } break;
                case LPAREN:
                    var lparen = Current;
                    Advance();
                    if (Check(RPAREN))
                    {
                        result = new NodeTuple(lparen, Current, new List<NodeExpr>());
                        Advance();
                        break;
                    }
                    bool trailingComma;
                    var exprs = ParseCommaList(out trailingComma);
                    if (exprs.Count == 1 && !trailingComma)
                    {
                        Expect(RPAREN, "Expected ')' to match opening '('.");
                        result = new NodeEnclosed(lparen, Last, exprs[0]);
                    }
                    else
                    {
                        Expect(RPAREN, "Expected ')' to close tuple.");
                        result = new NodeTuple(lparen, Last, exprs);
                    }
                    break;
                case TRUE: case FALSE:
                {
                    result = new NodeBool(Current);
                    Advance();
                } break;
                case INT:
                {
                    result = new NodeInt(Current);
                    Advance();
                } break;
                case STR:
                {
                    result = new NodeStr(Current);
                    Advance();
                } break;
                case IDENT:
                {
                    result = new NodeId(Current);
                    Advance();
                } break;
                default:
                    if (doError)
                    {
                        log.Error(GetLastSpan(), "Unexpected token '{0}' when parsing primary expression.", Current);
                        Advance();
                    }
                    return null;
            }

            // TODO(kai): check field index.
            while (Check(DOT))
            {
                var dot = Current;
                Advance();
                result = new NodeIndex(result, dot, new NodeId(ExpectIdent("Identifier expected for type index.")));
            }

            return ParseInvoke(result, isEnclosed);
        }