コード例 #1
0
ファイル: Parser.cs プロジェクト: Benglin/designscript
        void Assoc_FunctionDecl(out Node node)
        {
            codeSegmentStarted = true;
            DesignScript.Parser.Associative.FunctionDefinitionNode f = null;
            f = new DesignScript.Parser.Associative.FunctionDefinitionNode()
            {
               Line = la.line,
               Col = la.col
            };

            if (la.kind == 26) {
            Get();
            if (t.val == "external")
               f.Kwexternal.SetValue(t.val, t.line, t.col);

            if (la.kind == 22) {
                Get();
                if (t.val == "native")
                   f.Kwnative.SetValue(t.val, t.line, t.col);

            }
            Assoc_ExternalLibraryReference(ref f);
            }
            Expect(25);
            if (t.val == "def")
               f.Kwdef.SetValue(t.val, t.line, t.col);
            else
               Get();

            DesignScript.Parser.Associative.IDEHelpNode IdentName = f.name;
            DesignScript.Parser.Associative.TypeNode IDEType = new DesignScript.Parser.Associative.TypeNode();

            DesignScript.Parser.Associative.ArgumentSignatureNode argumentSignature = null;
            DesignScript.Parser.Associative.Pattern pattern = null;

            Assoc_MethodSignature(out argumentSignature, out pattern, ref IdentName, ref IDEType);
            f.IDEReturnType = IDEType;
            f.name = IdentName;
            f.Pattern = pattern;
            f.Singnature = argumentSignature;

            while (!(StartOf(3))) {SynErr(76); Get();}
            Node functionBody = null;
            if (la.kind == 20) {
            Get();
            f.endLine.SetValue(t.val, t.line, t.col);
            } else if (la.kind == 53) {
            Get();
            DesignScript.Parser.Associative.CodeBlockNode func = new DesignScript.Parser.Associative.CodeBlockNode();
            DesignScript.Parser.Associative.BinaryExpressionNode binaryExpr = new DesignScript.Parser.Associative.BinaryExpressionNode();
            binaryExpr.op.SetValue(t.val, t.line, t.col);
            Node expr;

            Assoc_Expression(out expr);
            binaryExpr.RightNode = expr;
            List<Node> body = new List<Node>();
            body.Add(binaryExpr);
            func.Body = body;
            f.FunctionBody = func as DesignScript.Parser.Associative.CodeBlockNode;

            Expect(20);
            f.endLine.SetValue(t.val, t.line, t.col);

            } else if (la.kind == 50) {
            Assoc_FunctionalMethodBodyMultiLine(out functionBody);
            f.FunctionBody = functionBody as DesignScript.Parser.Associative.CodeBlockNode;
            } else SynErr(77);
            node = f;
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: Benglin/designscript
        void Assoc_FunctionalMethodBodyMultiLine(out Node funcBody)
        {
            DesignScript.Parser.Associative.CodeBlockNode functionBody = new DesignScript.Parser.Associative.CodeBlockNode();
            List<Node> body = new List<Node>();

            if (la.val == "{") functionBody.openBrace.SetValue(la.val, la.line, la.col); functionBody.Line = la.line; functionBody.Col = la.col;
            Expect(50);
            Assoc_StatementList(out body);
            functionBody.Body =body;
            if (la.val == "}" && functionBody.openBrace.Value != null) functionBody.closeBrace.SetValue(la.val, la.line, la.col); else if (la.val != "}") functionBody.openBrace.Value = null;
            Expect(51);
            funcBody = functionBody;
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: Benglin/designscript
 public Parser(Scanner scanner, ProtoCore.Core coreObj)
 {
     this.scanner = scanner;
     errors = new Errors();
     opKwData = new ProtoCore.DSASM.OpKeywordData();
     core = coreObj;
     root = new DesignScript.Parser.Associative.CodeBlockNode();
 }
コード例 #4
0
ファイル: Parser.cs プロジェクト: Benglin/designscript
        void Hydrogen(out Node node)
        {
            DesignScript.Parser.Associative.CodeBlockNode code = null;
            code = new DesignScript.Parser.Associative.CodeBlockNode();
            code.Line = la.line; code.Col = la.col; node = null;

            while (la.kind != _EOF && la.val != "}") {
            bool valid = false;
            if (la.kind == 41) {
                Import_Statement(out node);
                valid = true;
            } else if (StartOf(1)) {
                Assoc_Statement(out node);
                valid = true;
            } else if (la.kind == 25 || la.kind == 26) {
                Assoc_FunctionDecl(out node);
                valid = true;
            } else if (la.kind == 23) {
                Assoc_ClassDecl(out node);
                valid = true;
            } else if (la.kind == 7) {
                Assoc_LanguageBlock(out node);
                valid = true;
            } else SynErr(84);
            if (false == valid)
               Get();
            if (node != null)
               code.Body.Add(node);

            }
            node = code;
        }
コード例 #5
0
ファイル: Parser.cs プロジェクト: Benglin/designscript
        void Assoc_LanguageBlock(out Node node)
        {
            codeSegmentStarted = true;
            DesignScript.Parser.Associative.LanguageBlockNode langblock = null;
            langblock = new DesignScript.Parser.Associative.LanguageBlockNode();

            if (la.val == "[")
               langblock.openBracket.SetValue(la.val, la.line, la.col);

            Expect(7);
            langblock.Line = t.line;
            langblock.Col = t.col;

            if (la.val == "Imperative" || la.val == "Associative")
               langblock.language.SetValue(la.val, la.line, la.col);

            if (la.val == "Imperative")
               langblock.languageblock.language = ProtoCore.Language.kImperative;
            else if (la.val == "Associative")
               langblock.languageblock.language = ProtoCore.Language.kAssociative;

            Expect(1);
            while (la.kind == 52) {
            string comma = null; string key = null; string equal = null;
            Get();
            if (t.val == ",") comma = t.val; int comma_line = t.line; int comma_col = t.col;
            Expect(1);
            if (t.kind == _ident) key = t.val; int key_line = t.line; int key_col = t.col;
            Expect(53);
            if (t.val == "=") equal = t.val; int equal_line = t.line; int equal_col = t.col;
            Expect(4);
            DesignScript.Parser.Associative.StringNode stringNode = null;
            stringNode = new DesignScript.Parser.Associative.StringNode();
            if (t.kind == _textstring)
            {
               stringNode.value = t.val;
               stringNode.Line = t.line;
               stringNode.Col = t.col;
            }

            langblock.AddProperty(comma, comma_line, comma_col, key, key_line, key_col, equal, equal_line, equal_col, stringNode);

            }
            if (la.val == "]" && langblock.openBracket.Value != null) langblock.closeBracket.SetValue(la.val, la.line, la.col); else if (la.val != "]") langblock.openBracket.Value = null;
            Expect(8);
            if (la.val == "{") langblock.openBrace.SetValue(la.val, la.line, la.col);
            Expect(50);
            Node codeNode = null;
            if (langblock.languageblock.language == ProtoCore.Language.kAssociative) {
            Hydrogen(out codeNode);
            } else if (langblock.languageblock.language == ProtoCore.Language.kImperative) {
            Imperative(out codeNode);
            } else SynErr(81);
            if (langblock.languageblock.language == ProtoCore.Language.kInvalid) {
            int openCurlyBraceCount = 0, closeCurlyBraceCount = 0;
            DesignScript.Parser.Associative.CodeBlockNode codeBlockInvalid;
            codeBlockInvalid = new DesignScript.Parser.Associative.CodeBlockNode();

            while (closeCurlyBraceCount <= openCurlyBraceCount) {
                if (la.kind == 7) {
                    Assoc_LanguageBlock(out codeNode);
                    codeBlockInvalid.Body.Add(codeNode);
                } else if (la.kind == 50) {
                    Get();
                    openCurlyBraceCount++;
                } else if (la.kind == 51) {
                    if (la.val == "}" && langblock.openBrace.Value != null)
                       langblock.closeBrace.SetValue(la.val, la.line, la.col);
                    else if (la.val != "}")
                       langblock.openBrace.Value = null;

                    Get();
                    closeCurlyBraceCount++;
                } else if (la.kind == 0) {
                    Get();
                    Expect(51);
                    break;
                } else if (true) {
                    Get();
                } else SynErr(82);
            }
            codeNode = codeBlockInvalid;
            } else if (true) {
            if (la.val == "}" && langblock.openBrace.Value != null)
               langblock.closeBrace.SetValue(la.val, la.line, la.col);
            else if (la.val != "}")
               langblock.openBrace.Value = null;

            Expect(51);
            } else SynErr(83);
            langblock.code = codeNode; node = langblock;
        }
コード例 #6
0
ファイル: Parser.cs プロジェクト: samuto/designscript
 public Parser(Scanner scanner, ProtoCore.Core coreObj)
 {
     this.scanner = scanner;
     errors = new Errors();
     core = coreObj;
     root = new DesignScript.Parser.Associative.CodeBlockNode();
 }