Inheritance: NodeExpr
コード例 #1
0
ファイル: ModAnalyzer.cs プロジェクト: YourLocalFax/OLD-Score
 public void Visit(NodeIndex index)
 {
     log.Error(index.Span, "Expressions are not valid in this placement. Perhaps you meant to put it in a function?");
 }
コード例 #2
0
ファイル: ModCompiler.cs プロジェクト: YourLocalFax/OLD-Score
 public void Visit(NodeIndex index)
 {
     throw new NotImplementedException();
 }
コード例 #3
0
ファイル: AstWriter.cs プロジェクト: YourLocalFax/OLD-Score
 public void Visit(NodeIndex index)
 {
     Write("'(' ");
     index.target.Accept(this);
     Write(" ')'");
     Write(" '.' " + index.index.Image);
 }
コード例 #4
0
ファイル: TyChecker.cs プロジェクト: YourLocalFax/OLD-Score
 public void Visit(NodeIndex index)
 {
     index.target.Accept(this);
 }
コード例 #5
0
ファイル: Parser.cs プロジェクト: YourLocalFax/OLD-Score
        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);
        }