本文整理汇总了C#中Irony.Parsing.NonTerminal类的典型用法代码示例。如果您正苦于以下问题:C# NonTerminal类的具体用法?C# NonTerminal怎么用?C# NonTerminal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NonTerminal类属于Irony.Parsing命名空间,在下文中一共展示了NonTerminal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: E2Grammar
public E2Grammar()
{
LineTerminators = "\r\n";
var program = new NonTerminal("Program");
var directiveList = new NonTerminal("DirectiveList");
var directive = new NonTerminal("Directive");
var directiveName = new IdentifierTerminal("DirectiveName");
var directiveBody = new NonTerminal("DirectiveBody");
var statementList = new NonTerminal("StatementList");
var statement = new NonTerminal("Statement");
var assignment = new NonTerminal("Assignment");
var expression = new NonTerminal("Expression");
var parenExpression = new NonTerminal("ParenExpression");
var methodCall = new NonTerminal("MethodCall");
var argumentList = new NonTerminal("ArgumentList");
var argumentTail = new NonTerminal("ArgumentTail");
var @operator = new NonTerminal("Operator");
var operation = new NonTerminal("Operation");
var identifier = new IdentifierTerminal("Identifier");
var @string = new StringLiteral("String", "\"");
var number = new NumberLiteral("Number");
var ifStatement = new NonTerminal("IfStatement");
var whileStatement = new NonTerminal("WhileStatement");
var comment = new CommentTerminal("comment", "#", new[] {"\n"});
var dcom = new CommentTerminal("commentCheat", "@", new[] {"\n"});
Root = program;
NonGrammarTerminals.Add(comment);
NonGrammarTerminals.Add(dcom);
RegisterBracePair("{", "}");
program.Rule = /* directiveList + */statementList;
//directiveList.Rule = MakePlusRule(directiveList, null, directive);
//directiveBody.Rule = new CommentTerminal()
//directive.Rule = ToTerm("@") + directiveName + directiveBody;
statementList.Rule = MakePlusRule(statementList, null, statement);
statement.Rule = methodCall | assignment;
expression.Rule = operation | @string | number | methodCall | identifier;
parenExpression.Rule = ToTerm("(") + expression + ")";
methodCall.Rule = expression + ":" + identifier + "(" + argumentList + ")";
argumentList.Rule = MakeStarRule(argumentList, ToTerm(","), expression);
operation.Rule = expression + @operator + expression;
@operator.Rule = ToTerm("+") | "-" | "*" | "/" | "&" | "|";
assignment.Rule = identifier + "=" + expression;
ifStatement.Rule = ToTerm("if") + parenExpression + "{" + statementList + "}";
whileStatement.Rule = ToTerm("while") + parenExpression + "{" + statementList + "}";
}
示例2: ListRules
public ListRules(PieGrammar grammar)
{
this.grammar = grammar;
StarIdentifierList = new NonTerminal("star_identifer_list");
PlusIdentifierList = new NonTerminal("plus_identfier_list");
}
示例3: ProjectsGrammar
public ProjectsGrammar()
{
// Todo
// Fix Note to work actually right, just take the rest of the text
// Define Terminals
var taskName = new TaskTerminal("TaskName");
var projectName = new ProjectTerminal("ProjectName");
var noteText = new NoteTerminal("NoteText");
// Define Non-Terminals
var notes = new NonTerminal("Notes", typeof(StatementListNode));
var project = new NonTerminal("Project", typeof (StatementListNode));
var task = new NonTerminal("Task", typeof (StatementListNode));
var tasks = new NonTerminal("Tasks", typeof (StatementListNode));
var program = new NonTerminal("ProgramLine", typeof(StatementListNode));
// Define Rules
notes.Rule = MakeStarRule(notes, noteText);
task.Rule = taskName + notes;
tasks.Rule = MakeStarRule(tasks, task);
project.Rule = projectName +notes + tasks;
program.Rule = MakeStarRule(program, project);
Root = program;
LanguageFlags = LanguageFlags.CreateAst
| LanguageFlags.CanRunSample;
}
示例4: SpeechExpression
public SpeechExpression()
{
FreeTextLiteral text = new FreeTextLiteral(TextLiteralName, FreeTextOptions.AllowEof, AliasSymbol, VarSymbol, OpenBracketSymbol, ArgSeparatorSymbol, CloseBracketSymbol);
IdentifierTerminal name = TerminalFactory.CreateCSharpIdentifier(NameLiteralName);
NonTerminal root = new NonTerminal(RootExpressionName);
NonTerminal expression = new NonTerminal(ExpressionLiteralName);
NonTerminal argumentList = new NonTerminal(ArgumentListLiteralName);
NonTerminal alias = new NonTerminal(AliasLiteralName);
NonTerminal variable = new NonTerminal(VariableLiteralName);
argumentList.Rule = MakePlusRule(argumentList, ToTerm(ArgSeparatorSymbol), root);
alias.Rule = AliasSymbol + name + OpenBracketSymbol + argumentList + CloseBracketSymbol | AliasSymbol + name;
variable.Rule = VarSymbol + name;
expression.Rule = text | variable | alias;
root.Rule = MakeStarRule(root, expression);
Root = root;
text.Escapes.Add("\\" + AliasSymbol, AliasSymbol);
text.Escapes.Add("\\" + VarSymbol, VarSymbol);
text.Escapes.Add("\\" + OpenBracketSymbol, OpenBracketSymbol);
text.Escapes.Add("\\" + CloseBracketSymbol, CloseBracketSymbol);
text.Escapes.Add("\\" + ArgSeparatorSymbol, ArgSeparatorSymbol);
MarkTransient(root, expression);
RegisterBracePair(OpenBracketSymbol, CloseBracketSymbol);
}
示例5: FabricGrammar
public FabricGrammar(): base(false) // case non-sensitive
{
// Terminal Definitions
RegexBasedTerminal number = new RegexBasedTerminal("number", "[0-9]+");
// Non-Terminal Definitions
NonTerminal program = new NonTerminal("program"),
createStatement = new NonTerminal("createStatement"),
startStatement = new NonTerminal("startStatement"),
moveStatements = new NonTerminal("moveStatements"),
moveStatement = new NonTerminal("moveStatement"),
direction = new NonTerminal("direction");
// Relation Definitions
program.Rule = createStatement + startStatement + moveStatements;
createStatement.Rule = ToTerm("Create") + "a" + number + "by" + number + "grid";
startStatement.Rule = ToTerm("Start") + "at" + "location" + number + "," + number;
moveStatements.Rule = MakePlusRule(moveStatements, moveStatement);
moveStatement.Rule = ToTerm("Move") + direction + number;
direction.Rule = ToTerm("up") | "down" | "right" | "left";
// Set the Root
this.Root = program;
// Set the Markup Register
MarkPunctuation("Create", "a", "grid", "by", "Start", "at", "location", ",", "Move");
}
示例6: ExceptionRules
public ExceptionRules(PieGrammar grammar)
{
this.grammar = grammar;
ExceptionHandlingBlock = new NonTerminal("exception_handling_block");
ThrowStatement = new NonTerminal("throw_statement");
}
示例7: ForCircleDefinition
public override void ForCircleDefinition(NonTerminal circleDef, NonTerminal coordSet)
{
AstBuilder(circleDef, (context, node) =>
{
throw new InvalidOperationException("SqlGeometryParser cannot handle circle-like structures if the output style is set to GeometryCollection");
});
}
示例8: ForLoopRules
public ForLoopRules(PieGrammar grammar)
{
this.grammar = grammar;
SimpleForLoop = new NonTerminal("simple_for_loop");
BodiedForLoop = new NonTerminal("bodied_for_loop");
}
示例9: GrammarExL514
public GrammarExL514() {
NonTerminal A = new NonTerminal("A");
Terminal a = new Terminal("a");
A.Rule = "(" + A + ")" | a;
this.Root = A;
}//method
示例10: JsonGrammar
public JsonGrammar() {
//Terminals
var jstring = new StringLiteral("string", "\"");
var jnumber = new NumberLiteral("number");
var comma = ToTerm(",");
//Nonterminals
var jobject = new NonTerminal("Object");
var jobjectBr = new NonTerminal("ObjectBr");
var jarray = new NonTerminal("Array");
var jarrayBr = new NonTerminal("ArrayBr");
var jvalue = new NonTerminal("Value");
var jprop = new NonTerminal("Property");
//Rules
jvalue.Rule = jstring | jnumber | jobjectBr | jarrayBr | "true" | "false" | "null";
jobjectBr.Rule = "{" + jobject + "}";
jobject.Rule = MakeStarRule(jobject, comma, jprop);
jprop.Rule = jstring + ":" + jvalue;
jarrayBr.Rule = "[" + jarray + "]";
jarray.Rule = MakeStarRule(jarray, comma, jvalue);
//Set grammar root
this.Root = jvalue;
MarkPunctuation("{", "}", "[", "]", ":", ",");
this.MarkTransient(jvalue, jarrayBr, jobjectBr);
}//constructor
示例11: Define
public void Define()
{
/* case <expression>:
* <expression>
*/
var caseBlock = new NonTerminal("case_block");
caseBlock.Rule = grammar.Keywords.Case
+ grammar.expression
+ grammar.ToTerm(":")
+ grammar.Eos
+ grammar.MethodDeclarations.OptionalMethodBody;
// List of case block expressions.
var caseBlockList = new NonTerminal("case_block_list");
caseBlockList.Rule = grammar.MakeStarRule(caseBlockList, caseBlock);
// The list of case block expressions is optional.
var caseBlockListOpt = new NonTerminal("case_block_list_opt");
caseBlockListOpt.Rule = (grammar.Indent + caseBlockList +grammar.Dedent) | grammar.Empty;
/* switch <expression>:
* case <expression>:
* <expression>
*/
SwitchBlock.Rule = grammar.Keywords.Switch
+ grammar.expression
+ grammar.ToTerm(":")
+ grammar.Eos
+ caseBlockListOpt;
}
示例12: Parser
/// <summary>
/// Initializes a new instance of the <see cref="Parser"/> class.
/// </summary>
/// <param name="language">The language.</param>
/// <param name="scanner">The scanner.</param>
/// <param name="root">The root.</param>
/// <exception cref="Exception">
/// </exception>
public Parser(LanguageData language, Scanner scanner, NonTerminal root)
{
Language = language;
Context = new ParsingContext(this);
Scanner = scanner ?? language.CreateScanner();
if (Scanner != null)
{
Scanner.Initialize(this);
}
else
{
Language.Errors.Add(GrammarErrorLevel.Error, null, "Scanner is not initialized for this grammar");
}
CoreParser = new CoreParser(this);
Root = root;
if (Root == null)
{
Root = Language.Grammar.Root;
InitialState = Language.ParserData.InitialState;
}
else
{
if (Root != Language.Grammar.Root && !Language.Grammar.SnippetRoots.Contains(Root))
{
throw new Exception(string.Format(Resources.ErrRootNotRegistered, root.Name));
}
InitialState = Language.ParserData.InitialStates[Root];
}
}
示例13: GridWorldGrammar
public GridWorldGrammar()
{
this.GrammarComments = "A grammar for GridWorld";
//Terminals
RegexBasedTerminal number = new RegexBasedTerminal("number", "[0-9]+");
//Non terminals
NonTerminal program = new NonTerminal("program");
NonTerminal createStatement = new NonTerminal("createStatement", typeof(StartNode));
NonTerminal startStatement = new NonTerminal("startStatement", typeof(StartNode));
NonTerminal moveStatements = new NonTerminal("moveStatements", typeof(MovesNode));
NonTerminal moveStatement = new NonTerminal("moveStatement", typeof(MoveNode));
NonTerminal direction = new NonTerminal("direction", typeof(DirectionNode));
//BNF rules
program.Rule = createStatement + startStatement + moveStatements;
createStatement.Rule = ToTerm("Create") + "a" + number + "by" + number + "grid" + ".";
startStatement.Rule = ToTerm("Start") + "at" + "location" + number + "," + number + ".";
moveStatements.Rule = MakePlusRule(moveStatements, moveStatement);
moveStatement.Rule = "Move" + direction + number + ".";
direction.Rule = ToTerm("up") | "down" | "right" | "left";
this.Root = program;
this.LanguageFlags = LanguageFlags.CreateAst;
MarkPunctuation("Create", "a", "grid", "by", "Start", "at","location", ",", ".", "Move");
}
示例14: WhileLoopRules
public WhileLoopRules(PieGrammar grammar)
{
this.grammar = grammar;
SimpleWhileLoop = new NonTerminal("simple_while_loop");
BodiedWhileLoop = new NonTerminal("bodied_while_loop");
}
示例15: CameraControlGrammar
//#AS:2012/12/08: grammar is case-insensitive
public CameraControlGrammar()
: base(caseSensitive: false)
{
var program = new NonTerminal("program");
var cameraSize = new NonTerminal("cameraSize");
var cameraPosition = new NonTerminal("cameraPosition");
var commandList = new NonTerminal("commandList");
var command = new NonTerminal("command");
var direction = new NonTerminal("direction");
var number = new NumberLiteral("number");
this.Root = program;
//Grammar production rules in bnf form
// <Program> ::= <CameraSize> <CameraPosition> <CommandList>
program.Rule = cameraSize + cameraPosition + commandList;
// <CameraSize> ::= "set" "camera" "size" ":" <number> "by" <number> "pixels" "."
cameraSize.Rule = ToTerm("set") + "camera" + "size" + ":" +
number + "by" + number + "pixels" + ".";
// <CameraPosition> ::= "set" "camera" "position" ":" <number> "," <number> "."
cameraPosition.Rule = ToTerm("set") + "camera" + "position" +
":" + number + "," + number + ".";
// <CommandList> ::= <Command>+
commandList.Rule = MakePlusRule(commandList, null, command);
// <Command> ::= "move" <number> "pixels" <Direction> "."
command.Rule = ToTerm("move") + number + "pixels" + direction + ".";
// <Direction> ::= "up" | "down" | "left" | "right"
direction.Rule = ToTerm("up") | "down" | "left" | "right";
//#AS:2012/12/08: these symbols are defined as puntuation, so they will not be included in the ast
this.MarkPunctuation("set", ("camera"), "size", ":", "by", "pixels", ".", "position", ",", "move");
}