Exemple #1
0
    private string ParseLevelAction(string parsingState, Match token)
    {
        if (token.Groups["EndSequence"].Length != 0)
        {
            if (this.conditionStack.Count > 0)
            {
                ADLConditionAction condition = this.conditionStack.Pop();
                condition.totalActions = this.currentSequence.actions.Count - this.currentSequence.actions.IndexOf(condition) - 1;
                this.Log("End Condition");
            }
            else
            {
                parsingState = this.compilerStack.Pop();
            }
        }
        else if (token.Groups["Action"].Length != 0)
        {
            this.compilerStack.Push(parsingState);
            parsingState = "parameter";

            this.Log("Action : " + token.Groups["Action"]);

            ADLAction    action    = this.createNewADLAction(token.Groups["Action"].Value);
            ADLParameter parameter = new ADLParameter();
            this.currentAction    = action;
            this.currentParameter = parameter;
            this.currentAction.parameters.Add(parameter);
            this.currentSequence.actions.Add(action);
        }
        else if (token.Groups["If"].Length != 0)
        {
            this.compilerStack.Push(parsingState);
            parsingState = "parameter";

            ADLConditionAction action    = new ADLConditionAction(token.Groups["Action"].Value);
            ADLParameter       parameter = new ADLParameter();
            this.currentAction    = action;
            this.currentParameter = parameter;
            this.currentAction.parameters.Add(parameter);
            this.currentSequence.actions.Add(action);

            this.conditionStack.Push(action);
        }
        else if (token.Groups["Else"].Length != 0)
        {
        }
        return(parsingState);
    }
Exemple #2
0
    private string ParseLevelParameter(string parsingState, Match token)
    {
        if (token.Groups["EndAction"].Length != 0 ||
            token.Groups["EndIfBracket"].Length != 0)
        {
            parsingState = this.compilerStack.Pop();

            //Remove the first parameter from action if its number of tokens is zero
            if (this.currentAction.parameters.Count == 1 &&
                this.currentParameter.Tokens.Count == 0)
            {
                this.currentAction.parameters.Remove(this.currentParameter);
            }
        }
        else if (token.Groups["EndBracket"].Length != 0)
        {
            //The token is the ) of an ADLFunction
            if (this.functionStack.Count > 0)
            {
                //Remove the first parameter from function if its number of tokens is zero
                if (this.currentFunction.parameters.Count == 1 &&
                    this.currentParameter.Tokens.Count == 0)
                {
                    this.currentFunction.parameters.Remove(this.currentParameter);
                }

                functionStack.Pop();
                if (functionStack.Count > 0)
                {
                    this.currentFunction  = functionStack.Peek();
                    this.currentParameter = this.currentFunction.parameters[this.currentFunction.parameters.Count - 1];
                }
                else
                {
                    this.currentFunction  = null;
                    this.currentParameter = this.currentAction.parameters[this.currentAction.parameters.Count - 1];
                }
            }
        }
        else if (token.Groups["StartBracket"].Length != 0)
        {
        }
        else if (token.Groups["Function"].Length != 0)
        {
            this.Log("Function : " + token.Groups["Function"].Value);

            //Create new Function and push it to Function Stack
            //To tell the compiler that the next parameter found in this state will be a parameter of the recently generated function
            ADLFunction  function  = this.createNewADLFunction(token.Groups["Function"].Value);
            ADLParameter parameter = new ADLParameter();

            this.currentParameter.Tokens.Enqueue(new ADLToken(function));
            this.currentFunction  = function;
            this.currentParameter = parameter;
            this.currentFunction.parameters.Add(parameter);
            this.functionStack.Push(function);
        }
        else if (token.Groups["Comma"].Length == 0)
        {
            if (token.Groups["Double"].Length != 0)
            {
                this.currentParameter.Tokens.Enqueue(new ADLToken(float.Parse(token.Value)));
            }
            else if (token.Groups["Int"].Length != 0)
            {
                this.currentParameter.Tokens.Enqueue(new ADLToken(int.Parse(token.Value)));
            }
            else if (token.Groups["Pi"].Length != 0)
            {
                this.currentParameter.Tokens.Enqueue(new ADLToken(System.Convert.ToSingle(Math.PI)));
            }
            else if (token.Groups["Boolean_True"].Length != 0 || token.Groups["Boolean_False"].Length != 0)
            {
                this.currentParameter.Tokens.Enqueue(new ADLToken(bool.Parse(token.Value)));
            }
            else
            {
                this.currentParameter.Tokens.Enqueue(new ADLToken(token.Value));
            }
        }
        else if (token.Groups["Comma"].Length > 0)
        {
            ADLParameter paramater = new ADLParameter();
            if (functionStack.Count == 0)
            {
                this.currentAction.parameters.Add(paramater);
            }
            else
            {
                this.currentFunction.parameters.Add(paramater);
            }
            this.currentParameter = paramater;
        }
        return(parsingState);
    }