Пример #1
0
 public Symbol(Symbol parent, TypeAST type, string name, ArgAST[] args)
 {
     this.parent = parent;
     this.type   = type;
     this.name   = name;
     this.args   = args;
 }
Пример #2
0
 public ObjInstAST(Token instToken, TypeAST typeAST, AST value)
 {
     this.instToken = instToken;
     this.name      = instToken.value;
     this.typeAST   = typeAST;
     this.value     = value;
 }
 public MethodDeclFAST(FormParsAST par,TypeAST tip, Token id,BlockAST blo)
 {
     bloque=blo;
     parametros=par;
     ident=id;
     tipo=tip;
 }
 public MethodDeclMAST(DeclarationsAST decls, TypeAST tip, Token id,BlockAST blo)
 {
     bloque=blo;
     declaraciones=decls;
     ident=id;
     tipo=tip;
 }
Пример #5
0
        // parse unknown amount of arguments for a function, entry on open bracket
        ArgAST[] ParseArgs()
        {
            List <ArgAST> args = new List <ArgAST>();

            while (tokens.Next() != null && !tokens.IsType(TokenType.RParen))
            {
                if (tokens.IsType(TokenType.Comma))                     // end of this arg, got another tho
                {
                    tokens.Next();
                    if (tokens.IsType(TokenType.EndLine) || tokens.IsType(TokenType.EndFile))
                    {
                        ShowError("Incomplete arg list", tokens.Prev());
                    }
                }
                if (tokens.IsType(TokenType.AllIdentifiers))                     // type
                {
                    TypeAST type = new TypeAST(tokens.current);
                    tokens.Next();
                    if (tokens.IsType(TokenType.AllIdentifiers))                         // arg name
                    {
                        args.Add(new ArgAST(tokens.current, type));
                    }
                }
                else
                {
                    ShowError("Incomplete arg list", tokens.current);
                }
            }
            tokens.SkipPastEndLine();
            return(args.ToArray());
        }
Пример #6
0
 public FuncDefAST(Token token, TypeAST type, ArgAST[] args, BlockAST stmt)
 {
     this.token   = token;
     this.name    = token.value;
     this.retType = type;
     this.args    = args;
     this.stmt    = stmt;
 }
 public MethodDeclFMAST(FormParsAST par, DeclarationsAST decls, TypeAST tip, Token id,BlockAST blo)
 {
     bloque=blo;
     parametros=par;
     declaraciones=decls;
     ident=id;
     tipo=tip;
 }
Пример #8
0
            public void AddParent(TypeAST typeAST, string name, ArgAST[] argsAST)
            {
                Symbol sym = new Symbol(curSymbol, typeAST, name, argsAST);

                prevSymbols.Enqueue(curSymbol);
                symbols.Add(sym);
                curSymbol = sym;
            }
Пример #9
0
        private TempTypeBody ParseTempTypeBody()
        {
            var tempTypeBody = new TempTypeBody(fileAST);

            while (tape.HasCurrent)
            {
                SectionRaw section = tape.Current;
                if (section is SectionNameRaw)
                {
                    if (tempTypeBody.NameSection == null)
                    {
                        tempTypeBody.NameSection = (section as SectionNameRaw);
                        tape.MoveNext();
                    }
                    else
                    {
                        TypeAST tast = tempTypeBody.Parse();
                        fileAST.AddTypeAST(tast);
                        break;
                    }
                }
                //else if ((section is SectionExtendsRaw) || (section is SectionPropertiesRaw) || (section is SectionProcRaw))
                //{
                //    ParseTypeSection();
                //}
                else if (section is SectionExtendsRaw)
                {
                    tempTypeBody.ExtendsSection = (section as SectionExtendsRaw);
                    tape.MoveNext();
                }
                else if (section is SectionPropertiesRaw)
                {
                    tempTypeBody.PropertiesSection = (section as SectionPropertiesRaw);
                    tape.MoveNext();
                }
                else if (section is SectionProcRaw)
                {
                    tempTypeBody.Proces.Add(section as SectionProcRaw);
                    tape.MoveNext();
                }
                else
                {
                    throw new CCException();
                }
            }
            return(tempTypeBody);
        }
Пример #10
0
        public FileAST Parse(FileRaw fileRaw, ContextFile fileContext)
        {
            fileAST = new FileAST(fileContext);
            tape    = new ArrayTape <SectionRaw>(fileRaw.Sections);

            while (tape.HasCurrent)
            {
                SectionRaw section = tape.Current;
                if (section is SectionImportRaw)
                {
                    fileAST.ImportSection = new SectionImport(fileAST, section as SectionImportRaw);
                    tape.MoveNext();
                }
                else if (section is SectionUseRaw)
                {
                    //fileAST.UseSection = (section as SectionUse);
                    //fileAST.UseSection.FileContext = fileAST.FileContext;
                    //tape.MoveNext();
                    fileAST.UseSection = new SectionUse(fileAST, section as SectionUseRaw);
                    //fileAST.ImporteSection.FileContext = fileAST.FileContext;
                    tape.MoveNext();
                }
                //else if (section is SectionNameRaw)
                //{
                //    ParseType();
                //}
                else if ((section is SectionExtendsRaw) || (section is SectionPropertiesRaw) || (section is SectionProcRaw) || section is SectionNameRaw)
                {
                    //ParseTypeSection();
                    var     tempTypeBody = ParseTempTypeBody();
                    TypeAST tast         = tempTypeBody.Parse();
                    fileAST.AddTypeAST(tast);
                }
                else
                {
                    throw new CCException();
                }
            }

            return(fileAST);
        }
 public MethodDeclBasicAST(TypeAST tip, Token id,BlockAST blo)
 {
     bloque=blo;
     ident=id;
     tipo=tip;
 }
 public VarDeclUnIDAST(Token id, TypeAST tip)
 {
     identificador=id;
     tipo=tip;
 }
Пример #13
0
            public object DoForType(TypeAST t, object options = null)
            {
                ObjType ot = GetTypeFromName(t.token.value);

                return(ot);
            }
Пример #14
0
 public ArgAST(Token token, TypeAST typeAST)
 {
     this.token   = token;
     this.name    = token.value;
     this.typeAST = typeAST;
 }
Пример #15
0
 public object DoForType(TypeAST t, object options = null)
 {
     PositionOutput(t.token.indent);
     ConsoleEx.WriteLine("{0}(Type) {1}{2}", ConsoleColor.DarkBlue, ConsoleColor.Gray, t.token.value);
     return(options);
 }
Пример #16
0
            public void Add(TypeAST typeAST, string name, ArgAST[] argsAST)
            {
                Symbol sym = new Symbol(curSymbol, typeAST, name, argsAST);

                symbols.Add(sym);
            }
Пример #17
0
        BlockAST Statments(int startIndent = 0)
        {
            List <AST> stmts    = new List <AST>();
            Token      firstTok = tokens.current;

            do
            {
                string found = GetStmntMatch(tokens);
                switch (found)
                {
                case "Command": {
                    AST stmtAST = null;
                    switch (tokens.curTokenType)
                    {
                    case TokenType.Return:
                        Token   retTok = tokens.current;
                        ExprAST expAST = ParseExpr();
                        stmtAST = new RetCmdAST(retTok, expAST);
                        break;

                    default:
                        ShowError("Unknown command", tokens.current);
                        break;
                    }
                    if (stmtAST != null)
                    {
                        stmts.Add(stmtAST);
                    }
                    break;
                }

                case "Main": {
                    TypeAST  typeAST = new TypeAST(tokens.current);
                    Token    mainTok = tokens.Next();
                    ArgAST[] argsAST = ParseArgs();
                    symbols.AddParent(typeAST, mainTok.value, argsAST);
                    BlockAST stmtAST = Statments(startIndent + 1);
                    symbols.RemParent();
                    AST functAST = new FuncDefAST(mainTok, typeAST, argsAST, stmtAST);
                    stmts.Add(functAST);
                    break;
                }

                case "Function": {
                    TypeAST  typeAST = new TypeAST(tokens.current);
                    Token    instTok = tokens.Next();
                    ArgAST[] argsAST = ParseArgs();
                    symbols.AddParent(typeAST, instTok.value, argsAST);
                    BlockAST stmtAST = Statments(startIndent + 1);
                    symbols.RemParent();
                    AST functAST = new FuncDefAST(instTok, typeAST, argsAST, stmtAST);
                    stmts.Add(functAST);
                    break;
                }

                case "ObjectDef": {                             // TokenType.Identifier, TokenType.Colon
                    TypeAST typeAST = new TypeAST(tokens.current);
                    tokens.Next();
                    symbols.AddParent(typeAST, "", null);
                    tokens.Next();
                    BlockAST stmtAST = Statments(startIndent + 1);
                    symbols.RemParent();
                    ObjDefAST odAST = new ObjDefAST(tokens.current, stmtAST);
                    stmts.Add(odAST);
                    break;
                }

                case "SimpleObjectInst": {                          // TokenType.AllTypes, TokenType.Identifier
                    TypeAST typeAST = new TypeAST(tokens.current);
                    tokens.Next();
                    symbols.Add(typeAST, tokens.current.value, null);
                    ObjInstAST odAST = new ObjInstAST(tokens.current, typeAST, null);
                    stmts.Add(odAST);
                    break;
                }

                case "ObjectInst": {
                    TypeAST typeAST = new TypeAST(tokens.current);
                    tokens.Next();
                    symbols.Add(typeAST, tokens.current.value, null);
                    ObjInstAST odAST = new ObjInstAST(tokens.current, typeAST, null);
                    stmts.Add(odAST);
                    break;
                }

                case "SimpleObjectInstAssigned": {
                    TypeAST typeAST = new TypeAST(tokens.current);
                    Token   instTok = tokens.Next();
                    symbols.Add(typeAST, instTok.value, null);
                    tokens.Next();
                    NumAST     numAST = new NumAST(tokens.current, tokens.current.value, tokens.curTokenType);
                    ObjInstAST odAST  = new ObjInstAST(instTok, typeAST, numAST);
                    stmts.Add(odAST);
                    break;
                }

                case "ObjectInstAssigned": {
                    TypeAST typeAST = new TypeAST(tokens.current);
                    Token   instTok = tokens.Next();
                    symbols.Add(typeAST, instTok.value, null);
                    tokens.Next();
                    NumAST     numAST = new NumAST(tokens.current, tokens.current.value, tokens.curTokenType);
                    ObjInstAST odAST  = new ObjInstAST(instTok, typeAST, numAST);
                    stmts.Add(odAST);
                    break;
                }

                default:
                    ShowError("Unable to parse statement", tokens.current);
                    break;
                }
            } while (tokens.Remaining() > 0);
            return(new BlockAST(firstTok, stmts.ToArray()));
        }
 public UnFormParsAST(IDAST id,TypeAST tip)
 {
     tipo=tip;
     ident=id;
 }