Esempio n. 1
0
 void Assoc_ExternalLibraryReference(ref DesignScript.Parser.Associative.FunctionDefinitionNode f)
 {
     if (la.val == "(") f.libOpenBrace.SetValue(la.val, la.line, la.col);
     Expect(9);
     Expect(4);
     DesignScript.Parser.Associative.StringNode libName = new DesignScript.Parser.Associative.StringNode();
     if (t.kind == _textstring) { libName.value = t.val; libName.Line = t.line; libName.Col = t.col; } else Get();
     if (la.val == ")" && f.libOpenBrace.Value != null) f.libCloseBrace.SetValue(la.val, la.line, la.col); else if (la.val != ")") f.libOpenBrace.Value = null; f.libName = libName;
     Expect(10);
 }
Esempio n. 2
0
 void Assoc_String(out Node node)
 {
     node = null;
     Expect(4);
     DesignScript.Parser.Associative.StringNode _node = null;
     node = new DesignScript.Parser.Associative.StringNode();
     if (t.kind == _textstring)
     {
     _node = new DesignScript.Parser.Associative.StringNode() { value = t.val };
     _node.IDEValue.SetValue(t.val, t.line, t.col);
     _node.Line = t.line;
     _node.Col = t.col;
     }
     node = _node;
 }
Esempio n. 3
0
        void Import_Statement(out Node node)
        {
            DesignScript.Parser.Associative.ImportNode importNode = null;
            importNode = new DesignScript.Parser.Associative.ImportNode();

            while (!(la.kind == 0 || la.kind == 41)) {SynErr(72); Get();}
            Expect(41);
            if (t.kind == _Kw_import) importNode.KwImport.SetValue(t.val, t.line, t.col);
            if (la.val == "(") importNode.OpenParen.SetValue(la.val, la.line, la.col);
            Expect(9);
            if (la.kind == 4) {
            Get();
            if (t.kind == _textstring) { DesignScript.Parser.Associative.StringNode path = new DesignScript.Parser.Associative.StringNode() { value = t.val, Line = t.line, Col = t.col }; importNode.Path = path; }
            } else if (la.kind == 1) {
            Get();
            if (t.kind == _ident) importNode.Identifier.SetValue(t.val, t.line, t.col);
            Expect(42);
            if (t.kind == _Kw_from) importNode.KwFrom.SetValue(t.val, t.line, t.col);
            Expect(4);
            if (t.kind == _textstring) { DesignScript.Parser.Associative.StringNode path = new DesignScript.Parser.Associative.StringNode() { value = t.val, Line = t.line, Col = t.col }; importNode.Path = path; }
            } else SynErr(73);
            if (la.val == ")" && importNode.OpenParen.Value != null) importNode.CloseParen.SetValue(la.val, la.line, la.col); else if (la.val != ")") importNode.OpenParen.Value = null;
            Expect(10);
            if (la.kind == 43) {
            Get();
            if (t.kind == _Kw_prefix) importNode.KwPrefix.SetValue(t.val, t.line, t.col);
            Expect(1);
            if (t.kind == _ident) importNode.PrefixIdent.SetValue(t.val, t.line, t.col);
            }
            Expect(20);
            if (t.val == ";")
               importNode.EndLine.SetValue(t.val, t.line, t.col);
            else
            {
               if (null != importNode.OpenParen)
               importNode.OpenParen.SetValue(string.Empty, -1, -1);
               if (null != importNode.CloseParen)
               importNode.CloseParen.SetValue(string.Empty, -1, -1);
            }

            // We only allow "import" statements at the beginning of files,
            // so if any actual code started (anything that is not an import
            // statement), we will mark this import statement as invalid.
            //
            if (false != codeSegmentStarted)
            {
               if (null != importNode.KwImport)
               importNode.KwImport.SetValue(string.Empty, -1, -1);
            }

            string ModuleName = null;
            if (importNode.Path != null && importNode.Path.value != null && (ModuleName = GetImportedModuleFullPath(importNode.Path.value)) != null && Path.GetExtension(ModuleName) == ".ds")
            {
               if (GlobalModuleTable == null)
               {
               GlobalModuleTable = new Dictionary<string, DesignScript.Parser.Associative.ImportNode>();
               if (core.Options.RootModulePathName != null)
                   GlobalModuleTable[core.Options.RootModulePathName] = null;
               }

               if (GlobalModuleTable.ContainsKey(ModuleName))
               {
               importNode.CodeNode = null;
               importNode.HasBeenImported = true;
               }
               else
               {

               GlobalModuleTable[ModuleName] = importNode;

               string curDirectory = Directory.GetCurrentDirectory();
               Directory.SetCurrentDirectory(Path.GetDirectoryName(ModuleName));

               DesignScript.Parser.Scanner scanner = new DesignScript.Parser.Scanner(ModuleName);
               DesignScript.Parser.Parser parser = new DesignScript.Parser.Parser(scanner, core);
               parser.GlobalModuleTable = GlobalModuleTable;

               parser.Parse();
               Directory.SetCurrentDirectory(curDirectory);

               //if (parseErrors.ToString() != String.Empty)
                   //core.BuildStatus.LogSyntaxError(parseErrors.ToString());
               //core.BuildStatus.errorCount += parser.errors.count;

               importNode.CodeNode = parser.root as DesignScript.Parser.Associative.CodeBlockNode;
               }
            }

            node = importNode;
        }
Esempio n. 4
0
        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;
        }