public void AddTerminal(TerminalToken terminal) { if (!Enumerable.Contains <string>(Terminals.Select(x => x.Value), terminal.Value)) { Terminals.Add(terminal); } }
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); }
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); }
/** * 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 void ShowInputError(TerminalToken token) { ClearShowInputError(); int oldpos = this.inputBox.SelectionStart; this.inputBox.Select(token.Location.Position, token.Text.Length); this.inputBox.SelectionColor = Color.Red; this.inputBox.Select(oldpos, 0); this.inputBox.SelectionColor = Color.ForestGreen; }
private static object RuleSymbolNumberHandler(Parser p, TerminalToken t) { //Known to be a valid number or integer already //Culture has to be invariant because grammar has '.' hard-coded if (t.Text.IndexOf('.') >= 0) { return(Linq.Expression.Constant(double.Parse(t.Text, CultureInfo.InvariantCulture))); } return(Linq.Expression.Constant(int.Parse(t.Text, CultureInfo.InvariantCulture))); }
private void GetOutTarget(Token pToken) { /*<OutTarget> ::= Identifier | File ':' Identifier | File | BraceString ':' Identifier*/ if (pToken is NonterminalToken) { NonterminalToken NT = pToken as NonterminalToken; foreach (TerminalToken TT in NT.Tokens) { if (TT.Symbol.ToString() == "Identifier") { this.TableName = TT.Text.Trim(new char[] { '[', ']' }); //this.TableName = this.TableName.Replace("#", "."); this.TableName = this.TableName.Trim().Trim('\''); } if (TT.Symbol.ToString() == "File") { this.FilePath = TT.Text; } if (TT.Symbol.ToString() == "BraceString") { this.FilePath = TT.Text.Trim(new char[] { '{', '}' });; isConnectionString = true; } } } else { TerminalToken TT = pToken as TerminalToken; if (TT.Symbol.ToString() == "Identifier") { this.TableName = TT.Text.Trim(new char[] { '[', ']' }); //this.TableName = this.TableName.Replace("#", "."); this.TableName = this.TableName.Trim().Trim('\''); } if (TT.Symbol.ToString() == "File") { this.FilePath = TT.Text; } if (TT.Symbol.ToString() == "BraceString") { this.FilePath = TT.Text.Trim(new char[] { '{', '}' });; isConnectionString = true; } } }
public Rule_Value(Rule_Context pContext, Token pToken) : base(pContext) { /* ::= Identifier | <Literal> | Boolean | '(' <Expr List> ')' */ if (pToken is NonterminalToken) { NonterminalToken T = (NonterminalToken)pToken; if (T.Tokens.Length == 1) { switch (T.Rule.Rhs[0].ToString()) { case "Identifier": this.Id = this.GetCommandElement(T.Tokens, 0); break; case "<FunctionCall>": //this.value = new Rule_FunctionCall(pContext, (NonterminalToken)T.Tokens[0]); break; case "<Literal>": case "Boolean": default: this.value = this.GetCommandElement(T.Tokens, 0); break; } } else { //this.value = new Rule_ExprList(pContext, (NonterminalToken)T.Tokens[1]); } } else { TerminalToken TT = (TerminalToken)pToken; switch (TT.Symbol.ToString()) { case "Boolean": this.value = TT.Text; break; default: this.value = TT.Text; break; } } if (this.Id == null && this.value == null) { } }
private static void FillTreeView(NonterminalToken a, Token token) { if (token is TerminalToken) { TerminalToken t = (TerminalToken)token; if (!isbuild) { abc.Add(""); isbuild = true; } else { if (abc[abc.Count - 1].Contains("构建")) { abc[abc.Count - 1] += t.Text; } } if (t.Symbol.Name == "using") { abc[abc.Count - 1] += "构建using:"; } if (t.Symbol.Name == "MemberName") { isbuild = true; // abc[abc.Count - 1] += "构建using"; } if (t.Symbol.Name == ";") { isbuild = false; // abc[abc.Count - 1] += "构建using"; } // tokens.Add(t); // Console.WriteLine("t:" + StringUtil.ShowEscapeChars(t.Text)); // Console.WriteLine("tyie:" + t.Symbol.Name); } else if (token is NonterminalToken) { NonterminalToken t = (NonterminalToken)token; // Console.WriteLine(t.Symbol.Name); foreach (Token childToken in t.Tokens) { FillTreeView(t, childToken); } } }
private object GetRecodeValue(Token token) { object result = null; if (token is NonterminalToken) { NonterminalToken nonterm = (NonterminalToken)token; string os = Environment.OSVersion.VersionString; //<RecodeValue> ::= <Literal> | Boolean | Identifier string name = nonterm.Tokens[0].ToString(); string symbolName = nonterm.Symbol.Name; switch (symbolName) { case "Real_Number": case "Decimal_Number": string commandElementString = this.GetCommandElement(nonterm.Tokens, 0).Replace("\"", "").Trim(); double commandElementDouble = double.NaN; System.Double.TryParse(commandElementString, out commandElementDouble); if (commandElementDouble != double.NaN) { result = commandElementDouble; } break; case "Literal_Date": result = DateTime.Parse(name); break; case "Literal_String": case "RecodeValue": case "Recoded_Value": result = this.GetCommandElement(nonterm.Tokens, 0).Replace("\"", "").Trim(); break; } } else { TerminalToken TT = (TerminalToken)token; result = TT.ToString(); } return(result); }
static public List <AnalysisRule> GetFunctionParameters(Rule_Context context, Token token) { List <AnalysisRule> result = new List <AnalysisRule>(); if (token is NonterminalToken) { NonterminalToken nonterminal = (NonterminalToken)token; switch (nonterminal.Symbol.ToString()) { case "<NonEmptyFunctionParameterList>": result.AddRange(AnalysisRule.GetFunctionParameters(context, nonterminal)); break; case "<SingleFunctionParameterList>": result.AddRange(AnalysisRule.GetFunctionParameters(context, nonterminal)); break; case "<EmptyFunctionParameterList>": break; case "<MultipleFunctionParameterList>": result.AddRange(AnalysisRule.GetFunctionParameters(context, nonterminal.Tokens[0])); result.Add(AnalysisRule.BuildStatments(context, nonterminal.Tokens[2])); break; case "<FuncName2>": case "<Expression>": case "<expression>": case "<FunctionCall>": default: result.Add(AnalysisRule.BuildStatments(context, nonterminal)); break; } } else { TerminalToken terminal = (TerminalToken)token; if (terminal.Text != ",") { result.Add(new Rule_Value(context, token)); } } return(result); }
void Getusing(calitha.goldparser.Token token) { if (token is TerminalToken) { TerminalToken t = (TerminalToken)token; var n = StringUtil.ShowEscapeChars(t.Text); } else if (token is NonterminalToken) { NonterminalToken t = (NonterminalToken)token; var n = (t.Rule.ToString(), 1, 1); foreach (calitha.goldparser.Token childToken in t.Tokens) { Getusing(childToken); } } }
public Rule_Tables(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { //this.isExceptionList = false; commandText = this.ExtractTokens(pToken.Tokens); foreach (Token T in pToken.Tokens) { if (T is NonterminalToken) { NonterminalToken NT = (NonterminalToken)T; switch (NT.Symbol.ToString()) { case "<table_exposure>": this.SetTableExposure(NT); break; case "<table_outcome>": this.SetTableOutcome(NT); break; case "<FreqOpts>": //this.SetFreqOpts(NT); this.SetFreqOpts(NT); break; case "<FreqOpt>": this.SetFreqOpt(NT); break; } } else { TerminalToken TT = (TerminalToken)T; switch (TT.Symbol.ToString()) { case "<table_exposure>": case "<table_outcome>": case "<FreqOpts>": break; } } } }
internal List <Token> Scan(Grammar grammar, string content) { mContent = content.Replace("\r\n", "\n"); mGrammar = grammar; List <Token> tokens = new List <Token>(); mLine = 1; mCol = 1; State state = State.None; while (ReadChar()) { Token token = GetToken(ref state); if (token || CurrentTerminal) { OldPosition = mPosition; } if (token) { tokens.Add(token); } if (CurrentTerminal) { tokens.Add(CurrentTerminal); CurrentTerminal = null; } if (Peek == '\n') { mCol = 1; mLine++; } else { mCol++; } } return(tokens); }
private void FillTreeViewRecursive(TreeView tree, TreeNode parentNode, Token token) { if (token is TerminalToken) { TerminalToken t = (TerminalToken)token; TreeNode node = new TreeNode(StringUtil.ShowEscapeChars(t.Text), 0, 0); parentNode.Nodes.Add(node); } else if (token is NonterminalToken) { NonterminalToken t = (NonterminalToken)token; TreeNode node = new TreeNode(t.Rule.ToString(), 1, 1); parentNode.Nodes.Add(node); foreach (Token childToken in t.Tokens) { FillTreeViewRecursive(tree, node, childToken); } } }
public Rule_Relate(Rule_Context context, NonterminalToken nonterminal) : base(context) { foreach (Token token in nonterminal.Tokens) { if (token is NonterminalToken) { NonterminalToken nextNonterminal = (NonterminalToken)token; switch (nextNonterminal.Symbol.ToString()) { case "<Qualified ID>": _identifier = SetQualifiedId(nextNonterminal); break; case "<KeyDef>": case "<KeyExprIdentifier>": _keyDef = ExtractTokens(nextNonterminal.Tokens).Trim(); break; case "<JoinOpt>": _joinOpts.AddRange(ExtractTokens(nextNonterminal.Tokens).ToUpperInvariant().Split(StringLiterals.SPACE.ToCharArray())); break; } } else { TerminalToken nextTerminal = (TerminalToken)token; switch (nextTerminal.Symbol.ToString()) { case "BraceString": _filePath = nextTerminal.Text.Trim(new char[] { '{', '}' }); break; case "File": _filePath = nextTerminal.Text.Trim(new char[] { '\'', '"' }); break; } } } }
public static List <Token> find(Token token) { var list = new List <Token>(); if (token is TerminalToken) { TerminalToken t = (TerminalToken)token; if (t.Symbol.Name == "Identifier " || t.Symbol.Name == "using" || t.Symbol.Name == ";") { list.Add(t); } } else if (token is NonterminalToken) { NonterminalToken t = (NonterminalToken)token; foreach (Token childToken in t.Tokens) { list.AddRange(find(childToken)); } } return(list); }
static bool IsTerminal(Scanner scanner) { if (scanner.Peek == '\n') { LineFeedToken token = new LineFeedToken(); token.Line = scanner.Line; token.Column = scanner.Column; scanner.CurrentTerminal = token; return(true); } int len = scanner.GetTerminal(); if (len > 0) { TerminalToken token = new TerminalToken(); token.Word = scanner.Content.Substring(scanner.Position, len); token.Line = scanner.Line; token.Column = scanner.Column; scanner.CurrentTerminal = token; return(true); } return(false); }
public Rule_Graph(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { _commandText = this.ExtractTokens(pToken.Tokens); string caseSymbol = string.Empty; foreach (Token token in pToken.Tokens) { if (token is NonterminalToken) { NonterminalToken nonterminalToken = (NonterminalToken)token; caseSymbol = nonterminalToken.Symbol.ToString(); switch (caseSymbol) { case "<Graph_Type>": _graphType = nonterminalToken.Tokens[0].ToString(); break; case "<Graph_Interval>": string intervalText = (((NonterminalToken)nonterminalToken).Tokens[2]).ToString(); intervalText = intervalText.Trim(new char[] { '"' }); string[] intervalArray = intervalText.Split(' '); _graphInterval = intervalArray[0]; _graphIntervalUnits = intervalArray[1]; break; case "<Graph_StartFrom>": _graphStartFrom = this.GetCommandElement(nonterminalToken.Tokens, 2); break; case "<Graph_Variable>": _independentVariableList = nonterminalToken.Tokens[0].ToString().Trim(new char[] { '[', ']' }); break; case "<Graph_Variable_List>": this.SetIdentifierList(nonterminalToken); break; case "<Graph_CrossTab>": _graphCrossTab = nonterminalToken.Tokens[0].ToString().Trim(new char[] { '[', ']' }); break; case "<Graph_Option_List>": this.SetOptionList(nonterminalToken); break; case "<Graph_Title>": _graphTitle = this.GetCommandElement(nonterminalToken.Tokens, 2); break; case "<Graph_XAxisLabel>": _graphXAxisLabel = this.GetCommandElement(nonterminalToken.Tokens, 2); break; case "<Graph_YAxisLabel>": _graphYAxisLabel = this.GetCommandElement(nonterminalToken.Tokens, 2); break; case "<Graph_StrataVar>": _strataVar = (((NonterminalToken)nonterminalToken).Tokens[2]).ToString(); break; case "<Graph_DateFormat>": _graphDateFormat = (((NonterminalToken)nonterminalToken).Tokens[2]).ToString(); break; case "<Graph_WeightVar>": object tokenObject = (((NonterminalToken)nonterminalToken).Tokens[2]); if (tokenObject is TerminalToken) { _weightVar = ((TerminalToken)tokenObject).Text.Trim(new char[] { '[', ']' }); } else { _aggregateFunction = this.GetCommandElement(((NonterminalToken)tokenObject).Tokens, 0); Token tok = null; if (((NonterminalToken)tokenObject).Tokens.Length == 1) { tok = ((NonterminalToken)tokenObject).Tokens[0]; if (_aggregateFunction.ToUpperInvariant() == "PERCENT()") { _aggregateFunction = _aggregateFunction.TrimEnd(new char[] { '(', ')' }); _weightVar = _independentVariableList.Trim(new char[] { ',' }); break; } } else { tok = ((NonterminalToken)tokenObject).Tokens[2]; tok = ((NonterminalToken)(tok)).Tokens[0]; } _weightVar = ((TerminalToken)(tok)).Text; _weightVar = _weightVar.Trim(new char[] { '[', ']' }); } break; } } else { TerminalToken terminalToken = (TerminalToken)token; switch (terminalToken.Symbol.ToString()) { case "Identifier": _independentVariableList = terminalToken.ToString().Trim(new char[] { '[', ']' }); break; } } } }
public static void Fx() { var r = new Queue <TerminalToken>(); foreach (var tt in tokens) { r.Enqueue(tt); } TerminalToken token = null; var str = ""; string current = ""; string start = ""; string last = ""; string class_type = ""; System.Threading.Tasks.Task.Run(() => { while (true) { if (!r.TryDequeue(out token)) { break; } current = token.Symbol.Name; if (current == "using") { start = "using"; Console.Write("构建using列表:"); } if (current == "namespace") { start = "ns"; Console.Write("构建命名空间:"); } if (current == "public") { class_type = current; } if (current == "private") { class_type = current; } if (current == "class") { start = "cs"; Console.Write($"伪造一个{class_type}类型:"); } if (current == "Identifier") { if (start == "using") { Console.Write(token.Text); } if (start == "ns") { Console.Write(token.Text); } if (start == "cs") { Console.Write(token.Text); } } if (current == "MemberName") { if (start == "using") { Console.Write(token.Text); } if (start == "ns") { Console.Write(token.Text); } } if (current == ";") { if (start == "using") { start = ""; Console.WriteLine(""); // Console.WriteLine("结束"); } } if (current == "{") { if (start == "ns" || start == "cs") { start = ""; Console.WriteLine(""); } } last = current; } }); }
internal Token(short tokenId, TerminalToken terminal) { _tokenId = tokenId; _tokenValue = terminal; }
// <summary> // Creates a new token representing a terminal. // </summary> // <param name="tokenId"> tokenid </param> // <param name="termToken"> lexical value </param> internal static Token NewToken(short tokenId, TerminalToken termToken) { return(new Token(tokenId, termToken)); }
internal Token(short tokenId, TerminalToken terminal) { _tokenId = tokenId; _tokenValue = terminal; }
public Token GetToken() { State = LexicAnalyserState.Initial; Value = HasNext ? Character.ToString() : ""; Token token = null; while (HasNext && token == null) { switch (State) { case LexicAnalyserState.Initial: HandleInitial(); break; case LexicAnalyserState.NonTerminal: token = new NonTerminalToken(Value); CurrentIndex++; break; case LexicAnalyserState.Space: token = new SpaceToken(); CurrentIndex++; break; case LexicAnalyserState.Terminal: token = new TerminalToken(Value); CurrentIndex++; break; case LexicAnalyserState.Empty: token = new EmptyToken(); CurrentIndex++; break; case LexicAnalyserState.NewLine: token = new NewLineToken(Value); CurrentIndex++; break; case LexicAnalyserState.Identifier: token = new IdentifierToken(Value); CurrentIndex++; break; case LexicAnalyserState.Number: token = new NumberToken(Value); CurrentIndex++; break; case LexicAnalyserState.Var: token = new VarToken(); CurrentIndex++; break; case LexicAnalyserState.Write: token = new WriteToken(); CurrentIndex++; break; case LexicAnalyserState.Read: token = new ReadToken(); CurrentIndex++; break; case LexicAnalyserState.If: token = new IfToken(); CurrentIndex++; break; case LexicAnalyserState.End: token = new EndToken(); CurrentIndex++; break; case LexicAnalyserState.Then: token = new ThenToken(); CurrentIndex++; break; case LexicAnalyserState.Begin: token = new BeginToken(); CurrentIndex++; break; case LexicAnalyserState.While: token = new WhileToken(); CurrentIndex++; break; case LexicAnalyserState.Do: token = new DoToken(); CurrentIndex++; break; case LexicAnalyserState.SemiColon: token = new SemiColonToken(); CurrentIndex++; break; case LexicAnalyserState.OpenParentheses: token = new OpenParenthesesToken(); CurrentIndex++; break; case LexicAnalyserState.CloseParentheses: token = new CloseParenthesesToken(); CurrentIndex++; break; case LexicAnalyserState.Plus: token = new PlusToken(); CurrentIndex++; break; case LexicAnalyserState.Sub: token = new SubToken(); CurrentIndex++; break; case LexicAnalyserState.Great: token = new GreatToken(); CurrentIndex++; break; case LexicAnalyserState.Less: token = new LessToken(); CurrentIndex++; break; case LexicAnalyserState.Equal: token = new EqualToken(); CurrentIndex++; break; case LexicAnalyserState.Repeat: token = new RepeatToken(); CurrentIndex++; break; case LexicAnalyserState.Until: token = new UntilToken(); CurrentIndex++; break; case LexicAnalyserState.Attribution: token = new AttributionToken(); CurrentIndex++; break; case LexicAnalyserState.NotEqual: token = new NotEqualToken(); CurrentIndex++; break; case LexicAnalyserState.GreatOrEqual: token = new GreatOrEqualToken(); CurrentIndex++; break; case LexicAnalyserState.LessOrEqual: token = new LessOrEqualToken(); CurrentIndex++; break; default: throw new ArgumentOutOfRangeException(); } } return(token); }
private Object CreateObject(TerminalToken token) { return(null); }
static public List <EnterRule> GetFunctionParameters(Rule_Context pContext, Token pToken) { List <EnterRule> result = new List <EnterRule>(); if (pToken is NonterminalToken) { NonterminalToken NT = (NonterminalToken)pToken; switch (NT.Symbol.ToString()) { case "<NonEmptyFunctionParameterList>": //this.paramList.Push(new Rule_NonEmptyFunctionParameterList(T, this.paramList)); result.AddRange(EnterRule.GetFunctionParameters(pContext, NT)); break; case "<SingleFunctionParameterList>": result.AddRange(EnterRule.GetFunctionParameters(pContext, NT)); break; case "<EmptyFunctionParameterList>": //this.paramList = new Rule_EmptyFunctionParameterList(T); // do nothing the parameterlist is empty break; case "<MultipleFunctionParameterList>": //this.MultipleParameterList = new Rule_MultipleFunctionParameterList(pToken); //<NonEmptyFunctionParameterList> ',' <Expression> //result.Add(AnalysisRule.BuildStatments(pContext, NT.Tokens[0])); result.AddRange(EnterRule.GetFunctionParameters(pContext, NT.Tokens[0])); result.Add(EnterRule.BuildStatments(pContext, NT.Tokens[2])); break; case "<FuncName2>": case "<Expression>": case "<expression>": case "<FunctionCall>": default: result.Add(EnterRule.BuildStatments(pContext, NT)); break; } } else { TerminalToken TT = (TerminalToken)pToken; if (TT.Text != ",") { result.Add(new Rule_Value(pContext, pToken)); } } /* * <FunctionCall> ::= Identifier '(' <FunctionParameterList> ')' | FORMAT '(' <FunctionParameterList> ')' | <FuncName2> | ! | <FuncName1> '(' <FunctionCall> ')' | <FunctionParameterList> ::= <EmptyFunctionParameterList> | <NonEmptyFunctionParameterList> | <NonEmptyFunctionParameterList> ::= <MultipleFunctionParameterList> | <SingleFunctionParameterList> | | <MultipleFunctionParameterList> ::= <NonEmptyFunctionParameterList> ',' <Expression> | <SingleFunctionParameterList> ::= <expression> | <EmptyFunctionParameterList> ::= */ /* * foreach (Token T in pToken.Tokens) * { * if (T is NonterminalToken) * { * * NonterminalToken NT = (NonterminalToken)T; * * switch (NT.Rule.Lhs.ToString()) * { * case "<NonEmptyFunctionParameterList>": * * * //this.paramList.Push(new Rule_NonEmptyFunctionParameterList(T, this.paramList)); * result.AddRange(EnterRule.GetFunctionParameters(pContext, NT)); * break; * case "<SingleFunctionParameterList>": * * result.AddRange(EnterRule.GetFunctionParameters(pContext, NT)); * break; * case "<EmptyFunctionParameterList>": * //this.paramList = new Rule_EmptyFunctionParameterList(T); * // do nothing the parameterlist is empty * break; * case "<MultipleFunctionParameterList>": * * //this.MultipleParameterList = new Rule_MultipleFunctionParameterList(pToken); * result.AddRange(EnterRule.GetFunctionParameters(pContext, NT)); * break; * case "<FuncName2>": * case "<Expression>": * case "<expression>": * case "<FunctionCall>": * * result.Add(EnterRule.BuildStatments(pContext, NT)); * break; * default: * result.Add(new Rule_Value(pContext, T)); * break; * } * } * else * { * TerminalToken TT = (TerminalToken)T; * if (TT.Text != ",") * { * result.Add(new Rule_Value(pContext, TT)); * } * } * }*/ return(result); }
public Rule_Freq(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { this.IdentifierList = new List <string>(); /*<Freq_Variable_List> ::= Identifier | Identifier <Freq_Variable_List> * * <Freq_All_Statement> ::= FREQ '*' | FREQ '*' <FreqOpts> | FREQ <Freq_Variable_List> | FREQ <Freq_Variable_List> <FreqOpts> | FREQ '*' EXCEPT <Freq_Variable_List> | FREQ '*' EXCEPT <Freq_Variable_List> <FreqOpts> | | <FreqOpts> ::= <FreqOpts> <FreqOpt> | <FreqOpt> | | <FreqOpt> ::= WEIGHTVAR '=' Identifier | STRATAVAR '=' <Freq_Variable_List> |NOWRAP |COLUMNSIZE '=' DecLiteral |PSUVAR '=' Identifier | OUTTABLE '=' Identifier | <SetClause> */ commandText = this.ExtractTokens(pToken.Tokens); foreach (Token T in pToken.Tokens) { if (T is NonterminalToken) { NonterminalToken NT = (NonterminalToken)T; switch (NT.Symbol.ToString()) { case "<Freq_Variable_List>": this.IdentifierList.AddRange(AnalysisRule.SpliIdentifierList(this.ExtractTokens(NT.Tokens).Trim())); break; case "<FreqOpts>": this.SetFrequencyOptions(NT); break; case "<FreqOpt>": this.SetFrequencyOption(NT); break; } } else { TerminalToken TT = (TerminalToken)T; switch (TT.Symbol.ToString()) { case "*": this.IdentifierList.AddRange("*".Split(' ')); break; case "EXCEPT": this.isExceptionList = true; break; } } } /* * if (pToken.Tokens.Length == 2) * { * this.IdentifierList = this.GetCommandElement(pToken.Tokens, 1).Split(' '); * } * else if (pToken.Tokens.Length <= 3) * { * this.IdentifierList = this.GetCommandElement(pToken.Tokens, 1).Split(' '); * NonterminalToken T = (NonterminalToken)pToken.Tokens[2]; * * this.SetFrequencyOptions(T); * * } * else * { * this.IdentifierList = this.GetCommandElement(pToken.Tokens, 3).Split(' '); * //this.isExceptionList = true; * this.SetFrequencyOptions((NonterminalToken)pToken.Tokens[4]); * }*/ //<OutTableOpt> ::= OUTTABLE '=' Identifier <KeyVarList> //<KeyVarList> ::= KEYVARS '=' <IdentifierList> /* * !*** Freq Statement ***! * <Freq_All_Statement> ::= FREQ '*' <FreqOpts> * <Freq_Columns_Statement> ::= FREQ <IdentifierList> <FreqOpts> * <Freq_All_Except_Statement> ::= FREQ '*' EXCEPT <IdentifierList> <FreqOpts> * * <FreqOpts> ::= <FreqOpts> <FreqOpt> | <FreqOpt> | !Null * * <FreqOpt> ::= <WeightOpt> | <FreqOptStrata> | <OutTableOpt> | <SetClause> | <FreqOptNoWrap> | <FreqOptColumnSize> | <FreqOptPsuvar> | | <WeightOpt> ::= WEIGHTVAR '=' Identifier | <FreqOptStrata> ::= STRATAVAR '=' <IdentifierList> | <FreqOptNoWrap> ::= NOWRAP | <FreqOptColumnSize> ::= COLUMNSIZE '=' DecLiteral | <FreqOptPsuvar> ::= PSUVAR '=' Identifier | | !*** End ***! */ }
/// <summary> /// Creates a new token representing a terminal. /// </summary> /// <param name="tokenId">tokenid</param> /// <param name="termToken">lexical value</param> /// <returns></returns> static internal Token NewToken(short tokenId, TerminalToken termToken) { return new Token(tokenId, termToken); }
static public EnterRule BuildStatments(Rule_Context pContext, Token pToken) { EnterRule result = null; if (pToken is NonterminalToken) { NonterminalToken NT = (NonterminalToken)pToken; switch (NT.Symbol.ToString()) { // H1N1 case "<Program>": result = new Rule_Program(pContext, NT); break; case "<Always_Statement>": result = new Rule_Always(pContext, NT); break; case "<Simple_Assign_Statement>": case "<Let_Statement>": case "<Assign_Statement>": result = new Rule_Assign(pContext, NT); break; case "<Assign_DLL_Statement>": result = new Rule_Assign_DLL_Statement(pContext, NT); break; case "<If_Statement>": case "<If_Else_Statement>": result = new Rule_If_Then_Else_End(pContext, NT); break; case "<Else_If_Statement>": result = new Rule_Else_If_Statement(pContext, NT); break; case "<Define_Variable_Statement>": result = new Rule_Define(pContext, NT); break; case "<Define_Dll_Statement>": result = new Rule_DLL_Statement(pContext, NT); break; case "<FuncName2>": case "<FunctionCall>": result = new Rule_FunctionCall(pContext, NT); break; case "<Hide_Some_Statement>": case "<Hide_Except_Statement>": result = new Rule_Hide(pContext, NT); break; case "<Unhide_Some_Statement>": case "<Unhide_Except_Statement>": result = new Rule_UnHide(pContext, NT); break; case "<Go_To_Variable_Statement>": case "<Go_To_Page_Statement>": case "<Go_To_Form_Statement>": result = new Rule_GoTo(pContext, NT); break; case "<Simple_Dialog_Statement>": case "<Numeric_Dialog_Implicit_Statement>": case "<Numeric_Dialog_Explicit_Statement>": case "<TextBox_Dialog_Statement>": case "<Db_Values_Dialog_Statement>": case "<YN_Dialog_Statement>": case "<Db_Views_Dialog_Statement>": case "<Databases_Dialog_Statement>": case "<Db_Variables_Dialog_Statement>": case "<Multiple_Choice_Dialog_Statement>": case "<Dialog_Read_Statement>": case "<Dialog_Write_Statement>": case "<Dialog_Read_Filter_Statement>": case "<Dialog_Write_Filter_Statement>": case "<Dialog_Date_Statement>": case "<Dialog_Time_Statement>": case "<Dialog_DateTime_Statement>": case "<Dialog_Date_Mask_Statement>": result = new Rule_Dialog(pContext, NT); break; case "<Comment_Line>": result = new Rule_CommentLine(pContext, NT); break; case "<Simple_Execute_Statement>": case "<Execute_File_Statement>": case "<Execute_Url_Statement>": case "<Execute_Wait_For_Exit_File_Statement>": case "<Execute_Wait_For_Exit_String_Statement>": case "<Execute_Wait_For_Exit_Url_Statement>": case "<Execute_No_Wait_For_Exit_File_Statement>": case "<Execute_No_Wait_For_Exit_String_Statement>": case "<Execute_No_Wait_For_Exit_Url_Statement>": result = new Rule_Execute(pContext, NT); break; case "<Beep_Statement>": result = new Rule_Beep(pContext, NT); break; case "<Auto_Search_Statement>": result = new Rule_AutoSearch(pContext, NT); break; case "<Quit_Statement>": result = new Rule_Quit(pContext); break; case "<Clear_Statement>": result = new Rule_Clear(pContext, NT); break; case "<New_Record_Statement>": result = new Rule_NewRecord(pContext, NT); break; case "<Save_Record_Statement>": result = new Rule_SaveRecord(pContext, NT); break; case "<Simple_Undefine_Statement>": result = new Rule_Undefine(pContext, NT); break; case "<Geocode_Statement>": result = new Rule_Geocode(pContext, NT); break; case "<DefineVariables_Statement>": result = new Rule_DefineVariables_Statement(pContext, NT); break; case "<Field_Checkcode_Statement>": result = new Rule_Field_Checkcode_Statement(pContext, NT); break; case "<View_Checkcode_Statement>": result = new Rule_View_Checkcode_Statement(pContext, NT); break; case "<Record_Checkcode_Statement>": result = new Rule_Record_Checkcode_Statement(pContext, NT); break; case "<Page_Checkcode_Statement>": result = new Rule_Page_Checkcode_Statement(pContext, NT); break; case "<Subroutine_Statement>": result = new Rule_Subroutine_Statement(pContext, NT); break; case "<Call_Statement>": result = new Rule_Call(pContext, NT); break; case "<Expr List>": result = new Rule_ExprList(pContext, NT); break; case "<Expression>": result = new Rule_Expression(pContext, NT); break; case "<And Exp>": result = new Rule_AndExp(pContext, NT); break; case "<Not Exp>": result = new Rule_NotExp(pContext, NT); break; case "<Compare Exp>": result = new Rule_CompareExp(pContext, NT); break; case "<Concat Exp>": result = new Rule_ConcatExp(pContext, NT); break; case "<Add Exp>": result = new Rule_AddExp(pContext, NT); break; case "<Mult Exp>": result = new Rule_MultExp(pContext, NT); break; case "<Pow Exp>": result = new Rule_PowExp(pContext, NT); break; case "<Negate Exp>": result = new Rule_NegateExp(pContext, NT); break; case "<Begin_Before_statement>": result = new Rule_Begin_Before_Statement(pContext, NT); break; case "<Begin_After_statement>": result = new Rule_Begin_After_Statement(pContext, NT); break; case "<Begin_Click_statement>": result = new Rule_Begin_Click_Statement(pContext, NT); break; case "<CheckCodeBlock>": result = new Rule_CheckCodeBlock(pContext, NT); break; case "<CheckCodeBlocks>": result = new Rule_CheckCodeBlocks(pContext, NT); break; case "<Simple_Run_Statement>": break; case "<Statements>": result = new Rule_Statements(pContext, NT); break; case "<Statement>": result = new Rule_Statement(pContext, NT); break; case "<Define_Statement_Group>": result = new Rule_Define_Statement_Group(pContext, NT); break; case "<Define_Statement_Type>": result = new Rule_Define_Statement_Type(pContext, NT); break; case "<Highlight_Statement>": result = new Rule_Highlight(pContext, NT); break; case "<UnHighlight_Statement>": result = new Rule_UnHighlight(pContext, NT); break; case "<Enable_Statement>": result = new Rule_Enable(pContext, NT); break; case "<Disable_Statement>": result = new Rule_Disable(pContext, NT); break; case "<Set_Required_Statement>": result = new Rule_SetRequired(pContext, NT); break; case "<Set_Not_Required_Statement>": result = new Rule_SetNOTRequired(pContext, NT); break; case "<Value>": default: result = new Rule_Value(pContext, NT); break; //result = new Rule_Value(pContext, NT); //throw new Exception("Missing rule in EnterRule.BuildStatments " + NT.Symbol.ToString()); } } else // terminal token { TerminalToken TT = (TerminalToken)pToken; switch (TT.Symbol.ToString()) { case "<Value>": default: result = new Rule_Value(pContext, TT); break; } } return(result); }
/// <summary> /// Constructor for Rule_List /// </summary> /// <param name="pToken">The token used to build the reduction.</param> public Rule_List(Rule_Context pContext, NonterminalToken pToken) : base(pContext) { config = Configuration.GetNewInstance(); repOfYes = config.Settings.RepresentationOfYes; repOfNo = config.Settings.RepresentationOfNo; repOfMissing = config.Settings.RepresentationOfMissing; CommandText = this.ExtractTokens(pToken.Tokens); foreach (Token T in pToken.Tokens) { if (T is NonterminalToken) { NonterminalToken NT = (NonterminalToken)T; switch (NT.Symbol.ToString()) { case "<List_Identifier_List>": this.SetIdentifierList(NT); break; case "<ListOpt>": this.SetListOpt(NT); break; case "<ListGridOpt>": this.SetListOpt(NT); break; } } else { TerminalToken TT = (TerminalToken)T; switch (TT.Symbol.ToString()) { case "*": this.IdentifierList.Add("*"); break; case "EXCEPT": this.IsExceptionList = true; break; } } } if (this.IdentifierList.Count > 1 && this.IdentifierList[0] == "*") { this.IdentifierList.Remove("*"); } /* * !*** List Statement ***! * <List_Statement> ::= LIST | LIST <ListOpt> | LIST '*' | LIST '*' <ListOpt> | LIST <List_Identifier_List> | LIST <List_Identifier_List> <ListOpt> | LIST '*' EXCEPT <List_Identifier_List> | LIST '*' EXCEPT <List_Identifier_List> <ListOpt> | | <ListOpt> ::= <ListGridOpt> | <ListUpdateOpt> | <ListHTMLOpt> | | <ListGridOpt> ::= GRIDTABLE | <ListUpdateOpt> ::= UPDATE | | <ListHTMLOpt> ::= <ListHTMLOptOneColumn> | <ListHTMLOptTwoColumns> | <ListHTMLOptThreeColumns> | <ListHTMLOptNoImage> | <ListHTMLOptNowrap> | <ListHTMLOptLine> | !Null | | <ListHTMLOptOneColumn> ::= <ListHTMLOpt> COULMNSIZE '=' DecLiteral | <ListHTMLOptTwoColumns> ::= <ListHTMLOpt> COULMNSIZE '=' DecLiteral ',' DecLiteral | <ListHTMLOptThreeColumns> ::= <ListHTMLOpt> COULMNSIZE '=' DecLiteral ',' DecLiteral ',' DecLiteral | <ListHTMLOptNoImage> ::= <ListHTMLOpt> NOIMAGE | <ListHTMLOptNoWrap> ::= <ListHTMLOpt> NOWRAP | <ListHTMLOptLine> ::= <ListHTMLOpt> LINENUMBERS | !*** End ***! */ }
public Rule_Value(Rule_Context pContext, Token pToken) : base(pContext) { /* ::= Identifier | <Literal> | Boolean | '(' <Expr List> ')' */ if (pToken is NonterminalToken) { NonterminalToken T = (NonterminalToken)pToken; if (T.Tokens.Length == 1) { DateTime dateTime_temp; switch (T.Rule.Rhs[0].ToString()) { case "<Qualified ID>": this.Id = this.SetQualifiedId(T.Tokens[0]); break; case "Identifier": this.Id = this.GetCommandElement(T.Tokens, 0).Trim(new char[] {'[',']'}); break; case "(": case "<FunctionCall>": this.value = new Rule_FunctionCall(pContext, (NonterminalToken)T.Tokens[1]); break; case "<Literal>": this.value = this.GetCommandElement(T.Tokens, 0).Trim('"'); break; case "<Literal_String>": case "String": this.value = this.GetCommandElement(T.Tokens, 0).Trim('"'); break; case "<Literal_Char>": case "CharLiteral": this.value = this.GetCommandElement(T.Tokens, 0).Trim('\''); break; case "Boolean": string string_temp = this.GetCommandElement(T.Tokens, 0); if (string_temp == "(+)" || string_temp.ToLowerInvariant() == "true" || string_temp.ToLowerInvariant() == "yes") { this.value = true; } else if (string_temp == "(-)" || string_temp.ToLowerInvariant() == "false" || string_temp.ToLowerInvariant() == "no") { this.value = false; } else if (string_temp == "(.)") { this.value = null; } break; case "<Decimal_Number>": case "<Number>": case "<Real_Number>": case "<Hex_Number>": case "DecLiteral": case "RealLiteral": case "HexLiteral": double Decimal_temp; if (double.TryParse(this.GetCommandElement(T.Tokens, 0), out Decimal_temp)) { this.value = Decimal_temp; } break; case "<Literal_Date>": case "Date": if (DateTime.TryParse(this.GetCommandElement(T.Tokens, 0), out dateTime_temp)) { DateTime dt = new DateTime(dateTime_temp.Year, dateTime_temp.Month, dateTime_temp.Day); this.value = dt; } else { this.value = null; } break; case "<Literal_Time>": case "<Literal_Date_Time>": case "Time": case "Date Time": if (DateTime.TryParse(this.GetCommandElement(T.Tokens, 0), out dateTime_temp)) { this.value = dateTime_temp; } break; case "<Value>": this.value = new Rule_Value(this.Context, T.Tokens[0]); break; default: this.value = this.GetCommandElement(T.Tokens, 0).Trim('"');; break; } } else { //this.value = new Rule_ExprList(pContext, (NonterminalToken)T.Tokens[1]); //this.value = AnalysisRule.BuildStatments(pContext, T.Tokens[1]); if (T.Tokens.Length == 0) { this.value = AnalysisRule.BuildStatments(pContext, T); } else { this.value = AnalysisRule.BuildStatments(pContext, T.Tokens[1]); } } } else { TerminalToken TT = (TerminalToken)pToken; DateTime dateTime_temp; switch (TT.Symbol.ToString()) { case "Identifier": this.Id = TT.Text; break; case "<Literal>": this.value = TT.Text.Trim('"'); break; case "<Literal_String>": case "String": this.value = TT.Text.Trim('"'); break; case "<Literal_Char>": case "CharLiteral": this.value = TT.Text.Trim('\''); break; case "Boolean": string string_temp = TT.Text; if (string_temp == "(+)" || string_temp.ToLowerInvariant() == "true" || string_temp.ToLowerInvariant() == "yes") { this.value = true; } else if (string_temp == "(-)" || string_temp.ToLowerInvariant() == "false" || string_temp.ToLowerInvariant() == "no") { this.value = false; } else if (string_temp == "(.)") { this.value = null; } break; case "<Decimal_Number>": case "<Number>": case "<Real_Number>": case "<Hex_Number>": case "DecLiteral": case "RealLiteral": case "HexLiteral": double Decimal_temp; if (double.TryParse(TT.Text, out Decimal_temp)) { this.value = Decimal_temp; } break; case "<Literal_Date>": case "Date": if (DateTime.TryParse(TT.Text, out dateTime_temp)) { DateTime dt = new DateTime(dateTime_temp.Year, dateTime_temp.Month, dateTime_temp.Day); this.value = dt; } else { this.value = null; } break; case "<Literal_Time>": case "<Literal_Date_Time>": case "Time": case "Date Time": if (DateTime.TryParse(TT.Text, out dateTime_temp)) { this.value = dateTime_temp; } break; default: this.value = TT.Text.Trim('"');; break; } } if (this.Id == null && this.value == null) { } }
private Object CreateObjectFromTerminal(TerminalToken token) { switch (token.Symbol.Id) { case (int)SymbolConstants.SYMBOL_EOF: //(EOF) return(null); case (int)SymbolConstants.SYMBOL_ERROR: //(Error) return(null); case (int)SymbolConstants.SYMBOL_COMMENT: //Comment return(null); case (int)SymbolConstants.SYMBOL_NEWLINE: //NewLine return(null); case (int)SymbolConstants.SYMBOL_WHITESPACE: //Whitespace return(null); case (int)SymbolConstants.SYMBOL_TIMESDIV: //'*/' return(null); case (int)SymbolConstants.SYMBOL_DIVTIMES: //'/*' return(null); case (int)SymbolConstants.SYMBOL_DIVDIV: //'//' return(null); case (int)SymbolConstants.SYMBOL_LPAREN: //'(' return(null); case (int)SymbolConstants.SYMBOL_RPAREN: //')' return(null); case (int)SymbolConstants.SYMBOL_COMMA: //',' return(null); case (int)SymbolConstants.SYMBOL_COLON: //':' return(null); case (int)SymbolConstants.SYMBOL_SEMI: //';' return(null); case (int)SymbolConstants.SYMBOL_LBRACKET: //'[' return(null); case (int)SymbolConstants.SYMBOL_RBRACKET: //']' return(null); case (int)SymbolConstants.SYMBOL_LBRACE: //'{' return(null); case (int)SymbolConstants.SYMBOL_RBRACE: //'}' return(null); case (int)SymbolConstants.SYMBOL_LT: //'<' return(null); case (int)SymbolConstants.SYMBOL_EQ: //'=' return(null); case (int)SymbolConstants.SYMBOL_GT: //'>' return(null); case (int)SymbolConstants.SYMBOL_ENUM: //enum return(null); case (int)SymbolConstants.SYMBOL_HINTNAME: //HintName return(token.Text); case (int)SymbolConstants.SYMBOL_LIST: //list return(null); case (int)SymbolConstants.SYMBOL_MAP: //map return(null); case (int)SymbolConstants.SYMBOL_NAME: //Name return(token.Text); case (int)SymbolConstants.SYMBOL_PRIMITIVE: //Primitive return(token.Text); case (int)SymbolConstants.SYMBOL_SET: //set return(null); case (int)SymbolConstants.SYMBOL_STRING: //String string text = token.Text; // Pull the quotes off text = text.Substring(1, text.Length - 2); // Unescape any escape sequences (e.g. backslash "n" for new line) text = Regex.Unescape(text); return(text); case (int)SymbolConstants.SYMBOL_TYPE: //type return(null); case (int)SymbolConstants.SYMBOL_TYPEID: //TypeId int newTypeId; if (token.Text == null) { newTypeId = 0; } else if (token.Text.Equals("#")) { newTypeId = -1; } else { newTypeId = int.Parse(token.Text); } return(newTypeId); case (int)SymbolConstants.SYMBOL_AGGREGATEARG: //<AggregateArg> return(token.Text); case (int)SymbolConstants.SYMBOL_BASETYPE: //<BaseType> return(token.Text); case (int)SymbolConstants.SYMBOL_BASETYPENAME: //<BaseTypeName> return(token.Text); case (int)SymbolConstants.SYMBOL_ENUM2: //<Enum> return(null); case (int)SymbolConstants.SYMBOL_ENUMNAME: //<EnumName> return(token.Text); case (int)SymbolConstants.SYMBOL_ENUMVALUE: //<EnumValue> return(token.Text); case (int)SymbolConstants.SYMBOL_FIELDNAME: //<FieldName> return(token.Text); case (int)SymbolConstants.SYMBOL_HINT: //<Hint> return(null); case (int)SymbolConstants.SYMBOL_HINTNAME2: //<HintName> return(token.Text); case (int)SymbolConstants.SYMBOL_HINTVALUE: //<HintValue> return(token.Text); case (int)SymbolConstants.SYMBOL_LISTFIELD: //<ListField> return(null); case (int)SymbolConstants.SYMBOL_MAPFIELD: //<MapField> return(null); case (int)SymbolConstants.SYMBOL_PRIMITIVEFIELD: //<PrimitiveField> return(null); case (int)SymbolConstants.SYMBOL_PRIMITIVEFIELDTYPE: //<PrimitiveFieldType> return(token.Text); case (int)SymbolConstants.SYMBOL_REFERENCEFIELD: //<ReferenceField> return(null); case (int)SymbolConstants.SYMBOL_REFERENCEFIELDTYPE: //<ReferenceFieldType> return(token.Text); case (int)SymbolConstants.SYMBOL_SCHEMA: //<Schema> return(null); case (int)SymbolConstants.SYMBOL_SCHEMAELEMENT: //<SchemaElement> return(null); case (int)SymbolConstants.SYMBOL_SCHEMANAME: //<SchemaName> return(token.Text); case (int)SymbolConstants.SYMBOL_SCHEMANAMEELEMENT: //<SchemaNameElement> return(null); case (int)SymbolConstants.SYMBOL_SETFIELD: //<SetField> return(null); case (int)SymbolConstants.SYMBOL_TYPE2: //<Type> return(null); case (int)SymbolConstants.SYMBOL_TYPEFIELD: //<TypeField> return(null); case (int)SymbolConstants.SYMBOL_TYPEID2: //<TypeId> return(token.Text); case (int)SymbolConstants.SYMBOL_TYPENAME: //<TypeName> return(token.Text); } throw new SymbolException("Unknown symbol"); }