本文整理汇总了C#中IdentifierTerminal.AddKeywords方法的典型用法代码示例。如果您正苦于以下问题:C# IdentifierTerminal.AddKeywords方法的具体用法?C# IdentifierTerminal.AddKeywords怎么用?C# IdentifierTerminal.AddKeywords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IdentifierTerminal
的用法示例。
在下文中一共展示了IdentifierTerminal.AddKeywords方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RubyGrammar
public RubyGrammar()
{
#region Terminals
//String Literals with single and double-quote start/end symbols
StringLiteral STRING = new StringLiteral("STRING", TermOptions.SpecialIgnoreCase);
STRING.AddStartEnd("\"", ScanFlags.None);
STRING.AddStartEnd("'", ScanFlags.None);
Terminal HereDoc = new Terminal("HereDoc"); //-- implement me!
Terminal RegExLiteral = new Terminal("RegExLiteral"); //-- implement me!
IdentifierTerminal IDENTIFIER = new IdentifierTerminal("identifier", "_!?", "[email protected]");
// name extraChars extraFirstChars
IDENTIFIER.DisplayName = "variable";
//we need to isolate reserved words to avoid ambiguities in grammar
IDENTIFIER.AddKeywords("do", "end", "def", "class",
"if", "case", "return", "yield", "while", "until"); //and some others...
Terminal Number = new NumberLiteral("Number");
Terminal Comment = new CommentTerminal("Comment", "#", "\n");
NonGrammarTerminals.Add(Comment); //add comment explicitly to this list as it is not reachable from Root
//some conveniency variables
Terminal Pipe = Symbol("|");
Terminal dot = Symbol(".");
Terminal comma = Symbol(",");
#endregion
#region NonTerminals
//NT variables names match element names in original grammar
NonTerminal PROGRAM = new NonTerminal("PROGRAM");
NonTerminal COMPSTMT = new NonTerminal("COMPSTMT");
NonTerminal STMT = new NonTerminal("STMT");
NonTerminal BLOCK = new NonTerminal("BLOCK");
NonTerminal EXPR = new NonTerminal("EXPR");
//NonTerminal CALL = new NonTerminal("CALL");
NonTerminal COMMAND = new NonTerminal("COMMAND");
NonTerminal FUNCTION = new NonTerminal("FUNCTION");
NonTerminal ARG = EXPR;// new NonTerminal("ARG");
NonTerminal PRIMARY = new NonTerminal("PRIMARY", "operand");
NonTerminal WHEN_ARGS = new NonTerminal("WHEN_ARGS");
NonTerminal THEN = new NonTerminal("THEN");
NonTerminal BLOCK_BEGIN = new NonTerminal("BLOCK_BEGIN");
NonTerminal BLOCK_END = new NonTerminal("BLOCK_END");
NonTerminal BLOCK_VAR = new NonTerminal("BLOCK_VAR");
// NonTerminal MLHS_ITEM = new NonTerminal("MLHS_ITEM");
NonTerminal LHS = new NonTerminal("LHS");
NonTerminal MRHS = new NonTerminal("MRHS");
// NonTerminal MLHS = MRHS; // new NonTerminal("MLHS");
NonTerminal CALL_ARGS = new NonTerminal("CALL_ARGS");
NonTerminal CALL_ARGS_P = new NonTerminal("CALL_ARGS_P");
NonTerminal AMP_ARG = new NonTerminal("AMP_ARG");
NonTerminal STAR_ARG = new NonTerminal("STAR_ARG");
NonTerminal ARGS = new NonTerminal("ARGS");
NonTerminal ARGDECL = new NonTerminal("ARGDECL");
NonTerminal ARGLIST = new NonTerminal("ARGLIST");
// NonTerminal SINGLETON = new NonTerminal("SINGLETON");
NonTerminal ASSOCS = new NonTerminal("ASSOCS");
NonTerminal ASSOC = new NonTerminal("ASSOC");
// NonTerminal VARIABLE = new NonTerminal("VARIABLE"); --merged into IDENTIFIER
NonTerminal LITERAL = new NonTerminal("LITERAL", "value");
NonTerminal TERM = new NonTerminal("TERM");
NonTerminal DO = new NonTerminal("DO");
// NonTerminal VARNAME = new NonTerminal("VARNAME"); // note 1
NonTerminal GLOBAL = new NonTerminal("GLOBAL");
NonTerminal RETURN_STMT = new NonTerminal("RETURN_STMT");
NonTerminal YIELD_STMT = new NonTerminal("YIELD_STMT");
NonTerminal DEFINEDQ_STMT = new NonTerminal("DEFINEDQ_STMT");
NonTerminal FUNCTION_STMT = new NonTerminal("FUNCTION_STMT");
NonTerminal IF_STMT = new NonTerminal("IF_STMT");
NonTerminal UNLESS_STMT = new NonTerminal("UNLESS_STMT");
NonTerminal WHILE_STMT = new NonTerminal("WHILE_STMT");
NonTerminal UNTIL_STMT = new NonTerminal("UNTIL_STMT");
NonTerminal CASE_STMT = new NonTerminal("CASE_STMT");
NonTerminal FOR_STMT = new NonTerminal("FOR_STMT");
NonTerminal BLOCK_STMT = new NonTerminal("BLOCK_STMT");
NonTerminal CLASS_DEF = new NonTerminal("CLASS_DEF");
NonTerminal BASE_REF = new NonTerminal("BASE_REF");
NonTerminal MODULE = new NonTerminal("MODULE_STMT");
NonTerminal DEFFUNC_STMT = new NonTerminal("DEFFUNC_STMT");
NonTerminal DEFSING_STMT = new NonTerminal("DEFSING_STMT");
NonTerminal SINGLETON = new NonTerminal("SINGLETON");
NonTerminal END = new NonTerminal("end");
NonTerminal SYMBOL = new NonTerminal("SYMBOL");
//Not in original grammar
NonTerminal FNAME = new NonTerminal("FNAME");
BLOCK_BEGIN.Rule = Symbol("do") | "{";
BLOCK_END.Rule = Symbol("end") | "}";
NonTerminal OPERATION = new NonTerminal("OPERATION");
// Terminal VARNAME = IDENTIFIER;
NonTerminal AUG_ASGN = new NonTerminal("AUG_ASGN");
NonTerminal BINOP = new NonTerminal("BINOP", "operator");
NonTerminal UNOP = new NonTerminal("UNOP");
NonTerminal DELIM = new NonTerminal("DELIM");
#endregion
#region Rules
//Set grammar root
this.Root = PROGRAM;
//PROGRAM : COMPSTMT
//.........这里部分代码省略.........
示例2: CreatePythonIdentifier
public static IdentifierTerminal CreatePythonIdentifier(string name)
{
IdentifierTerminal id = new IdentifierTerminal("Identifier"); //defaults are OK
id.AddKeywords("and", "del", "from", "not", "while", "as", "elif", "global", "or", "with",
"assert", "else", "if", "pass", "yield", "break", "except", "import", "print",
"class", "exec", "in", "raise", "continue", "finally", "is", "return",
"def", "for", "lambda", "try");
return id;
}
示例3: CreateScriptNetIdentifier
/// <summary>
/// Creates identifier terminal for script grammar
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private static IdentifierTerminal CreateScriptNetIdentifier(string name)
{
IdentifierTerminal id = new IdentifierTerminal(name);
id.SetOption(TermOptions.CanStartWithEscape);
id.AddKeywords("true", "false", "null", "if", "else",
"while", "for", "foreach", "in",
"switch", "case", "default", "break",
"continue", "return", "function", "is",
"pre", "post", "invariant", "new", "using",
"global");
id.AddPrefixFlag("@", ScanFlags.IsNotKeyword | ScanFlags.DisableEscapes);
//From spec:
//Start char is "_" or letter-character, which is a Unicode character of classes Lu, Ll, Lt, Lm, Lo, or Nl
id.StartCharCategories.AddRange(new UnicodeCategory[] {
UnicodeCategory.UppercaseLetter, //Ul
UnicodeCategory.LowercaseLetter, //Ll
UnicodeCategory.TitlecaseLetter, //Lt
UnicodeCategory.ModifierLetter, //Lm
UnicodeCategory.OtherLetter, //Lo
UnicodeCategory.LetterNumber //Nl
});
//Internal chars
/* From spec:
identifier-part-character: letter-character | decimal-digit-character | connecting-character | combining-character |
formatting-character
*/
id.CharCategories.AddRange(id.StartCharCategories); //letter-character categories
id.CharCategories.AddRange(new UnicodeCategory[] {
UnicodeCategory.DecimalDigitNumber, //Nd
UnicodeCategory.ConnectorPunctuation, //Pc
UnicodeCategory.SpacingCombiningMark, //Mc
UnicodeCategory.NonSpacingMark, //Mn
UnicodeCategory.Format //Cf
});
//Chars to remove from final identifier
id.CharsToRemoveCategories.Add(UnicodeCategory.Format);
return id;
}
示例4: FlGrammar
public FlGrammar()
{
// turn off case sensitivity
CaseSensitive = false;
// define all the non-terminals
var program = new NonTerminal("program", typeof(ProgramNode));
var statementList = new NonTerminal("statementList", typeof(StatementNode));
var statement = new NonTerminal("statement", typeof(SkipNode));
var expression = new NonTerminal("expression", typeof(ExpressionNode));
var binaryOperator = new NonTerminal("binaryOperator", typeof(SkipNode));
var variableDeclaration = new NonTerminal("variableDeclaration", typeof(VariableDeclarationNode));
var variableAssignment = new NonTerminal("variableAssignment", typeof(VariableAssignmentNode));
var ifStatement = new NonTerminal("ifStatement", typeof(IfStatementNode));
var elseStatement = new NonTerminal("elseStatement", typeof(ElseStatementNode));
// define all the terminals
var variable = new IdentifierTerminal("variable");
variable.AddKeywords("set", "var" , "to", "if", "freight", "cost", "is", "loop", "through", "order");
var number = new NumberLiteral("number");
var stringLiteral = new StringLiteral("string", "\"", ScanFlags.None);
RegisterPunctuation(";", "[", "]", "(", ")");
//var lpar = new Terminal("(");
//var rpar = new Terminal(")");
//var lbr = new Terminal("{");
//var rbr = new Terminal("}");
// specify the non-terminal which is the root of the AST
//Root = program;
//binaryOperator.Rule = Symbol("+") | "-" | "*" | "/" | "<" | "==" | "!=" | ">" | "<=" | ">=" | "is";
//program.Rule = statementList;
//statementList.Rule = MakeStarRule(statementList, null, statement);
//statement.Rule = variableDeclaration + ";" | variableAssignment + ";" | expression + ";" | ifStatement;
//variableAssignment.Rule = variable + "=" + expression;
//variableDeclaration.Rule = Symbol("var") + variable;
//ifStatement.Rule = Symbol("if") + "(" + expression + ")"
// + "{" + expression + "}"
// + elseStatement;
//elseStatement.Rule = Empty | "else" + "{" + expression + "}";
//expression.Rule = number | variable | stringLiteral
// | expression + binaryOperator + expression
// | "(" + expression + ")";
Root = program;
binaryOperator.Rule = Symbol("+") | "-" | "*" | "/" | "<" | "==" | "!=" | ">" | "<=" | ">=" | "is";
program.Rule = statementList;
statementList.Rule = MakeStarRule(statementList, null, statement);
statement.Rule = variableDeclaration + ";" | variableAssignment + ";" | expression + ";" | ifStatement;
variableAssignment.Rule = variable + "=" + expression;
variableDeclaration.Rule = Symbol("var") + variable;
ifStatement.Rule = "if" + Symbol("(") + expression + Symbol(")")
+ Symbol("{") + statementList + Symbol("}")
+ elseStatement;
elseStatement.Rule = Empty | "else" + Symbol("{") + statementList + Symbol("}");
expression.Rule = number | variable | stringLiteral
| expression + binaryOperator + expression
| "(" + expression + ")";
}