Exemple #1
0
        private CersvaNode GetCersvaNode(IList <Token> tokens, ref int index)
        {
            var   cersvaNode = new CersvaNode();
            Token token      = tokens[++index];

            if (token != null)
            {
                string name = (token as Identifier).Name;

                if (name.All(char.IsDigit) && char.IsDigit((name ?? "0").FirstOrDefault()))
                {
                    throw new ApplicationException($"Invalid identifier: cersva {name}");
                }
                else
                {
                    cersvaNode.Name = new IdentifierNode
                    {
                        Value = name
                    };

                    this.functionIdentifiers.Add(cersvaNode.Name);
                }
            }
            else
            {
                throw new ApplicationException($"Invalid value: cersva {token}");
            }

            token = tokens[++index];
            if (token.Type != TokenType.L_CIRC)
            {
                throw new ApplicationException($"Not found '(': cersva {cersvaNode.Name.Value}");
            }

            index++;
            cersvaNode.Arguments = GetArguments(tokens, ref index);

            token = tokens[index];
            if (token.Type != TokenType.R_CIRC)
            {
                throw new ApplicationException($"Not found ')': cersva {cersvaNode.Name.Value}");
            }

            token = tokens[++index];
            if (token.Type != TokenType.RINYV)
            {
                throw new ApplicationException($"Not found 'rinyv': cersva {cersvaNode.Name.Value}");
            }

            index++;
            cersvaNode.Syntaxes = GetSyntaxNode(tokens, ref index);

            token = tokens[index];
            if (token.Type != TokenType.SITUV)
            {
                throw new ApplicationException($"Not found 'situv': cersva {cersvaNode.Name.Value}");
            }

            return(cersvaNode);
        }
Exemple #2
0
        protected override void ToCersva(CersvaNode node)
        {
            var anaxList = node.Syntaxes.Where(x => x is AnaxNode)
                           .Select(x => (x as AnaxNode)).ToList();
            var anaxDictionary = new Dictionary <IdentifierNode, uint>();
            int stackCount     = anaxList.Select(x => int.Parse(x.Length.Value)).Sum();

            cersvaStackCount = stackCount;

            this.writer.WriteLine("nll {0} ; cersva {0}", node.Name.Value);
            this.writer.WriteLine("nta 4 f5 krz f3 f5@ ; allocate variables");
            this.writer.WriteLine("krz f5 f3");
            this.writer.WriteLine("nta {0} f5", stackCount * 4);

            // 引数の設定
            int count = node.Arguments.Count;

            foreach (var anax in node.Arguments)
            {
                anaxDictionary.Add(anax.Name, (uint)((count + 1) * 4));
                count--;
            }

            // 内部変数の設定
            count = 0;
            foreach (var anax in anaxList)
            {
                count += int.Parse(anax.Length.Value);
                anaxDictionary.Add(anax.Name, (uint)(-count * 4));
                ToAnax(anax, anaxDictionary);
            }

            OutputSyntax(node.Syntaxes, anaxDictionary);
            this.writer.WriteLine();

            this.cersvaStackCount = 0;
        }
Exemple #3
0
 protected abstract void ToCersva(CersvaNode node);