build: Add lexer/parser.cs files to src ctrl
Move all lexer/parser files into a single dir, DataStreamGrammar, for organizational purposes and to avoid dependency conflicts when generating code. Note that we'll only need to regen cs if we modify the parser/lexer files, which seems unlikely.
This commit is contained in:
1 parent
86a1695286
commit
cc2959249e
18 files changed
+13590
-56
No files matched your search
@@ -0,0 +1,229 @@
|
||||
%parser BooleanExpressionTokens.lexer
|
||||
%namespace BCG.Evaluator.BooleanExpression
|
||||
|
||||
%left OrOp AndOp XorOp
|
||||
%right NotOp
|
||||
|
||||
%symbol BooleanProgram {
|
||||
public Definitions definitions;
|
||||
public BooleanExpressionEvaluator eval;
|
||||
|
||||
public BooleanProgram(BooleanExpression expressions) =>
|
||||
eval = expressions.eval;
|
||||
|
||||
public BooleanProgram(Definitions definitions, BooleanExpression expressions) {
|
||||
this.eval = expressions.eval;
|
||||
this.definitions = definitions;
|
||||
}
|
||||
}
|
||||
|
||||
%symbol BooleanExpression {
|
||||
public BooleanExpressionEvaluator eval;
|
||||
}
|
||||
|
||||
%symbol SingleDef {
|
||||
public string id;
|
||||
public DefArgList args;
|
||||
public BooleanExpressionEvaluator eval;
|
||||
|
||||
public SingleDef(string id, DefArgList args, BooleanExpression exp) {
|
||||
this.id = id;
|
||||
this.args = args;
|
||||
this.eval = exp.eval;
|
||||
}
|
||||
}
|
||||
|
||||
%symbol Definitions {
|
||||
public SingleDef def;
|
||||
public Definitions next;
|
||||
|
||||
public Definitions(SingleDef def) =>
|
||||
this.def = def;
|
||||
|
||||
public Definitions(SingleDef def, Definitions next) {
|
||||
this.def = def;
|
||||
this.next = next;
|
||||
}
|
||||
}
|
||||
|
||||
%symbol DefArgList {
|
||||
public string arg;
|
||||
public DefArgList rest;
|
||||
|
||||
public DefArgList(string arg) =>
|
||||
this.arg = arg;
|
||||
|
||||
public DefArgList(string arg, DefArgList rest) {
|
||||
this.arg = arg;
|
||||
this.rest = rest;
|
||||
}
|
||||
}
|
||||
|
||||
%node SubExpression : BooleanExpression {
|
||||
public SubExpression (BooleanExpression e) =>
|
||||
eval = e.eval;
|
||||
}
|
||||
|
||||
%node AndNode : BooleanExpression {
|
||||
public AndNode (BooleanExpression left, BooleanExpression right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.and));
|
||||
}
|
||||
|
||||
%node OrNode : BooleanExpression {
|
||||
public OrNode (BooleanExpression left, BooleanExpression right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.or));
|
||||
}
|
||||
|
||||
%node XorNode : BooleanExpression {
|
||||
public XorNode (BooleanExpression left, BooleanExpression right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.xor));
|
||||
}
|
||||
|
||||
%node NotNode : BooleanExpression {
|
||||
public NotNode (BooleanExpression toperand) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
toperand.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.not));
|
||||
}
|
||||
|
||||
%node EqualPredicate : BooleanExpression {
|
||||
public EqualPredicate(Value left, Value right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.equal));
|
||||
}
|
||||
|
||||
%node SmallerEqualPredicate : BooleanExpression {
|
||||
public SmallerEqualPredicate(Value left, Value right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.smallerEqual));
|
||||
}
|
||||
|
||||
%node GreaterEqualPredicate : BooleanExpression {
|
||||
public GreaterEqualPredicate (Value left, Value right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.greaterEqual));
|
||||
}
|
||||
|
||||
%node SmallerPredicate : BooleanExpression {
|
||||
public SmallerPredicate (Value left, Value right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.smaller));
|
||||
}
|
||||
|
||||
%node GreaterPredicate : BooleanExpression {
|
||||
public GreaterPredicate (Value left, Value right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.greater));
|
||||
}
|
||||
|
||||
%node DifferentPredicate : BooleanExpression {
|
||||
public DifferentPredicate (Value left, Value right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.different));
|
||||
}
|
||||
|
||||
%node MatchesPredicate : BooleanExpression {
|
||||
public MatchesPredicate (Value left, Value right) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
left.eval, right.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.matches));
|
||||
|
||||
}
|
||||
|
||||
%node ValuePredicate : BooleanExpression {
|
||||
public ValuePredicate(Value v) =>
|
||||
eval = new BooleanExpressionEvaluator(
|
||||
v.eval, new BCG.BooleanEval(BooleanExpressionEvaluator.booleanValue));
|
||||
}
|
||||
|
||||
|
||||
%symbol Value {
|
||||
public BooleanExpressionValue eval;
|
||||
}
|
||||
|
||||
%node ConstantValue : Value {
|
||||
public ConstantValue (object tvalue) =>
|
||||
eval = new BooleanExpressionConstant(tvalue);
|
||||
}
|
||||
|
||||
%node IdentifierValue : Value {
|
||||
public IdentifierValue (string tidentifier) =>
|
||||
eval = new BooleanExpressionVariable(tidentifier);
|
||||
}
|
||||
|
||||
%node FunctionValue: Value {
|
||||
public FunctionValue (string tidentifier, ArgumentList args) =>
|
||||
eval = new BooleanExpressionFunction(tidentifier,args == null ? null : args.args);
|
||||
}
|
||||
|
||||
%symbol ArgumentList {
|
||||
public System.Collections.ArrayList args = new System.Collections.ArrayList();
|
||||
|
||||
public ArgumentList(SingleArgument s) =>
|
||||
args.Add(((Value) s.kids[0]).eval);
|
||||
|
||||
public ArgumentList(ArgumentList a1,SingleArgument s) {
|
||||
if (a1 != null) {
|
||||
args.AddRange(a1.args);
|
||||
}
|
||||
args.AddRange(new ArgumentList(s).args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BooleanProgram : Definitions BooleanExpression %BooleanProgram($1,$2)
|
||||
| BooleanExpression %BooleanProgram($1) ;
|
||||
|
||||
Definitions : SingleDef %Definitions($1)
|
||||
| SingleDef Definitions %Definitions($1,$2) ;
|
||||
|
||||
SingleDef : Define Identifier OpenParenthesis DefArgList CloseParenthesis BeginDef BooleanExpression EndDef %SingleDef($2.yytext,$4,$7);
|
||||
|
||||
DefArgList: %DefArgList(null)
|
||||
| Identifier %DefArgList($1.yytext)
|
||||
| Identifier Comma DefArgList %DefArgList($1.yytext, $3 )
|
||||
;
|
||||
|
||||
|
||||
BooleanExpression : BooleanExpression OrOp BooleanExpression %OrNode($1,$3)
|
||||
| BooleanExpression AndOp BooleanExpression %AndNode($1,$3)
|
||||
| BooleanExpression XorOp BooleanExpression %XorNode($1,$3)
|
||||
| NotOp BooleanExpression %NotNode($2)
|
||||
| OpenParenthesis BooleanExpression CloseParenthesis %SubExpression ($2)
|
||||
| Predicate
|
||||
;
|
||||
|
||||
|
||||
Predicate : Value EqualsOp Value %EqualPredicate ($1,$3)
|
||||
| Value SmallerEqualOp Value %SmallerEqualPredicate ($1,$3)
|
||||
| Value GreaterEqualOp Value %GreaterEqualPredicate ($1,$3)
|
||||
| Value SmallerOp Value %SmallerPredicate ($1,$3)
|
||||
| Value GreaterOp Value %GreaterPredicate ($1,$3)
|
||||
| Value DifferentOp Value %DifferentPredicate ($1,$3)
|
||||
| Value DifferentOp2 Value %DifferentPredicate ($1,$3)
|
||||
| Value MatchesOp Value %MatchesPredicate ($1,$3)
|
||||
| Value %ValuePredicate($1)
|
||||
;
|
||||
|
||||
Value : Identifier %IdentifierValue($1.yytext)
|
||||
| BooleanConstant %ConstantValue($1.value)
|
||||
| NullConstant %ConstantValue($1.value)
|
||||
| RealConstant %ConstantValue($1.value)
|
||||
| StringConstant %ConstantValue($1.value)
|
||||
| IntegerConstant %ConstantValue($1.value)
|
||||
| DateTimeConstant %ConstantValue($1.value)
|
||||
| FunctionCall
|
||||
;
|
||||
|
||||
FunctionCall: Identifier:n OpenParenthesis ArgumentList:al CloseParenthesis %FunctionValue(n.yytext,al) ;
|
||||
|
||||
ArgumentList: %null
|
||||
| SingleArgument %ArgumentList($1)
|
||||
| ArgumentList Comma SingleArgument %ArgumentList($1,$3)
|
||||
;
|
||||
|
||||
SingleArgument: Value
|
||||
;
|
||||
|
||||
|
||||
Reference in new issue
Block a user