public string SetFully_Qualified_Id(NonterminalToken pToken) { string result = null; result = this.GetCommandElement(pToken.Tokens, 0).Trim(new char[] { '[', ']' }) + "." + this.SetQualifiedId(pToken.Tokens[2]); return(result); }
public Rule_CoxPH(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { /* * <Simple_Cox_Statement> ::= COXPH Identifier '=' <CoxTermList> '*' Identifier '(' DecLiteral ')' <CoxOptList> * <Boolean_Cox_Statement> ::= COXPH Identifier '=' <CoxTermList> '*' Identifier '(' Boolean ')' <CoxOptList>*/ //!COXPH <time variable>= <covariate(s)>[: <time function>:] * <censor variable> (<value>) [TIMEUNIT="<time unit>"] [OUTTABLE=<tablename>] [GRAPHTYPE="<graph type>"] [WEIGHTVAR=<weight variable>] [STRATAVAR=<strata variable(s)>] [GRAPH=<graph variable(s)>] string[] saCensorArray; this.commandText = this.ExtractTokens(pToken.Tokens); this.time_variable = this.GetCommandElement(pToken.Tokens, 1).Trim(new char[] { '[', ']' }); saCensorArray = GetUncensoredVarVal(this.GetCommandElement(pToken.Tokens, 5)); this.censor_variable = saCensorArray[0].Trim(new char[] { '[', ']' }); this.censor_value = saCensorArray[1].Trim(new char[] { '[', ']' }); this.SetTermList((NonterminalToken)pToken.Tokens[3]); if (pToken.Tokens.Length > 6) { this.SetOptionList((NonterminalToken)pToken.Tokens[6]); } }
/** * Returns the subtoken of the given symbol ID, if it exists. */ private static Token GetSubToken(this NonterminalToken token, int symbolId) { if (token == null) { throw new ArgumentNullException("token"); } foreach (Token subtoken in token.Tokens) { if (subtoken is NonterminalToken) { NonterminalToken nonterminalSubToken = (NonterminalToken)subtoken; if (nonterminalSubToken.Symbol.Id == symbolId) { return(nonterminalSubToken); } } else if (subtoken is TerminalToken) { TerminalToken terminalSubtoken = (TerminalToken)subtoken; if (terminalSubtoken.Symbol.Id == symbolId) { return(terminalSubtoken); } } else { Console.WriteLine("huh wha token?"); } } return(null); }
public Rule_Assign(Rule_Context pContext, NonterminalToken pTokens) : base(pContext) { //ASSIGN <Qualified ID> '=' <Expression> //<Let_Statement> ::= LET Identifier '=' <Expression> //<Simple_Assign_Statement> ::= Identifier '=' <Expression> switch (pTokens.Rule.Lhs.ToString()) { case "<Assign_Statement>": NonterminalToken T = (NonterminalToken)pTokens.Tokens[1]; this.QualifiedId = T.Tokens[0].ToString(); //this.value = new Rule_Expression(pContext, (NonterminalToken)pTokens.Tokens[3]); break; case "<Let_Statement>": this.QualifiedId = pTokens.Tokens[1].ToString(); //this.value = new Rule_Expression(pContext, (NonterminalToken)pTokens.Tokens[3]); break; case "<Simple_Assign_Statement>": //Identifier '=' <Expression> //T = (NonterminalToken)pTokens.Tokens[1]; this.QualifiedId = this.GetCommandElement(pTokens.Tokens, 0); //this.value = new Rule_Expression(pContext, (NonterminalToken)pTokens.Tokens[2]); break; } }
private void SetTermList(NonterminalToken pToken) { //<CoxTermList> ::= <CoxTerm> | <CoxTerm> <CoxTermList> if (pToken.Symbol.ToString() == "<Cox_Covariate>") { this.SetTerm(pToken); } else if (pToken.Symbol.ToString() == "<Cox_CovariateList>") { this.SetTerm((NonterminalToken)pToken.Tokens[0]); this.SetTermList((NonterminalToken)pToken.Tokens[1]); } else { foreach (Token T in pToken.Tokens) { if (T is NonterminalToken) { NonterminalToken NT = (NonterminalToken)T; switch (NT.Symbol.ToString()) { case "<CoxTerm>": case "<Cox_Covariate>": this.SetTerm(NT); break; case "<CoxTermList>": this.SetTermList(NT); break; } } } } }
public Rule_Define(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { //DEFINE Identifier <Variable_Scope> <VariableTypeIndicator> <Define_Prompt> //DEFINE Identifier '=' <Expression> Identifier = GetCommandElement(pToken.Tokens, 1); if (pContext.IsVariableValidationEnable) { if (!string.IsNullOrEmpty(Identifier)) { if (!this.Context.CommandVariableCheck.ContainsKey(Identifier.ToLowerInvariant())) { this.Context.CommandVariableCheck.Add(Identifier, "define"); } } } if (GetCommandElement(pToken.Tokens, 2) == "=") { this.Expression = EnterRule.BuildStatments(pContext, pToken.Tokens[3]); // set some defaults Variable_Scope = "STANDARD"; VariableTypeIndicator = ""; Define_Prompt = ""; } else { Variable_Scope = GetCommandElement(pToken.Tokens, 2);//STANDARD | GLOBAL | PERMANENT |!NULL VariableTypeIndicator = GetCommandElement(pToken.Tokens, 3); Define_Prompt = GetCommandElement(pToken.Tokens, 4); } }
private void SetTerm(NonterminalToken pToken) { /* * <KMTerm> ::= Identifier | '(' Identifier ')' | Identifier ':' <Expression> | '(' Identifier ')' ':' <Expression> | Identifier ':' Identifier ':' | '(' Identifier ')' ':' Identifier ':' */ string value = null; switch (pToken.Rule.Rhs[0].ToString()) { case "Identifier": //"Identifier": //"Identifier ':' <Expression>": //"Identifier ':' Identifier ':'": value = this.GetCommandElement(pToken.Tokens, 0); break; case "(": //"(' Identifier ')": //"'(' Identifier ')' ':' Identifier ':'": value = this.GetCommandElement(pToken.Tokens, 1); break; default: // do nothing break; } }
public Rule_Recode_B(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { //this.value1 = this.CreateNegateRecode(pToken.Tokens[0]); this.value1 = this.GetCommandElement(pToken.Tokens, 0).Replace("\"", ""); this.equalValue = this.GetCommandElement(pToken.Tokens, 2).Replace("\"", ""); }
public Rule_CompareExp(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { // <Concat Exp> LIKE String // <Concat Exp> '=' <Compare Exp> // <Concat Exp> '<>' <Compare Exp> // <Concat Exp> '>' <Compare Exp> // <Concat Exp> '>=' <Compare Exp> // <Concat Exp> '<' <Compare Exp> // <Concat Exp> '<=' <Compare Exp> // <Concat Exp> this.ConcatExp = EnterRule.BuildStatments(pContext, pToken.Tokens[0]); if (pToken.Tokens.Length > 1) { op = pToken.Tokens[1].ToString(); if (pToken.Tokens[1].ToString().Equals("LIKE", StringComparison.OrdinalIgnoreCase)) { this.STRING = pToken.Tokens[2].ToString().Trim(new char[] { '"' }); } else { this.CompareExp = EnterRule.BuildStatments(pContext, pToken.Tokens[2]); } } }
public Rule_Recode_M(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { //this.value1 = this.GetCommandElement(pToken.Tokens, 0); //this.value2 = this.GetCommandElement(pToken.Tokens, 2); this.equalValue = this.GetCommandElement(pToken.Tokens, 4).Replace("\"", ""); }
private object GetEqualsValue(Token pToken) { object result = null; if (pToken is NonterminalToken) { NonterminalToken NT = (NonterminalToken)pToken; //<RecodeValue> ::= <Literal> | Boolean | Identifier string dataTypeIdentifier = NT.Rule.Rhs[0].ToString(); switch (dataTypeIdentifier) { case "<Literal>": result = this.GetCommandElement(NT.Tokens, 0).Replace("\"", "").Trim(); break; case "DecLiteral": result = this.GetCommandElement(NT.Tokens, 0).Replace("\"", "").Trim(); break; default: result = this.ExtractTokens(NT.Tokens).Replace("\"", "").Trim(); break; } } else { TerminalToken TT = (TerminalToken)pToken; result = TT.ToString(); } return(result); }
public Rule_AutoSearch(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { /*<Auto_Search_Statement> ::= AUTOSEARCH <IdentifierList> |AUTOSEARCH <IdentifierList> Always |AUTOSEARCH <IdentifierList> DisplayList <IdentifierList> |AUTOSEARCH <IdentifierList> DisplayList <IdentifierList> Always*/ this.IdentifierList = this.GetCommandElement(pToken.Tokens, 1).Split(' '); if (pToken.Tokens.Length > 2) { if (pToken.Tokens[2].ToString().Equals("Always", StringComparison.OrdinalIgnoreCase)) { this.AlwaysShow = true; } else { this.DisplayList = this.GetCommandElement(pToken.Tokens, 2).Split(' '); } } if (pToken.Tokens.Length == 5) { this.AlwaysShow = true; } }
public Rule_Dialog_Date_Statement(Rule_Context pContext, NonterminalToken token) : base(pContext, token) { //<Dialog_Date_Statement> ::= DIALOG String Identifier DATEFORMAT <TitleOpt> Prompt = this.GetCommandElement(token.Tokens, 1); TitleText = this.GetCommandElement(token.Tokens, 4); }
private void SetTitleFont(NonterminalToken nonterminalToken) { _color = null; _size = null; for (int i = 0; i < nonterminalToken.Tokens.Length; i++) { if (nonterminalToken.Tokens[i] is NonterminalToken) { _color = this.GetCommandElement(nonterminalToken.Tokens, i); } else { Token token = (Token)nonterminalToken.Tokens[i]; switch (token.ToString().ToUpperInvariant()) { case "TEXTFONT": break; case "-": case "+": _size = nonterminalToken.Tokens[i].ToString() + nonterminalToken.Tokens[i + 1].ToString(); i++; break; default: _size = token.ToString(); break; } } } }
/// <summary> /// Constructor for Rule_FunctionParameterList /// </summary> /// <param name="pToken">The token to build the reduction with.</param> public Rule_FunctionParameterList(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { //<FunctionParameterList> ::= <EmptyFunctionParameterList> //<FunctionParameterList> ::= <NonEmptyFunctionParameterList> NonterminalToken T = (NonterminalToken)pToken.Tokens[0]; switch (T.Rule.Lhs.ToString()) { case "<NonEmptyFunctionParameterList>": this.paramList = new Stack<EnterRule>(); //this.paramList.Push(new Rule_NonEmptyFunctionParameterList(T, this.paramList)); new Rule_NonEmptyFunctionParameterList(pContext, T, this.paramList); break; case "<SingleFunctionParameterList>": this.paramList = new Stack<EnterRule>(); new Rule_SingleFunctionParameterList(pContext, T, this.paramList); break; case "<EmptyFunctionParameterList>": //this.paramList = new Rule_EmptyFunctionParameterList(T); // do nothing the parameterlist is empty break; case "<MultipleFunctionParameterList>": this.paramList = new Stack<EnterRule>(); //this.MultipleParameterList = new Rule_MultipleFunctionParameterList(pToken); new Rule_MultipleFunctionParameterList(pContext, T, this.paramList); break; } }
public Rule_If_Then_Else_End(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { /* * * <If_Statement> ::= IF <Expression> THEN <Statements> END-IF | IF <Expression> THEN <Statements> END | <If_Else_Statement> ::= IF <Expression> THEN <Statements> <Else_If_Statement> END-IF | IF <Expression> THEN <Statements> <Else_If_Statement> END | IF <Expression> THEN <Statements> ELSE <Statements> END-IF | IF <Expression> THEN <Statements> ELSE <Statements> END */ IfClause = EnterRule.BuildStatments(pContext, pToken.Tokens[1]); ThenClause = EnterRule.BuildStatments(pContext, pToken.Tokens[3]); if (this.GetCommandElement(pToken.Tokens, 4).Equals("Else", StringComparison.OrdinalIgnoreCase)) { ElseClause = EnterRule.BuildStatments(pContext, pToken.Tokens[5]); } /* * else * { * ElseClause = EnterRule.BuildStatments(pContext, pToken.Tokens[4]); * }*/ }
public Rule_NonEmptyFunctionParameterList(Rule_Context pContext, NonterminalToken pToken, Stack<EnterRule> pList) : base(pContext) { //<NonEmptyFunctionParameterList> ::= <MultipleFunctionParameterList> //<NonEmptyFunctionParameterList> ::= <SingleFunctionParameterList> NonterminalToken T = (NonterminalToken) pToken.Tokens[0]; switch (T.Rule.Lhs.ToString()) { case "<MultipleFunctionParameterList>": new Rule_MultipleFunctionParameterList(pContext, T, pList); break; case "<SingleFunctionParameterList>": new Rule_SingleFunctionParameterList(pContext, T, pList); break; default: break; } if (pToken.Tokens.Length > 2) { Rule_Expression Expression = new Rule_Expression(pContext, (NonterminalToken)pToken.Tokens[2]); pList.Push(Expression); } }
static object RuleExpressionFunctionHandler(Parser p, NonterminalToken t) { //<Function> ::= <FId> '()' //<Function> ::= Id '()' //<Function> ::= <FId> '(' <Arg> ')' //<Function> ::= Id '(' <Arg> ')' var fn = (string)t.Tokens[0].UserObject; List <Linq.Expression> args; if (t.Tokens.Length == 2) { args = null; } else { args = t.Tokens[2].UserObject as List <Linq.Expression>; if (args == null) { args = new List <Linq.Expression>() { (Linq.Expression)t.Tokens[2].UserObject }; } } return(Functions.Process(fn, args)); }
private void AcceptEvent(LALRParser parser, AcceptEventArgs args) { //System.Console.WriteLine("AcceptEvent "); NonterminalToken T = (NonterminalToken)args.Token; /* * try * { * Configuration.Load(Configuration.DefaultConfigurationPath); * this.Context.module = new MemoryRegion(); * } * catch (System.Exception ex) * { * Configuration.CreateDefaultConfiguration(); * Configuration.Load(Configuration.DefaultConfigurationPath); * this.Context.module = new MemoryRegion(); * }*/ if (this.RunMode == Rule_Context.eRunMode.Enter) { //mContext.EnterCheckCodeInterface = this.EnterCheckCodeInterface; mContext.RunMode = Rule_Context.eRunMode.Enter; } else if (this.RunMode == Rule_Context.eRunMode.Analysis) { //mContext.AnalysisCheckCodeInterface = this.AnalysisCheckCodeInterface; mContext.RunMode = Rule_Context.eRunMode.Analysis; } this.ProgramStart = new Rule_Statements(mContext, T); this.ProgramStart.Execute(); }
static object RuleExpressionAmpHandler(Parser p, NonterminalToken t) { return(Helpers.GenerateStaticMethodCall("Concat", Helpers.CStr(t.Tokens[0].UserObject), Helpers.CStr(t.Tokens[2].UserObject) )); }
public Rule_Highlight(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { //<IdentifierList> ::= <IdentifierList> Identifier | Identifier if (pToken.Tokens.Length > 2) { //<Hide_Except_Statement> ::= HIDE '*' EXCEPT <IdentifierList> this.IsExceptList = true; this.IdentifierList = this.GetCommandElement(pToken.Tokens, 3).ToString().Split(' '); } else { //<Hide_Some_Statement> ::= HIDE <IdentifierList> this.IdentifierList = this.GetCommandElement(pToken.Tokens, 1).ToString().Split(' '); } if (pContext.IsVariableValidationEnable) { if (IdentifierList.Length > 0) { foreach (var item in IdentifierList) { if (!string.IsNullOrEmpty(item) && !this.Context.CommandVariableCheck.ContainsKey(item.ToLowerInvariant())) { this.Context.CommandVariableCheck.Add(item, "highlight"); } } } } }
static object RuleExpressionRemainderHandler(Parser p, NonterminalToken t) { return(Linq.Expression.Divide( Helpers.CType(t.Tokens[0].UserObject, typeof(int)), Helpers.CType(t.Tokens[2].UserObject, typeof(int)) )); }
public Rule_Field_Checkcode_Statement(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { //<Field_Checkcode_Statement> ::= Field Identifier <Begin_Before_statement> <Begin_After_statement> <Begin_Click_statement> End this.TextField = this.ExtractTokensWithFormat(pToken.Tokens); this.Identifier = this.GetCommandElement(pToken.Tokens, 1).Trim(new char[] { '[', ']' }); for (int i = 2; i < pToken.Tokens.Length; i++) { if (pToken.Tokens[i] is NonterminalToken) { NonterminalToken T = (NonterminalToken)pToken.Tokens[i]; switch (T.Symbol.ToString()) { case "<Begin_Before_statement>": this.BeginBefore = EnterRule.BuildStatments(pContext, T); break; case "<Begin_After_statement>": this.BeginAfter = EnterRule.BuildStatments(pContext, T); break; case "<Begin_Click_statement>": this.BeginClick = EnterRule.BuildStatments(pContext, T); break; } } } }
static object RuleExpressionPowHandler(Parser p, NonterminalToken t) { return(Linq.Expression.Power( Helpers.CType(t.Tokens[0].UserObject, typeof(double)), Helpers.CType(t.Tokens[2].UserObject, typeof(double)) )); }
private void SetOptionList(NonterminalToken pToken) { //<CoxOptList> ::= <CoxOpt> | <CoxOpt> <CoxOptList> switch (pToken.Symbol.ToString()) { case "<CoxOpt>": this.SetOption(pToken); break; case "<CoxOptList>": foreach (Token T in pToken.Tokens) { if (T is NonterminalToken) { NonterminalToken NT = (NonterminalToken)T; switch (NT.Symbol.ToString()) { case "<CoxOpt>": this.SetOption(NT); break; case "<CoxOptList>": this.SetOptionList(NT); break; } } } break; } }
private void SetQualifiedIdList(Token pToken) { /* * <QualifiedIdList> ::= <QualifiedIdList> <Qualified ID> | <Qualified ID> */ if (pToken is NonterminalToken) { NonterminalToken NT = (NonterminalToken)pToken; switch (NT.Symbol.ToString()) { case "<QualifiedIdList>": this.SetQualifiedIdList((NonterminalToken)NT.Tokens[0]); this.IdList.Add(this.SetQualifiedId(NT.Tokens[1])); break; case "<Qualified ID>": this.IdList.Add(SetQualifiedId(NT.Tokens[0])); break; } } else { this.IdList.Add(this.SetQualifiedId(pToken)); } }
/// <summary> /// creates a negateexp from a token /// </summary> /// <returns>Rule_NegateExp</returns> public string CreateNegateRecode(Token pToken) { NonterminalToken T = (NonterminalToken)((NonterminalToken)pToken).Tokens[0]; Rule_NegateExp result = new Rule_NegateExp(this.Context, T); return(result.Execute().ToString()); }
public Rule_Geocode(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { // Geocode address_field_name, latitude_field_name, longitude_field_name //<Geocode_Statement> ::= Geocode Identifier ',' Identifier ',' Identifier this.address_field_name = this.GetCommandElement(pToken.Tokens, 1); this.latitude_field_name = this.GetCommandElement(pToken.Tokens, 3); this.longitude_field_name = this.GetCommandElement(pToken.Tokens, 5); if (pContext.IsVariableValidationEnable) { if (!string.IsNullOrEmpty(address_field_name)) { if (!this.Context.CommandVariableCheck.ContainsKey(address_field_name.ToLowerInvariant())) { this.Context.CommandVariableCheck.Add(address_field_name, "Geocode"); } } if (!string.IsNullOrEmpty(latitude_field_name)) { if (!this.Context.CommandVariableCheck.ContainsKey(latitude_field_name.ToLowerInvariant())) { this.Context.CommandVariableCheck.Add(latitude_field_name, "Geocode"); } } if (!string.IsNullOrEmpty(longitude_field_name)) { if (!this.Context.CommandVariableCheck.ContainsKey(longitude_field_name.ToLowerInvariant())) { this.Context.CommandVariableCheck.Add(longitude_field_name, "Geocode"); } } } }
private void SetSort(NonterminalToken pToken) { /* * <Sort> ::= Identifier <SortOpt> * <SortOpt> ::= ASCENDING | DESCENDING | !Null */ if (pToken.Tokens.Length > 1) { this.SortList.Add(this.GetCommandElement(pToken.Tokens, 0).Trim(new char[] { '[', ']' })); switch (this.GetCommandElement(pToken.Tokens, 1).ToUpperInvariant()) { case "DESCENDING": case "DESC": this.SortOption.Add("DESC"); break; default: this.SortOption.Add("ASC"); break; } } else { this.SortList.Add(this.GetCommandElement(pToken.Tokens, 0).Trim(new char[] { '[', ']' })); this.SortOption.Add("ASC"); } }
public string SetQualifiedId(Token token) { string result = null; if (token is NonterminalToken) { NonterminalToken nonterminal = (NonterminalToken)token; switch (nonterminal.Symbol.ToString()) { case "<Fully_Qualified_Id>": result = this.SetFully_Qualified_Id(nonterminal); break; default: result = this.GetCommandElement(nonterminal.Tokens, 0).Trim(new char[] { '[', ']' }); break; } } else { TerminalToken terminal = (TerminalToken)token; result = terminal.Text.Trim(new char[] { '[', ']' }); } return(result); }