Exemplo n.º 1
0
        private NewNode New()
        {
            Token <TokenType> t = GetNextToken();

            Assertion.AreEqual(TokenType.New, t.TokenType, "Should be new keyword.");

            t = GetNextToken();
            if (t.TokenType != TokenType.Left_Square_Bracket)
            {
                ExceptionHelper.ThrowExpectToken(TokenType.Left_Square_Bracket, t.Position);
            }

            Node typeNode = Obj();

            Assertion.IsTrue(typeNode is ClassQualifierNode, "First object should be class qualifi node.");

            ParamListNode paramList = ValueList();

            t = GetNextToken();
            if (t.TokenType != TokenType.Right_Square_Bracket)
            {
                ExceptionHelper.ThrowExpectToken(TokenType.Right_Square_Bracket, t.Position);
            }

            return(new NewNode(typeNode, paramList));
        }
Exemplo n.º 2
0
        private ParamListNode ValueList()
        {
            ParamListNode     param_list_node = new ParamListNode(new List <Node>());
            Token <TokenType> t = PeekNextToken();

            if (t.TokenType == TokenType.Right_Parenthesis || t.TokenType == TokenType.Right_Square_Bracket)
            {
                return(param_list_node);
            }
            else
            {
                Node node = Value();
                param_list_node.AppendNode(node);
                while (PeekNextToken().TokenType == TokenType.Comma)
                {
                    Token <TokenType> commaToken = GetNextToken();
                    if (commaToken.TokenType != TokenType.Comma)
                    {
                        ExceptionHelper.ThrowExpectToken(TokenType.Comma, commaToken.Position);
                    }

                    node = Value();
                    param_list_node.AppendNode(node);
                }
                return(param_list_node);
            }
        }
Exemplo n.º 3
0
        public ParamListNode finishParamList()
        {
            ParamListNode paramList = curParamList;

            curParamList = null;
            symbolTable.exitscope();
            return(paramList);
        }
Exemplo n.º 4
0
        public ParamEditor(ParamListNode node)
        {
            InitializeComponent();
            Node = node;
            tbl  = new DataTable();
            tbl.Columns.Add(new DataColumn("Name")
            {
                ReadOnly = true
            });
            tbl.Columns.Add("Value");
            dataGridView1.DataSource = tbl;

            for (int i = 0; i < node.Parameters.Count; i++)
            {
                tbl.Rows.Add(i);

                // Set second column to value
                var entry = node.Parameters[i];
                switch (entry.Type)
                {
                case ParamType.u8:
                    tbl.Rows[i][1] = (byte)entry.Value;
                    break;

                case ParamType.s8:
                    tbl.Rows[i][1] = (byte)entry.Value;
                    break;

                case ParamType.u16:
                    tbl.Rows[i][1] = (ushort)entry.Value;
                    break;

                case ParamType.s16:
                    tbl.Rows[i][1] = (short)entry.Value;
                    break;

                case ParamType.u32:
                    tbl.Rows[i][1] = (uint)entry.Value;
                    break;

                case ParamType.s32:
                    tbl.Rows[i][1] = (int)entry.Value;
                    break;

                case ParamType.f32:
                    tbl.Rows[i][1] = (float)entry.Value;
                    break;

                case ParamType.str:
                    tbl.Rows[i][1] = (string)entry.Value;
                    break;

                default:
                    tbl.Rows[i][1] = entry.Value.ToString();
                    break;
                }
            }
        }
Exemplo n.º 5
0
        public Arbor(Parser _parser)
        {
            parser  = _parser;
            options = parser.options;

            symbolTable  = new SymbolTable();
            curModule    = null;
            curFunc      = null;
            blockStack   = new List <Block>();
            curBlock     = null;
            curParamList = null;

            defineBaseTypes();
        }
Exemplo n.º 6
0
        public void SimpleTest6()
        {
            string        expr = ExpressionsForTest.Expr6;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            SymanticParser sp = new SymanticParser();

            sp.SetParseContent(tokens);
            ExpressionLanguageAST ast = sp.Parse();

            Assert.IsTrue(ast.Root is MethodNode);
            MethodNode    mNode  = ast.Root as MethodNode;
            ParamListNode plNode = mNode.Args as ParamListNode;

            Assert.IsTrue(plNode.Values.Count == 2);
        }
Exemplo n.º 7
0
        public void PopulateParams()
        {
            int group = 0;

            foreach (var grp in ParamFile.Groups)
            {
                var groupnode = new TreeNode($"Group[{group}]");
                if (grp is ParamGroup)
                {
                    int entry = 0;
                    foreach (var chunk in ((ParamGroup)grp).Chunks)
                    {
                        var node = new ParamListNode(group, entry)
                        {
                            Text = $"Entry[{entry}]"
                        };
                        foreach (var val in chunk)
                        {
                            node.Parameters.Add(val);
                        }
                        groupnode.Nodes.Add(node);
                        entry++;
                    }
                }
                else
                {
                    var node = new ParamListNode(group, 0)
                    {
                        Text = $"Values[{group}]"
                    };
                    foreach (var col in grp.Values)
                    {
                        node.Parameters.Add(new ParamEntry(col.Value, col.Type));
                    }
                    groupnode.Nodes.Add(node);
                }

                var paramnode = FileTree.Nodes.Find("nPARAMS", false)[0];
                paramnode?.Nodes.Add(groupnode);
                group++;
            }
        }
Exemplo n.º 8
0
 public void startParamList()
 {
     curParamList = new ParamListNode();
     symbolTable.enterScope();
 }
Exemplo n.º 9
0
 public DeclaratorNode makeFuncDeclarNode(ParamListNode paramList)
 {
     return(null);
 }
Exemplo n.º 10
0
        private Node Factor()
        {
            Node node           = Obj();
            Token <TokenType> t = PeekNextToken();

            while (!t.End)
            {
                if (t.TokenType == TokenType.Dot)
                {
                    GetNextToken();
                    Token <TokenType> idToken = GetNextToken();
                    if (idToken.TokenType != TokenType.ID)
                    {
                        ExceptionHelper.ThrowExpectToken(TokenType.ID, idToken.Position);
                    }
                    if (PeekNextToken().TokenType == TokenType.Left_Parenthesis)//Note:Method Call
                    {
                        GetNextToken();
                        ParamListNode     method_param_node = ValueList();
                        Token <TokenType> rightToken        = GetNextToken();
                        if (rightToken.TokenType != TokenType.Right_Parenthesis)
                        {
                            ExceptionHelper.ThrowExpectToken(TokenType.Right_Parenthesis, rightToken.Position);
                        }

                        MethodNode methodNode = new MethodNode(node, new SimpleNode(idToken), method_param_node);
                        node = methodNode;

                        t = PeekNextToken();
                        continue;
                    }
                    else//Note:Property
                    {
                        PropertyNode propNode = new PropertyNode(node, new SimpleNode(idToken));
                        node = propNode;
                    }
                }
                else if (t.TokenType == TokenType.Left_Square_Bracket)
                {
                    GetNextToken();
                    ParamListNode     index_param_node = ValueList();
                    Token <TokenType> rightToken       = GetNextToken();
                    if (rightToken.TokenType != TokenType.Right_Square_Bracket)
                    {
                        ExceptionHelper.ThrowExpectToken(TokenType.Right_Square_Bracket, rightToken.Position);
                    }

                    IndexerNode indexerNode = new IndexerNode(node, index_param_node);
                    node = indexerNode;
                }
                else if (t.TokenType == TokenType.Left_Parenthesis)
                {
                    GetNextToken();
                    ParamListNode     static_method_param_node = ValueList();
                    Token <TokenType> rightToken = GetNextToken();
                    if (rightToken.TokenType != TokenType.Right_Parenthesis)
                    {
                        ExceptionHelper.ThrowExpectToken(TokenType.Right_Parenthesis, t.Position);
                    }

                    MethodNode staticMethodNode = new MethodNode(null, node, static_method_param_node);
                    node = staticMethodNode;
                }
                else
                {
                    break;
                }

                t = PeekNextToken();
            }
            return(node);
        }