예제 #1
0
        private static void ParseField(Lexer.Lexer lexer, out Exp k, out Exp v)
        {
            k = null;
            v = null;

            if (lexer.LookAhead() == ETokenType.SepLBracket)
            {
                lexer.NextToken(out _, out _, out _);
                k = ParseExp(lexer);
                lexer.NextTokenOfKind(ETokenType.SepRBracket, out _, out _);
                lexer.NextTokenOfKind(ETokenType.OpAssign, out _, out _);
                v = ParseExp(lexer);
                return;
            }

            var exp = ParseExp(lexer);

            if (exp is NameExp nameExp)
            {
                if (lexer.LookAhead() == ETokenType.OpAssign)
                {
                    lexer.NextToken(out _, out _, out _);
                    k = new StringExp {
                        Line = nameExp.Line, Str = nameExp.Name
                    };
                    v = ParseExp(lexer);
                    return;
                }
            }

            v = exp;
        }
예제 #2
0
        private static Exp FinishPrefixExp(Lexer.Lexer lexer, Exp exp)
        {
            while (true)
            {
                switch (lexer.LookAhead())
                {
                case ETokenType.SepLBracket:
                {
                    lexer.NextToken(out _, out _, out _);
                    var keyExp = ParseExp(lexer);
                    lexer.NextTokenOfKind(ETokenType.SepRBracket, out _, out _);
                    exp = new TableAccessExp
                    {
                        LastLine  = lexer.Line,
                        PrefixExp = exp,
                        KeyExp    = keyExp
                    };
                    break;
                }

                case ETokenType.SepDot:
                {
                    lexer.NextToken(out _, out _, out _);
                    lexer.NextIdentifier(out var line, out var name);
                    var keyExp = new StringExp
                    {
                        Line = line,
                        Str  = name
                    };
                    exp = new TableAccessExp
                    {
                        LastLine  = line,
                        PrefixExp = exp,
                        KeyExp    = keyExp
                    };
                    break;
                }

                case ETokenType.SepColon:
                case ETokenType.SepLParen:
                case ETokenType.SepLCurly:
                case ETokenType.String:
                {
                    exp = FinishFuncCallExp(lexer, exp);
                    break;
                }

                default:
                    return(exp);
                }
            }
        }
예제 #3
0
        private static void ParseFuncName(Lexer.Lexer lexer, out Exp exp, out bool hasColon)
        {
            hasColon = false;
            lexer.NextIdentifier(out var line, out var name);
            exp = new NameExp {
                Line = line, Name = name
            };

            while (lexer.LookAhead() == ETokenType.SepDot)
            {
                lexer.NextToken(out _, out _, out _);
                lexer.NextIdentifier(out line, out name);
                var idx = new StringExp {
                    Line = line, Str = name
                };
                exp = new TableAccessExp
                {
                    LastLine  = line,
                    KeyExp    = idx,
                    PrefixExp = exp,
                };
            }

            if (lexer.LookAhead() == ETokenType.SepColon)
            {
                lexer.NextToken(out _, out _, out _);
                lexer.NextIdentifier(out line, out name);
                var idx = new StringExp {
                    Line = line, Str = name
                };
                exp = new TableAccessExp
                {
                    LastLine  = line,
                    PrefixExp = exp,
                    KeyExp    = idx,
                };
                hasColon = true;
            }
        }
예제 #4
0
파일: typecheck.cs 프로젝트: ydunk/masters
 public void StringExp(StringExp e)
 {
     e.ExpType = typeof(CList);
 }
예제 #5
0
파일: codegen.cs 프로젝트: ydunk/masters
 public void StringExp(StringExp e)
 {
     il.Emit(OpCodes.Ldstr, (e.Value));
     il.Emit(OpCodes.Call, ((typeof(LispRuntime)).GetMethod("Init")));
 }