private void AssertProgram(ProgramNode program) { if (program.Expressions.Count == 0) { // no free-floating expressions, so we need to make sure there is at least one group with an expression var hasExpressions = false; foreach (var group in program.Groups) { if (group.Expressions.Count > 0) { hasExpressions = true; break; } } if (!hasExpressions) { throw new InvalidScheduleException("Schedule must contain at least one expression.", Input); } } foreach (var group in program.Groups) { Group(group); } ExpressionList(program.Expressions); }
/// <summary> /// This method assumes the AST is valid and makes absolutely no attempt to further validate any node. /// </summary> /// <param name="program"></param> /// <returns></returns> public static IrProgram CompileAst(ProgramNode program) { var ir = new IrProgram(); // free-floating expressions are placed in an implicit group var irGroup = CompileGroup(program.Expressions); if (irGroup != null) ir.Groups.Add(irGroup); // compile all groups foreach (var groupNode in program.Groups) { irGroup = CompileGroup(groupNode.Expressions); if (irGroup != null) ir.Groups.Add(irGroup); } return ir; }
/// <summary> /// This method assumes the AST is valid and makes absolutely no attempt to further validate any node. /// </summary> /// <param name="program"></param> /// <returns></returns> public static IrProgram CompileAst(ProgramNode program) { var ir = new IrProgram(); // free-floating expressions are placed in an implicit group var irGroup = CompileGroup(program.Expressions); if (irGroup != null) { ir.Groups.Add(irGroup); } // compile all groups foreach (var groupNode in program.Groups) { irGroup = CompileGroup(groupNode.Expressions); if (irGroup != null) { ir.Groups.Add(irGroup); } } return(ir); }
public Validator(string input, ProgramNode program) { Input = input; Program = program; }
private ProgramNode ParseProgram() { var program = new ProgramNode(); while (!IsNext(TokenType.EndOfInput)) { if (IsNext(TokenType.OpenCurly)) { program.AddGroup(ParseGroup()); } else if (IsNext(TokenType.ExpressionName)) { program.AddExpression(ParseExpression()); } else { throw WrongTokenException(TokenType.OpenCurly, TokenType.ExpressionName, TokenType.Comma); } if (IsNext(TokenType.Comma)) // optional comma { program.AddToken(Advance()); } } program.AddToken(Expect(TokenType.EndOfInput)); return program; }