private bool EvaluateParameterValue(CommandState state, out double paramValue) { var lineStream = new ParserStreamReader() { Line = GCodeAdd }; var expressionParser = new GCodeExpressionParser(lineStream) { ParameterValues = state.ParameterValues }; expressionParser.Parse(); if (expressionParser.IsError()) { paramValue = 0; return(false); } paramValue = expressionParser.Answer; return(true); }
public bool TryGetVariable(char name, CommandState state, out double val) { Variable var = GetVariable(name); if (var?.Value != null) { val = var.Value.Value; return(true); } if (var?.Parameter != null) { if (var.ParameterIsTerm) { var lineStream = new ParserStreamReader() { Line = var.Parameter }; var expressionParser = new GCodeExpressionParser(lineStream) { ParameterValues = state.ParameterValues }; expressionParser.Parse(); if (!expressionParser.IsError()) { val = expressionParser.Answer; return(true); } } else if (int.TryParse(var.Parameter, out int parameterNo) && state.ParameterValues.ContainsKey(parameterNo)) { val = state.ParameterValues[parameterNo]; return(true); } } val = 0; return(false); }
public GCodeExpressionParser(ParserStreamReader reader) : base(reader) { LeftParenthesis = '['; RightParenthesis = ']'; }
public GCodeParser(ParserStreamReader reader) : base(reader) { }