コード例 #1
0
 /// Author: Max Hamulyak
 /// Date:	29-06-2015
 /// <summary>
 /// Parses the declaration of an function, so it can be reused througout the program.
 /// </summary>
 /// <returns>The function declaration.</returns>
 /// <param name="tokensToParse">Tokens to parse.</param>
 /// <param name="currentLine">Current line.</param>
 protected virtual FunctionBlock ParseFunctionDeclaration(List<Token> tokensToParse, int currentLine)
 {
     List<Token> tokensAtCurrentLine = tokensToParse.Where (x => x.Position.Line == currentLine).ToList();
     tokensToParse.RemoveAll (x => x.Position.Line == currentLine);
     string functionName = ParseFunctionHeader(tokensAtCurrentLine,currentLine);
     FunctionBlock functionBlock = new FunctionBlock (functionName);
     List<Token> childTokens = BuildCodeBlock (tokensToParse, currentLine);
     if (childTokens.Count > 0) {
         int last = childTokens.Last ().Position.Line;
         Token lastToken = tokensToParse.First (x => x.Position.Line == last + incrementIndex);
         EndOfBlockTokenCorrect (lastToken, "end;", ETokenType.FUNCTIONDeclaration);
         RemoveTokensAtLine (tokensToParse, last + incrementIndex);
         List<ICodeBlock> childeren = BuildCommandBlok (childTokens, currentLine + 1, last + 1);
         if (childeren.Count > 0) {
             foreach (var item in childeren) {
                 functionBlock.addChild (item);
             }
             functionBlock.LineNumber = currentLine;
             return functionBlock;
         } else {
             throw EmptyCodeBlock (currentLine, ETokenType.FUNCTIONDeclaration);
         }
     } else {
         throw EmptyCodeBlock (currentLine, ETokenType.FUNCTIONDeclaration);
     }
 }
コード例 #2
0
 /// Author: Bert van Montfort
 /// <summary>
 /// Adds a FunctionBlock with key name to the FunctionBlockList
 /// </summary>
 /// <param name="name">Key used to later retrieve the added FunctionBlock</param>
 /// <param name="function">The FunctionBlock to be added.</param>
 public static void addFunction(string name, FunctionBlock function)
 {
     functions.Add (name, function);
 }