Beispiel #1
0
        FoundKeyWord GetLongestFoundKeyWord(List <FoundKeyWord> foundKeyWords)
        {
            FoundKeyWord longesKeyWord = foundKeyWords.FirstOrDefault();

            foreach (var keyWord in foundKeyWords)
            {
                if (keyWord.FoundPattern.Length > longesKeyWord?.FoundPattern.Length)
                {
                    longesKeyWord = keyWord;
                }
            }

            return(longesKeyWord);
        }
Beispiel #2
0
        public static string GenerateCodeComperators(FoundKeyWord token)
        {
            var tokenPattern = token.FoundPattern;
            var result       = new StringBuilder();

            result.Append("cmp(");
            string x;

            switch (tokenPattern)
            {
            case ">":
            { x = "gt,"; }
            break;

            case "<":
                x = "sm,";
                break;

            case ">=":
                x = "gteq,";
                break;

            case "<=":
                x = "smeq,";
                break;

            case "=":
                x = "eq,";
                break;

            case "/=":
                x = "noteq,";
                break;

            default:
                return("Not Implemeted");
            }

            result.Append(x);
            result.Append("[");
            return(result.ToString());
        }
Beispiel #3
0
        public static string GenerateCodeMatematicalOperator(FoundKeyWord token)
        {
            var tokenPattern = token.FoundPattern;

            switch (tokenPattern)
            {
            case "+":
                return("sum([");

            case "-":
                return("sub([");

            case "*":
                return("multiply([");

            case "/":
                return("divide([");

            default:
                return("Not Implemeted");
            }
        }
Beispiel #4
0
        public static string GenerateCode(FoundKeyWord token)
        {
            var tokenType    = token.GetKeyWordName();
            var tokenPattern = token.FoundPattern;

            switch (tokenType)
            {
            case "Comma":
                return(",");

            case "IfStatment":
                return("ifstm([");

            case "MatemticalOperator":
                return(GenerateCodeMatematicalOperator(token));

            case "EndOfCode":
                return("." + Environment.NewLine);

            case "ClosingBracket":
                StackCounter--;
                return("])");

            case "Float":
                return(tokenPattern);

            case "Integer":
                return(tokenPattern);

            case "OpeningBracket":
            {
                if (StackCounter++ == 0)
                {
                    FunCounter++;
                    return("fun" + FunCounter + "() -> ");
                }

                return("");
            }

            case "OpeningThread":
                if (StackCounter++ == 0)
                {
                    FunCounter++;
                    return("fun" + FunCounter + "() -> spawn(");
                }
                return("");

            case "ClosingThread":
                StackCounter--;
                return("])");

            case "Write":
                return("write([");

            case "Comparator":
                return(GenerateCodeComperators(token));

            case "InLineErlang":
                return(token.FoundPattern.Remove(token.FoundPattern.Length - 1, 1).Remove(0, 1));

            default:
                return("Not Implemeted");
            }
        }
Beispiel #5
0
 public static void AddNextToken(FoundKeyWord token)
 {
     TokenzedProgram.Add(token);
 }