public static PropExpression Parse(string source)
        {
            var lexer = new PropLogicLexer(source);

            lexer.NextToken();
            PropExpression result = MatchExpression(lexer);

            ExpectToken(lexer, LexerTokenType.End);
            return(result);
        }
 private static PropExpression MatchUnary(PropLogicLexer lexer)
 {
     if (lexer.CurrentTokenType == LexerTokenType.Not)
     {
         lexer.NextToken();
         PropExpression result = MatchAtom(lexer);
         return(new PropNegation(result));
     }
     return(MatchAtom(lexer));
 }
        private static PropExpression MatchAtom(PropLogicLexer lexer)
        {
            ExpectToken(lexer, LexerTokenType.Identifier, LexerTokenType.OpenParen);

            PropExpression result;

            if (lexer.CurrentTokenType == LexerTokenType.Identifier)
            {
                result = new PropIdentifier(lexer.CurrentTokenValue);
                lexer.NextToken();
            }
            else
            {
                lexer.NextToken();
                result = MatchExpression(lexer);
                ExpectToken(lexer, LexerTokenType.CloseParen);
                lexer.NextToken();
            }
            return(result);
        }
        private static PropExpression MatchAndTerm(PropLogicLexer lexer)
        {
            PropExpression result = MatchUnary(lexer);

            while (lexer.CurrentTokenType == LexerTokenType.And)
            {
                lexer.NextToken();
                PropExpression right = MatchUnary(lexer);
                result = new PropConjunction(result, right);
            }
            return(result);
        }