public void Run() { // Run the state machine LexFunction function = LexFunctions.LexText; while (function != null) { function = function(this); } }
public LexFunction Clone() { LexFunction copy = MemberwiseClone() as LexFunction; copy.returnType = returnType.Clone(); copy.parameters = new List <LexVariable>(); foreach (var param in parameters) { copy.parameters.Add(param.Clone()); } return(copy); }
void btnAdd_Click(object sender, EventArgs e) { try { PhraseComparer pc = new PhraseComparer(sa, lfDict); //Actant[] arrActArg, arrActVal; LexFunction lf = (LexFunction)(lvLf.SelectedIndices[0] + 1); //if (lf == LexFunction.Conv) // pc.ParseConvParam(tbParam.Text, out arrActArg, out arrActVal); lfDict.AddLF(new LFArgVal(wArg, wVal, lf, tbParam.Text)); } catch { MessageBox.Show("Ошибка добавления лексической функции"); return; } tbVal.Text = ""; }
LexFunction ParseFunction(string data, ProtectLevel protectLevel, int begin, int end) { LexFunction res = new LexFunction() { begin = begin, end = end, data = data }; if (isNextLexTemplate) { res.isTemplate = true; res.templates = templatesBuffer; isNextLexTemplate = false; } res.returnType = new LexVariableType(); res.definition = data; res.protectLevel = protectLevel; int caret = 0; string typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); if (typeWord == "virtual") { res.isVirtual = true; typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); } if (typeWord == "static") { res.isStatic = true; typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); } if (typeWord == "inline") typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); if (typeWord == "typename") typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); if (typeWord == "explicit") typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); if (typeWord == "operator") { string nextWord = ReadWord(data, ref caret, " \n\r(){}[]"); res.name = typeWord + nextWord; res.returnType.name = "void"; } else { if (GetNextSymbol(data, caret, " \n\r\t") == '(') { res.name = typeWord; res.returnType.name = "void"; } else { string typeDefinition = typeWord; if (typeWord == "const") { typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); res.returnType.isContstant = true; typeDefinition += " " + typeWord; } if (typeWord.Last() == '&') res.returnType.type = LexVariableType.Type.Reference; if (typeWord.Last() == '*') res.returnType.type = LexVariableType.Type.Pointer; res.returnType.name = typeWord; res.returnType.definition = typeDefinition; res.name = ReadWord(data, ref caret, " \n\r(){}[]"); if (res.name == "operator") res.name += " " + ReadWord(data, ref caret, " \n\r(){}"); } } string paramsStr = ReadBraces(data, ref caret).Trim(' ', '\n', '\r', '\t'); string afterParamWord = ReadWord(data, ref caret); if (afterParamWord == "const") res.isContstant = true; if (paramsStr.Length > 0) { var paramsArr = Split(paramsStr, ','); foreach (var prm in paramsArr) { string trimmedParam = prm.Trim(' ', '\r', '\n', '\t'); res.parameters.Add(ParseVariable(trimmedParam, ProtectLevel.Public, begin, end)); } } return res; }
LexFunction ParseFunction(string data, ProtectLevel protectLevel, int begin, int end) { LexFunction res = new LexFunction() { begin = begin, end = end, data = data }; if (isNextLexTemplate) { res.isTemplate = true; res.templates = templatesBuffer; isNextLexTemplate = false; } res.returnType = new LexVariableType(); res.definition = data; res.protectLevel = protectLevel; int caret = 0; string typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); if (typeWord == "virtual") { res.isVirtual = true; typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); } if (typeWord == "static") { res.isStatic = true; typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); } if (typeWord == "inline") { typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); } if (typeWord == "typename") { typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); } if (typeWord == "explicit") { typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); } if (typeWord == "operator") { string nextWord = ReadWord(data, ref caret, " \n\r(){}[]"); res.name = typeWord + nextWord; res.returnType.name = "void"; } else { if (GetNextSymbol(data, caret, " \n\r\t") == '(') { res.name = typeWord; res.returnType.name = "void"; } else { string typeDefinition = typeWord; if (typeWord == "const") { typeWord = ReadWord(data, ref caret, " \n\r(){}[]"); res.returnType.isContstant = true; typeDefinition += " " + typeWord; } if (typeWord.Last() == '&') { res.returnType.type = LexVariableType.Type.Reference; } if (typeWord.Last() == '*') { res.returnType.type = LexVariableType.Type.Pointer; } res.returnType.name = typeWord; res.returnType.definition = typeDefinition; res.name = ReadWord(data, ref caret, " \n\r(){}[]"); if (res.name == "operator") { res.name += " " + ReadWord(data, ref caret, " \n\r(){}"); } } } string paramsStr = ReadBraces(data, ref caret).Trim(' ', '\n', '\r', '\t'); string afterParamWord = ReadWord(data, ref caret); if (afterParamWord == "const") { res.isContstant = true; } if (paramsStr.Length > 0) { var paramsArr = Split(paramsStr, ','); foreach (var prm in paramsArr) { string trimmedParam = prm.Trim(' ', '\r', '\n', '\t'); res.parameters.Add(ParseVariable(trimmedParam, ProtectLevel.Public, begin, end)); } } return(res); }