Ejemplo n.º 1
0
        TKTArgModel parseFnArg()
        {
            TKTArgModel argt = new TKTArgModel();

            if (CurrentKind == TokenKind.Ident)
            {
                argt.ArgType = CurrentToken.GetText();
                MoveNext();
                if (CurrentKind == TokenKind.Colon)
                {
                    MoveNext();
                    if (CurrentKind == TokenKind.Ident)
                    {
                        argt.ArgName = CurrentToken.GetText();
                        MoveNext();
                        return(argt);
                    }
                    else
                    {
                        //error("参数名称不正确");
                    }
                }
                else
                {
                    //error("应该是':'");
                }
            }
            else
            {
                //error("参数类型不正确");
                MoveNext();
            }
            return(null);
        }
Ejemplo n.º 2
0
        TKTPropertyModel parseProperty(CodePostion parentPostion)
        {
            TKTPropertyModel ast = new TKTPropertyModel();

            ast.Postion = CurrentToken.Postion;
            if (CurrentKind != TokenKind.Ident)
            {
                //error("不是正确的名称");
            }
            else
            {
                ast.PropertyType = CurrentToken.GetText();
            }
            MoveNext();
            match(TokenKind.Colon);
            if (CurrentKind != TokenKind.Ident)
            {
                //error("不是正确的变量名称");
            }
            else
            {
                ast.PropertyName = CurrentToken.GetText();
            }
            MoveNext();
            if (CurrentKind == TokenKind.Assign)
            {
                MoveNext();
                skipToSemi();
                //Exp exp = parseExp();
                //ast.ValueExp = exp;
            }
            match(TokenKind.Semi);
            return(ast);
        }
Ejemplo n.º 3
0
        string parseFnText()
        {
            string text = CurrentToken.GetText();

            MoveNext();
            return(text);
        }
Ejemplo n.º 4
0
        string parseFnText()
        {
            string text = CurrentToken.GetText();

            //FnText textterm = new FnText ();
            //textterm.TextToken = CurrentToken;
            MoveNext();
            return(text);
        }
Ejemplo n.º 5
0
        TKTProcModel parseFnName()
        {
            TKTProcModel fname = new TKTProcModel();

            fname.Postion = CurrentToken.Postion;
            var curline = CurrentToken.Line;

            while (CurrentToken.Kind != TokenKind.EOF && curline == CurrentToken.Line)
            {
                if (CurrentKind == TokenKind.LBS)
                {
                    var arg = parseFnMuArg();
                    if (arg != null)
                    {
                        fname.Elements.Add(arg);
                    }
                }
                else if (CurrentKind == TokenKind.Ident)
                {
                    var textt = parseFnText();
                    if (textt != null)
                    {
                        fname.Elements.Add(textt);
                    }
                }
                else if (CurrentKind == TokenKind.AssignTo)
                {
                    if (fname.Elements == null || fname.Elements.Count == 0)
                    {
                        //error("过程没有名称");
                        MoveNext();
                    }
                    else
                    {
                        MoveNext();
                        if (CurrentKind == TokenKind.Ident)
                        {
                            fname.RetType = CurrentToken.GetText();
                            MoveNext();
                        }
                        else
                        {
                            //error("错误的过程结果");
                            MoveNext();
                        }
                    }
                }
                else
                {
                    //error("错误的过程名称");
                    MoveNext();
                }
            }
            return(fname);
        }
Ejemplo n.º 6
0
        public FileAST ParseFile()
        {
            prog = new FileAST();
            while (CurrentToken.Kind != TokenKind.EOF)
            {
                if (CurrentToken.IsKeyIdent("使用包" /*,"使用类型","简略使用"*/) && NextToken.Kind == TokenKind.Colon)
                {
                    var ast = ParseImport();
                    prog.Add(ast);
                }

                if (CurrentToken.IsKeyIdent("简略使用") && NextToken.Kind == TokenKind.Colon)
                {
                    var ast = ParseSimpleUse();
                    prog.Add(ast);
                }

                if (CurrentKind == TokenKind.Ident && CurrentText == "过程" && NextToken.Kind == TokenKind.Colon)
                {
                    MethodAST ast = ParseMethod();
                    prog.Add(ast);
                }
                else if (CurrentKind == TokenKind.Ident && CurrentText == "属性" && NextToken.Kind == TokenKind.Colon)
                {
                    parseStaticPropertyPart();
                }
                else if (CurrentToken.IsKeyIdent("属于") && NextToken.Kind == TokenKind.Colon)
                {
                    parseExtends();
                }
                else if (CurrentToken.IsKeyIdent("名称") && NextToken.Kind == TokenKind.Colon)
                {
                    parseName();
                }
                else if (CurrentToken.IsKeyIdent("约定") && NextToken.Kind == TokenKind.Colon)
                {
                    parseAgreement();
                }
                else
                {
                    error("无法识别'" + CurrentToken.GetText() + "'");
                    MoveNext();
                }
            }
            return(prog);
        }
Ejemplo n.º 7
0
        public TKTClassModel Parse(List <Token> tokens)
        {
            this.srcTokens = tokens;
            tktclass       = new TKTClassModel();
            this.srcTokens.Add(Token.EOF);
            this.srcTokens.Add(Token.EOF);
            this.srcTokens.Add(Token.EOF);
            this.index = 0;

            while (CurrentToken.Kind != TokenKind.EOF)
            {
                /*while (CurrentToken.IsKeyIdent("使用包","使用类型","简略使用")&& NextToken.Kind == TokenKind.Colon)
                 * {
                 *  ParseImport();
                 * }*/
                if (CurrentToken.IsKeyIdent("导入") && NextToken.Kind == TokenKind.Colon)
                {
                    ParseImport();
                }

                if (CurrentToken.IsKeyIdent("使用") && NextToken.Kind == TokenKind.Colon)
                {
                    ParseSimpleUse();
                }
                if (CurrentToken.GetText().EndsWith("类型") && CurrentToken.Kind == TokenKind.Ident && NextToken.Kind == TokenKind.Colon)
                {
                    parseExtends();
                }
                else if (CurrentToken.IsKeyIdent("名称") && NextToken.Kind == TokenKind.Colon)
                {
                    parseName();
                }
                else if (CurrentKind == TokenKind.Ident && CurrentText == "过程" && NextToken.Kind == TokenKind.Colon)
                {
                    var    ast      = ParseMethod();
                    string typeName = tktclass.GetTypeName();
                    if (ast.IsContruct())
                    {
                        tktclass.ContructList.Add(ast.ToContruct());
                    }
                    else if (!string.IsNullOrEmpty(typeName) && ast.IsContruct(typeName))
                    {
                        tktclass.ContructList.Add(ast.ToContruct());
                    }
                    else
                    {
                        tktclass.ProcList.Add(ast);
                    }
                    //tktclass. //prog.Add(ast);
                }
                else if (CurrentKind == TokenKind.Ident && CurrentText == "属性" && NextToken.Kind == TokenKind.Colon)
                {
                    parsePropertyPart();
                }

                else if (CurrentToken.IsKeyIdent("约定") && NextToken.Kind == TokenKind.Colon)
                {
                    parseAgreement();
                }
                else
                {
                    //error("无法识别'"+CurrentToken.GetText()+"'");
                    MoveNext();
                }
            }
            return(tktclass);
        }